@cratis/arc 19.11.1 → 20.0.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/Globals.ts +20 -1
- package/dist/cjs/Globals.d.ts +4 -0
- package/dist/cjs/Globals.d.ts.map +1 -1
- package/dist/cjs/Globals.js +6 -1
- package/dist/cjs/Globals.js.map +1 -1
- package/dist/cjs/queries/HubConnectionKeepAlive.d.ts +11 -0
- package/dist/cjs/queries/HubConnectionKeepAlive.d.ts.map +1 -0
- package/dist/cjs/queries/HubConnectionKeepAlive.js +33 -0
- package/dist/cjs/queries/HubConnectionKeepAlive.js.map +1 -0
- package/dist/cjs/queries/IObservableQueryHubConnection.d.ts +11 -0
- package/dist/cjs/queries/IObservableQueryHubConnection.d.ts.map +1 -0
- package/dist/cjs/queries/IReconnectPolicy.d.ts +8 -0
- package/dist/cjs/queries/IReconnectPolicy.d.ts.map +1 -0
- package/dist/cjs/queries/ObservableQueryConnection.d.ts +3 -1
- package/dist/cjs/queries/ObservableQueryConnection.d.ts.map +1 -1
- package/dist/cjs/queries/ObservableQueryConnection.js +8 -21
- package/dist/cjs/queries/ObservableQueryConnection.js.map +1 -1
- package/dist/cjs/queries/ObservableQueryConnectionFactory.d.ts +13 -0
- package/dist/cjs/queries/ObservableQueryConnectionFactory.d.ts.map +1 -0
- package/dist/cjs/queries/ObservableQueryConnectionFactory.js +62 -0
- package/dist/cjs/queries/ObservableQueryConnectionFactory.js.map +1 -0
- package/dist/cjs/queries/ObservableQueryConnectionPool.d.ts +9 -0
- package/dist/cjs/queries/ObservableQueryConnectionPool.d.ts.map +1 -0
- package/dist/cjs/queries/ObservableQueryConnectionPool.js +23 -0
- package/dist/cjs/queries/ObservableQueryConnectionPool.js.map +1 -0
- package/dist/cjs/queries/ObservableQueryFor.d.ts +1 -0
- package/dist/cjs/queries/ObservableQueryFor.d.ts.map +1 -1
- package/dist/cjs/queries/ObservableQueryFor.js +10 -5
- package/dist/cjs/queries/ObservableQueryFor.js.map +1 -1
- package/dist/cjs/queries/ObservableQueryMultiplexer.d.ts +30 -0
- package/dist/cjs/queries/ObservableQueryMultiplexer.d.ts.map +1 -0
- package/dist/cjs/queries/ObservableQueryMultiplexer.js +120 -0
- package/dist/cjs/queries/ObservableQueryMultiplexer.js.map +1 -0
- package/dist/cjs/queries/QueryInstanceCache.d.ts +29 -0
- package/dist/cjs/queries/QueryInstanceCache.d.ts.map +1 -0
- package/dist/cjs/queries/QueryInstanceCache.js +95 -0
- package/dist/cjs/queries/QueryInstanceCache.js.map +1 -0
- package/dist/cjs/queries/QueryTransportMethod.d.ts +5 -0
- package/dist/cjs/queries/QueryTransportMethod.d.ts.map +1 -0
- package/dist/cjs/queries/QueryTransportMethod.js +8 -0
- package/dist/cjs/queries/QueryTransportMethod.js.map +1 -0
- package/dist/cjs/queries/ReconnectPolicy.d.ts +15 -0
- package/dist/cjs/queries/ReconnectPolicy.d.ts.map +1 -0
- package/dist/cjs/queries/ReconnectPolicy.js +43 -0
- package/dist/cjs/queries/ReconnectPolicy.js.map +1 -0
- package/dist/cjs/queries/ServerSentEventHubConnection.d.ts +39 -0
- package/dist/cjs/queries/ServerSentEventHubConnection.d.ts.map +1 -0
- package/dist/cjs/queries/ServerSentEventHubConnection.js +233 -0
- package/dist/cjs/queries/ServerSentEventHubConnection.js.map +1 -0
- package/dist/cjs/queries/ServerSentEventQueryConnection.d.ts +14 -0
- package/dist/cjs/queries/ServerSentEventQueryConnection.d.ts.map +1 -0
- package/dist/cjs/queries/ServerSentEventQueryConnection.js +59 -0
- package/dist/cjs/queries/ServerSentEventQueryConnection.js.map +1 -0
- package/dist/cjs/queries/WebSocketHubConnection.d.ts +55 -0
- package/dist/cjs/queries/WebSocketHubConnection.d.ts.map +1 -0
- package/dist/cjs/queries/WebSocketHubConnection.js +193 -0
- package/dist/cjs/queries/WebSocketHubConnection.js.map +1 -0
- package/dist/cjs/queries/for_HubConnectionKeepAlive/behavior.d.ts +2 -0
- package/dist/cjs/queries/for_HubConnectionKeepAlive/behavior.d.ts.map +1 -0
- package/dist/cjs/queries/for_ObservableQueryConnection/given/an_observable_query_connection.d.ts +1 -2
- package/dist/cjs/queries/for_ObservableQueryConnection/given/an_observable_query_connection.d.ts.map +1 -1
- package/dist/cjs/queries/for_ObservableQueryConnectionFactory/given/a_descriptor.d.ts +9 -0
- package/dist/cjs/queries/for_ObservableQueryConnectionFactory/given/a_descriptor.d.ts.map +1 -0
- package/dist/cjs/queries/for_ObservableQueryConnectionFactory/when_creating/with_direct_mode_and_sse_transport.d.ts +2 -0
- package/dist/cjs/queries/for_ObservableQueryConnectionFactory/when_creating/with_direct_mode_and_sse_transport.d.ts.map +1 -0
- package/dist/cjs/queries/for_ObservableQueryConnectionFactory/when_creating/with_direct_mode_and_websocket_transport.d.ts +2 -0
- package/dist/cjs/queries/for_ObservableQueryConnectionFactory/when_creating/with_direct_mode_and_websocket_transport.d.ts.map +1 -0
- package/dist/cjs/queries/for_ObservableQueryConnectionFactory/when_creating/with_hub_mode_and_sse_transport.d.ts +2 -0
- package/dist/cjs/queries/for_ObservableQueryConnectionFactory/when_creating/with_hub_mode_and_sse_transport.d.ts.map +1 -0
- package/dist/cjs/queries/for_ObservableQueryConnectionFactory/when_creating/with_hub_mode_and_websocket_transport.d.ts +2 -0
- package/dist/cjs/queries/for_ObservableQueryConnectionFactory/when_creating/with_hub_mode_and_websocket_transport.d.ts.map +1 -0
- package/dist/cjs/queries/for_ObservableQueryConnectionPool/when_acquiring/with_multiple_slots/and_least_loaded_slot_is_chosen.d.ts +2 -0
- package/dist/cjs/queries/for_ObservableQueryConnectionPool/when_acquiring/with_multiple_slots/and_least_loaded_slot_is_chosen.d.ts.map +1 -0
- package/dist/cjs/queries/for_ObservableQueryConnectionPool/when_acquiring/with_multiple_slots/and_size_is_zero.d.ts +2 -0
- package/dist/cjs/queries/for_ObservableQueryConnectionPool/when_acquiring/with_multiple_slots/and_size_is_zero.d.ts.map +1 -0
- package/dist/cjs/queries/for_ObservableQueryConnectionPool/when_acquiring/with_single_slot/and_one_subscriber.d.ts +2 -0
- package/dist/cjs/queries/for_ObservableQueryConnectionPool/when_acquiring/with_single_slot/and_one_subscriber.d.ts.map +1 -0
- package/dist/cjs/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_and_sse_transport.d.ts +2 -0
- package/dist/cjs/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_and_sse_transport.d.ts.map +1 -0
- package/dist/cjs/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_disabled_and_sse_transport.d.ts +2 -0
- package/dist/cjs/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_disabled_and_sse_transport.d.ts.map +1 -0
- package/dist/cjs/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_enabled.d.ts +2 -0
- package/dist/cjs/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_enabled.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_building_key/with_arguments.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_building_key/with_arguments.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_building_key/with_empty_arguments_object.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_building_key/with_empty_arguments_object.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_building_key/with_same_arguments_different_order.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_building_key/with_same_arguments_different_order.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_building_key/without_arguments.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_building_key/without_arguments.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_getting_last_result/with_no_result_stored.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_getting_last_result/with_no_result_stored.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_getting_last_result/with_stored_result.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_getting_last_result/with_stored_result.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_getting_or_creating/with_existing_entry.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_getting_or_creating/with_existing_entry.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_getting_or_creating/with_new_entry.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_getting_or_creating/with_new_entry.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_releasing/a_key_that_does_not_exist.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_releasing/a_key_that_does_not_exist.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_releasing/one_of_two_subscribers.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_releasing/one_of_two_subscribers.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_setting_last_result/with_a_result.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_setting_last_result/with_a_result.d.ts.map +1 -0
- package/dist/cjs/queries/for_ReconnectPolicy/when_canceling/with_pending_timer.d.ts +2 -0
- package/dist/cjs/queries/for_ReconnectPolicy/when_canceling/with_pending_timer.d.ts.map +1 -0
- package/dist/cjs/queries/for_ReconnectPolicy/when_cancelling/with_pending_timer.d.ts +2 -0
- package/dist/cjs/queries/for_ReconnectPolicy/when_cancelling/with_pending_timer.d.ts.map +1 -0
- package/dist/cjs/queries/for_ReconnectPolicy/when_resetting/after_scheduling.d.ts +2 -0
- package/dist/cjs/queries/for_ReconnectPolicy/when_resetting/after_scheduling.d.ts.map +1 -0
- package/dist/cjs/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_not_reached/delay_is_capped_at_max.d.ts +2 -0
- package/dist/cjs/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_not_reached/delay_is_capped_at_max.d.ts.map +1 -0
- package/dist/cjs/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_not_reached/first_attempt.d.ts +2 -0
- package/dist/cjs/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_not_reached/first_attempt.d.ts.map +1 -0
- package/dist/cjs/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_reached/abandons_reconnect.d.ts +2 -0
- package/dist/cjs/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_reached/abandons_reconnect.d.ts.map +1 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.d.ts +21 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.d.ts.map +1 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_connect_timeout_fires/triggers_reconnect.d.ts +2 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_connect_timeout_fires/triggers_reconnect.d.ts.map +1 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_disposing/cleans_up_resources.d.ts +2 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_disposing/cleans_up_resources.d.ts.map +1 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_keep_alive_is_idle/triggers_reconnect.d.ts +2 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_keep_alive_is_idle/triggers_reconnect.d.ts.map +1 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_reconnecting/after_error.d.ts +2 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_reconnecting/after_error.d.ts.map +1 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_subscribing/queues_until_connected.d.ts +2 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_subscribing/queues_until_connected.d.ts.map +1 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_subscribing/sends_subscribe_post.d.ts +2 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_subscribing/sends_subscribe_post.d.ts.map +1 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.d.ts +2 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.d.ts.map +1 -0
- package/dist/cjs/queries/for_ServerSentEventQueryConnection/when_connecting/with_query_arguments.d.ts +2 -0
- package/dist/cjs/queries/for_ServerSentEventQueryConnection/when_connecting/with_query_arguments.d.ts.map +1 -0
- package/dist/cjs/queries/for_ServerSentEventQueryConnection/when_connecting/without_event_source_available.d.ts +2 -0
- package/dist/cjs/queries/for_ServerSentEventQueryConnection/when_connecting/without_event_source_available.d.ts.map +1 -0
- package/dist/cjs/queries/for_ServerSentEventQueryConnection/when_disconnecting/after_connecting.d.ts +2 -0
- package/dist/cjs/queries/for_ServerSentEventQueryConnection/when_disconnecting/after_connecting.d.ts.map +1 -0
- package/dist/cjs/queries/for_ServerSentEventQueryConnection/when_disconnecting/before_message_arrives.d.ts +2 -0
- package/dist/cjs/queries/for_ServerSentEventQueryConnection/when_disconnecting/before_message_arrives.d.ts.map +1 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/given/a_web_socket_hub_connection.d.ts +23 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/given/a_web_socket_hub_connection.d.ts.map +1 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_disposing/cleans_up_resources.d.ts +2 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_disposing/cleans_up_resources.d.ts.map +1 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_keep_alive_is_idle/sends_a_ping.d.ts +2 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_keep_alive_is_idle/sends_a_ping.d.ts.map +1 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_receiving_a_message/resets_keep_alive_timer.d.ts +2 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_receiving_a_message/resets_keep_alive_timer.d.ts.map +1 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_reconnecting/after_unexpected_close.d.ts +2 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_reconnecting/after_unexpected_close.d.ts.map +1 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_reconnecting/resubscribes_all_queries.d.ts +2 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_reconnecting/resubscribes_all_queries.d.ts.map +1 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_subscribing/to_a_query.d.ts +2 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_subscribing/to_a_query.d.ts.map +1 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_unsubscribing/the_only_query.d.ts +2 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_unsubscribing/the_only_query.d.ts.map +1 -0
- package/dist/cjs/queries/index.d.ts +12 -0
- package/dist/cjs/queries/index.d.ts.map +1 -1
- package/dist/cjs/queries/index.js +34 -0
- package/dist/cjs/queries/index.js.map +1 -1
- package/dist/esm/Globals.d.ts +4 -0
- package/dist/esm/Globals.d.ts.map +1 -1
- package/dist/esm/Globals.js +6 -1
- package/dist/esm/Globals.js.map +1 -1
- package/dist/esm/queries/HubConnectionKeepAlive.d.ts +11 -0
- package/dist/esm/queries/HubConnectionKeepAlive.d.ts.map +1 -0
- package/dist/esm/queries/HubConnectionKeepAlive.js +31 -0
- package/dist/esm/queries/HubConnectionKeepAlive.js.map +1 -0
- package/dist/esm/queries/IObservableQueryHubConnection.d.ts +11 -0
- package/dist/esm/queries/IObservableQueryHubConnection.d.ts.map +1 -0
- package/dist/esm/queries/IObservableQueryHubConnection.js +2 -0
- package/dist/esm/queries/IObservableQueryHubConnection.js.map +1 -0
- package/dist/esm/queries/IReconnectPolicy.d.ts +8 -0
- package/dist/esm/queries/IReconnectPolicy.d.ts.map +1 -0
- package/dist/esm/queries/IReconnectPolicy.js +2 -0
- package/dist/esm/queries/IReconnectPolicy.js.map +1 -0
- package/dist/esm/queries/ObservableQueryConnection.d.ts +3 -1
- package/dist/esm/queries/ObservableQueryConnection.d.ts.map +1 -1
- package/dist/esm/queries/ObservableQueryConnection.js +8 -21
- package/dist/esm/queries/ObservableQueryConnection.js.map +1 -1
- package/dist/esm/queries/ObservableQueryConnectionFactory.d.ts +13 -0
- package/dist/esm/queries/ObservableQueryConnectionFactory.d.ts.map +1 -0
- package/dist/esm/queries/ObservableQueryConnectionFactory.js +58 -0
- package/dist/esm/queries/ObservableQueryConnectionFactory.js.map +1 -0
- package/dist/esm/queries/ObservableQueryConnectionPool.d.ts +9 -0
- package/dist/esm/queries/ObservableQueryConnectionPool.d.ts.map +1 -0
- package/dist/esm/queries/ObservableQueryConnectionPool.js +21 -0
- package/dist/esm/queries/ObservableQueryConnectionPool.js.map +1 -0
- package/dist/esm/queries/ObservableQueryFor.d.ts +1 -0
- package/dist/esm/queries/ObservableQueryFor.d.ts.map +1 -1
- package/dist/esm/queries/ObservableQueryFor.js +10 -5
- package/dist/esm/queries/ObservableQueryFor.js.map +1 -1
- package/dist/esm/queries/ObservableQueryMultiplexer.d.ts +30 -0
- package/dist/esm/queries/ObservableQueryMultiplexer.d.ts.map +1 -0
- package/dist/esm/queries/ObservableQueryMultiplexer.js +114 -0
- package/dist/esm/queries/ObservableQueryMultiplexer.js.map +1 -0
- package/dist/esm/queries/QueryInstanceCache.d.ts +29 -0
- package/dist/esm/queries/QueryInstanceCache.d.ts.map +1 -0
- package/dist/esm/queries/QueryInstanceCache.js +93 -0
- package/dist/esm/queries/QueryInstanceCache.js.map +1 -0
- package/dist/esm/queries/QueryTransportMethod.d.ts +5 -0
- package/dist/esm/queries/QueryTransportMethod.d.ts.map +1 -0
- package/dist/esm/queries/QueryTransportMethod.js +8 -0
- package/dist/esm/queries/QueryTransportMethod.js.map +1 -0
- package/dist/esm/queries/ReconnectPolicy.d.ts +15 -0
- package/dist/esm/queries/ReconnectPolicy.d.ts.map +1 -0
- package/dist/esm/queries/ReconnectPolicy.js +41 -0
- package/dist/esm/queries/ReconnectPolicy.js.map +1 -0
- package/dist/esm/queries/ServerSentEventHubConnection.d.ts +39 -0
- package/dist/esm/queries/ServerSentEventHubConnection.d.ts.map +1 -0
- package/dist/esm/queries/ServerSentEventHubConnection.js +231 -0
- package/dist/esm/queries/ServerSentEventHubConnection.js.map +1 -0
- package/dist/esm/queries/ServerSentEventQueryConnection.d.ts +14 -0
- package/dist/esm/queries/ServerSentEventQueryConnection.d.ts.map +1 -0
- package/dist/esm/queries/ServerSentEventQueryConnection.js +56 -0
- package/dist/esm/queries/ServerSentEventQueryConnection.js.map +1 -0
- package/dist/esm/queries/WebSocketHubConnection.d.ts +55 -0
- package/dist/esm/queries/WebSocketHubConnection.d.ts.map +1 -0
- package/dist/esm/queries/WebSocketHubConnection.js +191 -0
- package/dist/esm/queries/WebSocketHubConnection.js.map +1 -0
- package/dist/esm/queries/for_HubConnectionKeepAlive/behavior.d.ts +2 -0
- package/dist/esm/queries/for_HubConnectionKeepAlive/behavior.d.ts.map +1 -0
- package/dist/esm/queries/for_HubConnectionKeepAlive/behavior.js +57 -0
- package/dist/esm/queries/for_HubConnectionKeepAlive/behavior.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryConnection/given/an_observable_query_connection.d.ts +1 -2
- package/dist/esm/queries/for_ObservableQueryConnection/given/an_observable_query_connection.d.ts.map +1 -1
- package/dist/esm/queries/for_ObservableQueryConnection/given/an_observable_query_connection.js +9 -5
- package/dist/esm/queries/for_ObservableQueryConnection/given/an_observable_query_connection.js.map +1 -1
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/given/a_descriptor.d.ts +9 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/given/a_descriptor.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/given/a_descriptor.js +19 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/given/a_descriptor.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/when_creating/with_direct_mode_and_sse_transport.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/when_creating/with_direct_mode_and_sse_transport.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/when_creating/with_direct_mode_and_sse_transport.js +49 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/when_creating/with_direct_mode_and_sse_transport.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/when_creating/with_direct_mode_and_websocket_transport.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/when_creating/with_direct_mode_and_websocket_transport.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/when_creating/with_direct_mode_and_websocket_transport.js +47 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/when_creating/with_direct_mode_and_websocket_transport.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/when_creating/with_hub_mode_and_sse_transport.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/when_creating/with_hub_mode_and_sse_transport.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/when_creating/with_hub_mode_and_sse_transport.js +54 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/when_creating/with_hub_mode_and_sse_transport.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/when_creating/with_hub_mode_and_websocket_transport.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/when_creating/with_hub_mode_and_websocket_transport.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/when_creating/with_hub_mode_and_websocket_transport.js +49 -0
- package/dist/esm/queries/for_ObservableQueryConnectionFactory/when_creating/with_hub_mode_and_websocket_transport.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryConnectionPool/when_acquiring/with_multiple_slots/and_least_loaded_slot_is_chosen.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryConnectionPool/when_acquiring/with_multiple_slots/and_least_loaded_slot_is_chosen.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryConnectionPool/when_acquiring/with_multiple_slots/and_least_loaded_slot_is_chosen.js +34 -0
- package/dist/esm/queries/for_ObservableQueryConnectionPool/when_acquiring/with_multiple_slots/and_least_loaded_slot_is_chosen.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryConnectionPool/when_acquiring/with_multiple_slots/and_size_is_zero.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryConnectionPool/when_acquiring/with_multiple_slots/and_size_is_zero.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryConnectionPool/when_acquiring/with_multiple_slots/and_size_is_zero.js +18 -0
- package/dist/esm/queries/for_ObservableQueryConnectionPool/when_acquiring/with_multiple_slots/and_size_is_zero.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryConnectionPool/when_acquiring/with_single_slot/and_one_subscriber.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryConnectionPool/when_acquiring/with_single_slot/and_one_subscriber.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryConnectionPool/when_acquiring/with_single_slot/and_one_subscriber.js +32 -0
- package/dist/esm/queries/for_ObservableQueryConnectionPool/when_acquiring/with_single_slot/and_one_subscriber.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_and_sse_transport.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_and_sse_transport.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_and_sse_transport.js +54 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_and_sse_transport.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_disabled_and_sse_transport.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_disabled_and_sse_transport.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_disabled_and_sse_transport.js +55 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_disabled_and_sse_transport.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_enabled.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_enabled.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_enabled.js +45 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_enabled.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_partially_missing_required_arguments.js +18 -11
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_partially_missing_required_arguments.js.map +1 -1
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_route_and_query_args.js +12 -5
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_route_and_query_args.js.map +1 -1
- package/dist/esm/queries/for_QueryInstanceCache/when_building_key/with_arguments.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_building_key/with_arguments.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_building_key/with_arguments.js +12 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_building_key/with_arguments.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_building_key/with_empty_arguments_object.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_building_key/with_empty_arguments_object.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_building_key/with_empty_arguments_object.js +11 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_building_key/with_empty_arguments_object.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_building_key/with_same_arguments_different_order.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_building_key/with_same_arguments_different_order.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_building_key/with_same_arguments_different_order.js +13 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_building_key/with_same_arguments_different_order.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_building_key/without_arguments.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_building_key/without_arguments.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_building_key/without_arguments.js +11 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_building_key/without_arguments.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_getting_last_result/with_no_result_stored.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_getting_last_result/with_no_result_stored.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_getting_last_result/with_no_result_stored.js +12 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_getting_last_result/with_no_result_stored.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_getting_last_result/with_stored_result.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_getting_last_result/with_stored_result.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_getting_last_result/with_stored_result.js +16 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_getting_last_result/with_stored_result.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_getting_or_creating/with_existing_entry.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_getting_or_creating/with_existing_entry.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_getting_or_creating/with_existing_entry.js +23 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_getting_or_creating/with_existing_entry.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_getting_or_creating/with_new_entry.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_getting_or_creating/with_new_entry.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_getting_or_creating/with_new_entry.js +16 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_getting_or_creating/with_new_entry.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/a_key_that_does_not_exist.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/a_key_that_does_not_exist.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/a_key_that_does_not_exist.js +17 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/a_key_that_does_not_exist.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/one_of_two_subscribers.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/one_of_two_subscribers.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/one_of_two_subscribers.js +13 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/one_of_two_subscribers.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber.js +17 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_a_result.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_a_result.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_a_result.js +15 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_a_result.js.map +1 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_canceling/with_pending_timer.d.ts +2 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_canceling/with_pending_timer.d.ts.map +1 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_canceling/with_pending_timer.js +24 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_canceling/with_pending_timer.js.map +1 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_cancelling/with_pending_timer.d.ts +2 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_cancelling/with_pending_timer.d.ts.map +1 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_cancelling/with_pending_timer.js +24 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_cancelling/with_pending_timer.js.map +1 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_resetting/after_scheduling.d.ts +2 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_resetting/after_scheduling.d.ts.map +1 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_resetting/after_scheduling.js +29 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_resetting/after_scheduling.js.map +1 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_not_reached/delay_is_capped_at_max.d.ts +2 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_not_reached/delay_is_capped_at_max.d.ts.map +1 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_not_reached/delay_is_capped_at_max.js +33 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_not_reached/delay_is_capped_at_max.js.map +1 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_not_reached/first_attempt.d.ts +2 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_not_reached/first_attempt.d.ts.map +1 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_not_reached/first_attempt.js +28 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_not_reached/first_attempt.js.map +1 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_reached/abandons_reconnect.d.ts +2 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_reached/abandons_reconnect.d.ts.map +1 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_reached/abandons_reconnect.js +29 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_reached/abandons_reconnect.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.d.ts +21 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.js +50 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connect_timeout_fires/triggers_reconnect.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connect_timeout_fires/triggers_reconnect.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connect_timeout_fires/triggers_reconnect.js +24 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connect_timeout_fires/triggers_reconnect.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_disposing/cleans_up_resources.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_disposing/cleans_up_resources.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_disposing/cleans_up_resources.js +27 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_disposing/cleans_up_resources.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_keep_alive_is_idle/triggers_reconnect.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_keep_alive_is_idle/triggers_reconnect.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_keep_alive_is_idle/triggers_reconnect.js +26 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_keep_alive_is_idle/triggers_reconnect.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_reconnecting/after_error.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_reconnecting/after_error.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_reconnecting/after_error.js +46 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_reconnecting/after_error.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/queues_until_connected.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/queues_until_connected.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/queues_until_connected.js +21 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/queues_until_connected.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/sends_subscribe_post.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/sends_subscribe_post.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/sends_subscribe_post.js +32 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/sends_subscribe_post.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.js +21 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventQueryConnection/when_connecting/with_query_arguments.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventQueryConnection/when_connecting/with_query_arguments.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventQueryConnection/when_connecting/with_query_arguments.js +38 -0
- package/dist/esm/queries/for_ServerSentEventQueryConnection/when_connecting/with_query_arguments.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventQueryConnection/when_connecting/without_event_source_available.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventQueryConnection/when_connecting/without_event_source_available.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventQueryConnection/when_connecting/without_event_source_available.js +23 -0
- package/dist/esm/queries/for_ServerSentEventQueryConnection/when_connecting/without_event_source_available.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventQueryConnection/when_disconnecting/after_connecting.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventQueryConnection/when_disconnecting/after_connecting.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventQueryConnection/when_disconnecting/after_connecting.js +24 -0
- package/dist/esm/queries/for_ServerSentEventQueryConnection/when_disconnecting/after_connecting.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventQueryConnection/when_disconnecting/before_message_arrives.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventQueryConnection/when_disconnecting/before_message_arrives.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventQueryConnection/when_disconnecting/before_message_arrives.js +24 -0
- package/dist/esm/queries/for_ServerSentEventQueryConnection/when_disconnecting/before_message_arrives.js.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/given/a_web_socket_hub_connection.d.ts +23 -0
- package/dist/esm/queries/for_WebSocketHubConnection/given/a_web_socket_hub_connection.d.ts.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/given/a_web_socket_hub_connection.js +47 -0
- package/dist/esm/queries/for_WebSocketHubConnection/given/a_web_socket_hub_connection.js.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_disposing/cleans_up_resources.d.ts +2 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_disposing/cleans_up_resources.d.ts.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_disposing/cleans_up_resources.js +24 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_disposing/cleans_up_resources.js.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_keep_alive_is_idle/sends_a_ping.d.ts +2 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_keep_alive_is_idle/sends_a_ping.d.ts.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_keep_alive_is_idle/sends_a_ping.js +29 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_keep_alive_is_idle/sends_a_ping.js.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_receiving_a_message/resets_keep_alive_timer.d.ts +2 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_receiving_a_message/resets_keep_alive_timer.d.ts.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_receiving_a_message/resets_keep_alive_timer.js +31 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_receiving_a_message/resets_keep_alive_timer.js.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/after_unexpected_close.d.ts +2 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/after_unexpected_close.d.ts.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/after_unexpected_close.js +30 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/after_unexpected_close.js.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/resubscribes_all_queries.d.ts +2 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/resubscribes_all_queries.d.ts.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/resubscribes_all_queries.js +31 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/resubscribes_all_queries.js.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_subscribing/to_a_query.d.ts +2 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_subscribing/to_a_query.d.ts.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_subscribing/to_a_query.js +32 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_subscribing/to_a_query.js.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_unsubscribing/the_only_query.d.ts +2 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_unsubscribing/the_only_query.d.ts.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_unsubscribing/the_only_query.js +23 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_unsubscribing/the_only_query.js.map +1 -0
- package/dist/esm/queries/index.d.ts +12 -0
- package/dist/esm/queries/index.d.ts.map +1 -1
- package/dist/esm/queries/index.js +10 -0
- package/dist/esm/queries/index.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/queries/HubConnectionKeepAlive.ts +61 -0
- package/queries/IObservableQueryHubConnection.ts +50 -0
- package/queries/IReconnectPolicy.ts +39 -0
- package/queries/ObservableQueryConnection.ts +8 -24
- package/queries/ObservableQueryConnectionFactory.ts +118 -0
- package/queries/ObservableQueryConnectionPool.ts +64 -0
- package/queries/ObservableQueryFor.ts +11 -5
- package/queries/ObservableQueryMultiplexer.ts +214 -0
- package/queries/QueryInstanceCache.ts +243 -0
- package/queries/QueryTransportMethod.ts +17 -0
- package/queries/ReconnectPolicy.ts +68 -0
- package/queries/ServerSentEventHubConnection.ts +309 -0
- package/queries/ServerSentEventQueryConnection.ts +84 -0
- package/queries/WebSocketHubConnection.ts +291 -0
- package/queries/for_HubConnectionKeepAlive/behavior.ts +73 -0
- package/queries/for_ObservableQueryConnection/given/an_observable_query_connection.ts +13 -9
- package/queries/for_ObservableQueryConnectionFactory/given/a_descriptor.ts +26 -0
- package/queries/for_ObservableQueryConnectionFactory/when_creating/with_direct_mode_and_sse_transport.ts +62 -0
- package/queries/for_ObservableQueryConnectionFactory/when_creating/with_direct_mode_and_websocket_transport.ts +59 -0
- package/queries/for_ObservableQueryConnectionFactory/when_creating/with_hub_mode_and_sse_transport.ts +69 -0
- package/queries/for_ObservableQueryConnectionFactory/when_creating/with_hub_mode_and_websocket_transport.ts +61 -0
- package/queries/for_ObservableQueryConnectionPool/when_acquiring/with_multiple_slots/and_least_loaded_slot_is_chosen.ts +47 -0
- package/queries/for_ObservableQueryConnectionPool/when_acquiring/with_multiple_slots/and_size_is_zero.ts +26 -0
- package/queries/for_ObservableQueryConnectionPool/when_acquiring/with_single_slot/and_one_subscriber.ts +44 -0
- package/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_and_sse_transport.ts +69 -0
- package/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_disabled_and_sse_transport.ts +70 -0
- package/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_enabled.ts +57 -0
- package/queries/for_ObservableQueryFor/when_subscribing/with_partially_missing_required_arguments.ts +19 -11
- package/queries/for_ObservableQueryFor/when_subscribing/with_route_and_query_args.ts +14 -7
- package/queries/for_QueryInstanceCache/when_building_key/with_arguments.ts +17 -0
- package/queries/for_QueryInstanceCache/when_building_key/with_empty_arguments_object.ts +16 -0
- package/queries/for_QueryInstanceCache/when_building_key/with_same_arguments_different_order.ts +18 -0
- package/queries/for_QueryInstanceCache/when_building_key/without_arguments.ts +16 -0
- package/queries/for_QueryInstanceCache/when_getting_last_result/with_no_result_stored.ts +17 -0
- package/queries/for_QueryInstanceCache/when_getting_last_result/with_stored_result.ts +23 -0
- package/queries/for_QueryInstanceCache/when_getting_or_creating/with_existing_entry.ts +29 -0
- package/queries/for_QueryInstanceCache/when_getting_or_creating/with_new_entry.ts +21 -0
- package/queries/for_QueryInstanceCache/when_releasing/a_key_that_does_not_exist.ts +21 -0
- package/queries/for_QueryInstanceCache/when_releasing/one_of_two_subscribers.ts +18 -0
- package/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber.ts +23 -0
- package/queries/for_QueryInstanceCache/when_setting_last_result/with_a_result.ts +20 -0
- package/queries/for_ReconnectPolicy/when_canceling/with_pending_timer.ts +33 -0
- package/queries/for_ReconnectPolicy/when_cancelling/with_pending_timer.ts +33 -0
- package/queries/for_ReconnectPolicy/when_resetting/after_scheduling.ts +39 -0
- package/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_not_reached/delay_is_capped_at_max.ts +44 -0
- package/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_not_reached/first_attempt.ts +38 -0
- package/queries/for_ReconnectPolicy/when_scheduling/and_max_attempts_reached/abandons_reconnect.ts +39 -0
- package/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.ts +85 -0
- package/queries/for_ServerSentEventHubConnection/when_connect_timeout_fires/triggers_reconnect.ts +46 -0
- package/queries/for_ServerSentEventHubConnection/when_disposing/cleans_up_resources.ts +34 -0
- package/queries/for_ServerSentEventHubConnection/when_keep_alive_is_idle/triggers_reconnect.ts +48 -0
- package/queries/for_ServerSentEventHubConnection/when_reconnecting/after_error.ts +62 -0
- package/queries/for_ServerSentEventHubConnection/when_subscribing/queues_until_connected.ts +31 -0
- package/queries/for_ServerSentEventHubConnection/when_subscribing/sends_subscribe_post.ts +42 -0
- package/queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.ts +32 -0
- package/queries/for_ServerSentEventQueryConnection/when_connecting/with_query_arguments.ts +63 -0
- package/queries/for_ServerSentEventQueryConnection/when_connecting/without_event_source_available.ts +31 -0
- package/queries/for_ServerSentEventQueryConnection/when_disconnecting/after_connecting.ts +36 -0
- package/queries/for_ServerSentEventQueryConnection/when_disconnecting/before_message_arrives.ts +38 -0
- package/queries/for_WebSocketHubConnection/given/a_web_socket_hub_connection.ts +81 -0
- package/queries/for_WebSocketHubConnection/when_disposing/cleans_up_resources.ts +31 -0
- package/queries/for_WebSocketHubConnection/when_keep_alive_is_idle/sends_a_ping.ts +47 -0
- package/queries/for_WebSocketHubConnection/when_receiving_a_message/resets_keep_alive_timer.ts +53 -0
- package/queries/for_WebSocketHubConnection/when_reconnecting/after_unexpected_close.ts +41 -0
- package/queries/for_WebSocketHubConnection/when_reconnecting/resubscribes_all_queries.ts +43 -0
- package/queries/for_WebSocketHubConnection/when_subscribing/to_a_query.ts +42 -0
- package/queries/for_WebSocketHubConnection/when_unsubscribing/the_only_query.ts +30 -0
- package/queries/index.ts +12 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Globals.d.ts","sourceRoot":"","sources":["../../Globals.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,QAAQ;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB,EAAE,MAAM,CAAC;IAC/B,2BAA2B,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"Globals.d.ts","sourceRoot":"","sources":["../../Globals.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAEtE,MAAM,WAAW,QAAQ;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB,EAAE,MAAM,CAAC;IAC/B,2BAA2B,EAAE,MAAM,CAAC;IACpC,oBAAoB,EAAE,oBAAoB,CAAC;IAO3C,oBAAoB,EAAE,MAAM,CAAC;IAM7B,eAAe,EAAE,OAAO,CAAC;CAC5B;AAED,eAAO,MAAM,OAAO,EAAE,QASrB,CAAC"}
|
package/dist/esm/Globals.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { QueryTransportMethod } from './queries/QueryTransportMethod.js';
|
|
2
|
+
|
|
1
3
|
const Globals = {
|
|
2
4
|
microservice: '',
|
|
3
5
|
apiBasePath: '',
|
|
4
6
|
origin: '',
|
|
5
7
|
microserviceHttpHeader: 'x-cratis-microservice',
|
|
6
|
-
microserviceWSQueryArgument: 'x-cratis-microservice'
|
|
8
|
+
microserviceWSQueryArgument: 'x-cratis-microservice',
|
|
9
|
+
queryTransportMethod: QueryTransportMethod.WebSocket,
|
|
10
|
+
queryConnectionCount: 1,
|
|
11
|
+
queryDirectMode: false,
|
|
7
12
|
};
|
|
8
13
|
|
|
9
14
|
export { Globals };
|
package/dist/esm/Globals.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Globals.js","sources":["../../Globals.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nexport interface IGlobals {\n microservice: string;\n apiBasePath: string;\n origin: string;\n microserviceHttpHeader: string;\n microserviceWSQueryArgument: string;\n}\n\nexport const Globals: IGlobals = {\n microservice: '',\n apiBasePath: '',\n origin: '',\n microserviceHttpHeader: 'x-cratis-microservice',\n microserviceWSQueryArgument: 'x-cratis-microservice'
|
|
1
|
+
{"version":3,"file":"Globals.js","sources":["../../Globals.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { QueryTransportMethod } from './queries/QueryTransportMethod';\n\nexport interface IGlobals {\n microservice: string;\n apiBasePath: string;\n origin: string;\n microserviceHttpHeader: string;\n microserviceWSQueryArgument: string;\n queryTransportMethod: QueryTransportMethod;\n /**\n * Number of hub connections maintained for observable queries.\n * When greater than one, queries are distributed across the pool round-robin.\n * Only applies when {@link queryTransportMethod} is a centralized hub transport.\n * Defaults to 1.\n */\n queryConnectionCount: number;\n /**\n * When true, observable queries connect directly to the per-query WebSocket URL\n * instead of routing through the centralized hub endpoint.\n * Defaults to false (use the centralized hub).\n */\n queryDirectMode: boolean;\n}\n\nexport const Globals: IGlobals = {\n microservice: '',\n apiBasePath: '',\n origin: '',\n microserviceHttpHeader: 'x-cratis-microservice',\n microserviceWSQueryArgument: 'x-cratis-microservice',\n queryTransportMethod: QueryTransportMethod.WebSocket,\n queryConnectionCount: 1,\n queryDirectMode: false,\n};"],"names":[],"mappings":";;AA2BO,MAAM,OAAO,GAAa;AAC7B,IAAA,YAAY,EAAE,EAAE;AAChB,IAAA,WAAW,EAAE,EAAE;AACf,IAAA,MAAM,EAAE,EAAE;AACV,IAAA,sBAAsB,EAAE,uBAAuB;AAC/C,IAAA,2BAA2B,EAAE,uBAAuB;IACpD,oBAAoB,EAAE,oBAAoB,CAAC,SAAS;AACpD,IAAA,oBAAoB,EAAE,CAAC;AACvB,IAAA,eAAe,EAAE,KAAK;;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class HubConnectionKeepAlive {
|
|
2
|
+
private readonly _intervalMs;
|
|
3
|
+
private readonly _onIdle;
|
|
4
|
+
private _lastActivityTime;
|
|
5
|
+
private _timer?;
|
|
6
|
+
constructor(_intervalMs: number, _onIdle: () => void);
|
|
7
|
+
start(): void;
|
|
8
|
+
stop(): void;
|
|
9
|
+
recordActivity(): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=HubConnectionKeepAlive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HubConnectionKeepAlive.d.ts","sourceRoot":"","sources":["../../../queries/HubConnectionKeepAlive.ts"],"names":[],"mappings":"AAeA,qBAAa,sBAAsB;IAW3B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAX5B,OAAO,CAAC,iBAAiB,CAAc;IACvC,OAAO,CAAC,MAAM,CAAC,CAAiC;gBAS3B,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,IAAI;IAMxC,KAAK,IAAI,IAAI;IAab,IAAI,IAAI,IAAI;IAWZ,cAAc,IAAI,IAAI;CAGzB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
class HubConnectionKeepAlive {
|
|
2
|
+
_intervalMs;
|
|
3
|
+
_onIdle;
|
|
4
|
+
_lastActivityTime = Date.now();
|
|
5
|
+
_timer;
|
|
6
|
+
constructor(_intervalMs, _onIdle) {
|
|
7
|
+
this._intervalMs = _intervalMs;
|
|
8
|
+
this._onIdle = _onIdle;
|
|
9
|
+
}
|
|
10
|
+
start() {
|
|
11
|
+
this.stop();
|
|
12
|
+
this._lastActivityTime = Date.now();
|
|
13
|
+
this._timer = setInterval(() => {
|
|
14
|
+
if (Date.now() - this._lastActivityTime >= this._intervalMs) {
|
|
15
|
+
this._onIdle();
|
|
16
|
+
}
|
|
17
|
+
}, this._intervalMs);
|
|
18
|
+
}
|
|
19
|
+
stop() {
|
|
20
|
+
if (this._timer !== undefined) {
|
|
21
|
+
clearInterval(this._timer);
|
|
22
|
+
this._timer = undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
recordActivity() {
|
|
26
|
+
this._lastActivityTime = Date.now();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { HubConnectionKeepAlive };
|
|
31
|
+
//# sourceMappingURL=HubConnectionKeepAlive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HubConnectionKeepAlive.js","sources":["../../../queries/HubConnectionKeepAlive.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/**\n * Manages keep-alive behavior for hub connections (both WebSocket and Server-Sent Events).\n *\n * Records connection activity (any message received or sent). An interval fires every\n * {@link intervalMs} milliseconds; if no activity has been recorded since the last tick the\n * provided {@link onIdle} callback is invoked — the caller decides whether to send a ping,\n * trigger a reconnect, or take some other action.\n *\n * Both {@link WebSocketHubConnection} and {@link ServerSentEventHubConnection} own one instance\n * of this class so the keep-alive logic is written once and behaves identically for both\n * transports.\n */\nexport class HubConnectionKeepAlive {\n private _lastActivityTime = Date.now();\n private _timer?: ReturnType<typeof setInterval>;\n\n /**\n * Initializes a new instance of {@link HubConnectionKeepAlive}.\n * @param {number} intervalMs How often (in milliseconds) to check for idle connections.\n * @param {() => void} onIdle Callback invoked when the interval fires and no activity has\n * been recorded in the last {@link intervalMs} milliseconds.\n */\n constructor(\n private readonly _intervalMs: number,\n private readonly _onIdle: () => void,\n ) {}\n\n /**\n * Start the keep-alive timer. Safe to call multiple times — a running timer is stopped first.\n */\n start(): void {\n this.stop();\n this._lastActivityTime = Date.now();\n this._timer = setInterval(() => {\n if (Date.now() - this._lastActivityTime >= this._intervalMs) {\n this._onIdle();\n }\n }, this._intervalMs);\n }\n\n /**\n * Stop the keep-alive timer.\n */\n stop(): void {\n if (this._timer !== undefined) {\n clearInterval(this._timer);\n this._timer = undefined;\n }\n }\n\n /**\n * Record that the connection has been active (message sent or received).\n * Resets the idle timer so that a keep-alive is not sent while data is already flowing.\n */\n recordActivity(): void {\n this._lastActivityTime = Date.now();\n }\n}\n"],"names":[],"mappings":"MAea,sBAAsB,CAAA;AAWV,IAAA,WAAA;AACA,IAAA,OAAA;AAXb,IAAA,iBAAiB,GAAG,IAAI,CAAC,GAAG,EAAE;AAC9B,IAAA,MAAM;IAQd,WAAA,CACqB,WAAmB,EACnB,OAAmB,EAAA;QADnB,IAAA,CAAA,WAAW,GAAX,WAAW;QACX,IAAA,CAAA,OAAO,GAAP,OAAO;IACzB;IAKH,KAAK,GAAA;QACD,IAAI,CAAC,IAAI,EAAE;AACX,QAAA,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,GAAG,EAAE;AACnC,QAAA,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,MAAK;AAC3B,YAAA,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAC,WAAW,EAAE;gBACzD,IAAI,CAAC,OAAO,EAAE;YAClB;AACJ,QAAA,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC;IACxB;IAKA,IAAI,GAAA;AACA,QAAA,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE;AAC3B,YAAA,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC;AAC1B,YAAA,IAAI,CAAC,MAAM,GAAG,SAAS;QAC3B;IACJ;IAMA,cAAc,GAAA;AACV,QAAA,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,GAAG,EAAE;IACvC;AACH;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DataReceived } from './ObservableQueryConnection';
|
|
2
|
+
import { SubscriptionRequest } from './WebSocketHubConnection';
|
|
3
|
+
export interface IObservableQueryHubConnection {
|
|
4
|
+
readonly queryCount: number;
|
|
5
|
+
readonly lastPingLatency: number;
|
|
6
|
+
readonly averageLatency: number;
|
|
7
|
+
subscribe(queryId: string, request: SubscriptionRequest, callback: DataReceived<any>): void;
|
|
8
|
+
unsubscribe(queryId: string): void;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=IObservableQueryHubConnection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IObservableQueryHubConnection.d.ts","sourceRoot":"","sources":["../../../queries/IObservableQueryHubConnection.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAW/D,MAAM,WAAW,6BAA6B;IAI1C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAK5B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAKjC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAQhC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAM5F,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAKnC,OAAO,IAAI,IAAI,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IObservableQueryHubConnection.js","sourceRoot":"","sources":["../../../queries/IObservableQueryHubConnection.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IReconnectPolicy.d.ts","sourceRoot":"","sources":["../../../queries/IReconnectPolicy.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC;AAM3C,MAAM,WAAW,gBAAgB;IAI7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IASzB,QAAQ,CAAC,WAAW,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAMjE,KAAK,IAAI,IAAI,CAAC;IAMd,MAAM,IAAI,IAAI,CAAC;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IReconnectPolicy.js","sourceRoot":"","sources":["../../../queries/IReconnectPolicy.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { IObservableQueryConnection } from './IObservableQueryConnection';
|
|
2
|
+
import { IReconnectPolicy } from './IReconnectPolicy';
|
|
2
3
|
import { QueryResult } from './QueryResult';
|
|
3
4
|
export type DataReceived<TDataType> = (data: QueryResult<TDataType>) => void;
|
|
4
5
|
export declare class ObservableQueryConnection<TDataType> implements IObservableQueryConnection<TDataType> {
|
|
5
6
|
private readonly _microservice;
|
|
7
|
+
private readonly _reconnectPolicy;
|
|
6
8
|
private _socket;
|
|
7
9
|
private _disconnected;
|
|
8
10
|
private _url;
|
|
@@ -12,7 +14,7 @@ export declare class ObservableQueryConnection<TDataType> implements IObservable
|
|
|
12
14
|
private _lastPongLatency;
|
|
13
15
|
private _latencySamples;
|
|
14
16
|
private _connectionStartTime?;
|
|
15
|
-
constructor(url: URL, _microservice: string, pingIntervalMs?: number);
|
|
17
|
+
constructor(url: URL, _microservice: string, pingIntervalMs?: number, _reconnectPolicy?: IReconnectPolicy);
|
|
16
18
|
dispose(): void;
|
|
17
19
|
get lastPingLatency(): number;
|
|
18
20
|
get averageLatency(): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableQueryConnection.d.ts","sourceRoot":"","sources":["../../../queries/ObservableQueryConnection.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,MAAM,YAAY,CAAC,SAAS,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;AAK7E,qBAAa,yBAAyB,CAAC,SAAS,CAAE,YAAW,0BAA0B,CAAC,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"ObservableQueryConnection.d.ts","sourceRoot":"","sources":["../../../queries/ObservableQueryConnection.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,MAAM,YAAY,CAAC,SAAS,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;AAK7E,qBAAa,yBAAyB,CAAC,SAAS,CAAE,YAAW,0BAA0B,CAAC,SAAS,CAAC;IAmBxE,OAAO,CAAC,QAAQ,CAAC,aAAa;IAA0C,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAjB/H,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,aAAa,CAAC,CAAiC;IACvD,OAAO,CAAC,eAAe,CAAiB;IACxC,OAAO,CAAC,iBAAiB,CAAC,CAAS;IACnC,OAAO,CAAC,gBAAgB,CAAa;IACrC,OAAO,CAAC,eAAe,CAAgB;IACvC,OAAO,CAAC,oBAAoB,CAAC,CAAS;gBAS1B,GAAG,EAAE,GAAG,EAAmB,aAAa,EAAE,MAAM,EAAE,cAAc,GAAE,MAAc,EAAmB,gBAAgB,GAAE,gBAAwC;IAkBzK,OAAO;IAOP,IAAI,eAAe,IAAI,MAAM,CAE5B;IAKD,IAAI,cAAc,IAAI,MAAM,CAM3B;IAGD,OAAO,CAAC,YAAY,EAAE,YAAY,CAAC,SAAS,CAAC,EAAE,cAAc,CAAC,EAAE,MAAM;IA+CtE,UAAU;IAaV,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,QAAQ;IAchB,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,UAAU;CAYrB"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Globals } from '../Globals.js';
|
|
2
|
+
import { ReconnectPolicy } from './ReconnectPolicy.js';
|
|
2
3
|
import { WebSocketMessageType } from './WebSocketMessage.js';
|
|
3
4
|
|
|
4
5
|
class ObservableQueryConnection {
|
|
5
6
|
_microservice;
|
|
7
|
+
_reconnectPolicy;
|
|
6
8
|
_socket;
|
|
7
9
|
_disconnected = false;
|
|
8
10
|
_url;
|
|
@@ -12,8 +14,9 @@ class ObservableQueryConnection {
|
|
|
12
14
|
_lastPongLatency = 0;
|
|
13
15
|
_latencySamples = [];
|
|
14
16
|
_connectionStartTime;
|
|
15
|
-
constructor(url, _microservice, pingIntervalMs = 10000) {
|
|
17
|
+
constructor(url, _microservice, pingIntervalMs = 10000, _reconnectPolicy = new ReconnectPolicy()) {
|
|
16
18
|
this._microservice = _microservice;
|
|
19
|
+
this._reconnectPolicy = _reconnectPolicy;
|
|
17
20
|
this._pingIntervalMs = pingIntervalMs;
|
|
18
21
|
const secure = url.protocol?.indexOf('https') === 0 || false;
|
|
19
22
|
this._url = `${secure ? 'wss' : 'ws'}://${url.host}${url.pathname}${url.search}`;
|
|
@@ -52,30 +55,13 @@ class ObservableQueryConnection {
|
|
|
52
55
|
const query = Object.keys(queryArguments).map(key => `${key}=${queryArguments[key]}`).join('&');
|
|
53
56
|
url = `${url}${query}`;
|
|
54
57
|
}
|
|
55
|
-
let timeToWait = 500;
|
|
56
|
-
const timeExponent = 500;
|
|
57
|
-
const retries = 100;
|
|
58
|
-
let currentAttempt = 0;
|
|
59
|
-
const maxTime = 10_000;
|
|
60
58
|
const connectSocket = () => {
|
|
61
|
-
const retry = () => {
|
|
62
|
-
currentAttempt++;
|
|
63
|
-
if (currentAttempt > retries) {
|
|
64
|
-
console.log(`Attempted ${retries} retries for route '${url}'. Abandoning.`);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
console.log(`Attempting to reconnect for '${url}' (#${currentAttempt})`);
|
|
68
|
-
setTimeout(connectSocket, timeToWait);
|
|
69
|
-
timeToWait += (timeExponent * currentAttempt);
|
|
70
|
-
timeToWait = timeToWait > maxTime ? maxTime : timeToWait;
|
|
71
|
-
};
|
|
72
59
|
this._socket = new WebSocket(url);
|
|
73
60
|
this._socket.onopen = () => {
|
|
74
61
|
if (this._disconnected)
|
|
75
62
|
return;
|
|
76
63
|
console.log(`Connection for '${url}' established`);
|
|
77
|
-
|
|
78
|
-
currentAttempt = 0;
|
|
64
|
+
this._reconnectPolicy.reset();
|
|
79
65
|
this._connectionStartTime = Date.now();
|
|
80
66
|
this.startPinging();
|
|
81
67
|
};
|
|
@@ -84,14 +70,14 @@ class ObservableQueryConnection {
|
|
|
84
70
|
return;
|
|
85
71
|
console.log(`Unexpected connection closed for route '${url}'`);
|
|
86
72
|
this.stopPinging();
|
|
87
|
-
|
|
73
|
+
this._reconnectPolicy.schedule(connectSocket, url);
|
|
88
74
|
};
|
|
89
75
|
this._socket.onerror = (error) => {
|
|
90
76
|
if (this._disconnected)
|
|
91
77
|
return;
|
|
92
78
|
console.log(`Error with connection for '${url}' - ${error}`);
|
|
93
79
|
this.stopPinging();
|
|
94
|
-
|
|
80
|
+
this._reconnectPolicy.schedule(connectSocket, url);
|
|
95
81
|
};
|
|
96
82
|
this._socket.onmessage = (ev) => {
|
|
97
83
|
if (this._disconnected) {
|
|
@@ -111,6 +97,7 @@ class ObservableQueryConnection {
|
|
|
111
97
|
}
|
|
112
98
|
console.log(`Disconnecting '${this._url}'`);
|
|
113
99
|
this._disconnected = true;
|
|
100
|
+
this._reconnectPolicy.cancel();
|
|
114
101
|
this.stopPinging();
|
|
115
102
|
this._socket?.close();
|
|
116
103
|
console.log(`Connection for '${this._url}' closed`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableQueryConnection.js","sources":["../../../queries/ObservableQueryConnection.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Globals } from '../Globals';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { QueryResult } from './QueryResult';\nimport { WebSocketMessage, WebSocketMessageType } from './WebSocketMessage';\n\nexport type DataReceived<TDataType> = (data: QueryResult<TDataType>) => void;\n\n/**\n * Represents the connection for an observable query.\n */\nexport class ObservableQueryConnection<TDataType> implements IObservableQueryConnection<TDataType> {\n\n private _socket!: WebSocket;\n private _disconnected = false;\n private _url: string;\n private _pingInterval?: ReturnType<typeof setInterval>;\n private _pingIntervalMs: number = 10000;\n private _lastPingSentTime?: number;\n private _lastPongLatency: number = 0;\n private _latencySamples: number[] = [];\n private _connectionStartTime?: number;\n\n /**\n * Initializes a new instance of the {@link ObservableQueryConnection<TDataType>} class.\n * @param {Url} url The fully qualified Url.\n * @param {string} _microservice The microservice name.\n * @param {number} pingIntervalMs The ping interval in milliseconds (default: 10000).\n */\n constructor(url: URL, private readonly _microservice: string, pingIntervalMs: number = 10000) {\n this._pingIntervalMs = pingIntervalMs;\n const secure = url.protocol?.indexOf('https') === 0 || false;\n\n this._url = `${secure ? 'wss' : 'ws'}://${url.host}${url.pathname}${url.search}`;\n if (this._microservice?.length > 0) {\n const microserviceParam = `${Globals.microserviceWSQueryArgument}=${this._microservice}`;\n if (this._url.indexOf('?') > 0) {\n this._url = `${this._url}&${microserviceParam}`;\n } else {\n this._url = `${this._url}?${microserviceParam}`;\n }\n }\n }\n\n /**\n * Disposes the connection.\n */\n dispose() {\n this.disconnect();\n }\n\n /**\n * Gets the latency of the last ping/pong sequence in milliseconds.\n */\n get lastPingLatency(): number {\n return this._lastPongLatency;\n }\n\n /**\n * Gets the average latency since the connection started in milliseconds.\n */\n get averageLatency(): number {\n if (this._latencySamples.length === 0) {\n return 0;\n }\n const sum = this._latencySamples.reduce((acc, val) => acc + val, 0);\n return sum / this._latencySamples.length;\n }\n\n /** @inheritdoc */\n connect(dataReceived: DataReceived<TDataType>, queryArguments?: object) {\n let url = this._url;\n if (queryArguments) {\n if (url.indexOf('?') < 0) {\n url = `${url}?`;\n } else {\n url = `${url}&`;\n }\n const query = Object.keys(queryArguments).map(key => `${key}=${queryArguments[key]}`).join('&');\n url = `${url}${query}`;\n }\n\n let timeToWait = 500;\n const timeExponent = 500;\n const retries = 100;\n let currentAttempt = 0;\n const maxTime = 10_000;\n\n const connectSocket = () => {\n const retry = () => {\n currentAttempt++;\n if (currentAttempt > retries) {\n console.log(`Attempted ${retries} retries for route '${url}'. Abandoning.`);\n return;\n }\n console.log(`Attempting to reconnect for '${url}' (#${currentAttempt})`);\n\n setTimeout(connectSocket, timeToWait);\n timeToWait += (timeExponent * currentAttempt);\n timeToWait = timeToWait > maxTime ? maxTime : timeToWait; \n };\n\n this._socket = new WebSocket(url);\n this._socket.onopen = () => {\n if (this._disconnected) return;\n console.log(`Connection for '${url}' established`);\n timeToWait = 500;\n currentAttempt = 0;\n this._connectionStartTime = Date.now();\n this.startPinging();\n };\n this._socket.onclose = () => {\n if (this._disconnected) return;\n console.log(`Unexpected connection closed for route '${url}'`);\n this.stopPinging();\n retry();\n };\n this._socket.onerror = (error) => {\n if (this._disconnected) return;\n console.log(`Error with connection for '${url}' - ${error}`);\n this.stopPinging();\n retry();\n };\n this._socket.onmessage = (ev) => {\n if (this._disconnected) {\n console.log('Received message after closing connection');\n return;\n }\n this.handleMessage(ev.data, dataReceived);\n };\n };\n\n if (this._disconnected) return;\n connectSocket();\n }\n\n /** @inheritdoc */\n disconnect() {\n if (this._disconnected) {\n return;\n }\n console.log(`Disconnecting '${this._url}'`);\n this._disconnected = true;\n this.stopPinging();\n this._socket?.close();\n console.log(`Connection for '${this._url}' closed`);\n this._socket = undefined!;\n }\n\n private startPinging() {\n this.stopPinging();\n this._pingInterval = setInterval(() => {\n this.sendPing();\n }, this._pingIntervalMs);\n }\n\n private stopPinging() {\n if (this._pingInterval) {\n clearInterval(this._pingInterval);\n this._pingInterval = undefined;\n }\n }\n\n private sendPing() {\n if (this._disconnected || !this._socket || this._socket.readyState !== WebSocket.OPEN) {\n return;\n }\n\n this._lastPingSentTime = Date.now();\n const pingMessage: WebSocketMessage = {\n type: WebSocketMessageType.Ping,\n timestamp: this._lastPingSentTime\n };\n\n this._socket.send(JSON.stringify(pingMessage));\n }\n\n private handleMessage(rawData: string, dataReceived: DataReceived<TDataType>) {\n try {\n const message = JSON.parse(rawData) as WebSocketMessage;\n\n // Handle messages based on type\n if (message.type === WebSocketMessageType.Pong) {\n this.handlePong(message);\n } else if (message.type === WebSocketMessageType.Data || !message.type) {\n // For backward compatibility, treat messages without a type as data messages\n const data = message.data ?? message;\n dataReceived(data as QueryResult<TDataType>);\n }\n } catch (error) {\n console.error('Error parsing WebSocket message:', error);\n }\n }\n\n private handlePong(message: WebSocketMessage) {\n if (message.timestamp && this._lastPingSentTime) {\n const latency = Date.now() - message.timestamp;\n this._lastPongLatency = latency;\n this._latencySamples.push(latency);\n\n // Keep only the last 100 samples for average calculation\n if (this._latencySamples.length > 100) {\n this._latencySamples.shift();\n }\n }\n }\n}\n"],"names":[],"mappings":";;;MAaa,yBAAyB,CAAA;AAkBK,IAAA,aAAA;AAhB/B,IAAA,OAAO;IACP,aAAa,GAAG,KAAK;AACrB,IAAA,IAAI;AACJ,IAAA,aAAa;IACb,eAAe,GAAW,KAAK;AAC/B,IAAA,iBA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ableQueryConnection.js","sources":["../../../queries/ObservableQueryConnection.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Globals } from '../Globals';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { IReconnectPolicy } from './IReconnectPolicy';\nimport { ReconnectPolicy } from './ReconnectPolicy';\nimport { QueryResult } from './QueryResult';\nimport { WebSocketMessage, WebSocketMessageType } from './WebSocketMessage';\n\nexport type DataReceived<TDataType> = (data: QueryResult<TDataType>) => void;\n\n/**\n * Represents the connection for an observable query.\n */\nexport class ObservableQueryConnection<TDataType> implements IObservableQueryConnection<TDataType> {\n\n private _socket!: WebSocket;\n private _disconnected = false;\n private _url: string;\n private _pingInterval?: ReturnType<typeof setInterval>;\n private _pingIntervalMs: number = 10000;\n private _lastPingSentTime?: number;\n private _lastPongLatency: number = 0;\n private _latencySamples: number[] = [];\n private _connectionStartTime?: number;\n\n /**\n * Initializes a new instance of the {@link ObservableQueryConnection<TDataType>} class.\n * @param {Url} url The fully qualified Url.\n * @param {string} _microservice The microservice name.\n * @param {number} pingIntervalMs The ping interval in milliseconds (default: 10000).\n * @param {IReconnectPolicy} reconnectPolicy The reconnect policy to use (default: {@link ReconnectPolicy}).\n */\n constructor(url: URL, private readonly _microservice: string, pingIntervalMs: number = 10000, private readonly _reconnectPolicy: IReconnectPolicy = new ReconnectPolicy()) {\n this._pingIntervalMs = pingIntervalMs;\n const secure = url.protocol?.indexOf('https') === 0 || false;\n\n this._url = `${secure ? 'wss' : 'ws'}://${url.host}${url.pathname}${url.search}`;\n if (this._microservice?.length > 0) {\n const microserviceParam = `${Globals.microserviceWSQueryArgument}=${this._microservice}`;\n if (this._url.indexOf('?') > 0) {\n this._url = `${this._url}&${microserviceParam}`;\n } else {\n this._url = `${this._url}?${microserviceParam}`;\n }\n }\n }\n\n /**\n * Disposes the connection.\n */\n dispose() {\n this.disconnect();\n }\n\n /**\n * Gets the latency of the last ping/pong sequence in milliseconds.\n */\n get lastPingLatency(): number {\n return this._lastPongLatency;\n }\n\n /**\n * Gets the average latency since the connection started in milliseconds.\n */\n get averageLatency(): number {\n if (this._latencySamples.length === 0) {\n return 0;\n }\n const sum = this._latencySamples.reduce((acc, val) => acc + val, 0);\n return sum / this._latencySamples.length;\n }\n\n /** @inheritdoc */\n connect(dataReceived: DataReceived<TDataType>, queryArguments?: object) {\n let url = this._url;\n if (queryArguments) {\n if (url.indexOf('?') < 0) {\n url = `${url}?`;\n } else {\n url = `${url}&`;\n }\n const query = Object.keys(queryArguments).map(key => `${key}=${queryArguments[key]}`).join('&');\n url = `${url}${query}`;\n }\n\n const connectSocket = () => {\n this._socket = new WebSocket(url);\n this._socket.onopen = () => {\n if (this._disconnected) return;\n console.log(`Connection for '${url}' established`);\n this._reconnectPolicy.reset();\n this._connectionStartTime = Date.now();\n this.startPinging();\n };\n this._socket.onclose = () => {\n if (this._disconnected) return;\n console.log(`Unexpected connection closed for route '${url}'`);\n this.stopPinging();\n this._reconnectPolicy.schedule(connectSocket, url);\n };\n this._socket.onerror = (error) => {\n if (this._disconnected) return;\n console.log(`Error with connection for '${url}' - ${error}`);\n this.stopPinging();\n this._reconnectPolicy.schedule(connectSocket, url);\n };\n this._socket.onmessage = (ev) => {\n if (this._disconnected) {\n console.log('Received message after closing connection');\n return;\n }\n this.handleMessage(ev.data, dataReceived);\n };\n };\n\n if (this._disconnected) return;\n connectSocket();\n }\n\n /** @inheritdoc */\n disconnect() {\n if (this._disconnected) {\n return;\n }\n console.log(`Disconnecting '${this._url}'`);\n this._disconnected = true;\n this._reconnectPolicy.cancel();\n this.stopPinging();\n this._socket?.close();\n console.log(`Connection for '${this._url}' closed`);\n this._socket = undefined!;\n }\n\n private startPinging() {\n this.stopPinging();\n this._pingInterval = setInterval(() => {\n this.sendPing();\n }, this._pingIntervalMs);\n }\n\n private stopPinging() {\n if (this._pingInterval) {\n clearInterval(this._pingInterval);\n this._pingInterval = undefined;\n }\n }\n\n private sendPing() {\n if (this._disconnected || !this._socket || this._socket.readyState !== WebSocket.OPEN) {\n return;\n }\n\n this._lastPingSentTime = Date.now();\n const pingMessage: WebSocketMessage = {\n type: WebSocketMessageType.Ping,\n timestamp: this._lastPingSentTime\n };\n\n this._socket.send(JSON.stringify(pingMessage));\n }\n\n private handleMessage(rawData: string, dataReceived: DataReceived<TDataType>) {\n try {\n const message = JSON.parse(rawData) as WebSocketMessage;\n\n // Handle messages based on type\n if (message.type === WebSocketMessageType.Pong) {\n this.handlePong(message);\n } else if (message.type === WebSocketMessageType.Data || !message.type) {\n // For backward compatibility, treat messages without a type as data messages\n const data = message.data ?? message;\n dataReceived(data as QueryResult<TDataType>);\n }\n } catch (error) {\n console.error('Error parsing WebSocket message:', error);\n }\n }\n\n private handlePong(message: WebSocketMessage) {\n if (message.timestamp && this._lastPingSentTime) {\n const latency = Date.now() - message.timestamp;\n this._lastPongLatency = latency;\n this._latencySamples.push(latency);\n\n // Keep only the last 100 samples for average calculation\n if (this._latencySamples.length > 100) {\n this._latencySamples.shift();\n }\n }\n }\n}\n"],"names":[],"mappings":";;;;MAea,yBAAyB,CAAA;AAmBK,IAAA,aAAA;AAAwE,IAAA,gBAAA;AAjBvG,IAAA,OAAO;IACP,aAAa,GAAG,KAAK;AACrB,IAAA,IAAI;AACJ,IAAA,aAAa;IACb,eAAe,GAAW,KAAK;AAC/B,IAAA,iBAAiB;IACjB,gBAAgB,GAAW,CAAC;IAC5B,eAAe,GAAa,EAAE;AAC9B,IAAA,oBAAoB;IAS5B,WAAA,CAAY,GAAQ,EAAmB,aAAqB,EAAE,cAAA,GAAyB,KAAK,EAAmB,gBAAA,GAAqC,IAAI,eAAe,EAAE,EAAA;QAAlI,IAAA,CAAA,aAAa,GAAb,aAAa;QAA2D,IAAA,CAAA,gBAAgB,GAAhB,gBAAgB;AAC3H,QAAA,IAAI,CAAC,eAAe,GAAG,cAAc;AACrC,QAAA,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,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UAAU,CAAC,OAAyB,EAAA;QACxC,IAAI,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,iBAAiB,EAAE;YAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,SAAS;AAC9C,YAAA,IAAI,CAAC,gBAAgB,GAAG,OAAO;AAC/B,YAAA,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC;YAGlC,IAAI,IAAI,CAAC,eAAe,CAAC,MAAM,GAAG,GAAG,EAAE;AACnC,gBAAA,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE;YAChC;QACJ;IACJ;AACH;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IObservableQueryConnection } from './IObservableQueryConnection';
|
|
2
|
+
export declare const SSE_SUBSCRIBE_ROUTE = "/.cratis/queries/sse/subscribe";
|
|
3
|
+
export declare const SSE_UNSUBSCRIBE_ROUTE = "/.cratis/queries/sse/unsubscribe";
|
|
4
|
+
export interface QueryConnectionDescriptor {
|
|
5
|
+
route: string;
|
|
6
|
+
queryName: string;
|
|
7
|
+
origin: string;
|
|
8
|
+
apiBasePath: string;
|
|
9
|
+
microservice: string;
|
|
10
|
+
args?: object;
|
|
11
|
+
}
|
|
12
|
+
export declare function createObservableQueryConnection<TDataType>(descriptor: QueryConnectionDescriptor): IObservableQueryConnection<TDataType>;
|
|
13
|
+
//# sourceMappingURL=ObservableQueryConnectionFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObservableQueryConnectionFactory.d.ts","sourceRoot":"","sources":["../../../queries/ObservableQueryConnectionFactory.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAW1E,eAAO,MAAM,mBAAmB,mCAAmC,CAAC;AAKpE,eAAO,MAAM,qBAAqB,qCAAqC,CAAC;AAOxE,MAAM,WAAW,yBAAyB;IAEtC,KAAK,EAAE,MAAM,CAAC;IAEd,SAAS,EAAE,MAAM,CAAC;IAElB,MAAM,EAAE,MAAM,CAAC;IAEf,WAAW,EAAE,MAAM,CAAC;IAEpB,YAAY,EAAE,MAAM,CAAC;IAErB,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAiBD,wBAAgB,+BAA+B,CAAC,SAAS,EAAE,UAAU,EAAE,yBAAyB,GAAG,0BAA0B,CAAC,SAAS,CAAC,CAUvI"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Globals } from '../Globals.js';
|
|
2
|
+
import { joinPaths } from '../joinPaths.js';
|
|
3
|
+
import { UrlHelpers } from '../UrlHelpers.js';
|
|
4
|
+
import { ObservableQueryConnection } from './ObservableQueryConnection.js';
|
|
5
|
+
import { QueryTransportMethod } from './QueryTransportMethod.js';
|
|
6
|
+
import { ServerSentEventQueryConnection, SSE_HUB_ROUTE } from './ServerSentEventQueryConnection.js';
|
|
7
|
+
import { ServerSentEventHubConnection } from './ServerSentEventHubConnection.js';
|
|
8
|
+
import { WebSocketHubConnection } from './WebSocketHubConnection.js';
|
|
9
|
+
import { getOrCreateMultiplexer, WS_HUB_ROUTE, MultiplexedObservableQueryConnection } from './ObservableQueryMultiplexer.js';
|
|
10
|
+
|
|
11
|
+
const SSE_SUBSCRIBE_ROUTE = '/.cratis/queries/sse/subscribe';
|
|
12
|
+
const SSE_UNSUBSCRIBE_ROUTE = '/.cratis/queries/sse/unsubscribe';
|
|
13
|
+
function createObservableQueryConnection(descriptor) {
|
|
14
|
+
const isSSE = Globals.queryTransportMethod === QueryTransportMethod.ServerSentEvents;
|
|
15
|
+
if (Globals.queryDirectMode) {
|
|
16
|
+
return isSSE
|
|
17
|
+
? createDirectSSEConnection(descriptor)
|
|
18
|
+
: createDirectWebSocketConnection(descriptor);
|
|
19
|
+
}
|
|
20
|
+
return createMultiplexedConnection(descriptor, isSSE);
|
|
21
|
+
}
|
|
22
|
+
function buildDirectUrl(descriptor) {
|
|
23
|
+
const { route } = UrlHelpers.replaceRouteParameters(descriptor.route, descriptor.args);
|
|
24
|
+
const actualRoute = joinPaths(descriptor.apiBasePath, route);
|
|
25
|
+
return UrlHelpers.createUrlFrom(descriptor.origin, descriptor.apiBasePath, actualRoute);
|
|
26
|
+
}
|
|
27
|
+
function createDirectWebSocketConnection(descriptor) {
|
|
28
|
+
return new ObservableQueryConnection(buildDirectUrl(descriptor), descriptor.microservice);
|
|
29
|
+
}
|
|
30
|
+
function createDirectSSEConnection(descriptor) {
|
|
31
|
+
return new ServerSentEventQueryConnection(buildDirectUrl(descriptor));
|
|
32
|
+
}
|
|
33
|
+
function createMultiplexedConnection(descriptor, isSSE) {
|
|
34
|
+
const transport = isSSE ? 'sse' : 'ws';
|
|
35
|
+
const cacheKey = `${Globals.queryConnectionCount}|${transport}|${descriptor.origin}|${descriptor.apiBasePath}|${descriptor.microservice}`;
|
|
36
|
+
const multiplexer = getOrCreateMultiplexer(() => {
|
|
37
|
+
if (isSSE) {
|
|
38
|
+
const sseRoute = joinPaths(descriptor.apiBasePath, SSE_HUB_ROUTE);
|
|
39
|
+
const sseUrl = UrlHelpers.createUrlFrom(descriptor.origin, descriptor.apiBasePath, sseRoute);
|
|
40
|
+
const subscribeRoute = joinPaths(descriptor.apiBasePath, SSE_SUBSCRIBE_ROUTE);
|
|
41
|
+
const subscribeUrl = UrlHelpers.createUrlFrom(descriptor.origin, descriptor.apiBasePath, subscribeRoute);
|
|
42
|
+
const unsubscribeRoute = joinPaths(descriptor.apiBasePath, SSE_UNSUBSCRIBE_ROUTE);
|
|
43
|
+
const unsubscribeUrl = UrlHelpers.createUrlFrom(descriptor.origin, descriptor.apiBasePath, unsubscribeRoute);
|
|
44
|
+
return new ServerSentEventHubConnection(sseUrl.toString(), subscribeUrl.toString(), unsubscribeUrl.toString(), descriptor.microservice);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const hubRoute = joinPaths(descriptor.apiBasePath, WS_HUB_ROUTE);
|
|
48
|
+
const hubUrl = UrlHelpers.createUrlFrom(descriptor.origin, descriptor.apiBasePath, hubRoute);
|
|
49
|
+
const secure = hubUrl.protocol?.indexOf('https') === 0;
|
|
50
|
+
const wsUrl = `${secure ? 'wss' : 'ws'}://${hubUrl.host}${hubUrl.pathname}${hubUrl.search}`;
|
|
51
|
+
return new WebSocketHubConnection(wsUrl, descriptor.microservice);
|
|
52
|
+
}
|
|
53
|
+
}, cacheKey);
|
|
54
|
+
return new MultiplexedObservableQueryConnection(multiplexer, descriptor.queryName);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { SSE_SUBSCRIBE_ROUTE, SSE_UNSUBSCRIBE_ROUTE, createObservableQueryConnection };
|
|
58
|
+
//# sourceMappingURL=ObservableQueryConnectionFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObservableQueryConnectionFactory.js","sources":["../../../queries/ObservableQueryConnectionFactory.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { ObservableQueryConnection } from './ObservableQueryConnection';\nimport { QueryTransportMethod } from './QueryTransportMethod';\nimport { ServerSentEventQueryConnection, SSE_HUB_ROUTE } from './ServerSentEventQueryConnection';\nimport { ServerSentEventHubConnection } from './ServerSentEventHubConnection';\nimport { WebSocketHubConnection } from './WebSocketHubConnection';\nimport { MultiplexedObservableQueryConnection, WS_HUB_ROUTE, getOrCreateMultiplexer } from './ObservableQueryMultiplexer';\n\n/**\n * The SSE subscribe POST endpoint route.\n */\nexport const SSE_SUBSCRIBE_ROUTE = '/.cratis/queries/sse/subscribe';\n\n/**\n * The SSE unsubscribe POST endpoint route.\n */\nexport const SSE_UNSUBSCRIBE_ROUTE = '/.cratis/queries/sse/unsubscribe';\n\n/**\n * Describes what the factory needs to know about a query in order to create\n * the right connection. Transport details are intentionally absent — the\n * factory reads those from {@link Globals}.\n */\nexport interface QueryConnectionDescriptor {\n /** The route template (e.g. `/api/accounts/debit/all-accounts`). */\n route: string;\n /** Fully-qualified backend query name used by hub transports. */\n queryName: string;\n /** Origin base URL (e.g. `http://localhost:5000`). */\n origin: string;\n /** API base path prefix. */\n apiBasePath: string;\n /** Microservice identifier. */\n microservice: string;\n /** Route/query arguments for the current subscription. */\n args?: object;\n}\n\n/**\n * Single entry-point for creating observable query connections.\n *\n * The transport is chosen as a 2x2 matrix of (direct | hub) x (WebSocket | SSE):\n *\n * | | Direct (per-query URL) | Hub (centralized endpoint) |\n * |----------------|-------------------------------|-------------------------------|\n * | **WebSocket** | ObservableQueryConnection | MultiplexedObservableQueryConnection |\n * | **SSE** | ServerSentEventQueryConnection | MultiplexedObservableQueryConnection |\n *\n * In multiplexed mode, both transports share the same multiplexer — it creates either\n * WebSocket or SSE connections depending on the transport setting.\n *\n * {@link ObservableQueryFor} never needs to know which transport is in use.\n */\nexport function createObservableQueryConnection<TDataType>(descriptor: QueryConnectionDescriptor): IObservableQueryConnection<TDataType> {\n const isSSE = Globals.queryTransportMethod === QueryTransportMethod.ServerSentEvents;\n\n if (Globals.queryDirectMode) {\n return isSSE\n ? createDirectSSEConnection<TDataType>(descriptor)\n : createDirectWebSocketConnection<TDataType>(descriptor);\n }\n\n return createMultiplexedConnection<TDataType>(descriptor, isSSE);\n}\n\n// ---- Direct mode: one connection per query, hitting the query's own URL ----\n\nfunction buildDirectUrl(descriptor: QueryConnectionDescriptor): URL {\n const { route } = UrlHelpers.replaceRouteParameters(descriptor.route, descriptor.args as object);\n const actualRoute = joinPaths(descriptor.apiBasePath, route);\n return UrlHelpers.createUrlFrom(descriptor.origin, descriptor.apiBasePath, actualRoute);\n}\n\nfunction createDirectWebSocketConnection<TDataType>(descriptor: QueryConnectionDescriptor): IObservableQueryConnection<TDataType> {\n return new ObservableQueryConnection<TDataType>(buildDirectUrl(descriptor), descriptor.microservice);\n}\n\nfunction createDirectSSEConnection<TDataType>(descriptor: QueryConnectionDescriptor): IObservableQueryConnection<TDataType> {\n return new ServerSentEventQueryConnection<TDataType>(buildDirectUrl(descriptor));\n}\n\n// ---- Multiplexed mode: centralized endpoint, multiple queries share connections ----\n\nfunction createMultiplexedConnection<TDataType>(descriptor: QueryConnectionDescriptor, isSSE: boolean): IObservableQueryConnection<TDataType> {\n const transport = isSSE ? 'sse' : 'ws';\n const cacheKey = `${Globals.queryConnectionCount}|${transport}|${descriptor.origin}|${descriptor.apiBasePath}|${descriptor.microservice}`;\n\n const multiplexer = getOrCreateMultiplexer(() => {\n if (isSSE) {\n const sseRoute = joinPaths(descriptor.apiBasePath, SSE_HUB_ROUTE);\n const sseUrl = UrlHelpers.createUrlFrom(descriptor.origin, descriptor.apiBasePath, sseRoute);\n const subscribeRoute = joinPaths(descriptor.apiBasePath, SSE_SUBSCRIBE_ROUTE);\n const subscribeUrl = UrlHelpers.createUrlFrom(descriptor.origin, descriptor.apiBasePath, subscribeRoute);\n const unsubscribeRoute = joinPaths(descriptor.apiBasePath, SSE_UNSUBSCRIBE_ROUTE);\n const unsubscribeUrl = UrlHelpers.createUrlFrom(descriptor.origin, descriptor.apiBasePath, unsubscribeRoute);\n return new ServerSentEventHubConnection(\n sseUrl.toString(),\n subscribeUrl.toString(),\n unsubscribeUrl.toString(),\n descriptor.microservice,\n );\n } else {\n const hubRoute = joinPaths(descriptor.apiBasePath, WS_HUB_ROUTE);\n const hubUrl = UrlHelpers.createUrlFrom(descriptor.origin, descriptor.apiBasePath, hubRoute);\n const secure = hubUrl.protocol?.indexOf('https') === 0;\n const wsUrl = `${secure ? 'wss' : 'ws'}://${hubUrl.host}${hubUrl.pathname}${hubUrl.search}`;\n return new WebSocketHubConnection(wsUrl, descriptor.microservice);\n }\n }, cacheKey);\n\n return new MultiplexedObservableQueryConnection<TDataType>(multiplexer, descriptor.queryName);\n}\n"],"names":[],"mappings":";;;;;;;;;;AA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,CAAA,EAAG,MAAM,CAAC,MAAM,CAAA,CAAE;YAC3F,OAAO,IAAI,sBAAsB,CAAC,KAAK,EAAE,UAAU,CAAC,YAAY,CAAC;QACrE;IACJ,CAAC,EAAE,QAAQ,CAAC;IAEZ,OAAO,IAAI,oCAAoC,CAAY,WAAW,EAAE,UAAU,CAAC,SAAS,CAAC;AACjG;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IObservableQueryConnection } from './IObservableQueryConnection';
|
|
2
|
+
import { DataReceived } from './ObservableQueryConnection';
|
|
3
|
+
export declare class ObservableQueryConnectionPool<TDataType> {
|
|
4
|
+
private readonly _factory;
|
|
5
|
+
private readonly _slots;
|
|
6
|
+
constructor(size: number, _factory: () => IObservableQueryConnection<TDataType>);
|
|
7
|
+
acquire(dataReceived: DataReceived<TDataType>, queryArguments?: object): () => void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=ObservableQueryConnectionPool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObservableQueryConnectionPool.d.ts","sourceRoot":"","sources":["../../../queries/ObservableQueryConnectionPool.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAuB3D,qBAAa,6BAA6B,CAAC,SAAS;IAU5C,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAT7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAa;gBAQhC,IAAI,EAAE,MAAM,EACK,QAAQ,EAAE,MAAM,0BAA0B,CAAC,SAAS,CAAC;IAY1E,OAAO,CAAC,YAAY,EAAE,YAAY,CAAC,SAAS,CAAC,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,IAAI;CActF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class ObservableQueryConnectionPool {
|
|
2
|
+
_factory;
|
|
3
|
+
_slots;
|
|
4
|
+
constructor(size, _factory) {
|
|
5
|
+
this._factory = _factory;
|
|
6
|
+
this._slots = Array.from({ length: Math.max(1, size) }, () => ({ queryCount: 0 }));
|
|
7
|
+
}
|
|
8
|
+
acquire(dataReceived, queryArguments) {
|
|
9
|
+
const slot = this._slots.reduce((min, current) => current.queryCount < min.queryCount ? current : min, this._slots[0]);
|
|
10
|
+
slot.queryCount++;
|
|
11
|
+
const connection = this._factory();
|
|
12
|
+
connection.connect(dataReceived, queryArguments);
|
|
13
|
+
return () => {
|
|
14
|
+
connection.disconnect();
|
|
15
|
+
slot.queryCount = Math.max(0, slot.queryCount - 1);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { ObservableQueryConnectionPool };
|
|
21
|
+
//# sourceMappingURL=ObservableQueryConnectionPool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObservableQueryConnectionPool.js","sources":["../../../queries/ObservableQueryConnectionPool.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { DataReceived } from './ObservableQueryConnection';\n\n/**\n * Tracks the number of active subscribers assigned to each pool slot.\n */\ninterface PoolSlot {\n queryCount: number;\n}\n\n/**\n * Represents a pool of observable query connection factories distributed round-robin across N slots.\n *\n * Each call to {@link acquire} picks the slot with the fewest active queries (falling back to\n * round-robin when counts are equal) and creates a fresh connection for that subscriber via the\n * provided factory. The connection is a dedicated instance per subscriber; the pool only tracks\n * slot utilization so future multiplexed transports (e.g. WebSocket) can share connections\n * across a fixed number of physical hub connections.\n *\n * When {@link size} is 1 (the default), all queries are counted against a single slot — the\n * natural behavior for a single multiplexed connection.\n *\n * @template TDataType The type of data received from the connections.\n */\nexport class ObservableQueryConnectionPool<TDataType> {\n private readonly _slots: PoolSlot[];\n\n /**\n * Initializes a new {@link ObservableQueryConnectionPool}.\n * @param {number} size Number of logical slots (hub connections) in the pool.\n * @param {() => IObservableQueryConnection<TDataType>} factory Factory that produces a new connection instance per subscriber.\n */\n constructor(\n size: number,\n private readonly _factory: () => IObservableQueryConnection<TDataType>\n ) {\n this._slots = Array.from({ length: Math.max(1, size) }, () => ({ queryCount: 0 }));\n }\n\n /**\n * Picks the least-loaded pool slot, creates a fresh connection via the factory, and starts\n * delivering data to the provided callback.\n * @param {DataReceived<TDataType>} dataReceived Callback invoked for each message.\n * @param {object} queryArguments Arguments forwarded to the connection.\n * @returns A cleanup function that decrements the slot counter and disconnects the connection.\n */\n acquire(dataReceived: DataReceived<TDataType>, queryArguments?: object): () => void {\n // Pick the slot with the fewest active queries.\n const slot = this._slots.reduce((min, current) => current.queryCount < min.queryCount ? current : min, this._slots[0]);\n slot.queryCount++;\n\n // Each subscriber gets its own dedicated connection instance.\n const connection = this._factory();\n connection.connect(dataReceived, queryArguments);\n\n return () => {\n connection.disconnect();\n slot.queryCount = Math.max(0, slot.queryCount - 1);\n };\n }\n}\n"],"names":[],"mappings":"MA2Ba,6BAA6B,CAAA;AAUjB,IAAA,QAAA;AATJ,IAAA,MAAM;IAOvB,WAAA,CACI,IAAY,EACK,QAAqD,EAAA;QAArD,IAAA,CAAA,QAAQ,GAAR,QAAQ;AAEzB,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC;IACtF;IASA,OAAO,CAAC,YAAqC,EAAE,cAAuB,EAAA;AAElE,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,GAAG,OAAO,GAAG,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACtH,IAAI,CAAC,UAAU,EAAE;AAGjB,QAAA,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,EAAE;AAClC,QAAA,UAAU,CAAC,OAAO,CAAC,YAAY,EAAE,cAAc,CAAC;AAEhD,QAAA,OAAO,MAAK;YACR,UAAU,CAAC,UAAU,EAAE;AACvB,YAAA,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;AACtD,QAAA,CAAC;IACL;AACH;;;;"}
|
|
@@ -17,6 +17,7 @@ export declare abstract class ObservableQueryFor<TDataType, TParameters = object
|
|
|
17
17
|
abstract readonly route: string;
|
|
18
18
|
abstract readonly defaultValue: TDataType;
|
|
19
19
|
readonly roles: string[];
|
|
20
|
+
readonly queryName?: string;
|
|
20
21
|
abstract readonly parameterDescriptors: ParameterDescriptor[];
|
|
21
22
|
abstract get requiredRequestParameters(): string[];
|
|
22
23
|
sorting: Sorting;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableQueryFor.d.ts","sourceRoot":"","sources":["../../../queries/ObservableQueryFor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"ObservableQueryFor.d.ts","sourceRoot":"","sources":["../../../queries/ObservableQueryFor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAK5E,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAA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CAAC,SAAS,CAAC;IAyC/G,OAAO,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAyDlE,OAAO,CAAC,iBAAiB;IAMzB,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,iBAAiB;CAW5B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ObservableQueryConnection } from './ObservableQueryConnection.js';
|
|
2
1
|
import { ObservableQuerySubscription } from './ObservableQuerySubscription.js';
|
|
3
2
|
import { ValidateRequestArguments } from './ValidateRequestArguments.js';
|
|
4
3
|
import { NullObservableQueryConnection } from './NullObservableQueryConnection.js';
|
|
4
|
+
import { createObservableQueryConnection } from './ObservableQueryConnectionFactory.js';
|
|
5
5
|
import { JsonSerializer } from '@cratis/fundamentals';
|
|
6
6
|
import { QueryResult } from './QueryResult.js';
|
|
7
7
|
import { Sorting } from './Sorting.js';
|
|
@@ -21,6 +21,7 @@ class ObservableQueryFor {
|
|
|
21
21
|
_connection;
|
|
22
22
|
_httpHeadersCallback;
|
|
23
23
|
roles = [];
|
|
24
|
+
queryName;
|
|
24
25
|
sorting;
|
|
25
26
|
paging;
|
|
26
27
|
constructor(modelType, enumerable) {
|
|
@@ -56,10 +57,14 @@ class ObservableQueryFor {
|
|
|
56
57
|
this._connection = new NullObservableQueryConnection(this.defaultValue);
|
|
57
58
|
}
|
|
58
59
|
else {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
this._connection = createObservableQueryConnection({
|
|
61
|
+
route: this.route,
|
|
62
|
+
queryName: this.queryName ?? this.constructor.name,
|
|
63
|
+
origin: this._origin,
|
|
64
|
+
apiBasePath: this._apiBasePath,
|
|
65
|
+
microservice: this._microservice,
|
|
66
|
+
args: args,
|
|
67
|
+
});
|
|
63
68
|
}
|
|
64
69
|
const parameterValues = ParametersHelper.collectParameterValues(this);
|
|
65
70
|
const { unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableQueryFor.js","sources":["../../../queries/ObservableQueryFor.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { IObservableQueryFor, OnNextResult } from './IObservableQueryFor';\nimport { ObservableQueryConnection } from './ObservableQueryConnection';\nimport { ObservableQuerySubscription } from './ObservableQuerySubscription';\nimport { ValidateRequestArguments } from './ValidateRequestArguments';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { NullObservableQueryConnection } from './NullObservableQueryConnection';\nimport { Constructor } from '@cratis/fundamentals';\nimport { JsonSerializer } from '@cratis/fundamentals';\nimport { QueryResult } from './QueryResult';\nimport { Sorting } from './Sorting';\nimport { Paging } from './Paging';\nimport { SortDirection } from './SortDirection';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor';\nimport { ParametersHelper } from '../reflection/ParametersHelper';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Represents an implementation of {@link IQueryFor}.\n * @template TDataType Type of data returned by the query.\n */\nexport abstract class ObservableQueryFor<TDataType, TParameters = object> implements IObservableQueryFor<TDataType, TParameters> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _connection?: IObservableQueryConnection<TDataType>;\n private _httpHeadersCallback: GetHttpHeaders;\n\n abstract readonly route: string;\n abstract readonly defaultValue: TDataType;\n readonly roles: string[] = [];\n abstract readonly parameterDescriptors: ParameterDescriptor[];\n abstract get requiredRequestParameters(): string[];\n sorting: Sorting;\n paging: Paging;\n\n /**\n * Initializes a new instance of the {@link ObservableQueryFor<,>}} class.\n * @param modelType Type of model, if an enumerable, this is the instance type.\n * @param enumerable Whether or not it is an enumerable.\n */\n constructor(readonly modelType: Constructor, readonly enumerable: boolean) {\n this.sorting = Sorting.none;\n this.paging = Paging.noPaging;\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /**\n * Disposes the query.\n */\n dispose() {\n this._connection?.disconnect();\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n subscribe(callback: OnNextResult<QueryResult<TDataType>>, args?: TParameters): ObservableQuerySubscription<TDataType> {\n if (this._connection) {\n this._connection.disconnect();\n }\n\n if (!this.validateArguments(args)) {\n this._connection = new NullObservableQueryConnection(this.defaultValue);\n } else {\n const { route } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n this._connection = new ObservableQueryConnection<TDataType>(url, this._microservice);\n }\n\n // Build query arguments including unused args parameters, parameter descriptor values, and paging/sorting\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const { unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const connectionQueryArguments: any = {\n ...unusedParameters,\n ...parameterValues,\n ...this.buildQueryArguments()\n };\n\n const subscriber = new ObservableQuerySubscription(this._connection);\n this._connection.connect(data => {\n const result: any = data;\n try {\n this.deserializeResult(result);\n callback(result);\n } catch (ex) {\n console.log(ex);\n }\n }, connectionQueryArguments);\n return subscriber;\n }\n\n /** @inheritdoc */\n async perform(args?: TParameters): Promise<QueryResult<TDataType>> {\n const noSuccess = { ...QueryResult.noSuccess, ...{ data: this.defaultValue } } as QueryResult<TDataType>;\n\n if (!this.validateArguments(args)) {\n return new Promise<QueryResult<TDataType>>((resolve) => {\n resolve(noSuccess);\n });\n }\n\n const { route, unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n let actualRoute = joinPaths(this._apiBasePath, route);\n \n const additionalParams: Record<string, string | number> = {};\n if (this.paging.hasPaging) {\n additionalParams.page = this.paging.page;\n additionalParams.pageSize = this.paging.pageSize;\n }\n\n if (this.sorting.hasSorting) {\n additionalParams.sortBy = this.sorting.field;\n additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n // Collect parameter values from parameterDescriptors that are set\n const parameterValues = ParametersHelper.collectParameterValues(this);\n\n const queryParams = UrlHelpers.buildQueryParams({ ...unusedParameters, ...parameterValues }, additionalParams);\n const queryString = queryParams.toString();\n if (queryString) {\n actualRoute += (actualRoute.includes('?') ? '&' : '?') + queryString;\n }\n\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n const headers = {\n ...(this._httpHeadersCallback?.() || {}),\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n const response = await fetch(url, {\n method: 'GET',\n headers\n });\n\n try {\n const result = await response.json();\n return new QueryResult(result, this.modelType, this.enumerable);\n } catch {\n return noSuccess;\n }\n }\n\n private validateArguments(args?: TParameters): boolean {\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const combinedArgs = { ...(args as object || {}), ...parameterValues };\n return ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, combinedArgs as object);\n }\n\n private buildQueryArguments(): any {\n const queryArguments: any = {};\n\n if (this.paging && this.paging.pageSize > 0) {\n queryArguments.pageSize = this.paging.pageSize;\n queryArguments.page = this.paging.page;\n }\n\n if (this.sorting.hasSorting) {\n queryArguments.sortBy = this.sorting.field;\n queryArguments.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n return queryArguments;\n }\n\n private deserializeResult(result: any): void {\n if (this.enumerable) {\n if (Array.isArray(result.data)) {\n result.data = JsonSerializer.deserializeArrayFromInstance(this.modelType, result.data);\n } else {\n result.data = [];\n }\n } else {\n result.data = JsonSerializer.deserializeFromInstance(this.modelType, result.data);\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;MA4BsB,kBAAkB,CAAA;AAoBf,IAAA,SAAA;AAAiC,IAAA,UAAA;AAnB9C,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,WAAW;AACX,IAAA,oBAAoB;IAInB,KAAK,GAAa,EAAE;AAG7B,IAAA,OAAO;AACP,IAAA,MAAM;IAON,WAAA,CAAqB,SAAsB,EAAW,UAAmB,EAAA;QAApD,IAAA,CAAA,SAAS,GAAT,SAAS;QAAwB,IAAA,CAAA,UAAU,GAAV,UAAU;AAC5D,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI;AAC3B,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ;QAC7B,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,YAAY,IAAI,EAAE;QAC/C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,IAAI,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE;QACnC,IAAI,CAAC,oBAAoB,GAAG,OAAO,EAAE,CAAC;IAC1C;IAKA,OAAO,GAAA;AACH,QAAA,IAAI,CAAC,WAAW,EAAE,UAAU,EAAE;IAClC;AAGA,IAAA,eAAe,CAAC,YAAoB,EAAA;AAChC,QAAA,IAAI,CAAC,aAAa,GAAG,YAAY;IACrC;AAGA,IAAA,cAAc,CAAC,WAAmB,EAAA;AAC9B,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW;IACnC;AAGA,IAAA,SAAS,CAAC,MAAc,EAAA;AACpB,Q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,IAAI,CAAC;QACrF;IACJ;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"ObservableQueryFor.js","sources":["../../../queries/ObservableQueryFor.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { IObservableQueryFor, OnNextResult } from './IObservableQueryFor';\nimport { ObservableQuerySubscription } from './ObservableQuerySubscription';\nimport { ValidateRequestArguments } from './ValidateRequestArguments';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { NullObservableQueryConnection } from './NullObservableQueryConnection';\nimport { createObservableQueryConnection } from './ObservableQueryConnectionFactory';\nimport { Constructor } from '@cratis/fundamentals';\nimport { JsonSerializer } from '@cratis/fundamentals';\nimport { QueryResult } from './QueryResult';\nimport { Sorting } from './Sorting';\nimport { Paging } from './Paging';\nimport { SortDirection } from './SortDirection';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor';\nimport { ParametersHelper } from '../reflection/ParametersHelper';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Represents an implementation of {@link IQueryFor}.\n * @template TDataType Type of data returned by the query.\n */\nexport abstract class ObservableQueryFor<TDataType, TParameters = object> implements IObservableQueryFor<TDataType, TParameters> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _connection?: IObservableQueryConnection<TDataType>;\n private _httpHeadersCallback: GetHttpHeaders;\n\n abstract readonly route: string;\n abstract readonly defaultValue: TDataType;\n readonly roles: string[] = [];\n /** Backend fully-qualified query name used when subscribing via the SSE hub. Overridden in generated proxies. */\n readonly queryName?: string;\n abstract readonly parameterDescriptors: ParameterDescriptor[];\n abstract get requiredRequestParameters(): string[];\n sorting: Sorting;\n paging: Paging;\n\n /**\n * Initializes a new instance of the {@link ObservableQueryFor<,>}} class.\n * @param modelType Type of model, if an enumerable, this is the instance type.\n * @param enumerable Whether or not it is an enumerable.\n */\n constructor(readonly modelType: Constructor, readonly enumerable: boolean) {\n this.sorting = Sorting.none;\n this.paging = Paging.noPaging;\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /**\n * Disposes the query.\n */\n dispose() {\n this._connection?.disconnect();\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n subscribe(callback: OnNextResult<QueryResult<TDataType>>, args?: TParameters): ObservableQuerySubscription<TDataType> {\n if (this._connection) {\n this._connection.disconnect();\n }\n\n if (!this.validateArguments(args)) {\n this._connection = new NullObservableQueryConnection(this.defaultValue);\n } else {\n this._connection = createObservableQueryConnection({\n route: this.route,\n queryName: this.queryName ?? this.constructor.name,\n origin: this._origin,\n apiBasePath: this._apiBasePath,\n microservice: this._microservice,\n args: args as object,\n });\n }\n\n // Build query arguments including unused args parameters, parameter descriptor values, and paging/sorting\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const { unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const connectionQueryArguments: any = {\n ...unusedParameters,\n ...parameterValues,\n ...this.buildQueryArguments()\n };\n\n const subscriber = new ObservableQuerySubscription(this._connection);\n this._connection.connect(data => {\n const result: any = data;\n try {\n this.deserializeResult(result);\n callback(result);\n } catch (ex) {\n console.log(ex);\n }\n }, connectionQueryArguments);\n return subscriber;\n }\n\n /** @inheritdoc */\n async perform(args?: TParameters): Promise<QueryResult<TDataType>> {\n const noSuccess = { ...QueryResult.noSuccess, ...{ data: this.defaultValue } } as QueryResult<TDataType>;\n\n if (!this.validateArguments(args)) {\n return new Promise<QueryResult<TDataType>>((resolve) => {\n resolve(noSuccess);\n });\n }\n\n const { route, unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n let actualRoute = joinPaths(this._apiBasePath, route);\n \n const additionalParams: Record<string, string | number> = {};\n if (this.paging.hasPaging) {\n additionalParams.page = this.paging.page;\n additionalParams.pageSize = this.paging.pageSize;\n }\n\n if (this.sorting.hasSorting) {\n additionalParams.sortBy = this.sorting.field;\n additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n // Collect parameter values from parameterDescriptors that are set\n const parameterValues = ParametersHelper.collectParameterValues(this);\n\n const queryParams = UrlHelpers.buildQueryParams({ ...unusedParameters, ...parameterValues }, additionalParams);\n const queryString = queryParams.toString();\n if (queryString) {\n actualRoute += (actualRoute.includes('?') ? '&' : '?') + queryString;\n }\n\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n const headers = {\n ...(this._httpHeadersCallback?.() || {}),\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n const response = await fetch(url, {\n method: 'GET',\n headers\n });\n\n try {\n const result = await response.json();\n return new QueryResult(result, this.modelType, this.enumerable);\n } catch {\n return noSuccess;\n }\n }\n\n private validateArguments(args?: TParameters): boolean {\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const combinedArgs = { ...(args as object || {}), ...parameterValues };\n return ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, combinedArgs as object);\n }\n\n private buildQueryArguments(): any {\n const queryArguments: any = {};\n\n if (this.paging && this.paging.pageSize > 0) {\n queryArguments.pageSize = this.paging.pageSize;\n queryArguments.page = this.paging.page;\n }\n\n if (this.sorting.hasSorting) {\n queryArguments.sortBy = this.sorting.field;\n queryArguments.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n return queryArguments;\n }\n\n private deserializeResult(result: any): void {\n if (this.enumerable) {\n if (Array.isArray(result.data)) {\n result.data = JsonSerializer.deserializeArrayFromInstance(this.modelType, result.data);\n } else {\n result.data = [];\n }\n } else {\n result.data = JsonSerializer.deserializeFromInstance(this.modelType, result.data);\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;MA4BsB,kBAAkB,CAAA;AAsBf,IAAA,SAAA;AAAiC,IAAA,UAAA;AArB9C,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,WAAW;AACX,IAAA,oBAAoB;IAInB,KAAK,GAAa,EAAE;AAEpB,IAAA,SAAS;AAGlB,IAAA,OAAO;AACP,IAAA,MAAM;IAON,WAAA,CAAqB,SAAsB,EAAW,UAAmB,EAAA;QAApD,IAAA,CAAA,SAAS,GAAT,SAAS;QAAwB,IAAA,CAAA,UAAU,GAAV,UAAU;AAC5D,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI;AAC3B,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ;QAC7B,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,YAAY,IAAI,EAAE;QAC/C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,IAAI,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE;QACnC,IAAI,CAAC,oBAAoB,GAAG,OAAO,EAAE,CAAC;IAC1C;IAKA,OAAO,GAAA;AACH,QAAA,IAAI,CAAC,WAAW,EAAE,UAAU,EAAE;IAClC;AAGA,IAAA,eAAe,CAAC,YAAoB,EAAA;AAChC,QAAA,IAAI,CAAC,aAAa,GAAG,YAAY;IACrC;AAGA,IAAA,cAAc,CAAC,WAAmB,EAAA;AAC9B,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW;IACnC;A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