@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.
Files changed (189) hide show
  1. package/dist/cjs/queries/ObservableQueryFor.js +6 -1
  2. package/dist/cjs/queries/ObservableQueryFor.js.map +1 -1
  3. package/dist/cjs/queries/QueryInstanceCache.js +6 -6
  4. package/dist/cjs/queries/QueryInstanceCache.js.map +1 -1
  5. package/dist/cjs/queries/QueryResult.js +23 -4
  6. package/dist/cjs/queries/QueryResult.js.map +1 -1
  7. package/dist/cjs/queries/QueryResultWithState.js +20 -7
  8. package/dist/cjs/queries/QueryResultWithState.js.map +1 -1
  9. package/dist/cjs/queries/ServerSentEventHubConnection.js +120 -58
  10. package/dist/cjs/queries/ServerSentEventHubConnection.js.map +1 -1
  11. package/dist/cjs/queries/WebSocketHubConnection.js +121 -51
  12. package/dist/cjs/queries/WebSocketHubConnection.js.map +1 -1
  13. package/dist/esm/queries/IQueryResult.d.ts +1 -0
  14. package/dist/esm/queries/IQueryResult.d.ts.map +1 -1
  15. package/dist/esm/queries/ObservableQueryFor.d.ts.map +1 -1
  16. package/dist/esm/queries/ObservableQueryFor.js +6 -1
  17. package/dist/esm/queries/ObservableQueryFor.js.map +1 -1
  18. package/dist/esm/queries/QueryInstanceCache.d.ts +1 -1
  19. package/dist/esm/queries/QueryInstanceCache.d.ts.map +1 -1
  20. package/dist/esm/queries/QueryInstanceCache.js +6 -6
  21. package/dist/esm/queries/QueryInstanceCache.js.map +1 -1
  22. package/dist/esm/queries/QueryResult.d.ts +2 -0
  23. package/dist/esm/queries/QueryResult.d.ts.map +1 -1
  24. package/dist/esm/queries/QueryResult.js +23 -4
  25. package/dist/esm/queries/QueryResult.js.map +1 -1
  26. package/dist/esm/queries/QueryResultWithState.d.ts +3 -3
  27. package/dist/esm/queries/QueryResultWithState.d.ts.map +1 -1
  28. package/dist/esm/queries/QueryResultWithState.js +20 -7
  29. package/dist/esm/queries/QueryResultWithState.js.map +1 -1
  30. package/dist/esm/queries/ServerSentEventHubConnection.d.ts +11 -4
  31. package/dist/esm/queries/ServerSentEventHubConnection.d.ts.map +1 -1
  32. package/dist/esm/queries/ServerSentEventHubConnection.js +120 -58
  33. package/dist/esm/queries/ServerSentEventHubConnection.js.map +1 -1
  34. package/dist/esm/queries/WebSocketHubConnection.d.ts +13 -2
  35. package/dist/esm/queries/WebSocketHubConnection.d.ts.map +1 -1
  36. package/dist/esm/queries/WebSocketHubConnection.js +121 -51
  37. package/dist/esm/queries/WebSocketHubConnection.js.map +1 -1
  38. package/dist/esm/queries/for_ObservableQueryFor/when_performing/with_a_not_ready_result.d.ts +2 -0
  39. package/dist/esm/queries/for_ObservableQueryFor/when_performing/with_a_not_ready_result.d.ts.map +1 -0
  40. package/dist/esm/queries/for_ObservableQueryFor/when_performing/with_a_not_ready_result.js +34 -0
  41. package/dist/esm/queries/for_ObservableQueryFor/when_performing/with_a_not_ready_result.js.map +1 -0
  42. package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_and_sse_transport.js +26 -2
  43. package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_and_sse_transport.js.map +1 -1
  44. package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_disabled_and_sse_transport.js +60 -3
  45. package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_disabled_and_sse_transport.js.map +1 -1
  46. package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_web_socket_hub_payload_without_readiness.d.ts +2 -0
  47. package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_web_socket_hub_payload_without_readiness.d.ts.map +1 -0
  48. package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_web_socket_hub_payload_without_readiness.js +83 -0
  49. package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_web_socket_hub_payload_without_readiness.js.map +1 -0
  50. package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_only_readiness_changed.d.ts +2 -0
  51. package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_only_readiness_changed.d.ts.map +1 -0
  52. package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_only_readiness_changed.js +22 -0
  53. package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_only_readiness_changed.js.map +1 -0
  54. package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result/with_readiness_false.d.ts +2 -0
  55. package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result/with_readiness_false.d.ts.map +1 -0
  56. package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result/with_readiness_false.js +17 -0
  57. package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result/with_readiness_false.js.map +1 -0
  58. package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result/without_readiness.d.ts +2 -0
  59. package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result/without_readiness.d.ts.map +1 -0
  60. package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result/without_readiness.js +16 -0
  61. package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result/without_readiness.js.map +1 -0
  62. package/dist/esm/queries/for_QueryResultWithState/when_creating_from_query_result/with_readiness_false.d.ts +2 -0
  63. package/dist/esm/queries/for_QueryResultWithState/when_creating_from_query_result/with_readiness_false.d.ts.map +1 -0
  64. package/dist/esm/queries/for_QueryResultWithState/when_creating_from_query_result/with_readiness_false.js +19 -0
  65. package/dist/esm/queries/for_QueryResultWithState/when_creating_from_query_result/with_readiness_false.js.map +1 -0
  66. package/dist/esm/queries/for_QueryResultWithState/when_creating_from_query_result/without_readiness.d.ts +2 -0
  67. package/dist/esm/queries/for_QueryResultWithState/when_creating_from_query_result/without_readiness.d.ts.map +1 -0
  68. package/dist/esm/queries/for_QueryResultWithState/when_creating_from_query_result/without_readiness.js +19 -0
  69. package/dist/esm/queries/for_QueryResultWithState/when_creating_from_query_result/without_readiness.js.map +1 -0
  70. package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_deferred_promise.d.ts +7 -0
  71. package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_deferred_promise.d.ts.map +1 -0
  72. package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_deferred_promise.js +12 -0
  73. package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_deferred_promise.js.map +1 -0
  74. package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.d.ts +2 -1
  75. package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.d.ts.map +1 -1
  76. package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.js +15 -4
  77. package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.js.map +1 -1
  78. package/dist/esm/queries/for_ServerSentEventHubConnection/when_a_retired_event_source_fires/ignores_connected_and_error_callbacks.d.ts +2 -0
  79. package/dist/esm/queries/for_ServerSentEventHubConnection/when_a_retired_event_source_fires/ignores_connected_and_error_callbacks.d.ts.map +1 -0
  80. package/dist/esm/queries/for_ServerSentEventHubConnection/when_a_retired_event_source_fires/ignores_connected_and_error_callbacks.js +44 -0
  81. package/dist/esm/queries/for_ServerSentEventHubConnection/when_a_retired_event_source_fires/ignores_connected_and_error_callbacks.js.map +1 -0
  82. package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_replaced.d.ts +2 -0
  83. package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_replaced.d.ts.map +1 -0
  84. package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_replaced.js +74 -0
  85. package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_replaced.js.map +1 -0
  86. package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_unsubscribed.d.ts +2 -0
  87. package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_unsubscribed.d.ts.map +1 -0
  88. package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_unsubscribed.js +74 -0
  89. package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_unsubscribed.js.map +1 -0
  90. package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_stale_request_is_rejected.d.ts +2 -0
  91. 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
  92. package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_stale_request_is_rejected.js +59 -0
  93. package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_stale_request_is_rejected.js.map +1 -0
  94. 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
  95. 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
  96. package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_stale_request_returns_non_ok.js +58 -0
  97. 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
  98. package/dist/esm/queries/for_ServerSentEventHubConnection/when_disposing/cleans_up_resources.js +6 -3
  99. package/dist/esm/queries/for_ServerSentEventHubConnection/when_disposing/cleans_up_resources.js.map +1 -1
  100. package/dist/esm/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.js +23 -6
  101. package/dist/esm/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.js.map +1 -1
  102. package/dist/esm/queries/for_ServerSentEventHubConnection/when_reconnecting/after_error.js +20 -5
  103. package/dist/esm/queries/for_ServerSentEventHubConnection/when_reconnecting/after_error.js.map +1 -1
  104. package/dist/esm/queries/for_ServerSentEventHubConnection/when_reconnecting/and_an_immediate_open_wins_the_backoff_race.d.ts +2 -0
  105. package/dist/esm/queries/for_ServerSentEventHubConnection/when_reconnecting/and_an_immediate_open_wins_the_backoff_race.d.ts.map +1 -0
  106. package/dist/esm/queries/for_ServerSentEventHubConnection/when_reconnecting/and_an_immediate_open_wins_the_backoff_race.js +20 -0
  107. package/dist/esm/queries/for_ServerSentEventHubConnection/when_reconnecting/and_an_immediate_open_wins_the_backoff_race.js.map +1 -0
  108. package/dist/esm/queries/for_ServerSentEventHubConnection/when_replacing_a_subscription/ignores_messages_from_the_retired_generation.d.ts +2 -0
  109. package/dist/esm/queries/for_ServerSentEventHubConnection/when_replacing_a_subscription/ignores_messages_from_the_retired_generation.d.ts.map +1 -0
  110. package/dist/esm/queries/for_ServerSentEventHubConnection/when_replacing_a_subscription/ignores_messages_from_the_retired_generation.js +68 -0
  111. package/dist/esm/queries/for_ServerSentEventHubConnection/when_replacing_a_subscription/ignores_messages_from_the_retired_generation.js.map +1 -0
  112. package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/sends_subscribe_post.js +38 -13
  113. package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/sends_subscribe_post.js.map +1 -1
  114. package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscription_revisions_are_not_advertised/uses_legacy_protocol.d.ts +2 -0
  115. package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscription_revisions_are_not_advertised/uses_legacy_protocol.d.ts.map +1 -0
  116. package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscription_revisions_are_not_advertised/uses_legacy_protocol.js +54 -0
  117. package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscription_revisions_are_not_advertised/uses_legacy_protocol.js.map +1 -0
  118. package/dist/esm/queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.js +18 -4
  119. package/dist/esm/queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.js.map +1 -1
  120. package/dist/esm/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.js +22 -5
  121. package/dist/esm/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.js.map +1 -1
  122. package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/ignores_a_pending_reconnect_and_stale_socket_callbacks.d.ts +2 -0
  123. package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/ignores_a_pending_reconnect_and_stale_socket_callbacks.d.ts.map +1 -0
  124. package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/ignores_a_pending_reconnect_and_stale_socket_callbacks.js +108 -0
  125. package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/ignores_a_pending_reconnect_and_stale_socket_callbacks.js.map +1 -0
  126. package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/replaces_a_closing_socket_safely.d.ts +2 -0
  127. package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/replaces_a_closing_socket_safely.d.ts.map +1 -0
  128. package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/replaces_a_closing_socket_safely.js +33 -0
  129. package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/replaces_a_closing_socket_safely.js.map +1 -0
  130. package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/resubscribes_all_queries.js +26 -4
  131. package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/resubscribes_all_queries.js.map +1 -1
  132. package/dist/esm/queries/for_WebSocketHubConnection/when_replacing_a_subscription/ignores_stale_result_unauthorized_and_error.d.ts +2 -0
  133. package/dist/esm/queries/for_WebSocketHubConnection/when_replacing_a_subscription/ignores_stale_result_unauthorized_and_error.d.ts.map +1 -0
  134. package/dist/esm/queries/for_WebSocketHubConnection/when_replacing_a_subscription/ignores_stale_result_unauthorized_and_error.js +62 -0
  135. package/dist/esm/queries/for_WebSocketHubConnection/when_replacing_a_subscription/ignores_stale_result_unauthorized_and_error.js.map +1 -0
  136. package/dist/esm/queries/for_WebSocketHubConnection/when_subscribing/to_a_query.js +18 -5
  137. package/dist/esm/queries/for_WebSocketHubConnection/when_subscribing/to_a_query.js.map +1 -1
  138. package/dist/esm/queries/for_WebSocketHubConnection/when_subscription_revisions_are_supported/upgrades_active_subscriptions_to_strict_mode.d.ts +2 -0
  139. package/dist/esm/queries/for_WebSocketHubConnection/when_subscription_revisions_are_supported/upgrades_active_subscriptions_to_strict_mode.d.ts.map +1 -0
  140. package/dist/esm/queries/for_WebSocketHubConnection/when_subscription_revisions_are_supported/upgrades_active_subscriptions_to_strict_mode.js +56 -0
  141. package/dist/esm/queries/for_WebSocketHubConnection/when_subscription_revisions_are_supported/upgrades_active_subscriptions_to_strict_mode.js.map +1 -0
  142. package/dist/esm/queries/for_WebSocketHubConnection/when_unsubscribing/the_only_query.js +16 -3
  143. package/dist/esm/queries/for_WebSocketHubConnection/when_unsubscribing/the_only_query.js.map +1 -1
  144. package/dist/esm/queries/for_WebSocketHubConnection/when_unsubscribing/with_revision_support_not_advertised.d.ts +2 -0
  145. package/dist/esm/queries/for_WebSocketHubConnection/when_unsubscribing/with_revision_support_not_advertised.d.ts.map +1 -0
  146. package/dist/esm/queries/for_WebSocketHubConnection/when_unsubscribing/with_revision_support_not_advertised.js +33 -0
  147. package/dist/esm/queries/for_WebSocketHubConnection/when_unsubscribing/with_revision_support_not_advertised.js.map +1 -0
  148. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  149. package/package.json +1 -1
  150. package/queries/IQueryResult.ts +10 -0
  151. package/queries/ObservableQueryFor.ts +44 -16
  152. package/queries/QueryInstanceCache.ts +42 -19
  153. package/queries/QueryResult.ts +145 -79
  154. package/queries/QueryResultWithState.ts +32 -9
  155. package/queries/ServerSentEventHubConnection.ts +270 -83
  156. package/queries/WebSocketHubConnection.ts +188 -56
  157. package/queries/for_ObservableQueryFor/when_performing/with_a_not_ready_result.ts +46 -0
  158. package/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_and_sse_transport.ts +91 -57
  159. package/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_disabled_and_sse_transport.ts +125 -53
  160. package/queries/for_ObservableQueryFor/when_subscribing/with_web_socket_hub_payload_without_readiness.ts +107 -0
  161. package/queries/for_QueryInstanceCache/when_setting_last_result/with_only_readiness_changed.ts +63 -0
  162. package/queries/for_QueryResult/when_constructing_from_a_server_result/with_readiness_false.ts +25 -0
  163. package/queries/for_QueryResult/when_constructing_from_a_server_result/without_readiness.ts +24 -0
  164. package/queries/for_QueryResultWithState/when_creating_from_query_result/with_readiness_false.ts +28 -0
  165. package/queries/for_QueryResultWithState/when_creating_from_query_result/without_readiness.ts +25 -0
  166. package/queries/for_ServerSentEventHubConnection/given/a_deferred_promise.ts +15 -0
  167. package/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.ts +18 -7
  168. package/queries/for_ServerSentEventHubConnection/when_a_retired_event_source_fires/ignores_connected_and_error_callbacks.ts +59 -0
  169. package/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_replaced.ts +113 -0
  170. package/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_unsubscribed.ts +109 -0
  171. package/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_stale_request_is_rejected.ts +81 -0
  172. package/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_stale_request_returns_non_ok.ts +83 -0
  173. package/queries/for_ServerSentEventHubConnection/when_disposing/cleans_up_resources.ts +30 -21
  174. package/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.ts +56 -32
  175. package/queries/for_ServerSentEventHubConnection/when_reconnecting/after_error.ts +23 -6
  176. package/queries/for_ServerSentEventHubConnection/when_reconnecting/and_an_immediate_open_wins_the_backoff_race.ts +41 -0
  177. package/queries/for_ServerSentEventHubConnection/when_replacing_a_subscription/ignores_messages_from_the_retired_generation.ts +92 -0
  178. package/queries/for_ServerSentEventHubConnection/when_subscribing/sends_subscribe_post.ts +69 -30
  179. package/queries/for_ServerSentEventHubConnection/when_subscription_revisions_are_not_advertised/uses_legacy_protocol.ts +69 -0
  180. package/queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.ts +43 -24
  181. package/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.ts +53 -29
  182. package/queries/for_WebSocketHubConnection/when_reconnecting/ignores_a_pending_reconnect_and_stale_socket_callbacks.ts +131 -0
  183. package/queries/for_WebSocketHubConnection/when_reconnecting/replaces_a_closing_socket_safely.ts +39 -0
  184. package/queries/for_WebSocketHubConnection/when_reconnecting/resubscribes_all_queries.ts +72 -36
  185. package/queries/for_WebSocketHubConnection/when_replacing_a_subscription/ignores_stale_result_unauthorized_and_error.ts +88 -0
  186. package/queries/for_WebSocketHubConnection/when_subscribing/to_a_query.ts +54 -27
  187. package/queries/for_WebSocketHubConnection/when_subscription_revisions_are_supported/upgrades_active_subscriptions_to_strict_mode.ts +72 -0
  188. package/queries/for_WebSocketHubConnection/when_unsubscribing/the_only_query.ts +43 -18
  189. 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,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AI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,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"}
