stream-chat 10.0.0-rc.2 → 10.0.0-rc.21
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/README.md +11 -8
- package/dist/cjs/index.browser.js +15397 -12090
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +15349 -11991
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +15164 -11880
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelManager.d.ts +246 -6
- package/dist/types/CooldownTimer.d.ts +22 -8
- package/dist/types/EventHandlerPipeline.d.ts +12 -16
- package/dist/types/LiveLocationManager.d.ts +69 -6
- package/dist/types/api-client.d.ts +22 -9
- package/dist/types/channel.d.ts +550 -300
- package/dist/types/channel_state.d.ts +167 -22
- package/dist/types/client.d.ts +325 -305
- package/dist/types/configuration/ConfigController.d.ts +172 -0
- package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +192 -0
- package/dist/types/configuration/index.d.ts +3 -0
- package/dist/types/configuration/keys.d.ts +31 -0
- package/dist/types/configuration/shape.d.ts +58 -0
- package/dist/types/configuration/types.d.ts +206 -50
- package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +59 -0
- package/dist/types/configuration/utils/copyConfigPatch.d.ts +1 -0
- package/dist/types/configuration/utils/declarativeSlices.d.ts +24 -0
- package/dist/types/configuration/utils/deepFreezeConfig.d.ts +22 -0
- package/dist/types/configuration/utils/index.d.ts +1 -0
- package/dist/types/configuration/utils/serverAuthority.d.ts +49 -0
- package/dist/types/connection/ConnectionIdManager.d.ts +67 -0
- package/dist/types/connection/ConnectionRecoveryManager.d.ts +164 -0
- package/dist/types/connection/index.d.ts +4 -0
- package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +153 -0
- package/dist/types/connection/networkConnection/index.d.ts +3 -0
- package/dist/types/connection/networkConnection/reporters.d.ts +43 -0
- package/dist/types/connection/networkConnection/types.d.ts +55 -0
- package/dist/types/connection/wsConnection/StableWSConnection.d.ts +204 -0
- package/dist/types/connection/wsConnection/WSConnection.d.ts +168 -0
- package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +55 -0
- package/dist/types/connection/wsConnection/config.d.ts +51 -0
- package/dist/types/connection/wsConnection/index.d.ts +4 -0
- package/dist/types/connection/wsConnection/types.d.ts +99 -0
- package/dist/types/constants.d.ts +3 -1
- package/dist/types/entityStore/EntityStore.d.ts +160 -40
- package/dist/types/entityStore/StoreBackedItemIndex.d.ts +48 -29
- package/dist/types/entityStore/index.d.ts +0 -1
- package/dist/types/errors.d.ts +24 -4
- package/dist/types/formatMessageMemo.d.ts +5 -0
- package/dist/types/gen/chat/ChannelApi.d.ts +51 -23
- package/dist/types/gen/chat/ChatApi.d.ts +215 -168
- package/dist/types/gen/models/index.d.ts +2164 -557
- package/dist/types/gen/models/timestamp-guard.d.ts +22 -0
- package/dist/types/gen/moderation/ModerationApi.d.ts +39 -32
- package/dist/types/gen-imports.d.ts +1 -0
- package/dist/types/index.d.ts +20 -7
- package/dist/types/languageNames.d.ts +97 -0
- package/dist/types/logger.d.ts +1 -1
- package/dist/types/messageComposer/CustomDataManager.d.ts +7 -1
- package/dist/types/messageComposer/LocationComposer.d.ts +10 -4
- package/dist/types/messageComposer/attachmentIdentity.d.ts +11 -0
- package/dist/types/messageComposer/attachmentManager.d.ts +48 -10
- package/dist/types/messageComposer/attachmentUtils.d.ts +34 -0
- package/dist/types/messageComposer/configuration/commands.configuration.d.ts +1 -3
- package/dist/types/messageComposer/configuration/configuration.d.ts +9 -1
- package/dist/types/messageComposer/configuration/index.d.ts +0 -1
- package/dist/types/messageComposer/configuration/types.d.ts +57 -1
- package/dist/types/messageComposer/index.d.ts +1 -0
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +10 -4
- package/dist/types/messageComposer/messageComposer.d.ts +210 -14
- package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +20 -1
- package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +11 -0
- package/dist/types/messageComposer/middleware/messageComposer/types.d.ts +2 -2
- package/dist/types/messageComposer/middleware/pollComposer/index.d.ts +1 -0
- package/dist/types/messageComposer/middleware/pollComposer/state.d.ts +3 -2
- package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +9 -2
- package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +44 -0
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +2 -2
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +94 -229
- package/dist/types/messageComposer/pollComposer.d.ts +8 -3
- package/dist/types/messageComposer/textComposer.d.ts +9 -1
- package/dist/types/messageComposer/types.d.ts +7 -3
- package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +64 -8
- package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +48 -11
- package/dist/types/messageOperations/FailedSendCache.d.ts +34 -0
- package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +52 -6
- package/dist/types/messageOperations/MessageOperations.d.ts +94 -11
- package/dist/types/{entityStore → messageOperations}/applyReactionLocally.d.ts +8 -2
- package/dist/types/messageOperations/createMessageOperations.d.ts +11 -0
- package/dist/types/messageOperations/index.d.ts +7 -1
- package/dist/types/messageOperations/reflectReactionEvent.d.ts +24 -0
- package/dist/types/messageOperations/sendOrdering.d.ts +17 -0
- package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +28 -0
- package/dist/types/messageOperations/types.d.ts +66 -1
- package/dist/types/middleware.d.ts +8 -0
- package/dist/types/moderation.d.ts +18 -4
- package/dist/types/notifications/NotificationManager.d.ts +43 -2
- package/dist/types/notifications/types.d.ts +55 -42
- package/dist/types/offline-support/offline_support_api.d.ts +128 -12
- package/dist/types/offline-support/offline_sync_manager.d.ts +26 -5
- package/dist/types/offline-support/queueableOperations.d.ts +106 -0
- package/dist/types/offline-support/types.d.ts +77 -28
- package/dist/types/pagination/FilterBuilder.d.ts +1 -18
- package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -1
- package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +21 -3
- package/dist/types/pagination/filterCompiler.d.ts +5 -0
- package/dist/types/pagination/paginators/BasePaginator.d.ts +331 -7
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +54 -11
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +283 -66
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +10 -9
- package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +17 -1
- package/dist/types/pagination/paginators/ReminderPaginator.d.ts +8 -8
- package/dist/types/pagination/paginators/ThreadPaginator.d.ts +57 -0
- package/dist/types/pagination/paginators/index.d.ts +1 -0
- package/dist/types/pagination/utility.normalization.d.ts +29 -2
- package/dist/types/poll.d.ts +41 -14
- package/dist/types/poll_manager.d.ts +3 -2
- package/dist/types/poll_optimistic_votes.d.ts +61 -0
- package/dist/types/reminders/Reminder.d.ts +17 -7
- package/dist/types/reminders/ReminderManager.d.ts +34 -6
- package/dist/types/search/BaseSearchSource.d.ts +50 -25
- package/dist/types/search/ChannelMemberSearchSource.d.ts +11 -6
- package/dist/types/search/ChannelSearchSource.d.ts +27 -5
- package/dist/types/search/MessageSearchSource.d.ts +36 -6
- package/dist/types/search/SearchController.d.ts +44 -11
- package/dist/types/search/UserSearchSource.d.ts +11 -5
- package/dist/types/search/types.d.ts +14 -1
- package/dist/types/signing.d.ts +0 -157
- package/dist/types/thread.d.ts +118 -62
- package/dist/types/thread_manager.d.ts +124 -35
- package/dist/types/token_manager.d.ts +5 -8
- package/dist/types/types.d.ts +138 -562
- package/dist/types/types.utility.d.ts +8 -0
- package/dist/types/upload-utils.d.ts +20 -0
- package/dist/types/uploadManager.d.ts +50 -2
- package/dist/types/utils/FixedSizeQueueCache.d.ts +2 -0
- package/dist/types/utils/WithSubscriptions.d.ts +1 -1
- package/dist/types/utils/objectPath.d.ts +49 -0
- package/dist/types/utils/time.d.ts +85 -0
- package/dist/types/utils.d.ts +63 -40
- package/package.json +22 -33
- package/src/ChannelManager.ts +561 -109
- package/src/CooldownTimer.ts +55 -45
- package/src/EventHandlerPipeline.ts +13 -23
- package/src/LiveLocationManager.ts +191 -37
- package/src/api-client.ts +144 -53
- package/src/channel.ts +1573 -1050
- package/src/channel_state.ts +239 -129
- package/src/client.ts +843 -892
- package/src/client_state.ts +2 -2
- package/src/configuration/ConfigController.ts +298 -0
- package/src/configuration/InstanceConfigurationRegistry.ts +430 -0
- package/src/configuration/index.ts +7 -0
- package/src/configuration/keys.ts +86 -0
- package/src/configuration/shape.ts +776 -0
- package/src/configuration/types.ts +218 -60
- package/src/configuration/utils/applyInstanceConfiguration.ts +184 -0
- package/src/configuration/utils/copyConfigPatch.ts +61 -0
- package/src/configuration/utils/declarativeSlices.ts +81 -0
- package/src/configuration/utils/deepFreezeConfig.ts +33 -0
- package/src/configuration/utils/index.ts +5 -0
- package/src/configuration/utils/serverAuthority.ts +146 -0
- package/src/connection/ConnectionIdManager.ts +153 -0
- package/src/connection/ConnectionRecoveryManager.ts +371 -0
- package/src/connection/index.ts +4 -0
- package/src/connection/networkConnection/NetworkConnectionObserver.ts +281 -0
- package/src/connection/networkConnection/index.ts +3 -0
- package/src/connection/networkConnection/reporters.ts +85 -0
- package/src/connection/networkConnection/types.ts +60 -0
- package/src/{connection.ts → connection/wsConnection/StableWSConnection.ts} +242 -151
- package/src/connection/wsConnection/WSConnection.ts +345 -0
- package/src/connection/wsConnection/WSConnectionFallback.ts +259 -0
- package/src/connection/wsConnection/config.ts +108 -0
- package/src/connection/wsConnection/index.ts +4 -0
- package/src/connection/wsConnection/types.ts +101 -0
- package/src/constants.ts +5 -3
- package/src/entityStore/EntityStore.ts +350 -10
- package/src/entityStore/StoreBackedItemIndex.ts +66 -37
- package/src/entityStore/index.ts +0 -1
- package/src/errors.ts +40 -7
- package/src/formatMessageMemo.ts +23 -0
- package/src/gen/chat/ChannelApi.ts +230 -44
- package/src/gen/chat/ChatApi.ts +1047 -1745
- package/src/gen/models/index.ts +2378 -3721
- package/src/gen/models/timestamp-guard.ts +27 -0
- package/src/gen/moderation/ModerationApi.ts +218 -388
- package/src/gen-imports.ts +1 -0
- package/src/index.ts +82 -6
- package/src/languageNames.ts +103 -0
- package/src/logger.ts +1 -1
- package/src/messageComposer/CustomDataManager.ts +10 -1
- package/src/messageComposer/LocationComposer.ts +68 -20
- package/src/messageComposer/attachmentIdentity.ts +39 -0
- package/src/messageComposer/attachmentManager.ts +191 -68
- package/src/messageComposer/attachmentUtils.ts +58 -0
- package/src/messageComposer/configuration/commands.configuration.ts +1 -26
- package/src/messageComposer/configuration/configuration.ts +22 -3
- package/src/messageComposer/configuration/index.ts +0 -1
- package/src/messageComposer/configuration/types.ts +58 -1
- package/src/messageComposer/index.ts +1 -0
- package/src/messageComposer/linkPreviewsManager.ts +16 -10
- package/src/messageComposer/messageComposer.ts +487 -98
- package/src/messageComposer/middleware/attachmentManager/postUpload/AttachmentPostUploadMiddlewareExecutor.ts +1 -1
- package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +58 -33
- package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +7 -2
- package/src/messageComposer/middleware/attachmentManager/preUpload/blockedUploadNotification.ts +3 -2
- package/src/messageComposer/middleware/messageComposer/attachments.ts +98 -1
- package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +20 -10
- package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +7 -2
- package/src/messageComposer/middleware/messageComposer/types.ts +2 -7
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +11 -6
- package/src/messageComposer/middleware/pollComposer/index.ts +1 -0
- package/src/messageComposer/middleware/pollComposer/state.ts +43 -11
- package/src/messageComposer/middleware/pollComposer/types.ts +9 -2
- package/src/messageComposer/middleware/pollComposer/validation.ts +76 -0
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +3 -2
- package/src/messageComposer/middleware/textComposer/commands.ts +1 -2
- package/src/messageComposer/middleware/textComposer/mentions.ts +91 -39
- package/src/messageComposer/pollComposer.ts +11 -3
- package/src/messageComposer/textComposer.ts +36 -4
- package/src/messageComposer/types.ts +19 -14
- package/src/messageDelivery/MessageDeliveryReporter.ts +154 -53
- package/src/messageDelivery/MessageReceiptsTracker.ts +136 -64
- package/src/messageOperations/FailedSendCache.ts +90 -0
- package/src/messageOperations/MessageOperationStatePolicy.ts +269 -27
- package/src/messageOperations/MessageOperations.ts +340 -136
- package/src/{entityStore → messageOperations}/applyReactionLocally.ts +10 -3
- package/src/messageOperations/createMessageOperations.ts +192 -0
- package/src/messageOperations/index.ts +7 -0
- package/src/messageOperations/reflectReactionEvent.ts +51 -0
- package/src/messageOperations/sendOrdering.ts +28 -0
- package/src/messageOperations/settlePendingAttachmentUploads.ts +110 -0
- package/src/messageOperations/types.ts +74 -0
- package/src/middleware.ts +11 -0
- package/src/moderation.ts +47 -24
- package/src/notifications/NotificationManager.ts +73 -3
- package/src/notifications/configuration.ts +10 -8
- package/src/notifications/types.ts +58 -42
- package/src/offline-support/offline_support_api.ts +380 -197
- package/src/offline-support/offline_sync_manager.ts +105 -32
- package/src/offline-support/queueableOperations.ts +270 -0
- package/src/offline-support/types.ts +85 -39
- package/src/pagination/FilterBuilder.ts +1 -22
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +11 -7
- package/src/pagination/cursorDerivation/linearPaginationFlags.ts +25 -7
- package/src/pagination/filterCompiler.ts +17 -0
- package/src/pagination/paginators/BasePaginator.ts +731 -81
- package/src/pagination/paginators/ChannelPaginator.ts +210 -102
- package/src/pagination/paginators/MessageIntervalPaginator.ts +703 -193
- package/src/pagination/paginators/MessagePaginator.ts +45 -36
- package/src/pagination/paginators/PinnedMessagePaginator.ts +74 -28
- package/src/pagination/paginators/ReminderPaginator.ts +15 -13
- package/src/pagination/paginators/ThreadPaginator.ts +181 -0
- package/src/pagination/paginators/UserGroupPaginator.ts +8 -1
- package/src/pagination/paginators/index.ts +1 -0
- package/src/pagination/utility.normalization.ts +37 -9
- package/src/poll.ts +189 -112
- package/src/poll_manager.ts +14 -8
- package/src/poll_optimistic_votes.ts +335 -0
- package/src/reminders/Reminder.ts +34 -16
- package/src/reminders/ReminderManager.ts +68 -41
- package/src/reminders/ReminderTimer.ts +7 -6
- package/src/search/BaseSearchSource.ts +133 -40
- package/src/search/ChannelMemberSearchSource.ts +27 -18
- package/src/search/ChannelSearchSource.ts +61 -7
- package/src/search/MessageSearchSource.ts +133 -28
- package/src/search/SearchController.ts +93 -16
- package/src/search/UserSearchSource.ts +27 -13
- package/src/search/types.ts +14 -1
- package/src/signing.ts +1 -315
- package/src/thread.ts +503 -511
- package/src/thread_manager.ts +339 -204
- package/src/token_manager.ts +12 -32
- package/src/types.ts +159 -780
- package/src/types.utility.ts +14 -0
- package/src/upload-utils.ts +53 -0
- package/src/uploadManager.ts +85 -7
- package/src/utils/FixedSizeQueueCache.ts +5 -0
- package/src/utils/WithSubscriptions.ts +1 -1
- package/src/utils/objectPath.ts +67 -0
- package/src/utils/time.ts +104 -0
- package/src/utils.ts +209 -157
- package/dist/types/base64.d.ts +0 -2
- package/dist/types/configuration/InstanceConfigurationService.d.ts +0 -26
- package/dist/types/connection.d.ts +0 -146
- package/dist/types/connection_fallback.d.ts +0 -42
- package/dist/types/gen/model-decoders/decoders.d.ts +0 -3
- package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +0 -6
- package/dist/types/insights.d.ts +0 -58
- package/dist/types/pagination/utility.queryChannel.d.ts +0 -26
- package/dist/types/permissions.d.ts +0 -55
- package/dist/types/store.d.ts +0 -125
- package/src/base64.ts +0 -78
- package/src/configuration/InstanceConfigurationService.ts +0 -73
- package/src/connection_fallback.ts +0 -215
- package/src/gen/model-decoders/decoders.ts +0 -2680
- package/src/gen/model-decoders/event-decoder-mapping.ts +0 -198
- package/src/insights.ts +0 -83
- package/src/pagination/utility.queryChannel.ts +0 -84
- package/src/permissions.ts +0 -102
- package/src/store.ts +0 -304
|
@@ -1,10 +1,41 @@
|
|
|
1
|
-
import { StateStore } from '
|
|
1
|
+
import { StateStore } from '@stream-io/state-store';
|
|
2
2
|
import type { AddNotificationPayload, Notification, NotificationManagerConfig, NotificationState } from './types';
|
|
3
|
+
import type { DeepPartial } from '../types.utility';
|
|
3
4
|
export declare class NotificationManager {
|
|
4
5
|
store: StateStore<NotificationState>;
|
|
5
6
|
private timeouts;
|
|
6
|
-
|
|
7
|
+
/** The shared configuration machinery — see {@link ConfigController}. */
|
|
8
|
+
private readonly configController;
|
|
9
|
+
/**
|
|
10
|
+
* Resolved configuration, as a store so consumers can react to it — the same shape every configurable
|
|
11
|
+
* class exposes (`configState` for the store, {@link config} for the current value).
|
|
12
|
+
*/
|
|
13
|
+
get configState(): StateStore<NotificationManagerConfig>;
|
|
7
14
|
constructor(config?: Partial<NotificationManagerConfig>);
|
|
15
|
+
/**
|
|
16
|
+
* The current resolved configuration. `Readonly` because the value is the store's live object —
|
|
17
|
+
* assigning to a field of it would change state without notifying anyone. Use {@link updateConfig}.
|
|
18
|
+
*/
|
|
19
|
+
get config(): Readonly<NotificationManagerConfig>;
|
|
20
|
+
/** Deep-merges a partial configuration into the resolved config and notifies subscribers. */
|
|
21
|
+
updateConfig(config: Partial<NotificationManagerConfig>): void;
|
|
22
|
+
/**
|
|
23
|
+
* Rebuilds the resolved configuration from package defaults plus the declarative slice, **replacing**
|
|
24
|
+
* what is there rather than merging into it. Called by the client's derivation, which shares one path
|
|
25
|
+
* with `client.config.reset()`.
|
|
26
|
+
*
|
|
27
|
+
* The distinction is not cosmetic here, and this manager is the only one that needs it.
|
|
28
|
+
* {@link updateConfig} deep-merges, and `sortComparator` is optional — so unlike every other field of
|
|
29
|
+
* every other manager config, it has no counterpart in {@link DEFAULT_NOTIFICATION_MANAGER_CONFIG} for
|
|
30
|
+
* a derivation to overwrite it with. Registering one through `client.config` therefore made it
|
|
31
|
+
* permanent: `reset()` re-derived, the merge kept it, and nothing could ever remove it. A merge cannot
|
|
32
|
+
* express a removal; this is the same rule `Channel.initializeConfig` follows for `requestHandlers`.
|
|
33
|
+
*
|
|
34
|
+
* The defaults are copied rather than spread, because a shallow spread would leave `durations`
|
|
35
|
+
* pointing at the module-level object and put it in the store, where a nested write would change the
|
|
36
|
+
* default for every client in the process.
|
|
37
|
+
*/
|
|
38
|
+
initializeConfig(config?: DeepPartial<NotificationManagerConfig>): void;
|
|
8
39
|
get notifications(): Notification[];
|
|
9
40
|
get warning(): Notification[];
|
|
10
41
|
get error(): Notification[];
|
|
@@ -17,6 +48,16 @@ export declare class NotificationManager {
|
|
|
17
48
|
addSuccess({ message, origin, options }: AddNotificationPayload): string;
|
|
18
49
|
clearTimeout(id: string): void;
|
|
19
50
|
startTimeout(id: string, durationOverride?: number): void;
|
|
51
|
+
/**
|
|
52
|
+
* Starts the notification's auto-dismiss countdown unless one is already running.
|
|
53
|
+
*
|
|
54
|
+
* The counterpart to {@link startTimeout}, which always restarts. Use this wherever the caller
|
|
55
|
+
* cannot know whether the countdown has been started already -- a UI component that remounts and
|
|
56
|
+
* has lost the record, or a second view displaying the same notification. Restarting there is
|
|
57
|
+
* invisible and open-ended: each call hands the notification another full lifetime, so it can
|
|
58
|
+
* outlive its duration indefinitely while looking like it is counting down.
|
|
59
|
+
*/
|
|
60
|
+
ensureTimeout(id: string, durationOverride?: number): void;
|
|
20
61
|
remove(id: string): void;
|
|
21
62
|
clear(): void;
|
|
22
63
|
}
|
|
@@ -13,11 +13,59 @@ export type NotificationOrigin = {
|
|
|
13
13
|
emitter: string;
|
|
14
14
|
context?: Record<string, unknown>;
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Every notification type emitted by `stream-chat` itself.
|
|
18
|
+
*
|
|
19
|
+
* Format is `domain:entity:operation:result`:
|
|
20
|
+
* - `domain` — where it happened: `api`, `validation`, `permission`, `network`, `auth`, `system`
|
|
21
|
+
* - `entity` — what was operated on: `attachment`, `poll`, `message`, `command`, `location`
|
|
22
|
+
* - `operation` — what was attempted, lowerCamelCase: `upload`, `create`, `castVote`, `jumpToLatest`
|
|
23
|
+
* - `result` — what happened: `failed`, `blocked`, `invalid`, `missing`, `limit`, `success`,
|
|
24
|
+
* or a short hyphenated state such as `in-progress` / `not-ready`
|
|
25
|
+
*
|
|
26
|
+
* **These values are public API.** UI SDKs key their translation tables on them, so renaming one is
|
|
27
|
+
* a breaking change. Emit them through this map rather than writing the literal inline, so the whole
|
|
28
|
+
* set stays greppable from one place and a typo is a compile error.
|
|
29
|
+
*
|
|
30
|
+
* Consumers translating notifications should switch on {@link Notification.type} rather than matching
|
|
31
|
+
* on {@link Notification.message}, which is untranslated English intended as a developer-facing
|
|
32
|
+
* fallback.
|
|
33
|
+
*/
|
|
34
|
+
export declare const CORE_NOTIFICATION_TYPE: {
|
|
35
|
+
readonly attachmentFileMissing: "validation:attachment:file:missing";
|
|
36
|
+
readonly attachmentIdMissing: "validation:attachment:id:missing";
|
|
37
|
+
readonly attachmentUploadBlocked: "validation:attachment:upload:blocked";
|
|
38
|
+
readonly attachmentUploadFailed: "api:attachment:upload:failed";
|
|
39
|
+
readonly attachmentUploadInProgress: "validation:attachment:upload:in-progress";
|
|
40
|
+
/** Carries `metadata.reason` (`'editing' | 'quoted_message'`), which the message depends on. */
|
|
41
|
+
readonly commandDisabled: "validation:command:disabled";
|
|
42
|
+
readonly commandNotReady: "validation:command:not-ready";
|
|
43
|
+
readonly locationCreateFailed: "api:location:create:failed";
|
|
44
|
+
/** Jumping to a specific message failed. */
|
|
45
|
+
readonly messageJumpFailed: "api:message:jump:failed";
|
|
46
|
+
/** Jumping to the latest message failed. */
|
|
47
|
+
readonly messageJumpToLatestFailed: "api:message:jumpToLatest:failed";
|
|
48
|
+
/** Sending a composed message failed. The message stays in the list, marked failed. */
|
|
49
|
+
readonly messageSendFailed: "api:message:send:failed";
|
|
50
|
+
/** Saving an edit failed. The edit is kept on the message, marked failed. */
|
|
51
|
+
readonly messageUpdateFailed: "api:message:update:failed";
|
|
52
|
+
readonly pollCastVoteLimit: "validation:poll:castVote:limit";
|
|
53
|
+
readonly pollCreateFailed: "api:poll:create:failed";
|
|
54
|
+
};
|
|
55
|
+
/** A notification type emitted by `stream-chat` itself. See {@link CORE_NOTIFICATION_TYPE}. */
|
|
56
|
+
export type CoreNotificationType = (typeof CORE_NOTIFICATION_TYPE)[keyof typeof CORE_NOTIFICATION_TYPE];
|
|
16
57
|
/** Represents a single notification message */
|
|
17
58
|
export type Notification = {
|
|
18
59
|
/** Unique identifier for the notification */
|
|
19
60
|
id: string;
|
|
20
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Untranslated English text describing what happened.
|
|
63
|
+
*
|
|
64
|
+
* This is a **developer-facing fallback, not display copy.** It is not localized and its exact
|
|
65
|
+
* wording is not part of the public contract — it can be reworded in a minor release. Anything
|
|
66
|
+
* user-facing should resolve {@link Notification.type} to its own copy and fall back to this string
|
|
67
|
+
* only for an identifier it does not recognize.
|
|
68
|
+
*/
|
|
21
69
|
message: string;
|
|
22
70
|
/** Timestamp when notification was created */
|
|
23
71
|
createdAt: number;
|
|
@@ -31,49 +79,14 @@ export type Notification = {
|
|
|
31
79
|
/** The severity level of the notification (defaults to `undefined` unless explicitly provided). */
|
|
32
80
|
severity?: NotificationSeverity;
|
|
33
81
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* domain: where the error occurred (api, validation, permission, etc)
|
|
37
|
-
* entity: what was being operated on (poll, attachment, message, etc)
|
|
38
|
-
* operation: what was being attempted (create, upload, validate, etc)
|
|
39
|
-
* result: what happened (failed, blocked, invalid, etc)
|
|
40
|
-
*
|
|
41
|
-
* Poll related errors
|
|
42
|
-
* 'api:poll:create:failed' // API call to create poll failed
|
|
43
|
-
* 'validation:poll:create:invalid' // Poll creation validation failed
|
|
44
|
-
*
|
|
45
|
-
* Attachment related errors
|
|
46
|
-
* 'validation:attachment:file:missing' // Required file is missing
|
|
47
|
-
* 'permission:attachment:upload:blocked' // Upload blocked due to permissions
|
|
48
|
-
* 'api:attachment:upload:failed' // API upload call failed
|
|
49
|
-
* 'validation:attachment:type:unsupported' // Unsupported file type
|
|
50
|
-
* 'validation:attachment:size:exceeded' // File size too large
|
|
51
|
-
* 'validation:attachment:count:exceeded' // Too many attachments
|
|
52
|
-
*
|
|
53
|
-
* MessageRequest related errors
|
|
54
|
-
* 'api:message:send:failed' // MessageRequest send failed
|
|
55
|
-
* 'validation:message:content:empty' // MessageRequest content validation failed
|
|
56
|
-
*
|
|
57
|
-
* Channel related errors
|
|
58
|
-
* 'api:channel:join:failed' // Channel join failed
|
|
59
|
-
* 'permission:channel:access:denied' // Channel access denied
|
|
60
|
-
*
|
|
61
|
-
* Authentication related errors
|
|
62
|
-
* 'auth:token:expired' // Auth token expired
|
|
63
|
-
* 'auth:token:invalid' // Invalid auth token
|
|
64
|
-
*
|
|
65
|
-
* Network related errors
|
|
66
|
-
* 'network:request:timeout' // Request timed out
|
|
67
|
-
* 'network:request:failed' // Network request failed
|
|
68
|
-
*
|
|
69
|
-
* Rate limiting
|
|
70
|
-
* 'rate:limit:exceeded' // Rate limit exceeded
|
|
82
|
+
* Stable identifier for what this notification is about, used to group notifications of the same
|
|
83
|
+
* kind and — for UI SDKs — to resolve a translation without matching on the English `message`.
|
|
71
84
|
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
85
|
+
* Values emitted by `stream-chat` are enumerated in {@link CORE_NOTIFICATION_TYPE}; those are the
|
|
86
|
+
* ones that autocomplete. The type stays open so SDKs and integrators can emit their own
|
|
87
|
+
* identifiers following the same `domain:entity:operation:result` convention.
|
|
75
88
|
*/
|
|
76
|
-
type?: string;
|
|
89
|
+
type?: CoreNotificationType | (string & {});
|
|
77
90
|
/** Optional auto-dismiss duration in milliseconds. The timeout starts when NotificationManager.startTimeout() is called. */
|
|
78
91
|
duration?: number;
|
|
79
92
|
/** Optional metadata to attach to the notification */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Event, EventPayload } from '../types';
|
|
2
|
-
import type { OfflineDBApi, OfflineDBState, PendingTask, PrepareBatchDBQueries } from './types';
|
|
1
|
+
import type { Event, EventPayload, LocalMessage } from '../types';
|
|
2
|
+
import type { ExecuteBatchDBQueriesType, OfflineDBApi, OfflineDBState, PendingTask, PrepareBatchDBQueries } from './types';
|
|
3
3
|
import type { StreamChat } from '../client';
|
|
4
4
|
import { OfflineDBSyncManager } from './offline_sync_manager';
|
|
5
|
-
import { StateStore } from '
|
|
5
|
+
import { StateStore } from '@stream-io/state-store';
|
|
6
6
|
/**
|
|
7
7
|
* Abstract base class for an offline database implementation used with StreamChat.
|
|
8
8
|
*
|
|
@@ -16,8 +16,14 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
|
|
|
16
16
|
private client;
|
|
17
17
|
syncManager: OfflineDBSyncManager;
|
|
18
18
|
state: StateStore<OfflineDBState>;
|
|
19
|
-
constructor({ client }: {
|
|
19
|
+
constructor({ client, syncMaxEventCount, }: {
|
|
20
20
|
client: StreamChat;
|
|
21
|
+
/**
|
|
22
|
+
* Optional positive cap forwarded to the {@link OfflineDBSyncManager}, which
|
|
23
|
+
* owns sync. `undefined` or any non-positive value means "no limit". See
|
|
24
|
+
* {@link OfflineDBSyncManager.syncMaxEventCount}.
|
|
25
|
+
*/
|
|
26
|
+
syncMaxEventCount?: number;
|
|
21
27
|
});
|
|
22
28
|
/**
|
|
23
29
|
* Inserts a reaction into the DB.
|
|
@@ -440,6 +446,14 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
|
|
|
440
446
|
execute?: boolean;
|
|
441
447
|
forceUpdate?: boolean;
|
|
442
448
|
}, createQueries: (executeOverride?: boolean) => Promise<PrepareBatchDBQueries[]>) => Promise<PrepareBatchDBQueries[]>;
|
|
449
|
+
/**
|
|
450
|
+
* Prepends the channel row to `createQueries`' output so the queries cannot fail on the `cid`
|
|
451
|
+
* foreign key, sourcing the channel from the event and falling back to the in-memory channel.
|
|
452
|
+
*
|
|
453
|
+
* Skips the write entirely when neither can supply it: without a channel row the queries would fail
|
|
454
|
+
* anyway, and dropping the event is what the caller expects.
|
|
455
|
+
*/
|
|
456
|
+
private queriesBehindChannelGuard;
|
|
443
457
|
/**
|
|
444
458
|
* Handles a message.new event. Will always use a channel guard for the inner queries
|
|
445
459
|
* and it is going to make sure that both messages and reads are upserted. It will not
|
|
@@ -476,6 +490,62 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
|
|
|
476
490
|
messageId: string;
|
|
477
491
|
execute?: boolean;
|
|
478
492
|
}) => Promise<PrepareBatchDBQueries[]>;
|
|
493
|
+
/**
|
|
494
|
+
* Hard-delete a set of messages by id in a single transaction. A convenience over N individual
|
|
495
|
+
* {@link hardDeleteMessage} calls: collects each delete's queries (`execute: false`) and runs them
|
|
496
|
+
* as one batch. Used e.g. by destructive reconciliation on reconnect to mirror a set of in-memory
|
|
497
|
+
* removals into the DB. No-op for an empty set.
|
|
498
|
+
*
|
|
499
|
+
* @param payload.ids - The ids of the messages to hard-delete.
|
|
500
|
+
* @param payload.execute - Whether to immediately execute the operation (optional, defaults to `true`).
|
|
501
|
+
*/
|
|
502
|
+
hardDeleteMessages: ({ ids, execute, }: {
|
|
503
|
+
ids: string[];
|
|
504
|
+
execute?: boolean;
|
|
505
|
+
}) => Promise<PrepareBatchDBQueries[]>;
|
|
506
|
+
/**
|
|
507
|
+
* Upsert a single message, first making sure its channel row exists so the insert cannot fail on the
|
|
508
|
+
* foreign key.
|
|
509
|
+
*
|
|
510
|
+
* Concrete on purpose — it composes {@link channelExists}, {@link upsertChannelData} and
|
|
511
|
+
* {@link upsertMessages}, so every implementation inherits it and no custom offline DB has to
|
|
512
|
+
* implement anything new (same reasoning as {@link hardDeleteMessages}).
|
|
513
|
+
*
|
|
514
|
+
* The guard matters because the message-operations engine writes optimistically, and the very first
|
|
515
|
+
* message in a freshly created channel can reach here before that channel has ever been persisted.
|
|
516
|
+
* `upsertMessages` alone is used rather than `updateMessage` because `updateMessage` is an
|
|
517
|
+
* UPDATE — it no-ops when the row does not exist yet, which is exactly the write-ahead case.
|
|
518
|
+
*
|
|
519
|
+
* @param payload.message - The message to persist. Its `cid` decides which channel row is guarded.
|
|
520
|
+
* @param payload.execute - Whether to immediately execute the operation (optional, defaults to `true`).
|
|
521
|
+
*/
|
|
522
|
+
upsertMessageWithChannelGuard: ({ message, execute, }: {
|
|
523
|
+
message: LocalMessage;
|
|
524
|
+
execute?: boolean;
|
|
525
|
+
}) => Promise<ExecuteBatchDBQueriesType>;
|
|
526
|
+
/**
|
|
527
|
+
* Writes the channel row ahead of the messages so the insert cannot fail on the `cid` foreign key.
|
|
528
|
+
* Skips the write when there is nothing to build a channel row from — the message stays correct in
|
|
529
|
+
* memory either way, and an insert that cannot resolve its foreign key is not worth attempting.
|
|
530
|
+
*/
|
|
531
|
+
private upsertMessageBehindChannelGuard;
|
|
532
|
+
/**
|
|
533
|
+
* The messages of a channel that are still in a local `failed` state, i.e. composed by this user but
|
|
534
|
+
* never accepted by the server.
|
|
535
|
+
*
|
|
536
|
+
* Concrete, composed from the existing {@link getChannels} primitive, so it adds nothing to
|
|
537
|
+
* {@link OfflineDBApi} that a custom offline DB would have to implement.
|
|
538
|
+
*
|
|
539
|
+
* This is the buffer that lets a failed message survive. v9 recovered such messages by diffing a
|
|
540
|
+
* second, lagging copy of the message list (the React SDK state) against `channel.state`; with a
|
|
541
|
+
* single reactive source of truth the persisted row is the only place that memory can be
|
|
542
|
+
* re-populated from — see `Channel.reload`.
|
|
543
|
+
*
|
|
544
|
+
* @param payload.cid - The channel whose failed messages to read.
|
|
545
|
+
*/
|
|
546
|
+
getFailedMessages: ({ cid, }: {
|
|
547
|
+
cid: string;
|
|
548
|
+
}) => Promise<LocalMessage[]>;
|
|
479
549
|
/**
|
|
480
550
|
* A utility method to handle read events. It will calculate the state of the reads if
|
|
481
551
|
* present in the event, or optionally rely on the hard override in unreadMessages.
|
|
@@ -528,7 +598,7 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
|
|
|
528
598
|
handleChannelVisibilityEvent: ({ event, execute, }: {
|
|
529
599
|
event: EventPayload<"channel.visible" | "channel.hidden">;
|
|
530
600
|
execute?: boolean;
|
|
531
|
-
}) => Promise<
|
|
601
|
+
}) => Promise<ExecuteBatchDBQueriesType>;
|
|
532
602
|
/**
|
|
533
603
|
* A utility handler used to handle channel.truncated events. It handles both
|
|
534
604
|
* removing all messages and relying on truncated_at as well. It will also upsert
|
|
@@ -566,7 +636,7 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
|
|
|
566
636
|
handleDraftEvent: ({ event, execute, }: {
|
|
567
637
|
event: EventPayload<`draft.${string}`>;
|
|
568
638
|
execute?: boolean;
|
|
569
|
-
}) => Promise<
|
|
639
|
+
}) => Promise<ExecuteBatchDBQueriesType>;
|
|
570
640
|
/**
|
|
571
641
|
* A generic event handler that decides which DB API to invoke based on
|
|
572
642
|
* event.type for all events we are currently handling. It is used to both
|
|
@@ -578,7 +648,7 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
|
|
|
578
648
|
handleEvent: ({ event, execute, }: {
|
|
579
649
|
event: Event;
|
|
580
650
|
execute?: boolean;
|
|
581
|
-
}) => Promise<
|
|
651
|
+
}) => Promise<ExecuteBatchDBQueriesType>;
|
|
582
652
|
/**
|
|
583
653
|
* A method used to enqueue a pending task if the execution of it fails.
|
|
584
654
|
* It will try to do the following:
|
|
@@ -589,6 +659,26 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
|
|
|
589
659
|
*
|
|
590
660
|
* It will return the response from the execution if it succeeded.
|
|
591
661
|
*
|
|
662
|
+
* A task payload is the argument list of the method being replayed, so it carries that
|
|
663
|
+
* method's trailing `requestOptions` too. How far an `AbortSignal` in there survives depends on
|
|
664
|
+
* the path:
|
|
665
|
+
*
|
|
666
|
+
* - Step 1 above never leaves memory, so the signal is live and the call is cancellable exactly
|
|
667
|
+
* as it would be outside the queue. This is the common case.
|
|
668
|
+
* - A task that reaches the pending-tasks table survives only as far as the concrete
|
|
669
|
+
* implementation's storage allows. {@link OfflineDBApi.addPendingTask} and
|
|
670
|
+
* {@link OfflineDBApi.getPendingTasks} make no serialization promise either way: a store that
|
|
671
|
+
* hands back the object it was given keeps the signal live, while one that encodes the payload
|
|
672
|
+
* (as a SQLite-backed store does) revives it as an inert `{}`. Across a process restart it is
|
|
673
|
+
* always the latter.
|
|
674
|
+
*
|
|
675
|
+
* `ApiClient` drops a signal it cannot listen to rather than handing it to axios (which would
|
|
676
|
+
* throw), so a replay that lost its signal simply runs uncancellable.
|
|
677
|
+
*
|
|
678
|
+
* Note that cancelling is not a way to drop a queued task after the fact — an aborted request is
|
|
679
|
+
* a definitive rejection ({@link isEphemeral} is `false` for it), so it is never queued in the
|
|
680
|
+
* first place.
|
|
681
|
+
*
|
|
592
682
|
* @param task - the pending task we want to execute
|
|
593
683
|
*/
|
|
594
684
|
queueTask: <T>({ task }: {
|
|
@@ -599,17 +689,33 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
|
|
|
599
689
|
* i.e. the failure is a definitive rejection rather than an ephemeral/retryable one. A task is
|
|
600
690
|
* kept in the queue only when its error is {@link isEphemeral} (connection/network error or a
|
|
601
691
|
* retryable server code). A non retryable server response (i.e bad request, not allowed etc) is
|
|
602
|
-
* skipped since retrying it would never succeed
|
|
692
|
+
* skipped since retrying it would never succeed, and so is a request the caller cancelled via
|
|
693
|
+
* `StreamRequestOptions.signal` - replaying it would defeat the point of aborting.
|
|
603
694
|
*
|
|
604
695
|
* @param error - The error thrown while executing the failed task.
|
|
605
696
|
*/
|
|
606
697
|
private shouldSkipQueueingTask;
|
|
607
|
-
private mergeFailedMessageUpdateIntoPendingSendMessage;
|
|
608
698
|
private isPendingSendMessageTask;
|
|
609
|
-
private handleOfflineFailedUpdateMessagePendingTask;
|
|
610
699
|
/**
|
|
611
|
-
*
|
|
612
|
-
*
|
|
700
|
+
* Folds an edit of a message the server has never seen into that message's queued `send-message`
|
|
701
|
+
* task, so a replay sends the edited text once instead of sending the original and then editing it.
|
|
702
|
+
* The send task keeps its row, and with it its place in the queue, which is what keeps the edited
|
|
703
|
+
* message ordered against everything queued after it.
|
|
704
|
+
*
|
|
705
|
+
* Keyed on a queued `send-message` task existing for this id - the only reliable statement of "the
|
|
706
|
+
* server has never seen this message". NOT on the edited message's status: `failed` is also what a
|
|
707
|
+
* rejected edit of a message the server has carries.
|
|
708
|
+
*
|
|
709
|
+
* Both payloads are already `MessageRequest`s (the send's from `localMessageToNewMessagePayload`, the
|
|
710
|
+
* edit's from `toUpdatedMessagePayload`), which is why they merge by a plain spread: normalizing again
|
|
711
|
+
* would map an already-flattened `mentioned_users` back over itself as `[undefined]`.
|
|
712
|
+
*
|
|
713
|
+
* With nothing to fold into, the edit is queued on its own and replays as an ordinary update.
|
|
714
|
+
*/
|
|
715
|
+
private handleUpdateMessagePendingTask;
|
|
716
|
+
/**
|
|
717
|
+
* Central ingress for persisting pending tasks. It either stores the task as-is or folds an edit of
|
|
718
|
+
* a message that has not been sent yet into that message's queued `send-message` task.
|
|
613
719
|
*/
|
|
614
720
|
handleAddPendingTask: ({ task }: {
|
|
615
721
|
task: PendingTask;
|
|
@@ -630,6 +736,16 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
|
|
|
630
736
|
* @param isPendingTask - a control value telling us if it's an actual pending task being executed
|
|
631
737
|
* or delayed execution
|
|
632
738
|
*/
|
|
739
|
+
/**
|
|
740
|
+
* Replays one queued operation, through the {@link QUEUEABLE_OPERATIONS} registry rather than a
|
|
741
|
+
* per-type branch here — the same registry a first attempt resolves through, so the two cannot
|
|
742
|
+
* describe different requests.
|
|
743
|
+
*
|
|
744
|
+
* @param task - the task to run.
|
|
745
|
+
* @param isPendingTask - whether this is a replay rather than a first attempt. A first attempt has an
|
|
746
|
+
* optimistic layer above it that settles local state; a replay does not, so some operations have to
|
|
747
|
+
* settle it themselves (see `onReplay`).
|
|
748
|
+
*/
|
|
633
749
|
private executeTask;
|
|
634
750
|
/**
|
|
635
751
|
* A utility method used to execute all pending tasks. As each task succeeds execution,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { StreamChat } from '../client';
|
|
2
2
|
import type { AbstractOfflineDB } from './offline_support_api';
|
|
3
|
+
import type { Unsubscribe } from '@stream-io/state-store';
|
|
3
4
|
/**
|
|
4
5
|
* Manages synchronization between the local offline database and the Stream backend.
|
|
5
6
|
*
|
|
@@ -8,17 +9,30 @@ import type { AbstractOfflineDB } from './offline_support_api';
|
|
|
8
9
|
* consistent with the server once connectivity is restored.
|
|
9
10
|
*/
|
|
10
11
|
export declare class OfflineDBSyncManager {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
isSynced: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Releases the subscription to the socket's status store. A bare unsubscribe now that this reads a
|
|
15
|
+
* store rather than an event, which no longer wraps it in an object.
|
|
16
|
+
*/
|
|
17
|
+
connectionChangedListener: Unsubscribe | null;
|
|
15
18
|
private syncStatusListeners;
|
|
16
19
|
private scheduledSyncStatusCallbacks;
|
|
17
20
|
private client;
|
|
18
21
|
private offlineDb;
|
|
19
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Optional positive cap on the number of events a single `/sync` response may
|
|
24
|
+
* contain before this manager skips event replay into local storage and relies
|
|
25
|
+
* on the reconnect-time channel refresh (queryChannels + `channel.watch()`) to
|
|
26
|
+
* bring visible surfaces up to date.
|
|
27
|
+
*
|
|
28
|
+
* `undefined` or any non-positive value means "no limit" and event replay always
|
|
29
|
+
* runs with whatever maximum the server decides to return.
|
|
30
|
+
*/
|
|
31
|
+
readonly syncMaxEventCount?: number;
|
|
32
|
+
constructor({ client, offlineDb, syncMaxEventCount, }: {
|
|
20
33
|
client: StreamChat;
|
|
21
34
|
offlineDb: AbstractOfflineDB;
|
|
35
|
+
syncMaxEventCount?: number;
|
|
22
36
|
});
|
|
23
37
|
/**
|
|
24
38
|
* Initializes the sync manager. Should only be called once per session.
|
|
@@ -58,6 +72,13 @@ export declare class OfflineDBSyncManager {
|
|
|
58
72
|
private sync;
|
|
59
73
|
/**
|
|
60
74
|
* Executes any tasks that were queued while offline and then performs a sync.
|
|
75
|
+
*
|
|
76
|
+
* Each step is isolated so a failure in one does not prevent the other, and
|
|
77
|
+
* neither can escape to the callers (init + the status subscription).
|
|
78
|
+
* This guarantees the subsequent invokeSyncStatusListeners(true) always runs,
|
|
79
|
+
* so isSynced recovers to true and gated channel queries are unblocked.
|
|
80
|
+
* Failed syncs degrade to "possibly stale data until the next query" rather
|
|
81
|
+
* than freezing all future queries. See issue #1816.
|
|
61
82
|
*/
|
|
62
83
|
private syncAndExecutePendingTasks;
|
|
63
84
|
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Channel } from '../channel';
|
|
2
|
+
import type { StreamChat } from '../client';
|
|
3
|
+
import type { PendingTaskOf, QueueableResult, QueueableType } from './types';
|
|
4
|
+
export type QueueableOperation<T extends QueueableType> = {
|
|
5
|
+
/**
|
|
6
|
+
* How a failed QUEUEING attempt is logged. Declared per operation rather than passed in per call,
|
|
7
|
+
* because the wording is a property of the operation, not of the caller — and the caller is then left
|
|
8
|
+
* saying only which operation it wants.
|
|
9
|
+
*/
|
|
10
|
+
logFailureAs: {
|
|
11
|
+
message: string;
|
|
12
|
+
method: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Whether a replay has to look the channel up from the task. Such a task is only queued when it
|
|
16
|
+
* carries `channelId` and `channelType`, because without them it could never be replayed.
|
|
17
|
+
*/
|
|
18
|
+
needsChannel: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Performs the request. Used both for a first attempt and for a replay.
|
|
21
|
+
*
|
|
22
|
+
* `channel` is the instance the CALLER already holds, when there is one. A first attempt comes from a
|
|
23
|
+
* channel's or thread's `messageOperations`, or a `Channel` method such as `createDraft`, and must run
|
|
24
|
+
* on that exact channel; only a replay has to look one up.
|
|
25
|
+
*/
|
|
26
|
+
run: (params: {
|
|
27
|
+
channel?: Channel;
|
|
28
|
+
client: StreamChat;
|
|
29
|
+
task: PendingTaskOf<T>;
|
|
30
|
+
}) => Promise<QueueableResult<T>>;
|
|
31
|
+
/**
|
|
32
|
+
* Local state to settle AFTER a replay, and only after a replay — a first attempt has an optimistic
|
|
33
|
+
* layer above it that already owns this. Declared per operation rather than hidden in a branch,
|
|
34
|
+
* because "a replay does more than a first attempt" is the kind of asymmetry that goes unnoticed.
|
|
35
|
+
*/
|
|
36
|
+
onReplay?: (params: {
|
|
37
|
+
client: StreamChat;
|
|
38
|
+
result: QueueableResult<T>;
|
|
39
|
+
task: PendingTaskOf<T>;
|
|
40
|
+
}) => void;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The registry: one entry per queueable operation, and the mapped type means a missing entry does not
|
|
44
|
+
* compile.
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export declare const QUEUEABLE_OPERATIONS: {
|
|
49
|
+
[T in QueueableType]: QueueableOperation<T>;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The shape every offline-aware request shares: try it through the pending-task queue so it can be
|
|
53
|
+
* replayed on reconnect, and otherwise — no offline DB, queueing not possible, or the queued attempt
|
|
54
|
+
* rejected — run it directly.
|
|
55
|
+
*
|
|
56
|
+
* Both paths resolve through {@link QUEUEABLE_OPERATIONS}, so "what this task actually runs" is defined
|
|
57
|
+
* once. Before, the caller passed its own direct call alongside the task, which meant the first attempt
|
|
58
|
+
* and the replay were two independent statements of the same thing.
|
|
59
|
+
*
|
|
60
|
+
* Note the direct call is BOTH the no-offline-DB path — its actual purpose — and, on a queue failure, a
|
|
61
|
+
* second attempt at a request that may already have reached the server. That predates this helper and
|
|
62
|
+
* is unchanged by it; having one place to fix it is a reason this exists.
|
|
63
|
+
*
|
|
64
|
+
* A failed queueing attempt is logged, not rethrown: falling back to running the request directly is
|
|
65
|
+
* the point. What it is logged as comes off the operation's own `logFailureAs`, so a caller says which
|
|
66
|
+
* operation it wants and nothing about how to describe it.
|
|
67
|
+
*
|
|
68
|
+
* @internal
|
|
69
|
+
*
|
|
70
|
+
* @param params.channel - The channel instance the caller already holds, so a first attempt runs on
|
|
71
|
+
* that exact object rather than one `client.channelManager.ensure()` might reconstruct.
|
|
72
|
+
* @param params.client - Resolves the operation, and carries the offline DB when one is registered.
|
|
73
|
+
* @param params.queue - Whether this task can be queued at all. `false` for a send with no message id,
|
|
74
|
+
* which there is nothing to key a queue entry on — it still runs, just not through the queue.
|
|
75
|
+
* @param params.task - Which operation to run, and the arguments to run it with.
|
|
76
|
+
*/
|
|
77
|
+
export declare const queueOrRun: <T extends QueueableType>({ channel, client, queue, task, }: {
|
|
78
|
+
channel?: Channel;
|
|
79
|
+
client: StreamChat;
|
|
80
|
+
queue?: boolean;
|
|
81
|
+
task: PendingTaskOf<T>;
|
|
82
|
+
}) => Promise<QueueableResult<T>>;
|
|
83
|
+
/**
|
|
84
|
+
* Resolves a task to its operation and runs it. Shared by a first attempt and by a replay.
|
|
85
|
+
*
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
export declare const runQueueableOperation: <T extends QueueableType>({ channel, client, task, }: {
|
|
89
|
+
channel?: Channel;
|
|
90
|
+
client: StreamChat;
|
|
91
|
+
task: PendingTaskOf<T>;
|
|
92
|
+
}) => Promise<QueueableResult<T>>;
|
|
93
|
+
/**
|
|
94
|
+
* Whether this message's mutation is sitting in the offline queue waiting to be replayed. A queued
|
|
95
|
+
* mutation is pending, not failed: nothing to roll back and nothing to mark.
|
|
96
|
+
*
|
|
97
|
+
* Reads the queue. Inferring it from the error's shape ("an initialized offline DB plus an
|
|
98
|
+
* `isEphemeral` error, so it must have been queued") over-reports, because the queue declines
|
|
99
|
+
* tasks no error shape can predict — an `update-message` whose payload still points at a local
|
|
100
|
+
* attachment URL is refused by `isMessageUpdateReplayable`, and the edit would then be suppressed as
|
|
101
|
+
* "pending" with nothing to replay it. A row in the pending-tasks table is the actual fact.
|
|
102
|
+
*
|
|
103
|
+
* Ordering is safe: `queueTask` awaits `handleAddPendingTask` before it rethrows, so the row exists by
|
|
104
|
+
* the time an operation's `catch` runs.
|
|
105
|
+
*/
|
|
106
|
+
export declare const isQueuedForReplay: (client: StreamChat, messageId: string, types: readonly QueueableType[]) => Promise<boolean>;
|