@cratis/arc 20.1.3 → 20.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/identity/IdentityProvider.d.ts +2 -1
- package/dist/cjs/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/cjs/identity/IdentityProvider.js +16 -2
- package/dist/cjs/identity/IdentityProvider.js.map +1 -1
- package/dist/cjs/identity/for_IdentityProvider/when_refreshing/with_unauthorized_response.d.ts +2 -0
- package/dist/cjs/identity/for_IdentityProvider/when_refreshing/with_unauthorized_response.d.ts.map +1 -0
- package/dist/cjs/queries/HubConnectionKeepAlive.d.ts +2 -1
- package/dist/cjs/queries/HubConnectionKeepAlive.d.ts.map +1 -1
- package/dist/cjs/queries/HubConnectionKeepAlive.js +4 -2
- package/dist/cjs/queries/HubConnectionKeepAlive.js.map +1 -1
- package/dist/cjs/queries/QueryInstanceCache.d.ts +8 -0
- package/dist/cjs/queries/QueryInstanceCache.d.ts.map +1 -1
- package/dist/cjs/queries/QueryInstanceCache.js +70 -9
- package/dist/cjs/queries/QueryInstanceCache.js.map +1 -1
- package/dist/cjs/queries/QueryResult.d.ts +1 -0
- package/dist/cjs/queries/QueryResult.d.ts.map +1 -1
- package/dist/cjs/queries/QueryResult.js +18 -0
- package/dist/cjs/queries/QueryResult.js.map +1 -1
- package/dist/cjs/queries/ReconnectPolicy.d.ts.map +1 -1
- package/dist/cjs/queries/ReconnectPolicy.js +1 -0
- package/dist/cjs/queries/ReconnectPolicy.js.map +1 -1
- package/dist/cjs/queries/ServerSentEventHubConnection.d.ts +1 -0
- package/dist/cjs/queries/ServerSentEventHubConnection.d.ts.map +1 -1
- package/dist/cjs/queries/ServerSentEventHubConnection.js +22 -3
- package/dist/cjs/queries/ServerSentEventHubConnection.js.map +1 -1
- package/dist/cjs/queries/WebSocketHubConnection.d.ts +1 -0
- package/dist/cjs/queries/WebSocketHubConnection.d.ts.map +1 -1
- package/dist/cjs/queries/WebSocketHubConnection.js +11 -0
- package/dist/cjs/queries/WebSocketHubConnection.js.map +1 -1
- package/dist/cjs/queries/for_HubConnectionKeepAlive/when_started_with_custom_idle_threshold/respects_threshold.d.ts +2 -0
- package/dist/cjs/queries/for_HubConnectionKeepAlive/when_started_with_custom_idle_threshold/respects_threshold.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_acquiring/after_release_in_development_mode.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_acquiring/after_release_in_development_mode.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_deferring_dispose/with_cancellation_before_timeout.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_deferring_dispose/with_cancellation_before_timeout.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_deferring_dispose/without_cancellation.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_deferring_dispose/without_cancellation.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_disposing/an_empty_cache.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_disposing/an_empty_cache.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_disposing/with_active_subscriptions.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_disposing/with_active_subscriptions.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_disposing/with_pending_deferred_cleanup.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_disposing/with_pending_deferred_cleanup.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_in_development_mode.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_in_development_mode.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_outside_development_mode.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_outside_development_mode.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_active_subscriptions.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_active_subscriptions.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_no_subscriptions.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_no_subscriptions.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.d.ts.map +1 -0
- package/dist/cjs/queries/for_ReconnectPolicy/when_scheduling/and_rescheduled_before_first_fires/cancels_previous_timer.d.ts +2 -0
- package/dist/cjs/queries/for_ReconnectPolicy/when_scheduling/and_rescheduled_before_first_fires/cancels_previous_timer.d.ts.map +1 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.d.ts +2 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.d.ts.map +1 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_subscribing/and_subscribe_post_fails.d.ts +2 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_subscribing/and_subscribe_post_fails.d.ts.map +1 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.d.ts +2 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.d.ts.map +1 -0
- package/dist/esm/identity/IdentityProvider.d.ts +2 -1
- package/dist/esm/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/esm/identity/IdentityProvider.js +16 -2
- package/dist/esm/identity/IdentityProvider.js.map +1 -1
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_unauthorized_response.d.ts +2 -0
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_unauthorized_response.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_unauthorized_response.js +19 -0
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_unauthorized_response.js.map +1 -0
- package/dist/esm/queries/HubConnectionKeepAlive.d.ts +2 -1
- package/dist/esm/queries/HubConnectionKeepAlive.d.ts.map +1 -1
- package/dist/esm/queries/HubConnectionKeepAlive.js +4 -2
- package/dist/esm/queries/HubConnectionKeepAlive.js.map +1 -1
- package/dist/esm/queries/QueryInstanceCache.d.ts +8 -0
- package/dist/esm/queries/QueryInstanceCache.d.ts.map +1 -1
- package/dist/esm/queries/QueryInstanceCache.js +70 -9
- package/dist/esm/queries/QueryInstanceCache.js.map +1 -1
- package/dist/esm/queries/QueryResult.d.ts +1 -0
- package/dist/esm/queries/QueryResult.d.ts.map +1 -1
- package/dist/esm/queries/QueryResult.js +18 -0
- package/dist/esm/queries/QueryResult.js.map +1 -1
- package/dist/esm/queries/ReconnectPolicy.d.ts.map +1 -1
- package/dist/esm/queries/ReconnectPolicy.js +1 -0
- package/dist/esm/queries/ReconnectPolicy.js.map +1 -1
- package/dist/esm/queries/ServerSentEventHubConnection.d.ts +1 -0
- package/dist/esm/queries/ServerSentEventHubConnection.d.ts.map +1 -1
- package/dist/esm/queries/ServerSentEventHubConnection.js +22 -3
- package/dist/esm/queries/ServerSentEventHubConnection.js.map +1 -1
- package/dist/esm/queries/WebSocketHubConnection.d.ts +1 -0
- package/dist/esm/queries/WebSocketHubConnection.d.ts.map +1 -1
- package/dist/esm/queries/WebSocketHubConnection.js +11 -0
- package/dist/esm/queries/WebSocketHubConnection.js.map +1 -1
- package/dist/esm/queries/for_HubConnectionKeepAlive/when_started_with_custom_idle_threshold/respects_threshold.d.ts +2 -0
- package/dist/esm/queries/for_HubConnectionKeepAlive/when_started_with_custom_idle_threshold/respects_threshold.d.ts.map +1 -0
- package/dist/esm/queries/for_HubConnectionKeepAlive/when_started_with_custom_idle_threshold/respects_threshold.js +33 -0
- package/dist/esm/queries/for_HubConnectionKeepAlive/when_started_with_custom_idle_threshold/respects_threshold.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_acquiring/after_release_in_development_mode.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_acquiring/after_release_in_development_mode.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_acquiring/after_release_in_development_mode.js +23 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_acquiring/after_release_in_development_mode.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_deferring_dispose/with_cancellation_before_timeout.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_deferring_dispose/with_cancellation_before_timeout.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_deferring_dispose/with_cancellation_before_timeout.js +23 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_deferring_dispose/with_cancellation_before_timeout.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_deferring_dispose/without_cancellation.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_deferring_dispose/without_cancellation.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_deferring_dispose/without_cancellation.js +21 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_deferring_dispose/without_cancellation.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/an_empty_cache.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/an_empty_cache.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/an_empty_cache.js +17 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/an_empty_cache.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/with_active_subscriptions.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/with_active_subscriptions.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/with_active_subscriptions.js +23 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/with_active_subscriptions.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/with_pending_deferred_cleanup.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/with_pending_deferred_cleanup.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/with_pending_deferred_cleanup.js +22 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/with_pending_deferred_cleanup.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_in_development_mode.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_in_development_mode.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_in_development_mode.js +28 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_in_development_mode.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_outside_development_mode.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_outside_development_mode.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_outside_development_mode.js +25 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_outside_development_mode.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_active_subscriptions.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_active_subscriptions.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_active_subscriptions.js +25 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_active_subscriptions.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_no_subscriptions.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_no_subscriptions.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_no_subscriptions.js +12 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_no_subscriptions.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.js +23 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.js.map +1 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_rescheduled_before_first_fires/cancels_previous_timer.d.ts +2 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_rescheduled_before_first_fires/cancels_previous_timer.d.ts.map +1 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_rescheduled_before_first_fires/cancels_previous_timer.js +24 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_rescheduled_before_first_fires/cancels_previous_timer.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_keep_alive_is_idle/triggers_reconnect.js +1 -1
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_keep_alive_is_idle/triggers_reconnect.js.map +1 -1
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.js +35 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/and_subscribe_post_fails.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/and_subscribe_post_fails.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/and_subscribe_post_fails.js +33 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/and_subscribe_post_fails.js.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.d.ts +2 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.d.ts.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.js +33 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/identity/IdentityProvider.ts +23 -2
- package/identity/for_IdentityProvider/when_refreshing/with_unauthorized_response.ts +26 -0
- package/package.json +1 -1
- package/queries/HubConnectionKeepAlive.ts +20 -6
- package/queries/QueryInstanceCache.ts +133 -12
- package/queries/QueryResult.ts +19 -0
- package/queries/ReconnectPolicy.ts +4 -0
- package/queries/ServerSentEventHubConnection.ts +29 -4
- package/queries/WebSocketHubConnection.ts +11 -0
- package/queries/for_HubConnectionKeepAlive/when_started_with_custom_idle_threshold/respects_threshold.ts +46 -0
- package/queries/for_QueryInstanceCache/when_acquiring/after_release_in_development_mode.ts +31 -0
- package/queries/for_QueryInstanceCache/when_deferring_dispose/with_cancellation_before_timeout.ts +31 -0
- package/queries/for_QueryInstanceCache/when_deferring_dispose/without_cancellation.ts +28 -0
- package/queries/for_QueryInstanceCache/when_disposing/an_empty_cache.ts +21 -0
- package/queries/for_QueryInstanceCache/when_disposing/with_active_subscriptions.ts +30 -0
- package/queries/for_QueryInstanceCache/when_disposing/with_pending_deferred_cleanup.ts +31 -0
- package/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_in_development_mode.ts +36 -0
- package/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_outside_development_mode.ts +33 -0
- package/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_active_subscriptions.ts +32 -0
- package/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_no_subscriptions.ts +18 -0
- package/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.ts +33 -0
- package/queries/for_ReconnectPolicy/when_scheduling/and_rescheduled_before_first_fires/cancels_previous_timer.ts +36 -0
- package/queries/for_ServerSentEventHubConnection/when_keep_alive_is_idle/triggers_reconnect.ts +5 -2
- package/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.ts +51 -0
- package/queries/for_ServerSentEventHubConnection/when_subscribing/and_subscribe_post_fails.ts +51 -0
- package/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.ts +47 -0
|
@@ -13,7 +13,8 @@ export declare class IdentityProvider extends IIdentityProvider {
|
|
|
13
13
|
static getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>>;
|
|
14
14
|
getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>>;
|
|
15
15
|
static refresh<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>>;
|
|
16
|
+
private static notSet;
|
|
16
17
|
private static getCookie;
|
|
17
|
-
|
|
18
|
+
static clearIdentityCookie(): void;
|
|
18
19
|
}
|
|
19
20
|
//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mBAAmB,IAAI,IAAI;CAIrC"}
|
|
@@ -45,7 +45,7 @@ class IdentityProvider extends IIdentityProvider.IIdentityProvider {
|
|
|
45
45
|
return IdentityProvider.getCurrent(type);
|
|
46
46
|
}
|
|
47
47
|
static async refresh(type) {
|
|
48
|
-
IdentityProvider.
|
|
48
|
+
IdentityProvider.clearIdentityCookie();
|
|
49
49
|
const origin = IdentityProvider.origin || Globals.Globals.origin || '';
|
|
50
50
|
const apiBasePath = IdentityProvider.apiBasePath || Globals.Globals.apiBasePath || '';
|
|
51
51
|
const route = joinPaths.joinPaths(apiBasePath, '/.cratis/me');
|
|
@@ -54,6 +54,9 @@ class IdentityProvider extends IIdentityProvider.IIdentityProvider {
|
|
|
54
54
|
method: 'GET',
|
|
55
55
|
headers: IdentityProvider.httpHeadersCallback?.() ?? {}
|
|
56
56
|
});
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
return IdentityProvider.notSet(type);
|
|
59
|
+
}
|
|
57
60
|
const result = await response.json();
|
|
58
61
|
const details = type ? fundamentals.JsonSerializer.deserializeFromInstance(type, result.details) : result.details;
|
|
59
62
|
return {
|
|
@@ -66,6 +69,17 @@ class IdentityProvider extends IIdentityProvider.IIdentityProvider {
|
|
|
66
69
|
refresh: () => IdentityProvider.refresh(type)
|
|
67
70
|
};
|
|
68
71
|
}
|
|
72
|
+
static notSet(type) {
|
|
73
|
+
return {
|
|
74
|
+
id: '',
|
|
75
|
+
name: '',
|
|
76
|
+
roles: [],
|
|
77
|
+
details: {},
|
|
78
|
+
isSet: false,
|
|
79
|
+
isInRole: () => false,
|
|
80
|
+
refresh: () => IdentityProvider.refresh(type)
|
|
81
|
+
};
|
|
82
|
+
}
|
|
69
83
|
static getCookie() {
|
|
70
84
|
if (typeof document === 'undefined')
|
|
71
85
|
return [];
|
|
@@ -78,7 +92,7 @@ class IdentityProvider extends IIdentityProvider.IIdentityProvider {
|
|
|
78
92
|
}
|
|
79
93
|
return [];
|
|
80
94
|
}
|
|
81
|
-
static
|
|
95
|
+
static clearIdentityCookie() {
|
|
82
96
|
if (typeof document === 'undefined')
|
|
83
97
|
return;
|
|
84
98
|
document.cookie = `${IdentityProvider.CookieName}=;expires=Thu, 01 Jan 1970 00:00:00 GMT`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdentityProvider.js","sources":["../../../identity/IdentityProvider.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 { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { IIdentityProvider } from './IIdentityProvider';\nimport { IIdentity } from './IIdentity';\nimport { IdentityProviderResult } from './IdentityProviderResult';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { Globals } from '../Globals';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { joinPaths } from '../joinPaths';\n\n/**\n * Represents an implementation of {@link IIdentityProvider}.\n*/\nexport class IdentityProvider extends IIdentityProvider {\n\n static readonly CookieName = '.cratis-identity';\n static httpHeadersCallback: GetHttpHeaders | undefined;\n static apiBasePath: string = '';\n static origin: string = '';\n\n /**\n * Sets the HTTP headers callback.\n * @param callback Callback to set.\n */\n static setHttpHeadersCallback(callback: GetHttpHeaders): void {\n IdentityProvider.httpHeadersCallback = callback;\n }\n\n /**\n * Sets the API base path.\n * @param apiBasePath API base path to set.\n */\n static setApiBasePath(apiBasePath: string): void {\n IdentityProvider.apiBasePath = apiBasePath;\n }\n\n /**\n * Sets the origin.\n * @param origin Origin to set.\n */\n static setOrigin(origin: string): void {\n IdentityProvider.origin = origin;\n }\n\n /**\n * Gets the current identity by optionally specifying the details type.\n * @param type Optional constructor for the details type to enable type-safe deserialization.\n * @returns The current identity as {@link IIdentity}.\n * @remarks The `extends object` constraint is required for compatibility with JsonSerializer.deserializeFromInstance().\n */\n static async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n const cookie = this.getCookie();\n if (cookie.length == 2) {\n const json = atob(cookie[1]);\n const result = JSON.parse(json) as IdentityProviderResult;\n const details = type ? JsonSerializer.deserializeFromInstance(type, result.details) : result.details;\n return {\n id: result.id,\n name: result.name,\n roles: result.roles || [],\n details: details as TDetails,\n isSet: true,\n isInRole: (role: string) => (result.roles || []).includes(role),\n refresh: () => IdentityProvider.refresh(type)\n } as IIdentity<TDetails>;\n } else {\n const identity = await this.refresh<TDetails>(type);\n return identity;\n }\n }\n\n /** @inheritdoc */\n async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n return IdentityProvider.getCurrent<TDetails>(type);\n }\n\n static async refresh<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n IdentityProvider.
|
|
1
|
+
{"version":3,"file":"IdentityProvider.js","sources":["../../../identity/IdentityProvider.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 { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { IIdentityProvider } from './IIdentityProvider';\nimport { IIdentity } from './IIdentity';\nimport { IdentityProviderResult } from './IdentityProviderResult';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { Globals } from '../Globals';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { joinPaths } from '../joinPaths';\n\n/**\n * Represents an implementation of {@link IIdentityProvider}.\n*/\nexport class IdentityProvider extends IIdentityProvider {\n\n static readonly CookieName = '.cratis-identity';\n static httpHeadersCallback: GetHttpHeaders | undefined;\n static apiBasePath: string = '';\n static origin: string = '';\n\n /**\n * Sets the HTTP headers callback.\n * @param callback Callback to set.\n */\n static setHttpHeadersCallback(callback: GetHttpHeaders): void {\n IdentityProvider.httpHeadersCallback = callback;\n }\n\n /**\n * Sets the API base path.\n * @param apiBasePath API base path to set.\n */\n static setApiBasePath(apiBasePath: string): void {\n IdentityProvider.apiBasePath = apiBasePath;\n }\n\n /**\n * Sets the origin.\n * @param origin Origin to set.\n */\n static setOrigin(origin: string): void {\n IdentityProvider.origin = origin;\n }\n\n /**\n * Gets the current identity by optionally specifying the details type.\n * @param type Optional constructor for the details type to enable type-safe deserialization.\n * @returns The current identity as {@link IIdentity}.\n * @remarks The `extends object` constraint is required for compatibility with JsonSerializer.deserializeFromInstance().\n */\n static async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n const cookie = this.getCookie();\n if (cookie.length == 2) {\n const json = atob(cookie[1]);\n const result = JSON.parse(json) as IdentityProviderResult;\n const details = type ? JsonSerializer.deserializeFromInstance(type, result.details) : result.details;\n return {\n id: result.id,\n name: result.name,\n roles: result.roles || [],\n details: details as TDetails,\n isSet: true,\n isInRole: (role: string) => (result.roles || []).includes(role),\n refresh: () => IdentityProvider.refresh(type)\n } as IIdentity<TDetails>;\n } else {\n const identity = await this.refresh<TDetails>(type);\n return identity;\n }\n }\n\n /** @inheritdoc */\n async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n return IdentityProvider.getCurrent<TDetails>(type);\n }\n\n static async refresh<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n IdentityProvider.clearIdentityCookie();\n const origin = IdentityProvider.origin || Globals.origin || '';\n const apiBasePath = IdentityProvider.apiBasePath || Globals.apiBasePath || '';\n const route = joinPaths(apiBasePath, '/.cratis/me');\n const url = UrlHelpers.createUrlFrom(origin, apiBasePath, route);\n const response = await fetch(\n url, {\n method: 'GET',\n headers: IdentityProvider.httpHeadersCallback?.() ?? {}\n });\n\n if (!response.ok) {\n return IdentityProvider.notSet(type);\n }\n\n const result = await response.json() as IdentityProviderResult;\n const details = type ? JsonSerializer.deserializeFromInstance(type, result.details) : result.details;\n\n return {\n id: result.id,\n name: result.name,\n roles: result.roles || [],\n details: details as TDetails,\n isSet: true,\n isInRole: (role: string) => (result.roles || []).includes(role),\n refresh: () => IdentityProvider.refresh(type)\n };\n }\n\n private static notSet<TDetails extends object = object>(type?: Constructor<TDetails>): IIdentity<TDetails> {\n return {\n id: '',\n name: '',\n roles: [],\n details: {} as TDetails,\n isSet: false,\n isInRole: () => false,\n refresh: () => IdentityProvider.refresh(type)\n };\n }\n\n private static getCookie() {\n if (typeof document === 'undefined') return [];\n const decoded = decodeURIComponent(document.cookie);\n const cookies = decoded.split(';').map(_ => _.trim());\n const cookie = cookies.find(_ => _.indexOf(`${IdentityProvider.CookieName}=`) == 0);\n if (cookie) {\n const keyValue = cookie.split('=');\n return [keyValue[0].trim(), keyValue[1].trim()];\n }\n return [];\n }\n\n /**\n * Clears the identity cookie used by Arc to cache the current identity.\n * Call this when the user logs out to ensure subsequent requests and WebSocket\n * connections do not carry stale credentials.\n */\n static clearIdentityCookie(): void {\n if (typeof document === 'undefined') return;\n document.cookie = `${IdentityProvider.CookieName}=;expires=Thu, 01 Jan 1970 00:00:00 GMT`;\n }\n}\n"],"names":["IIdentityProvider","JsonSerializer","Globals","joinPaths","UrlHelpers"],"mappings":";;;;;;;;AAeM,MAAO,gBAAiB,SAAQA,mCAAiB,CAAA;AAEnD,IAAA,OAAgB,UAAU,GAAG,kBAAkB;IAC/C,OAAO,mBAAmB;AAC1B,IAAA,OAAO,WAAW,GAAW,EAAE;AAC/B,IAAA,OAAO,MAAM,GAAW,EAAE;IAM1B,OAAO,sBAAsB,CAAC,QAAwB,EAAA;AAClD,QAAA,gBAAgB,CAAC,mBAAmB,GAAG,QAAQ;IACnD;IAMA,OAAO,cAAc,CAAC,WAAmB,EAAA;AACrC,QAAA,gBAAgB,CAAC,WAAW,GAAG,WAAW;IAC9C;IAMA,OAAO,SAAS,CAAC,MAAc,EAAA;AAC3B,QAAA,gBAAgB,CAAC,MAAM,GAAG,MAAM;IACpC;AAQA,IAAA,aAAa,UAAU,CAAmC,IAA4B,EAAA;AAClF,QAAA,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE;AAC/B,QAAA,IAAI,MAAM,CAAC,MAAM,IAA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O,QAAQ,KAAK,WAAW;AAAE,YAAA,OAAO,EAAE;QAC9C,MAAM,OAAO,GAAG,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC;QACnD,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;QACrD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAA,EAAG,gBAAgB,CAAC,UAAU,GAAG,CAAC,IAAI,CAAC,CAAC;QACnF,IAAI,MAAM,EAAE;YACR,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;AAClC,YAAA,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACnD;AACA,QAAA,OAAO,EAAE;IACb;AAOA,IAAA,OAAO,mBAAmB,GAAA;QACtB,IAAI,OAAO,QAAQ,KAAK,WAAW;YAAE;QACrC,QAAQ,CAAC,MAAM,GAAG,CAAA,EAAG,gBAAgB,CAAC,UAAU,yCAAyC;IAC7F;;;;;"}
|
package/dist/cjs/identity/for_IdentityProvider/when_refreshing/with_unauthorized_response.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_unauthorized_response.d.ts","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_refreshing/with_unauthorized_response.ts"],"names":[],"mappings":""}
|
|
@@ -3,7 +3,8 @@ export declare class HubConnectionKeepAlive {
|
|
|
3
3
|
private readonly _onIdle;
|
|
4
4
|
private _lastActivityTime;
|
|
5
5
|
private _timer?;
|
|
6
|
-
|
|
6
|
+
private readonly _idleThresholdMs;
|
|
7
|
+
constructor(_intervalMs: number, _onIdle: () => void, idleThresholdMs?: number);
|
|
7
8
|
start(): void;
|
|
8
9
|
stop(): void;
|
|
9
10
|
recordActivity(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HubConnectionKeepAlive.d.ts","sourceRoot":"","sources":["../../../queries/HubConnectionKeepAlive.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HubConnectionKeepAlive.d.ts","sourceRoot":"","sources":["../../../queries/HubConnectionKeepAlive.ts"],"names":[],"mappings":"AAqBA,qBAAa,sBAAsB;IAgB3B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAhB5B,OAAO,CAAC,iBAAiB,CAAc;IACvC,OAAO,CAAC,MAAM,CAAC,CAAiC;IAChD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;gBAarB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,IAAI,EACpC,eAAe,CAAC,EAAE,MAAM;IAQ5B,KAAK,IAAI,IAAI;IAab,IAAI,IAAI,IAAI;IAWZ,cAAc,IAAI,IAAI;CAGzB"}
|
|
@@ -5,15 +5,17 @@ class HubConnectionKeepAlive {
|
|
|
5
5
|
_onIdle;
|
|
6
6
|
_lastActivityTime = Date.now();
|
|
7
7
|
_timer;
|
|
8
|
-
|
|
8
|
+
_idleThresholdMs;
|
|
9
|
+
constructor(_intervalMs, _onIdle, idleThresholdMs) {
|
|
9
10
|
this._intervalMs = _intervalMs;
|
|
10
11
|
this._onIdle = _onIdle;
|
|
12
|
+
this._idleThresholdMs = idleThresholdMs ?? _intervalMs;
|
|
11
13
|
}
|
|
12
14
|
start() {
|
|
13
15
|
this.stop();
|
|
14
16
|
this._lastActivityTime = Date.now();
|
|
15
17
|
this._timer = setInterval(() => {
|
|
16
|
-
if (Date.now() - this._lastActivityTime >= this.
|
|
18
|
+
if (Date.now() - this._lastActivityTime >= this._idleThresholdMs) {
|
|
17
19
|
this._onIdle();
|
|
18
20
|
}
|
|
19
21
|
}, this._intervalMs);
|
|
@@ -1 +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
|
|
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\n * {@link idleThresholdMs} milliseconds the provided {@link onIdle} callback is invoked —\n * the caller decides whether to send a ping, trigger a reconnect, or take some other action.\n *\n * The idle threshold defaults to the check interval but can be set higher to tolerate\n * network latency between the server's keep-alive ping and the client's idle check.\n * For SSE connections, where the idle callback triggers a reconnect, a tolerance of\n * 1.5× the server's keep-alive interval prevents spurious reconnects caused by the\n * client's timer firing just before the server's ping arrives.\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 private readonly _idleThresholdMs: number;\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 within the idle threshold.\n * @param {number} idleThresholdMs Optional. How long (in milliseconds) without activity\n * before the connection is considered idle. Defaults to {@link intervalMs}. Set this\n * higher than {@link intervalMs} when the peer sends keep-alive messages on a similar\n * cadence to account for network latency and timer jitter.\n */\n constructor(\n private readonly _intervalMs: number,\n private readonly _onIdle: () => void,\n idleThresholdMs?: number,\n ) {\n this._idleThresholdMs = idleThresholdMs ?? _intervalMs;\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._idleThresholdMs) {\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":";;MAqBa,sBAAsB,CAAA;AAgBV,IAAA,WAAA;AACA,IAAA,OAAA;AAhBb,IAAA,iBAAiB,GAAG,IAAI,CAAC,GAAG,EAAE;AAC9B,IAAA,MAAM;AACG,IAAA,gBAAgB;AAYjC,IAAA,WAAA,CACqB,WAAmB,EACnB,OAAmB,EACpC,eAAwB,EAAA;QAFP,IAAA,CAAA,WAAW,GAAX,WAAW;QACX,IAAA,CAAA,OAAO,GAAP,OAAO;AAGxB,QAAA,IAAI,CAAC,gBAAgB,GAAG,eAAe,IAAI,WAAW;IAC1D;IAKA,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,gBAAgB,EAAE;gBAC9D,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;;;;"}
|
|
@@ -8,9 +8,13 @@ export interface QueryCacheEntry<TDataType> {
|
|
|
8
8
|
readonly listeners: Set<QueryCacheListener<TDataType>>;
|
|
9
9
|
teardown?: () => void;
|
|
10
10
|
subscribed: boolean;
|
|
11
|
+
pendingCleanup?: ReturnType<typeof setTimeout>;
|
|
11
12
|
}
|
|
12
13
|
export declare class QueryInstanceCache {
|
|
13
14
|
private readonly _entries;
|
|
15
|
+
private readonly _development;
|
|
16
|
+
private _pendingDispose?;
|
|
17
|
+
constructor(development?: boolean);
|
|
14
18
|
buildKey(queryTypeName: string, args?: object): QueryCacheKey;
|
|
15
19
|
getOrCreate<TInstance>(key: QueryCacheKey, factory: () => TInstance): {
|
|
16
20
|
instance: TInstance;
|
|
@@ -25,5 +29,9 @@ export declare class QueryInstanceCache {
|
|
|
25
29
|
isSubscribed(key: QueryCacheKey): boolean;
|
|
26
30
|
release(key: QueryCacheKey): void;
|
|
27
31
|
has(key: QueryCacheKey): boolean;
|
|
32
|
+
teardownAllSubscriptions(): void;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
deferDispose(): void;
|
|
35
|
+
cancelPendingDispose(): void;
|
|
28
36
|
}
|
|
29
37
|
//# sourceMappingURL=QueryInstanceCache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryInstanceCache.d.ts","sourceRoot":"","sources":["../../../queries/QueryInstanceCache.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAK9D,MAAM,MAAM,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new Map();
|
|
5
|
+
_development;
|
|
6
|
+
_pendingDispose;
|
|
7
|
+
constructor(development = false) {
|
|
8
|
+
this._development = development;
|
|
9
|
+
}
|
|
5
10
|
buildKey(queryTypeName, args) {
|
|
6
11
|
if (!args || Object.keys(args).length === 0) {
|
|
7
12
|
return `${queryTypeName}::`;
|
|
@@ -32,6 +37,10 @@ class QueryInstanceCache {
|
|
|
32
37
|
acquire(key) {
|
|
33
38
|
const entry = this._entries.get(key);
|
|
34
39
|
if (entry) {
|
|
40
|
+
if (entry.pendingCleanup !== undefined) {
|
|
41
|
+
clearTimeout(entry.pendingCleanup);
|
|
42
|
+
entry.pendingCleanup = undefined;
|
|
43
|
+
}
|
|
35
44
|
entry.subscriberCount++;
|
|
36
45
|
}
|
|
37
46
|
}
|
|
@@ -74,21 +83,73 @@ class QueryInstanceCache {
|
|
|
74
83
|
if (entry) {
|
|
75
84
|
entry.subscriberCount--;
|
|
76
85
|
if (entry.subscriberCount <= 0) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
if (this._development) {
|
|
87
|
+
entry.pendingCleanup = setTimeout(() => {
|
|
88
|
+
const current = this._entries.get(key);
|
|
89
|
+
if (current && current.subscriberCount <= 0) {
|
|
90
|
+
current.subscribed = false;
|
|
91
|
+
current.teardown?.();
|
|
92
|
+
current.teardown = undefined;
|
|
93
|
+
current.pendingCleanup = undefined;
|
|
94
|
+
this._entries.delete(key);
|
|
95
|
+
}
|
|
96
|
+
}, 0);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
entry.subscribed = false;
|
|
100
|
+
entry.teardown?.();
|
|
101
|
+
entry.teardown = undefined;
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
const current = this._entries.get(key);
|
|
104
|
+
if (current && current.subscriberCount <= 0) {
|
|
105
|
+
this._entries.delete(key);
|
|
106
|
+
}
|
|
107
|
+
}, 0);
|
|
108
|
+
}
|
|
86
109
|
}
|
|
87
110
|
}
|
|
88
111
|
}
|
|
89
112
|
has(key) {
|
|
90
113
|
return this._entries.has(key);
|
|
91
114
|
}
|
|
115
|
+
teardownAllSubscriptions() {
|
|
116
|
+
for (const [, entry] of this._entries) {
|
|
117
|
+
if (entry.pendingCleanup !== undefined) {
|
|
118
|
+
clearTimeout(entry.pendingCleanup);
|
|
119
|
+
entry.pendingCleanup = undefined;
|
|
120
|
+
}
|
|
121
|
+
entry.subscribed = false;
|
|
122
|
+
entry.teardown?.();
|
|
123
|
+
entry.teardown = undefined;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
dispose() {
|
|
127
|
+
for (const [, entry] of this._entries) {
|
|
128
|
+
if (entry.pendingCleanup !== undefined) {
|
|
129
|
+
clearTimeout(entry.pendingCleanup);
|
|
130
|
+
entry.pendingCleanup = undefined;
|
|
131
|
+
}
|
|
132
|
+
entry.subscribed = false;
|
|
133
|
+
entry.teardown?.();
|
|
134
|
+
entry.teardown = undefined;
|
|
135
|
+
}
|
|
136
|
+
this._entries.clear();
|
|
137
|
+
}
|
|
138
|
+
deferDispose() {
|
|
139
|
+
if (this._pendingDispose !== undefined) {
|
|
140
|
+
clearTimeout(this._pendingDispose);
|
|
141
|
+
}
|
|
142
|
+
this._pendingDispose = setTimeout(() => {
|
|
143
|
+
this._pendingDispose = undefined;
|
|
144
|
+
this.dispose();
|
|
145
|
+
}, 0);
|
|
146
|
+
}
|
|
147
|
+
cancelPendingDispose() {
|
|
148
|
+
if (this._pendingDispose !== undefined) {
|
|
149
|
+
clearTimeout(this._pendingDispose);
|
|
150
|
+
this._pendingDispose = undefined;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
92
153
|
}
|
|
93
154
|
|
|
94
155
|
exports.QueryInstanceCache = QueryInstanceCache;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryInstanceCache.js","sources":["../../../queries/QueryInstanceCache.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 { QueryResultWithState } from './QueryResultWithState';\n\n/**\n * Represents a key that uniquely identifies a query instance in the cache, based on the query type name and its serialized arguments.\n */\nexport type QueryCacheKey = string;\n\n/**\n * Callback invoked when the cached result for an entry changes.\n */\nexport type QueryCacheListener<TDataType> = (result: QueryResultWithState<TDataType>) => void;\n\n/**\n * Represents a single entry in the {@link QueryInstanceCache}.\n * @template TDataType The type of data returned by the query.\n */\nexport interface QueryCacheEntry<TDataType> {\n /**\n * The cached query instance.\n */\n readonly instance: unknown;\n\n /**\n * The last result received from the query, if any.\n */\n lastResult?: QueryResultWithState<TDataType>;\n\n /**\n * The number of active subscribers holding a reference to this entry.\n */\n subscriberCount: number;\n\n /**\n * Set of listener callbacks that are notified when {@link lastResult} changes.\n */\n readonly listeners: Set<QueryCacheListener<TDataType>>;\n\n /**\n * Cleanup function returned by the first subscriber that starts the query connection.\n * Called when the last subscriber releases the entry.\n */\n teardown?: () => void;\n\n /**\n * Whether an active subscription has been established for this entry.\n */\n subscribed: boolean;\n}\n\n/**\n * Provides a cache for query instances, keyed by query type and serialized arguments.\n *\n * Two callers requesting the same query type with identical arguments receive the same\n * cached instance and immediately see the last known result — without an additional\n * round trip to the server. When the last subscriber releases its reference the entry\n * is evicted.\n */\nexport class QueryInstanceCache {\n private readonly _entries = new Map<QueryCacheKey, QueryCacheEntry<unknown>>();\n\n /**\n * Builds the cache key for a query.\n * @param queryTypeName The name of the query constructor (i.e. `constructor.name`).\n * @param args Optional arguments supplied to the query.\n * @returns A stable string key.\n */\n buildKey(queryTypeName: string, args?: object): QueryCacheKey {\n if (!args || Object.keys(args).length === 0) {\n return `${queryTypeName}::`;\n }\n\n const sorted = Object.keys(args)\n .sort()\n .reduce<Record<string, unknown>>((accumulator, key) => {\n accumulator[key] = (args as Record<string, unknown>)[key];\n return accumulator;\n }, {});\n\n return `${queryTypeName}::${JSON.stringify(sorted)}`;\n }\n\n /**\n * Returns a cached instance for the given key, or creates a new one using the provided factory.\n * The subscriber count of the entry is incremented.\n * @template TInstance The type of the query instance.\n * @param key The cache key produced by {@link buildKey}.\n * @param factory A zero-argument factory that creates a fresh query instance when one is not yet cached.\n * @returns The cached (or newly created) instance and whether it was newly created.\n */\n getOrCreate<TInstance>(\n key: QueryCacheKey,\n factory: () => TInstance\n ): { instance: TInstance; isNew: boolean } {\n if (!this._entries.has(key)) {\n const entry: QueryCacheEntry<unknown> = {\n instance: factory(),\n lastResult: undefined,\n subscriberCount: 0,\n listeners: new Set(),\n subscribed: false,\n };\n\n this._entries.set(key, entry);\n return { instance: entry.instance as TInstance, isNew: true };\n }\n\n const entry = this._entries.get(key)!;\n return { instance: entry.instance as TInstance, isNew: false };\n }\n\n /**\n * Increments the active subscriber count for the given key.\n * Call from `useEffect` setup to pair with {@link release} in the cleanup.\n * @param key The cache key produced by {@link buildKey}.\n */\n acquire(key: QueryCacheKey): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.subscriberCount++;\n }\n }\n\n /**\n * Returns the last cached result for the given key, or `undefined` if no result has been stored yet.\n * @template TDataType The type of data returned by the query.\n * @param key The cache key produced by {@link buildKey}.\n * @returns The last {@link QueryResultWithState}, or `undefined`.\n */\n getLastResult<TDataType>(key: QueryCacheKey): QueryResultWithState<TDataType> | undefined {\n return this._entries.get(key)?.lastResult as QueryResultWithState<TDataType> | undefined;\n }\n\n /**\n * Stores the most recent result for the given key and notifies all registered listeners.\n * @template TDataType The type of data returned by the query.\n * @param key The cache key produced by {@link buildKey}.\n * @param result The result to store.\n */\n setLastResult<TDataType>(key: QueryCacheKey, result: QueryResultWithState<TDataType>): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.lastResult = result as QueryResultWithState<unknown>;\n\n for (const listener of entry.listeners) {\n (listener as QueryCacheListener<TDataType>)(result);\n }\n }\n }\n\n /**\n * Registers a listener that is invoked whenever the cached result for the given key changes.\n * @template TDataType The type of data returned by the query.\n * @param key The cache key produced by {@link buildKey}.\n * @param listener The callback to register.\n */\n addListener<TDataType>(key: QueryCacheKey, listener: QueryCacheListener<TDataType>): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.listeners.add(listener as QueryCacheListener<unknown>);\n }\n }\n\n /**\n * Removes a previously registered listener.\n * @template TDataType The type of data returned by the query.\n * @param key The cache key produced by {@link buildKey}.\n * @param listener The callback to remove.\n */\n removeListener<TDataType>(key: QueryCacheKey, listener: QueryCacheListener<TDataType>): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.listeners.delete(listener as QueryCacheListener<unknown>);\n }\n }\n\n /**\n * Stores a teardown function for the given key and marks the entry as subscribed.\n * Called automatically when the last subscriber releases the entry.\n * @param key The cache key produced by {@link buildKey}.\n * @param teardown Cleanup function that disconnects the underlying query subscription.\n */\n setTeardown(key: QueryCacheKey, teardown: () => void): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.teardown = teardown;\n entry.subscribed = true;\n }\n }\n\n /**\n * Returns whether an active subscription exists for the given key.\n * @param key The cache key to check.\n * @returns `true` if a subscription has been established; `false` otherwise.\n */\n isSubscribed(key: QueryCacheKey): boolean {\n return this._entries.get(key)?.subscribed ?? false;\n }\n\n /**\n * Decrements the subscriber count for the given key. When the count reaches zero the teardown\n * function is called (if set) and the entry is evicted.\n * @param key The cache key produced by {@link buildKey}.\n */\n release(key: QueryCacheKey): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.subscriberCount--;\n\n if (entry.subscriberCount <= 0) {\n entry.subscribed = false;\n entry.teardown?.();\n entry.teardown = undefined;\n\n // Defer deletion so React Strict Mode re-mounts can re-acquire the entry.\n setTimeout(() => {\n const current = this._entries.get(key);\n\n if (current && current.subscriberCount <= 0) {\n this._entries.delete(key);\n }\n }, 0);\n }\n }\n }\n\n /**\n * Returns whether an entry exists for the given key.\n * @param key The cache key to check.\n * @returns `true` if an entry exists; `false` otherwise.\n */\n has(key: QueryCac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AAK,EAAE;AACP,YAAA,KAAK,CAAC,QAAQ,GAAG,QAAQ;AACzB,YAAA,KAAK,CAAC,UAAU,GAAG,IAAI;QAC3B;IACJ;AAOA,IAAA,YAAY,CAAC,GAAkB,EAAA;AAC3B,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,UAAU,IAAI,KAAK;IACtD;AAOA,IAAA,OAAO,CAAC,GAAkB,EAAA;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;QAEpC,IAAI,KAAK,EAAE;YACP,KAAK,CAAC,eAAe,EAAE;AAEvB,YAAA,IAAI,KAAK,CAAC,eAAe,IAAI,CAAC,EAAE;AAC5B,gBAAA,KAAK,CAAC,UAAU,GAAG,KAAK;AACxB,gBAAA,KAAK,CAAC,QAAQ,IAAI;AAClB,gBAAA,KAAK,CAAC,QAAQ,GAAG,SAAS;gBAG1B,UAAU,CAAC,MAAK;oBACZ,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;oBAEtC,IAAI,OAAO,IAAI,OAAO,CAAC,eAAe,IAAI,CAAC,EAAE;AACzC,wBAAA,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC;oBAC7B;gBACJ,CAAC,EAAE,CAAC,CAAC;YACT;QACJ;IACJ;AAOA,IAAA,GAAG,CAAC,GAAkB,EAAA;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;IACjC;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"QueryInstanceCache.js","sources":["../../../queries/QueryInstanceCache.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 { QueryResultWithState } from './QueryResultWithState';\n\n/**\n * Represents a key that uniquely identifies a query instance in the cache, based on the query type name and its serialized arguments.\n */\nexport type QueryCacheKey = string;\n\n/**\n * Callback invoked when the cached result for an entry changes.\n */\nexport type QueryCacheListener<TDataType> = (result: QueryResultWithState<TDataType>) => void;\n\n/**\n * Represents a single entry in the {@link QueryInstanceCache}.\n * @template TDataType The type of data returned by the query.\n */\nexport interface QueryCacheEntry<TDataType> {\n /**\n * The cached query instance.\n */\n readonly instance: unknown;\n\n /**\n * The last result received from the query, if any.\n */\n lastResult?: QueryResultWithState<TDataType>;\n\n /**\n * The number of active subscribers holding a reference to this entry.\n */\n subscriberCount: number;\n\n /**\n * Set of listener callbacks that are notified when {@link lastResult} changes.\n */\n readonly listeners: Set<QueryCacheListener<TDataType>>;\n\n /**\n * Cleanup function returned by the first subscriber that starts the query connection.\n * Called when the last subscriber releases the entry.\n */\n teardown?: () => void;\n\n /**\n * Whether an active subscription has been established for this entry.\n */\n subscribed: boolean;\n\n /**\n * Timer handle for deferred cleanup when running in development mode.\n * Allows React StrictMode re-mounts to cancel the pending teardown\n * so the connection is reused instead of torn down and recreated.\n */\n pendingCleanup?: ReturnType<typeof setTimeout>;\n}\n\n/**\n * Provides a cache for query instances, keyed by query type and serialized arguments.\n *\n * Two callers requesting the same query type with identical arguments receive the same\n * cached instance and immediately see the last known result — without an additional\n * round trip to the server. When the last subscriber releases its reference the entry\n * is evicted.\n */\nexport class QueryInstanceCache {\n private readonly _entries = new Map<QueryCacheKey, QueryCacheEntry<unknown>>();\n private readonly _development: boolean;\n private _pendingDispose?: ReturnType<typeof setTimeout>;\n\n /**\n * Initializes a new instance of {@link QueryInstanceCache}.\n * @param development When true, teardown is deferred on release so React StrictMode\n * re-mounts can re-acquire the entry without an unnecessary disconnect/reconnect cycle.\n */\n constructor(development: boolean = false) {\n this._development = development;\n }\n\n /**\n * Builds the cache key for a query.\n * @param queryTypeName The name of the query constructor (i.e. `constructor.name`).\n * @param args Optional arguments supplied to the query.\n * @returns A stable string key.\n */\n buildKey(queryTypeName: string, args?: object): QueryCacheKey {\n if (!args || Object.keys(args).length === 0) {\n return `${queryTypeName}::`;\n }\n\n const sorted = Object.keys(args)\n .sort()\n .reduce<Record<string, unknown>>((accumulator, key) => {\n accumulator[key] = (args as Record<string, unknown>)[key];\n return accumulator;\n }, {});\n\n return `${queryTypeName}::${JSON.stringify(sorted)}`;\n }\n\n /**\n * Returns a cached instance for the given key, or creates a new one using the provided factory.\n * The subscriber count of the entry is incremented.\n * @template TInstance The type of the query instance.\n * @param key The cache key produced by {@link buildKey}.\n * @param factory A zero-argument factory that creates a fresh query instance when one is not yet cached.\n * @returns The cached (or newly created) instance and whether it was newly created.\n */\n getOrCreate<TInstance>(\n key: QueryCacheKey,\n factory: () => TInstance\n ): { instance: TInstance; isNew: boolean } {\n if (!this._entries.has(key)) {\n const entry: QueryCacheEntry<unknown> = {\n instance: factory(),\n lastResult: undefined,\n subscriberCount: 0,\n listeners: new Set(),\n subscribed: false,\n };\n\n this._entries.set(key, entry);\n return { instance: entry.instance as TInstance, isNew: true };\n }\n\n const entry = this._entries.get(key)!;\n return { instance: entry.instance as TInstance, isNew: false };\n }\n\n /**\n * Increments the active subscriber count for the given key.\n * If a deferred cleanup was pending (from a recent {@link release} in development mode),\n * it is cancelled so the existing subscription is reused.\n * Call from `useEffect` setup to pair with {@link release} in the cleanup.\n * @param key The cache key produced by {@link buildKey}.\n */\n acquire(key: QueryCacheKey): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n if (entry.pendingCleanup !== undefined) {\n clearTimeout(entry.pendingCleanup);\n entry.pendingCleanup = undefined;\n }\n\n entry.subscriberCount++;\n }\n }\n\n /**\n * Returns the last cached result for the given key, or `undefined` if no result has been stored yet.\n * @template TDataType The type of data returned by the query.\n * @param key The cache key produced by {@link buildKey}.\n * @returns The last {@link QueryResultWithState}, or `undefined`.\n */\n getLastResult<TDataType>(key: QueryCacheKey): QueryResultWithState<TDataType> | undefined {\n return this._entries.get(key)?.lastResult as QueryResultWithState<TDataType> | undefined;\n }\n\n /**\n * Stores the most recent result for the given key and notifies all registered listeners.\n * @template TDataType The type of data returned by the query.\n * @param key The cache key produced by {@link buildKey}.\n * @param result The result to store.\n */\n setLastResult<TDataType>(key: QueryCacheKey, result: QueryResultWithState<TDataType>): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.lastResult = result as QueryResultWithState<unknown>;\n\n for (const listener of entry.listeners) {\n (listener as QueryCacheListener<TDataType>)(result);\n }\n }\n }\n\n /**\n * Registers a listener that is invoked whenever the cached result for the given key changes.\n * @template TDataType The type of data returned by the query.\n * @param key The cache key produced by {@link buildKey}.\n * @param listener The callback to register.\n */\n addListener<TDataType>(key: QueryCacheKey, listener: QueryCacheListener<TDataType>): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.listeners.add(listener as QueryCacheListener<unknown>);\n }\n }\n\n /**\n * Removes a previously registered listener.\n * @template TDataType The type of data returned by the query.\n * @param key The cache key produced by {@link buildKey}.\n * @param listener The callback to remove.\n */\n removeListener<TDataType>(key: QueryCacheKey, listener: QueryCacheListener<TDataType>): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.listeners.delete(listener as QueryCacheListener<unknown>);\n }\n }\n\n /**\n * Stores a teardown function for the given key and marks the entry as subscribed.\n * Called automatically when the last subscriber releases the entry.\n * @param key The cache key produced by {@link buildKey}.\n * @param teardown Cleanup function that disconnects the underlying query subscription.\n */\n setTeardown(key: QueryCacheKey, teardown: () => void): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.teardown = teardown;\n entry.subscribed = true;\n }\n }\n\n /**\n * Returns whether an active subscription exists for the given key.\n * @param key The cache key to check.\n * @returns `true` if a subscription has been established; `false` otherwise.\n */\n isSubscribed(key: QueryCacheKey): boolean {\n return this._entries.get(key)?.subscribed ?? false;\n }\n\n /**\n * Decrements the subscriber count for the given key. When the count reaches zero the teardown\n * function is called (if set) and the entry is evicted.\n *\n * In development mode, both teardown and eviction are deferred by one microtask so that\n * React StrictMode re-mounts can re-acquire the entry and cancel the cleanup. This prevents\n * an unnecessary disconnect/reconnect cycle during the synthetic unmount/remount that\n * StrictMode performs in development builds.\n * @param key The cache key produced by {@link buildKey}.\n */\n release(key: QueryCacheKey): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.subscriberCount--;\n\n if (entry.subscriberCount <= 0) {\n if (this._development) {\n // Defer both teardown and deletion so StrictMode re-mounts can cancel.\n entry.pendingCleanup = setTimeout(() => {\n const current = this._entries.get(key);\n\n if (current && current.subscriberCount <= 0) {\n current.subscribed = false;\n current.teardown?.();\n current.teardown = undefined;\n current.pendingCleanup = undefined;\n this._entries.delete(key);\n }\n }, 0);\n } else {\n entry.subscribed = false;\n entry.teardown?.();\n entry.teardown = undefined;\n\n // Defer deletion so React Strict Mode re-mounts can re-acquire the entry.\n setTimeout(() => {\n const current = this._entries.get(key);\n\n if (current && current.subscriberCount <= 0) {\n this._entries.delete(key);\n }\n }, 0);\n }\n }\n }\n }\n\n /**\n * Returns whether an entry exists for the given key.\n * @param key The cache key to check.\n * @returns `true` if an entry exists; `false` otherwise.\n */\n has(key: QueryCacheKey): boolean {\n return this._entries.has(key);\n }\n\n /**\n * Tears down all active subscriptions and marks every entry as not subscribed,\n * but preserves entries, subscriber counts, and listeners. This allows\n * hooks whose effects re-run afterward to detect that the entry is no longer\n * subscribed and re-establish a fresh connection.\n *\n * Use this when the underlying transport must be replaced (e.g. after an\n * authentication change that requires new WebSocket connections with updated\n * credentials).\n */\n teardownAllSubscriptions(): void {\n for (const [, entry] of this._entries) {\n if (entry.pendingCleanup !== undefined) {\n clearTimeout(entry.pendingCleanup);\n entry.pendingCleanup = undefined;\n }\n\n entry.subscribed = false;\n entry.teardown?.();\n entry.teardown = undefined;\n }\n }\n\n /**\n * Immediately tears down all subscriptions, cancels any pending deferred cleanups,\n * and evicts all entries. Call when the owning component (e.g. the {@link Arc} provider)\n * unmounts permanently so that all query connections are closed synchronously.\n */\n dispose(): void {\n for (const [, entry] of this._entries) {\n if (entry.pendingCleanup !== undefined) {\n clearTimeout(entry.pendingCleanup);\n entry.pendingCleanup = undefined;\n }\n\n entry.subscribed = false;\n entry.teardown?.();\n entry.teardown = undefined;\n }\n\n this._entries.clear();\n }\n\n /**\n * Schedules a deferred {@link dispose} using {@code setTimeout(0)}.\n *\n * This allows React StrictMode re-mounts to call {@link cancelPendingDispose}\n * before the dispose fires, avoiding the destruction of cache entries that child\n * effects are about to re-acquire.\n *\n * If a deferred dispose is already pending, it is replaced.\n */\n deferDispose(): void {\n if (this._pendingDispose !== undefined) {\n clearTimeout(this._pendingDispose);\n }\n\n this._pendingDispose = setTimeout(() => {\n this._pendingDispose = undefined;\n this.dispose();\n }, 0);\n }\n\n /**\n * Cancels a pending deferred dispose scheduled by {@link deferDispose}.\n *\n * Call from the {@code useEffect} setup phase so that a StrictMode re-mount\n * prevents the synthetic unmount's deferred dispose from firing.\n */\n cancelPendingDispose(): void {\n if (this._pendingDispose !== undefined) {\n clearTimeout(this._pendingDispose);\n this._pendingDispose = undefined;\n }\n }\n}\n"],"names":[],"mappings":";;MAmEa,kBAAkB,CAAA;AACV,IAAA,QAAQ,GAAG,IAAI,GAAG,EAA2C;AAC7D,IAAA,YAAY;AACrB,IAAA,eAAe;AAOvB,IAAA,WAAA,CAAY,cAAuB,KAAK,EAAA;AACpC,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW;IACnC;IAQA,QAAQ,CAAC,aAAqB,EAAE,IAAa,EAAA;AACzC,QAAA,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;YACzC,OAAO,CAAA,EAAG,aAAa,CAAA,EAAA,CAAI;QAC/B;AAEA,QAAA,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI;AAC1B,aAAA,IAAI;AACJ,aAAA,MAAM,CAA0B,CAAC,WAAW,EAAE,GAAG,KAAI;YAClD,WAAW,CAAC,GAAG,CAAC,GAAI,IAAgC,CAAC,GAAG,CAAC;AACzD,YAAA,OAAO,WAAW;QAC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declare class QueryResult<TDataType = object> implements IQueryResult<TDataType> {
|
|
29
29
|
static empty<TDataType>(defaultValue: TDataType): QueryResult<TDataType>;
|
|
30
|
+
static unauthorized<TDataType>(): QueryResult<TDataType>;
|
|
30
31
|
static noSuccess: QueryResult;
|
|
31
32
|
constructor(result: ServerQueryResult, instanceType: Constructor, enumerable: boolean);
|
|
32
33
|
readonly data: TDataType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryResult.d.ts","sourceRoot":"","sources":["../../../queries/QueryResult.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,KAAK,iBAAiB,GAAG;IAErB,IAAI,EAAE,GAAG,CAAC;IAEV,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,EAAE,sBAAsB,EAAE,CAAC;IAC5C,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,gBAAgB,CAAC;CAC5B,CAAA;AAED,KAAK,sBAAsB,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACjB,CAAA;AAED,KAAK,gBAAgB,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACtB,CAAA;AAMD,qBAAa,WA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AE,MAAM,CAAC;IAKrC,IAAI,OAAO,IAAI,OAAO,CAQrB;CACJ"}
|
|
@@ -23,6 +23,24 @@ class QueryResult {
|
|
|
23
23
|
}
|
|
24
24
|
}, Object, false);
|
|
25
25
|
}
|
|
26
|
+
static unauthorized() {
|
|
27
|
+
return new QueryResult({
|
|
28
|
+
data: null,
|
|
29
|
+
isSuccess: false,
|
|
30
|
+
isAuthorized: false,
|
|
31
|
+
isValid: true,
|
|
32
|
+
hasExceptions: false,
|
|
33
|
+
validationResults: [],
|
|
34
|
+
exceptionMessages: [],
|
|
35
|
+
exceptionStackTrace: '',
|
|
36
|
+
paging: {
|
|
37
|
+
totalItems: 0,
|
|
38
|
+
totalPages: 0,
|
|
39
|
+
page: 0,
|
|
40
|
+
size: 0
|
|
41
|
+
}
|
|
42
|
+
}, Object, false);
|
|
43
|
+
}
|
|
26
44
|
static noSuccess = new QueryResult({
|
|
27
45
|
data: {},
|
|
28
46
|
isSuccess: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryResult.js","sources":["../../../queries/QueryResult.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 { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { IQueryResult } from './IQueryResult';\nimport { PagingInfo } from './PagingInfo';\n\ntype ServerQueryResult = {\n /* eslint-disable @typescript-eslint/no-explicit-any */\n data: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n isSuccess: boolean;\n isAuthorized: boolean;\n isValid: boolean;\n hasExceptions: boolean;\n validationResults: ServerValidationResult[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n paging: ServerPagingInfo;\n}\n\ntype ServerValidationResult = {\n severity: number;\n message: string;\n members: string[];\n state: object;\n}\n\ntype ServerPagingInfo = {\n page: number;\n size: number; \n totalItems: number;\n totalPages: number;\n}\n\n/**\n * Represents the result from executing a {@link IQueryFor}.\n * @template TDataType The data type.\n */\nexport class QueryResult<TDataType = object> implements IQueryResult<TDataType> {\n\n static empty<TDataType>(defaultValue: TDataType): QueryResult<TDataType> {\n return new QueryResult({\n data: defaultValue as object,\n isSuccess: true,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n\n }, Object, false);\n }\n\n static noSuccess: QueryResult = new QueryResult({\n data: {},\n isSuccess: false,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, Object, false);\n\n /**\n * Creates an instance of query result.\n * @param {*} result The raw result from the backend.\n * @param {Constructor} instanceType The type of instance to deserialize.\n * @param {boolean} enumerable Whether or not the result is supposed be an enumerable or not.\n */\n constructor(result: ServerQueryResult, instanceType: Constructor, enumerable: boolean) {\n this.isSuccess = result.isSuccess;\n this.isAuthorized = result.isAuthorized;\n this.isValid = result.isValid;\n this.hasExceptions = result.hasExceptions;\n this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.paging = new PagingInfo();\n this.paging.page = result.paging.page;\n this.paging.size = result.paging.size;\n this.paging.totalItems = result.paging.totalItems;\n this.paging.totalPages = result.paging.totalPages;\n\n if (result.data) {\n let data: object = result.data;\n if (enumerable) {\n if (Array.isArray(result.data)) {\n data = JsonSerializer.deserializeArrayFromInstance(instanceType, data);\n } else {\n data = [];\n }\n } else {\n data = JsonSerializer.deserializeFromInstance(instanceType, data);\n }\n\n this.data = data as TDataType;\n } else {\n this.data = null as TDataType;\n }\n }\n\n /** @inheritdoc */\n readonly data: TDataType;\n\n /** @inheritdoc */\n readonly paging: PagingInfo;\n\n /** @inheritdoc */\n readonly isSuccess: boolean;\n\n /** @inheritdoc */\n readonly isAuthorized: boolean;\n\n /** @inheritdoc */\n readonly isValid: boolean;\n\n /** @inheritdoc */\n readonly hasExceptions: boolean;\n\n /** @inheritdoc */\n readonly validationResults: ValidationResult[];\n\n /** @inheritdoc */\n readonly exceptionMessages: string[];\n\n /** @inheritdoc */\n readonly exceptionStackTrace: string;\n\n /**\n * Gets whether or not the query has data.\n */\n get hasData(): boolean {\n if (this.data) {\n if (Array.isArray(this.data)) {\n return this.data.length > 0;\n }\n return true;\n }\n return false;\n }\n}\n"],"names":["ValidationResult","PagingInfo","JsonSerializer"],"mappings":";;;;;;MAwCa,WAAW,CAAA;IAEpB,OAAO,KAAK,CAAY,YAAuB,EAAA;QAC3C,OAAO,IAAI,WAAW,CAAC;AACnB,YAAA,IAAI,EAAE,YAAsB;AAC5B,YAAA,SAAS,EAAE,IAAI;AACf,YAAA,YAAY,EAAE,IAAI;AAClB,YAAA,OAAO,EAAE,IAAI;AACb,YAAA,aAAa,EAAE,KAAK;AACpB,YAAA,iBAAiB,EAAE,EAAE;AACrB,YAAA,iBAAiB,EAAE,EAAE;AACrB,YAAA,mBAAmB,EAAE,EAAE;AACvB,YAAA,MAAM,EAAE;AACJ,gBAAA,UAAU,EAAE,CAAC;AACb,gBAAA,UAAU,EAAE,CAAC;AACb,gBAAA,IAAI,EAAE,CAAC;AACP,gBAAA,IAAI,EAAE;AACT;AAEJ,SAAA,EAAE,MAAM,EAAE,KAAK,CAAC;IACrB;AAEA,IAAA,OAAO,SAAS,GAAgB,IAAI,WAAW,CAAC;AAC5C,QAAA,IAAI,EAAE,EAAE;AACR,QAAA,SAAS,EAAE,KAAK;AAChB,QAAA,YAAY,EAAE,IAAI;AAClB,QAAA,OAAO,EAAE,IAAI;AACb,QAAA,aAAa,EAAE,KAAK;AACpB,QAAA,iBAAiB,EAAE,EAAE;AACrB,QAAA,iBAAiB,EAAE,EAAE;AACrB,QAAA,mBAAm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AAM,CAAC,IAAI;YAC9B,IAAI,UAAU,EAAE;gBACZ,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;oBAC5B,IAAI,GAAGC,2BAAc,CAAC,4BAA4B,CAAC,YAAY,EAAE,IAAI,CAAC;gBAC1E;qBAAO;oBACH,IAAI,GAAG,EAAE;gBACb;YACJ;iBAAO;gBACH,IAAI,GAAGA,2BAAc,CAAC,uBAAuB,CAAC,YAAY,EAAE,IAAI,CAAC;YACrE;AAEA,YAAA,IAAI,CAAC,IAAI,GAAG,IAAiB;QACjC;aAAO;AACH,YAAA,IAAI,CAAC,IAAI,GAAG,IAAiB;QACjC;IACJ;AAGS,IAAA,IAAI;AAGJ,IAAA,MAAM;AAGN,IAAA,SAAS;AAGT,IAAA,YAAY;AAGZ,IAAA,OAAO;AAGP,IAAA,aAAa;AAGb,IAAA,iBAAiB;AAGjB,IAAA,iBAAiB;AAGjB,IAAA,mBAAmB;AAK5B,IAAA,IAAI,OAAO,GAAA;AACP,QAAA,IAAI,IAAI,CAAC,IAAI,EAAE;YACX,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AAC1B,gBAAA,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC;YAC/B;AACA,YAAA,OAAO,IAAI;QACf;AACA,QAAA,OAAO,KAAK;IAChB;;;;;"}
|
|
1
|
+
{"version":3,"file":"QueryResult.js","sources":["../../../queries/QueryResult.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 { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { IQueryResult } from './IQueryResult';\nimport { PagingInfo } from './PagingInfo';\n\ntype ServerQueryResult = {\n /* eslint-disable @typescript-eslint/no-explicit-any */\n data: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n isSuccess: boolean;\n isAuthorized: boolean;\n isValid: boolean;\n hasExceptions: boolean;\n validationResults: ServerValidationResult[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n paging: ServerPagingInfo;\n}\n\ntype ServerValidationResult = {\n severity: number;\n message: string;\n members: string[];\n state: object;\n}\n\ntype ServerPagingInfo = {\n page: number;\n size: number; \n totalItems: number;\n totalPages: number;\n}\n\n/**\n * Represents the result from executing a {@link IQueryFor}.\n * @template TDataType The data type.\n */\nexport class QueryResult<TDataType = object> implements IQueryResult<TDataType> {\n\n static empty<TDataType>(defaultValue: TDataType): QueryResult<TDataType> {\n return new QueryResult({\n data: defaultValue as object,\n isSuccess: true,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n\n }, Object, false);\n }\n\n static unauthorized<TDataType>(): QueryResult<TDataType> {\n return new QueryResult({\n data: null as unknown as object,\n isSuccess: false,\n isAuthorized: false,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, Object, false);\n }\n\n static noSuccess: QueryResult = new QueryResult({\n data: {},\n isSuccess: false,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, Object, false);\n\n /**\n * Creates an instance of query result.\n * @param {*} result The raw result from the backend.\n * @param {Constructor} instanceType The type of instance to deserialize.\n * @param {boolean} enumerable Whether or not the result is supposed be an enumerable or not.\n */\n constructor(result: ServerQueryResult, instanceType: Constructor, enumerable: boolean) {\n this.isSuccess = result.isSuccess;\n this.isAuthorized = result.isAuthorized;\n this.isValid = result.isValid;\n this.hasExceptions = result.hasExceptions;\n this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.paging = new PagingInfo();\n this.paging.page = result.paging.page;\n this.paging.size = result.paging.size;\n this.paging.totalItems = result.paging.totalItems;\n this.paging.totalPages = result.paging.totalPages;\n\n if (result.data) {\n let data: object = result.data;\n if (enumerable) {\n if (Array.isArray(result.data)) {\n data = JsonSerializer.deserializeArrayFromInstance(instanceType, data);\n } else {\n data = [];\n }\n } else {\n data = JsonSerializer.deserializeFromInstance(instanceType, data);\n }\n\n this.data = data as TDataType;\n } else {\n this.data = null as TDataType;\n }\n }\n\n /** @inheritdoc */\n readonly data: TDataType;\n\n /** @inheritdoc */\n readonly paging: PagingInfo;\n\n /** @inheritdoc */\n readonly isSuccess: boolean;\n\n /** @inheritdoc */\n readonly isAuthorized: boolean;\n\n /** @inheritdoc */\n readonly isValid: boolean;\n\n /** @inheritdoc */\n readonly hasExceptions: boolean;\n\n /** @inheritdoc */\n readonly validationResults: ValidationResult[];\n\n /** @inheritdoc */\n readonly exceptionMessages: string[];\n\n /** @inheritdoc */\n readonly exceptionStackTrace: string;\n\n /**\n * Gets whether or not the query has data.\n */\n get hasData(): boolean {\n if (this.data) {\n if (Array.isArray(this.data)) {\n return this.data.length > 0;\n }\n return true;\n }\n return false;\n }\n}\n"],"names":["ValidationResult","PagingInfo","JsonSerializer"],"mappings":";;;;;;MAwCa,WAAW,CAAA;IAEpB,OAAO,KAAK,CAAY,YAAuB,EAAA;QAC3C,OAAO,IAAI,WAAW,CAAC;AACnB,YAAA,IAAI,EAAE,YAAsB;AAC5B,YAAA,SAAS,EAAE,IAAI;AACf,YAAA,YAAY,EAAE,IAAI;AAClB,YAAA,OAAO,EAAE,IAAI;AACb,YAAA,aAAa,EAAE,KAAK;AACpB,YAAA,iBAAiB,EAAE,EAAE;AACrB,YAAA,iBAAiB,EAAE,EAAE;AACrB,YAAA,mBAAmB,EAAE,EAAE;AACvB,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B,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;
|
|
1
|
+
{"version":3,"file":"ReconnectPolicy.d.ts","sourceRoot":"","sources":["../../../queries/ReconnectPolicy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAczE,qBAAa,eAAgB,YAAW,gBAAgB;IAYhD,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAdhC,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,MAAM,CAAC,CAAgC;gBAU1B,YAAY,GAAE,MAAY,EAC1B,eAAe,GAAE,MAAY,EAC7B,YAAY,GAAE,MAAY,EAC1B,WAAW,GAAE,MAAe;IAIjD,IAAI,OAAO,IAAI,MAAM,CAEpB;IAGD,QAAQ,CAAC,WAAW,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAkBhE,KAAK,IAAI,IAAI;IAMb,MAAM,IAAI,IAAI;CAMjB"}
|
|
@@ -21,6 +21,7 @@ class ReconnectPolicy {
|
|
|
21
21
|
console.log(`Reconnect: abandoned after ${this._maxAttempts} attempts for '${label}'`);
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
|
+
this.cancel();
|
|
24
25
|
this._attempt++;
|
|
25
26
|
const delay = Math.min(this._initialDelayMs + this._delayStepMs * this._attempt, this._maxDelayMs);
|
|
26
27
|
console.log(`Reconnect: attempt ${this._attempt} in ${delay}ms for '${label}'`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReconnectPolicy.js","sources":["../../../queries/ReconnectPolicy.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 { IReconnectPolicy, ReconnectCallback } from './IReconnectPolicy';\n\n/**\n * Default exponential back-off reconnect policy shared by all observable query connections.\n *\n * Delay formula: `Math.min(initialDelayMs + delayStepMs * attempt, maxDelayMs)`\n *\n * With the default parameters:\n * - Attempt 1 → 1 000 ms\n * - Attempt 2 → 1 500 ms\n * - …\n * - Attempt 19+ → 10 000 ms (capped)\n * - After 100 attempts → abandoned (returns `false`)\n */\nexport class ReconnectPolicy implements IReconnectPolicy {\n private _attempt = 0;\n private _timer?: ReturnType<typeof setTimeout>;\n\n /**\n * Initializes a new instance of {@link ReconnectPolicy}.\n * @param {number} maxAttempts Maximum number of reconnect attempts before giving up (default: 100).\n * @param {number} initialDelayMs Base delay in milliseconds added to every attempt (default: 500).\n * @param {number} delayStepMs Additional delay per attempt in milliseconds (default: 500).\n * @param {number} maxDelayMs Upper bound on the computed delay in milliseconds (default: 10 000).\n */\n constructor(\n private readonly _maxAttempts: number = 100,\n private readonly _initialDelayMs: number = 500,\n private readonly _delayStepMs: number = 500,\n private readonly _maxDelayMs: number = 10_000,\n ) {}\n\n /** @inheritdoc */\n get attempt(): number {\n return this._attempt;\n }\n\n /** @inheritdoc */\n schedule(onReconnect: ReconnectCallback, label: string): boolean {\n if (this._attempt >= this._maxAttempts) {\n console.log(`Reconnect: abandoned after ${this._maxAttempts} attempts for '${label}'`);\n return false;\n }\n\n this._attempt++;\n const delay = Math.min(this._initialDelayMs + this._delayStepMs * this._attempt, this._maxDelayMs);\n console.log(`Reconnect: attempt ${this._attempt} in ${delay}ms for '${label}'`);\n this._timer = setTimeout(onReconnect, delay);\n return true;\n }\n\n /** @inheritdoc */\n reset(): void {\n this._attempt = 0;\n this.cancel();\n }\n\n /** @inheritdoc */\n cancel(): void {\n if (this._timer) {\n clearTimeout(this._timer);\n this._timer = undefined;\n }\n }\n}\n"],"names":[],"mappings":";;MAiBa,eAAe,CAAA;AAYH,IAAA,YAAA;AACA,IAAA,eAAA;AACA,IAAA,YAAA;AACA,IAAA,WAAA;IAdb,QAAQ,GAAG,CAAC;AACZ,IAAA,MAAM;IASd,WAAA,CACqB,YAAA,GAAuB,GAAG,EAC1B,eAAA,GAA0B,GAAG,EAC7B,YAAA,GAAuB,GAAG,EAC1B,WAAA,GAAsB,MAAM,EAAA;QAH5B,IAAA,CAAA,YAAY,GAAZ,YAAY;QACZ,IAAA,CAAA,eAAe,GAAf,eAAe;QACf,IAAA,CAAA,YAAY,GAAZ,YAAY;QACZ,IAAA,CAAA,WAAW,GAAX,WAAW;IAC7B;AAGH,IAAA,IAAI,OAAO,GAAA;QACP,OAAO,IAAI,CAAC,QAAQ;IACxB;IAGA,QAAQ,CAAC,WAA8B,EAAE,KAAa,EAAA;QAClD,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,YAAY,EAAE;YACpC,OAAO,CAAC,GAAG,CAAC,CAAA,2BAAA,EAA8B,IAAI,CAAC,YAAY,CAAA,eAAA,EAAkB,KAAK,CAAA,CAAA,CAAG,CAAC;AACtF,YAAA,OAAO,KAAK;QAChB;
|
|
1
|
+
{"version":3,"file":"ReconnectPolicy.js","sources":["../../../queries/ReconnectPolicy.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 { IReconnectPolicy, ReconnectCallback } from './IReconnectPolicy';\n\n/**\n * Default exponential back-off reconnect policy shared by all observable query connections.\n *\n * Delay formula: `Math.min(initialDelayMs + delayStepMs * attempt, maxDelayMs)`\n *\n * With the default parameters:\n * - Attempt 1 → 1 000 ms\n * - Attempt 2 → 1 500 ms\n * - …\n * - Attempt 19+ → 10 000 ms (capped)\n * - After 100 attempts → abandoned (returns `false`)\n */\nexport class ReconnectPolicy implements IReconnectPolicy {\n private _attempt = 0;\n private _timer?: ReturnType<typeof setTimeout>;\n\n /**\n * Initializes a new instance of {@link ReconnectPolicy}.\n * @param {number} maxAttempts Maximum number of reconnect attempts before giving up (default: 100).\n * @param {number} initialDelayMs Base delay in milliseconds added to every attempt (default: 500).\n * @param {number} delayStepMs Additional delay per attempt in milliseconds (default: 500).\n * @param {number} maxDelayMs Upper bound on the computed delay in milliseconds (default: 10 000).\n */\n constructor(\n private readonly _maxAttempts: number = 100,\n private readonly _initialDelayMs: number = 500,\n private readonly _delayStepMs: number = 500,\n private readonly _maxDelayMs: number = 10_000,\n ) {}\n\n /** @inheritdoc */\n get attempt(): number {\n return this._attempt;\n }\n\n /** @inheritdoc */\n schedule(onReconnect: ReconnectCallback, label: string): boolean {\n if (this._attempt >= this._maxAttempts) {\n console.log(`Reconnect: abandoned after ${this._maxAttempts} attempts for '${label}'`);\n return false;\n }\n\n // Cancel any pending reconnect timer so we don't fire multiple\n // concurrent reconnect attempts when schedule() is called rapidly.\n this.cancel();\n\n this._attempt++;\n const delay = Math.min(this._initialDelayMs + this._delayStepMs * this._attempt, this._maxDelayMs);\n console.log(`Reconnect: attempt ${this._attempt} in ${delay}ms for '${label}'`);\n this._timer = setTimeout(onReconnect, delay);\n return true;\n }\n\n /** @inheritdoc */\n reset(): void {\n this._attempt = 0;\n this.cancel();\n }\n\n /** @inheritdoc */\n cancel(): void {\n if (this._timer) {\n clearTimeout(this._timer);\n this._timer = undefined;\n }\n }\n}\n"],"names":[],"mappings":";;MAiBa,eAAe,CAAA;AAYH,IAAA,YAAA;AACA,IAAA,eAAA;AACA,IAAA,YAAA;AACA,IAAA,WAAA;IAdb,QAAQ,GAAG,CAAC;AACZ,IAAA,MAAM;IASd,WAAA,CACqB,YAAA,GAAuB,GAAG,EAC1B,eAAA,GAA0B,GAAG,EAC7B,YAAA,GAAuB,GAAG,EAC1B,WAAA,GAAsB,MAAM,EAAA;QAH5B,IAAA,CAAA,YAAY,GAAZ,YAAY;QACZ,IAAA,CAAA,eAAe,GAAf,eAAe;QACf,IAAA,CAAA,YAAY,GAAZ,YAAY;QACZ,IAAA,CAAA,WAAW,GAAX,WAAW;IAC7B;AAGH,IAAA,IAAI,OAAO,GAAA;QACP,OAAO,IAAI,CAAC,QAAQ;IACxB;IAGA,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AkB;IAW1B,OAAO,CAAC,aAAa;IA0BrB,OAAO,CAAC,eAAe;CAkB1B"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var Globals = require('../Globals.js');
|
|
4
4
|
var HubConnectionKeepAlive = require('./HubConnectionKeepAlive.js');
|
|
5
5
|
var ReconnectPolicy = require('./ReconnectPolicy.js');
|
|
6
|
+
var QueryResult = require('./QueryResult.js');
|
|
6
7
|
var WebSocketHubConnection = require('./WebSocketHubConnection.js');
|
|
7
8
|
|
|
8
9
|
class ServerSentEventHubConnection {
|
|
@@ -28,12 +29,13 @@ class ServerSentEventHubConnection {
|
|
|
28
29
|
this._microservice = _microservice;
|
|
29
30
|
this._connectTimeoutMs = _connectTimeoutMs;
|
|
30
31
|
this._policy = _policy;
|
|
32
|
+
const idleThresholdMs = Math.round(keepAliveIntervalMs * 1.5);
|
|
31
33
|
this._keepAlive = new HubConnectionKeepAlive.HubConnectionKeepAlive(keepAliveIntervalMs, () => {
|
|
32
34
|
if (!this._disconnected && this._subscriptions.size > 0) {
|
|
33
|
-
console.warn(`SSE hub: no messages received for ${
|
|
35
|
+
console.warn(`SSE hub: no messages received for ${idleThresholdMs}ms, reconnecting '${this._sseUrl}'`);
|
|
34
36
|
this.reconnect();
|
|
35
37
|
}
|
|
36
|
-
});
|
|
38
|
+
}, idleThresholdMs);
|
|
37
39
|
}
|
|
38
40
|
get queryCount() {
|
|
39
41
|
return this._subscriptions.size;
|
|
@@ -168,6 +170,7 @@ class ServerSentEventHubConnection {
|
|
|
168
170
|
break;
|
|
169
171
|
case WebSocketHubConnection.HubMessageType.Unauthorized:
|
|
170
172
|
console.warn(`SSE hub: query '${message.queryId}' unauthorized`);
|
|
173
|
+
this.handleUnauthorized(message);
|
|
171
174
|
break;
|
|
172
175
|
case WebSocketHubConnection.HubMessageType.Error:
|
|
173
176
|
console.error(`SSE hub: query '${message.queryId}' error:`, message.payload);
|
|
@@ -196,6 +199,16 @@ class ServerSentEventHubConnection {
|
|
|
196
199
|
const result = message.payload;
|
|
197
200
|
sub.callback(result);
|
|
198
201
|
}
|
|
202
|
+
handleUnauthorized(message) {
|
|
203
|
+
if (!message.queryId)
|
|
204
|
+
return;
|
|
205
|
+
const sub = this._subscriptions.get(message.queryId);
|
|
206
|
+
if (!sub)
|
|
207
|
+
return;
|
|
208
|
+
this._subscriptions.delete(message.queryId);
|
|
209
|
+
this._pendingSubscriptions.delete(message.queryId);
|
|
210
|
+
sub.callback(QueryResult.QueryResult.unauthorized());
|
|
211
|
+
}
|
|
199
212
|
sendSubscribe(queryId, request) {
|
|
200
213
|
if (!this._connectionId)
|
|
201
214
|
return;
|
|
@@ -209,8 +222,14 @@ class ServerSentEventHubConnection {
|
|
|
209
222
|
method: 'POST',
|
|
210
223
|
headers: { 'Content-Type': 'application/json', ...customHeaders },
|
|
211
224
|
body: JSON.stringify(body),
|
|
225
|
+
}).then(response => {
|
|
226
|
+
if (!response.ok) {
|
|
227
|
+
console.warn(`SSE hub: subscribe POST for '${queryId}' returned ${response.status}, reconnecting`);
|
|
228
|
+
this.reconnect();
|
|
229
|
+
}
|
|
212
230
|
}).catch(error => {
|
|
213
|
-
console.error(`SSE hub: subscribe POST failed for '${queryId}'`, error);
|
|
231
|
+
console.error(`SSE hub: subscribe POST failed for '${queryId}', reconnecting`, error);
|
|
232
|
+
this.reconnect();
|
|
214
233
|
});
|
|
215
234
|
}
|
|
216
235
|
sendUnsubscribe(queryId) {
|