@@ -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({ type: HubMessageType.Connected, payload: 'conn-abc' });
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' && args[0].includes('unsubscribe'));
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
@@ -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,8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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({ type: HubMessageType.Unauthorized, queryId });
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.be.true;
38
+ callback.calledOnce.should.equal(true);
22
39
  });
23
40
  it('should report isAuthorized as false', () => {
24
- receivedResult.isAuthorized.should.be.false;
41
+ receivedResult.isAuthorized.should.equal(false);
25
42
  });
26
43
  it('should report isSuccess as false', () => {
27
- receivedResult.isSuccess.should.be.false;
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,CAAC,oDAAoD,EAAE,KAAK,CAAC,2BAA2B,EAAE,OAAO,CAAC,EAAE;IACxG,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;QAGvB,OAAO,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC;QAExE,cAAc,GAAG,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAqC,CAAC;IACrF,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACX,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC7C,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC3C,cAAe,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC;IACjD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;QACxC,cAAe,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACtC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC,CAAC"}
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,EA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CAAC,oCAAoC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5E,CAAC;IACL,CAAC;IAED,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC7C,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC3C,cAAe,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;QACxC,cAAe,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACtC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ignores_a_pending_reconnect_and_stale_socket_callbacks.d.ts.map
@@ -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":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,O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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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,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"}
@@ -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 re-send all active subscriptions', () => {
22
- context.fakeSocket.send.calledOnce.should.be.true;
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,CAAC,gCAAgC,EAAE,KAAK,CAAC,2BAA2B,EAAE,OAAO,CAAC,EAAE;IACpF,MA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EH,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;AACP,CAAC,CAAC,CAAC,CAAC"}
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;QAC5B,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,YAAY,CAAC,CAAC;QAC9E,OAAO,CAAC,YAAY,EAAE,CAAC;QACvB,OAAO,CAAC,eAAe,CAAC;YACpB,IAAI,EAAE,cAAc,CAAC,SAAS;YAC9B,6BAA6B,EAAE,IAAI;SACtC,CAAC,CAAC;QAGH,OAAO,CAAC,aAAa,EAAE,CAAC;QACxB,MAAM,iBAAiB,GACnB,OAAO,CAAC,MAAM,CAAC,QAClB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAsB,CAAC;QAC1C,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,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C,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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ignores_stale_result_unauthorized_and_error.d.ts.map
@@ -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,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@@ -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.be.true;
19
- const msg = JSON.parse(context.fakeSocket.send.getCall(0).args[0]);
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({ type: HubMessageType.QueryResult, queryId, payload: result });
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_sub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,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,8BAA8B,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QACtE,CAAC;IACL,CAAC;IAED,QAAQ,CAAC,qCAAqC,EAAE,GAAG,EAAE;QACjD,MAAM,MAAM,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QAEpD,UAAU,CAAC,GAAG,EAAE;YACZ,OAAO,CAAC,eAAe,CAAC;gBACpB,IAAI,EAAE,cAAc,CAAC,WAAW;gBAChC,OAAO;gBACP,OAAO,EAAE,MAAM;aAClB,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE,CAClD,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QACxC,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE,CACtC,QAAQ,CAAC,OAAO,CAAC,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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=upgrades_active_subscriptions_to_strict_mode.d.ts.map
@@ -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