stream-chat 10.0.0-rc.21 → 10.0.0-rc.23
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/index.browser.js +2196 -3902
- package/dist/cjs/index.browser.js.map +3 -3
- package/dist/cjs/index.node.js +2197 -3902
- package/dist/cjs/index.node.js.map +3 -3
- package/dist/esm/index.mjs +2199 -3905
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelManager.d.ts +120 -233
- package/dist/types/CooldownTimer.d.ts +8 -23
- package/dist/types/EventHandlerPipeline.d.ts +17 -37
- package/dist/types/LiveLocationManager.d.ts +22 -50
- package/dist/types/api-client.d.ts +9 -14
- package/dist/types/channel.d.ts +253 -448
- package/dist/types/channel_state.d.ts +48 -95
- package/dist/types/client.d.ts +245 -370
- package/dist/types/client_state.d.ts +1 -3
- package/dist/types/configuration/ConfigController.d.ts +30 -124
- package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +31 -123
- package/dist/types/configuration/keys.d.ts +5 -19
- package/dist/types/configuration/shape.d.ts +12 -29
- package/dist/types/configuration/types.d.ts +59 -87
- package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +13 -35
- package/dist/types/configuration/utils/copyConfigPatch.d.ts +8 -0
- package/dist/types/configuration/utils/declarativeSlices.d.ts +5 -16
- package/dist/types/configuration/utils/deepFreezeConfig.d.ts +3 -17
- package/dist/types/configuration/utils/serverAuthority.d.ts +9 -29
- package/dist/types/connection/ConnectionIdManager.d.ts +18 -40
- package/dist/types/connection/ConnectionRecoveryManager.d.ts +29 -120
- package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +32 -103
- package/dist/types/connection/networkConnection/reporters.d.ts +9 -32
- package/dist/types/connection/networkConnection/types.d.ts +12 -27
- package/dist/types/connection/wsConnection/StableWSConnection.d.ts +37 -116
- package/dist/types/connection/wsConnection/WSConnection.d.ts +41 -104
- package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +8 -16
- package/dist/types/connection/wsConnection/config.d.ts +8 -28
- package/dist/types/connection/wsConnection/types.d.ts +17 -70
- package/dist/types/entityStore/EntityStore.d.ts +153 -113
- package/dist/types/entityStore/StoreBackedItemIndex.d.ts +13 -46
- package/dist/types/errors.d.ts +7 -19
- package/dist/types/gen/chat/ChannelApi.d.ts +2 -1
- package/dist/types/gen/chat/ChatApi.d.ts +28 -14
- package/dist/types/gen/models/index.d.ts +769 -86
- package/dist/types/gen/moderation/ModerationApi.d.ts +4 -4
- package/dist/types/index.d.ts +2 -4
- package/dist/types/languageNames.d.ts +9 -24
- package/dist/types/logger.d.ts +1 -3
- package/dist/types/messageComposer/LocationComposer.d.ts +1 -1
- package/dist/types/messageComposer/attachmentIdentity.d.ts +1 -6
- package/dist/types/messageComposer/attachmentManager.d.ts +10 -32
- package/dist/types/messageComposer/attachmentUtils.d.ts +3 -14
- package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
- package/dist/types/messageComposer/configuration/types.d.ts +29 -56
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +6 -9
- package/dist/types/messageComposer/messageComposer.d.ts +30 -164
- package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +4 -14
- package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +2 -9
- package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +2 -4
- package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +7 -19
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +9 -0
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +11 -18
- package/dist/types/messageComposer/middleware/textComposer/textMiddlewareUtils.d.ts +9 -3
- package/dist/types/messageComposer/middleware/textComposer/types.d.ts +1 -6
- package/dist/types/messageComposer/pollComposer.d.ts +8 -4
- package/dist/types/messageComposer/textComposer.d.ts +3 -9
- package/dist/types/messageComposer/types.d.ts +5 -8
- package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +25 -79
- package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +15 -82
- package/dist/types/messageOperations/FailedSendCache.d.ts +4 -9
- package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +10 -20
- package/dist/types/messageOperations/MessageOperations.d.ts +20 -40
- package/dist/types/messageOperations/applyReactionLocally.d.ts +5 -22
- package/dist/types/messageOperations/createMessageOperations.d.ts +3 -5
- package/dist/types/messageOperations/reflectReactionEvent.d.ts +5 -13
- package/dist/types/messageOperations/sendOrdering.d.ts +4 -7
- package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +7 -15
- package/dist/types/messageOperations/types.d.ts +15 -30
- package/dist/types/middleware.d.ts +7 -5
- package/dist/types/moderation.d.ts +21 -14
- package/dist/types/notifications/NotificationManager.d.ts +8 -31
- package/dist/types/notifications/types.d.ts +19 -59
- package/dist/types/offline-support/offline_support_api.d.ts +145 -539
- package/dist/types/offline-support/offline_sync_manager.d.ts +18 -42
- package/dist/types/offline-support/queueableOperations.d.ts +24 -52
- package/dist/types/offline-support/types.d.ts +24 -187
- package/dist/types/pagination/ItemIndex.d.ts +4 -12
- package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +13 -0
- package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -4
- package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +2 -3
- package/dist/types/pagination/paginators/BasePaginator.d.ts +235 -622
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +67 -125
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +133 -292
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +69 -118
- package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +7 -26
- package/dist/types/pagination/paginators/ReminderPaginator.d.ts +2 -2
- package/dist/types/pagination/paginators/ThreadPaginator.d.ts +15 -23
- package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +2 -6
- package/dist/types/pagination/sortCompiler.d.ts +11 -22
- package/dist/types/pagination/utility.normalization.d.ts +5 -23
- package/dist/types/pagination/utility.search.d.ts +3 -8
- package/dist/types/poll.d.ts +14 -14
- package/dist/types/poll_manager.d.ts +11 -2
- package/dist/types/poll_optimistic_votes.d.ts +10 -14
- package/dist/types/reminders/Reminder.d.ts +4 -4
- package/dist/types/reminders/ReminderManager.d.ts +7 -20
- package/dist/types/search/BaseSearchSource.d.ts +7 -12
- package/dist/types/search/ChannelSearchSource.d.ts +7 -7
- package/dist/types/search/MessageSearchSource.d.ts +7 -9
- package/dist/types/search/SearchController.d.ts +17 -22
- package/dist/types/search/types.d.ts +6 -10
- package/dist/types/signing.d.ts +12 -3
- package/dist/types/thread.d.ts +23 -71
- package/dist/types/thread_manager.d.ts +45 -70
- package/dist/types/token_manager.d.ts +8 -13
- package/dist/types/types.d.ts +64 -125
- package/dist/types/types.utility.d.ts +3 -3
- package/dist/types/upload-utils.d.ts +5 -10
- package/dist/types/uploadManager.d.ts +17 -45
- package/dist/types/utils/FixedSizeQueueCache.d.ts +6 -11
- package/dist/types/utils/WithSubscriptions.d.ts +5 -15
- package/dist/types/utils/concurrency.d.ts +11 -19
- package/dist/types/utils/mergeWith/mergeWith.d.ts +8 -11
- package/dist/types/utils/mergeWith/mergeWithCore.d.ts +5 -13
- package/dist/types/utils/mergeWith/mergeWithDiff.d.ts +22 -0
- package/dist/types/utils/objectPath.d.ts +6 -41
- package/dist/types/utils/retryable.d.ts +8 -12
- package/dist/types/utils/throttling/throttle.d.ts +8 -23
- package/dist/types/utils/time.d.ts +24 -64
- package/dist/types/utils.d.ts +40 -86
- package/package.json +7 -2
- package/src/ChannelManager.ts +159 -300
- package/src/CooldownTimer.ts +11 -29
- package/src/EventHandlerPipeline.ts +21 -44
- package/src/LiveLocationManager.ts +35 -74
- package/src/api-client.ts +43 -61
- package/src/campaign.ts +1 -1
- package/src/channel.ts +396 -749
- package/src/channel_batch_updater.ts +1 -1
- package/src/channel_state.ts +50 -105
- package/src/client.ts +360 -588
- package/src/client_state.ts +1 -6
- package/src/configuration/ConfigController.ts +41 -157
- package/src/configuration/InstanceConfigurationRegistry.ts +42 -171
- package/src/configuration/index.ts +1 -1
- package/src/configuration/keys.ts +13 -32
- package/src/configuration/shape.ts +67 -70
- package/src/configuration/types.ts +60 -100
- package/src/configuration/utils/applyInstanceConfiguration.ts +21 -53
- package/src/configuration/utils/copyConfigPatch.ts +11 -32
- package/src/configuration/utils/declarativeSlices.ts +9 -39
- package/src/configuration/utils/deepFreezeConfig.ts +3 -17
- package/src/configuration/utils/index.ts +2 -4
- package/src/configuration/utils/serverAuthority.ts +20 -68
- package/src/connection/ConnectionIdManager.ts +20 -49
- package/src/connection/ConnectionRecoveryManager.ts +51 -178
- package/src/connection/networkConnection/NetworkConnectionObserver.ts +37 -114
- package/src/connection/networkConnection/reporters.ts +9 -36
- package/src/connection/networkConnection/types.ts +12 -27
- package/src/connection/wsConnection/StableWSConnection.ts +73 -193
- package/src/connection/wsConnection/WSConnection.ts +56 -131
- package/src/connection/wsConnection/WSConnectionFallback.ts +22 -31
- package/src/connection/wsConnection/config.ts +13 -48
- package/src/connection/wsConnection/types.ts +17 -70
- package/src/constants.ts +4 -4
- package/src/entityStore/EntityStore.ts +162 -167
- package/src/entityStore/StoreBackedItemIndex.ts +14 -47
- package/src/errors.ts +7 -19
- package/src/formatMessageMemo.ts +3 -9
- package/src/gen/chat/ChannelApi.ts +19 -0
- package/src/gen/chat/ChatApi.ts +87 -13
- package/src/gen/models/index.ts +793 -71
- package/src/gen/moderation/ModerationApi.ts +0 -4
- package/src/index.ts +10 -14
- package/src/languageNames.ts +9 -24
- package/src/logger.ts +1 -3
- package/src/messageComposer/LocationComposer.ts +7 -23
- package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
- package/src/messageComposer/attachmentIdentity.ts +2 -13
- package/src/messageComposer/attachmentManager.ts +17 -63
- package/src/messageComposer/attachmentUtils.ts +3 -17
- package/src/messageComposer/configuration/configuration.ts +5 -8
- package/src/messageComposer/configuration/types.ts +29 -56
- package/src/messageComposer/fileUtils.ts +1 -1
- package/src/messageComposer/linkPreviewsManager.ts +8 -20
- package/src/messageComposer/messageComposer.ts +54 -222
- package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +4 -16
- package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +1 -2
- package/src/messageComposer/middleware/messageComposer/attachments.ts +14 -40
- package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +3 -4
- package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +4 -11
- package/src/messageComposer/middleware/pollComposer/state.ts +2 -2
- package/src/messageComposer/middleware/pollComposer/types.ts +2 -4
- package/src/messageComposer/middleware/pollComposer/validation.ts +8 -26
- package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +1 -6
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +1 -2
- package/src/messageComposer/middleware/textComposer/commands.ts +11 -16
- package/src/messageComposer/middleware/textComposer/mentions.ts +32 -70
- package/src/messageComposer/middleware/textComposer/textMiddlewareUtils.ts +10 -4
- package/src/messageComposer/middleware/textComposer/types.ts +1 -6
- package/src/messageComposer/pollComposer.ts +11 -8
- package/src/messageComposer/textComposer.ts +9 -59
- package/src/messageComposer/types.ts +9 -12
- package/src/messageDelivery/MessageDeliveryReporter.ts +60 -113
- package/src/messageDelivery/MessageReceiptsTracker.ts +21 -105
- package/src/messageOperations/FailedSendCache.ts +4 -9
- package/src/messageOperations/MessageOperationStatePolicy.ts +40 -67
- package/src/messageOperations/MessageOperations.ts +33 -62
- package/src/messageOperations/applyReactionLocally.ts +9 -28
- package/src/messageOperations/createMessageOperations.ts +17 -33
- package/src/messageOperations/reflectReactionEvent.ts +5 -13
- package/src/messageOperations/sendOrdering.ts +4 -7
- package/src/messageOperations/settlePendingAttachmentUploads.ts +10 -21
- package/src/messageOperations/types.ts +15 -30
- package/src/middleware.ts +7 -10
- package/src/moderation.ts +25 -21
- package/src/notifications/NotificationManager.ts +11 -35
- package/src/notifications/types.ts +19 -59
- package/src/offline-support/offline_support_api.ts +178 -608
- package/src/offline-support/offline_sync_manager.ts +25 -69
- package/src/offline-support/queueableOperations.ts +31 -84
- package/src/offline-support/types.ts +25 -188
- package/src/pagination/ItemIndex.ts +4 -12
- package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +13 -62
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
- package/src/pagination/cursorDerivation/linearPaginationFlags.ts +4 -6
- package/src/pagination/filterCompiler.ts +11 -25
- package/src/pagination/paginators/BasePaginator.ts +422 -976
- package/src/pagination/paginators/ChannelPaginator.ts +130 -190
- package/src/pagination/paginators/MessageIntervalPaginator.ts +226 -457
- package/src/pagination/paginators/MessagePaginator.ts +135 -175
- package/src/pagination/paginators/PinnedMessagePaginator.ts +13 -38
- package/src/pagination/paginators/ReminderPaginator.ts +12 -15
- package/src/pagination/paginators/ThreadPaginator.ts +16 -26
- package/src/pagination/paginators/UserGroupPaginator.ts +6 -17
- package/src/pagination/paginators/stateThrottling.ts +5 -10
- package/src/pagination/sortCompiler.ts +23 -50
- package/src/pagination/utility.normalization.ts +8 -30
- package/src/pagination/utility.search.ts +4 -11
- package/src/poll.ts +19 -19
- package/src/poll_manager.ts +16 -20
- package/src/poll_optimistic_votes.ts +17 -22
- package/src/reminders/Reminder.ts +5 -6
- package/src/reminders/ReminderManager.ts +9 -34
- package/src/reminders/ReminderTimer.ts +1 -2
- package/src/search/BaseSearchSource.ts +14 -29
- package/src/search/ChannelSearchSource.ts +8 -8
- package/src/search/MessageSearchSource.ts +19 -25
- package/src/search/SearchController.ts +18 -24
- package/src/search/types.ts +6 -10
- package/src/segment.ts +1 -1
- package/src/signing.ts +23 -3
- package/src/thread.ts +72 -173
- package/src/thread_manager.ts +59 -76
- package/src/token_manager.ts +11 -21
- package/src/types.ts +78 -126
- package/src/types.utility.ts +3 -3
- package/src/upload-utils.ts +5 -10
- package/src/uploadManager.ts +22 -54
- package/src/utils/FixedSizeQueueCache.ts +13 -21
- package/src/utils/WithSubscriptions.ts +5 -15
- package/src/utils/concurrency.ts +16 -55
- package/src/utils/mergeWith/mergeWith.ts +10 -13
- package/src/utils/mergeWith/mergeWithCore.ts +24 -81
- package/src/utils/mergeWith/mergeWithDiff.ts +15 -33
- package/src/utils/objectPath.ts +6 -41
- package/src/utils/retryable.ts +10 -14
- package/src/utils/throttling/throttle.ts +9 -25
- package/src/utils/time.ts +26 -66
- package/src/utils.ts +72 -128
package/src/types.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AxiosResponse } from 'axios';
|
|
2
2
|
import type { CustomEventTypes } from './custom_types';
|
|
3
|
-
import type { NotificationManager } from './notifications';
|
|
4
|
-
import type { InstanceConfigTree } from './configuration/types';
|
|
5
|
-
import type { DeepPartial } from './types.utility';
|
|
6
3
|
import type {
|
|
7
4
|
APIError,
|
|
8
5
|
Attachment,
|
|
9
6
|
BanRequest,
|
|
10
7
|
ChannelConfigWithInfo,
|
|
8
|
+
ChannelMemberRequest,
|
|
11
9
|
ChannelOwnCapability,
|
|
12
10
|
ChannelStateResponseFields,
|
|
13
11
|
CreateDeviceRequest,
|
|
14
12
|
CreatePollRequest,
|
|
13
|
+
CustomEvent,
|
|
15
14
|
DraftPayloadResponse,
|
|
16
15
|
FlagRequest,
|
|
17
16
|
Images,
|
|
17
|
+
MessageRequest,
|
|
18
18
|
MessageResponse,
|
|
19
19
|
OwnUserResponse,
|
|
20
20
|
QueryChannelsRequest,
|
|
@@ -42,9 +42,6 @@ import type {
|
|
|
42
42
|
|
|
43
43
|
import type { ChatApi } from './gen-imports';
|
|
44
44
|
|
|
45
|
-
/**
|
|
46
|
-
* Utility Types
|
|
47
|
-
*/
|
|
48
45
|
export type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Omit<T, Keys> &
|
|
49
46
|
{
|
|
50
47
|
[K in Keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>>;
|
|
@@ -55,15 +52,8 @@ export type RequireAtLeastOne<T> = {
|
|
|
55
52
|
}[keyof T];
|
|
56
53
|
|
|
57
54
|
/**
|
|
58
|
-
*
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Legacy response envelope. Every generated response already carries `duration`, and the
|
|
63
|
-
* transport wraps results in `StreamResponse<T>`, which also carries `metadata`.
|
|
64
|
-
*
|
|
65
|
-
* Only still referenced by the hand-written `/moderation/*` methods on `StreamChat` that
|
|
66
|
-
* bypass the generated client. Delete this together with those.
|
|
55
|
+
* Used only by `StreamChat.unbanUser`, a hand-written `/moderation/*` call that bypasses the
|
|
56
|
+
* generated client.
|
|
67
57
|
*/
|
|
68
58
|
export type APIResponse = {
|
|
69
59
|
duration: string;
|
|
@@ -71,6 +61,33 @@ export type APIResponse = {
|
|
|
71
61
|
|
|
72
62
|
export type ChannelUpdateOptions = Omit<UpdateChannelRequest, 'message'>;
|
|
73
63
|
|
|
64
|
+
/**
|
|
65
|
+
* A channel update that adds or removes items (members, invitees, filter tags): the items, a message
|
|
66
|
+
* notifying the channel members, and any other `update()` option.
|
|
67
|
+
*/
|
|
68
|
+
type ChannelItemsUpdate<Key extends string, Item> = Record<Key, Item[]> & {
|
|
69
|
+
/** Message object for channel members notification (optional). */
|
|
70
|
+
message?: MessageRequest;
|
|
71
|
+
} & ChannelUpdateOptions;
|
|
72
|
+
|
|
73
|
+
/** Request of `channel.addMembers`: user IDs, or member requests with a role or custom data. */
|
|
74
|
+
export type AddMembersRequest = ChannelItemsUpdate<
|
|
75
|
+
'members',
|
|
76
|
+
string | ChannelMemberRequest
|
|
77
|
+
>;
|
|
78
|
+
|
|
79
|
+
/** Request of `channel.inviteMembers`. */
|
|
80
|
+
export type InviteMembersRequest = ChannelItemsUpdate<
|
|
81
|
+
'members',
|
|
82
|
+
string | Required<Omit<ChannelMemberRequest, 'channel_role'>>
|
|
83
|
+
>;
|
|
84
|
+
|
|
85
|
+
/** Request of `channel.removeMembers`: the user IDs to remove. */
|
|
86
|
+
export type RemoveMembersRequest = ChannelItemsUpdate<'members', string>;
|
|
87
|
+
|
|
88
|
+
/** Request of `channel.addFilterTags` and `channel.removeFilterTags`. */
|
|
89
|
+
export type FilterTagsRequest = ChannelItemsUpdate<'tags', string>;
|
|
90
|
+
|
|
74
91
|
export type ConnectAPIResponse = Promise<void | ConnectionOpen>;
|
|
75
92
|
|
|
76
93
|
export type LocalMessage = MessageResponse & {
|
|
@@ -81,33 +98,32 @@ export type LocalMessage = MessageResponse & {
|
|
|
81
98
|
|
|
82
99
|
export type GetThreadOptions = NonNullable<Parameters<ChatApi['getThread']>[1]>;
|
|
83
100
|
|
|
101
|
+
/** Options of `client.pinMessage`. */
|
|
102
|
+
export type PinMessageOptions = {
|
|
103
|
+
/** When the pin expires; `null` or leaving it out pins without expiry. */
|
|
104
|
+
pin_expires?: Date | string | null;
|
|
105
|
+
/** The pin time, which orders the pinned messages. Defaults to now. */
|
|
106
|
+
pinned_at?: Date | string;
|
|
107
|
+
};
|
|
108
|
+
|
|
84
109
|
/**
|
|
85
|
-
* The fields
|
|
86
|
-
* `
|
|
87
|
-
*
|
|
88
|
-
* Derived, never hand-listed: `client._handleUserEvent` uses this set (through
|
|
89
|
-
* `isOwnUserBaseProperty`) to decide which keys survive a `user.updated` event, so a field
|
|
90
|
-
* missing from it is silently deleted off `client.user`. Deriving it means a spec change
|
|
91
|
-
* cannot desynchronise the two.
|
|
110
|
+
* The fields of `OwnUserResponse` that a plain `UserResponse` lacks. `client._handleUserEvent` uses
|
|
111
|
+
* it (through `isOwnUserBaseProperty`) to decide which keys survive a `user.updated` event.
|
|
92
112
|
*/
|
|
93
113
|
export type OwnUserBase = Pick<
|
|
94
114
|
OwnUserResponse,
|
|
95
115
|
Exclude<keyof OwnUserResponse, keyof UserResponse>
|
|
96
116
|
>;
|
|
97
117
|
|
|
98
|
-
// Thumb URL(thumb_url) is added considering video attachments as the backend will return the thumbnail in the response.
|
|
99
118
|
export type BanUserOptions = Omit<BanRequest, 'target_user_id'>;
|
|
100
119
|
|
|
101
120
|
/**
|
|
102
121
|
* Everything `queryChannels()` accepts apart from the filter and the sort.
|
|
103
122
|
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* if the predefined filter has its own stored sort template that template wins and the request
|
|
109
|
-
* `sort` is ignored; if it does not, the request `sort` is used. `sort_values` interpolates the
|
|
110
|
-
* stored sort template's placeholders. All three are only read when `predefined_filter` is set.
|
|
123
|
+
* `predefined_filter` names a backend filter template, interpolated with `filter_values`. If that
|
|
124
|
+
* template has its own stored sort, it wins over the request `sort` and `sort_values` fills its
|
|
125
|
+
* placeholders; otherwise the request `sort` is used. `filter_values` and `sort_values` are sent
|
|
126
|
+
* only when `predefined_filter` is set.
|
|
111
127
|
*/
|
|
112
128
|
export type ChannelOptions = Omit<QueryChannelsRequest, 'filter_conditions' | 'sort'>;
|
|
113
129
|
|
|
@@ -116,12 +132,8 @@ export type ChannelStateOptions = {
|
|
|
116
132
|
skipInitialization?: string[];
|
|
117
133
|
skipHydration?: boolean;
|
|
118
134
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* This is a compatibility bridge for internal callers that need response level
|
|
122
|
-
* metadata such as `predefined_filter`. The default `queryChannels()` return value
|
|
123
|
-
* remains `Channel[]` to avoid a breaking change. This should be folded into a
|
|
124
|
-
* single full response API in the next major release.
|
|
135
|
+
* Makes `queryChannelsAndHydrate()` return the full query response (with hydrated `channels`,
|
|
136
|
+
* plus metadata such as `predefined_filter`) instead of `Channel[]`.
|
|
125
137
|
*/
|
|
126
138
|
withResponse?: boolean;
|
|
127
139
|
};
|
|
@@ -138,42 +150,6 @@ export type PinnedMessagePaginationOptions = Omit<
|
|
|
138
150
|
|
|
139
151
|
export type QueryMembersOptions = Partial<Omit<QueryMembersPayload, 'filter_conditions'>>;
|
|
140
152
|
|
|
141
|
-
export type StreamChatOptions = {
|
|
142
|
-
/**
|
|
143
|
-
* Used to disable warnings that are triggered by using connectUser or connectAnonymousUser server-side.
|
|
144
|
-
*/
|
|
145
|
-
allowServerSideConnect?: boolean;
|
|
146
|
-
axiosRequestConfig?: AxiosRequestConfig;
|
|
147
|
-
/**
|
|
148
|
-
* Base url to use for API
|
|
149
|
-
* such as https://chat-proxy-dublin.stream-io-api.com
|
|
150
|
-
*/
|
|
151
|
-
baseURL?: string;
|
|
152
|
-
browser?: boolean;
|
|
153
|
-
/**
|
|
154
|
-
* Custom notification manager service to use for the client.
|
|
155
|
-
* If not provided, a default notification manager will be created.
|
|
156
|
-
* Notifications are used to communicate events like errors, warnings, info, etc. Other services can publish notifications or subscribe to the NotificationManager state changes.
|
|
157
|
-
*/
|
|
158
|
-
notifications?: NotificationManager;
|
|
159
|
-
/**
|
|
160
|
-
* Declarative configuration for instances the SDK creates on your behalf, seeded before the client's
|
|
161
|
-
* own managers are constructed.
|
|
162
|
-
*
|
|
163
|
-
* Equivalent to calling `client.config.set(tree)` immediately after construction, except for the
|
|
164
|
-
* `client` subtree — the configuration registry is created inside the constructor, so this is the only
|
|
165
|
-
* way to configure `reminders` / `notifications` before they are built.
|
|
166
|
-
*/
|
|
167
|
-
config?: DeepPartial<InstanceConfigTree>;
|
|
168
|
-
/**
|
|
169
|
-
* When true, user will be persisted on client. Otherwise if `connectUser` call fails, then you need to
|
|
170
|
-
* call `connectUser` again to retry.
|
|
171
|
-
* This is mainly useful for chat application working in offline mode, where you will need client.user to
|
|
172
|
-
* persist even if connectUser call fails.
|
|
173
|
-
*/
|
|
174
|
-
persistUserOnConnectionFailure?: boolean;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
153
|
export type UnBanUserOptions = {
|
|
178
154
|
client_id?: string;
|
|
179
155
|
connection_id?: string;
|
|
@@ -188,13 +164,9 @@ export type UnBanUserOptions = {
|
|
|
188
164
|
export type UserOptions = Omit<QueryUsersPayload, 'filter_conditions' | 'sort'>;
|
|
189
165
|
|
|
190
166
|
/**
|
|
191
|
-
* Which
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
* `client.networkConnection`. `'ws'` is this client's WebSocket. They are different facts and routinely
|
|
195
|
-
* disagree: a socket dies on a working network (server close, expired token, health-check timeout),
|
|
196
|
-
* and a device goes offline while the socket has not noticed yet — which is why each has its own
|
|
197
|
-
* store and neither is derived from the other.
|
|
167
|
+
* Which connection a status refers to: `'network'` is the device's network (reported by the
|
|
168
|
+
* platform reporter installed on `client.networkConnection`), `'ws'` is this client's WebSocket.
|
|
169
|
+
* They can disagree, so each has its own store.
|
|
198
170
|
*/
|
|
199
171
|
export type ConnectionType = 'network' | 'ws';
|
|
200
172
|
|
|
@@ -234,14 +206,24 @@ type LocalEvent = (
|
|
|
234
206
|
export type Event =
|
|
235
207
|
| (WSEvent & { received_at?: TimestampNS })
|
|
236
208
|
| LocalEvent
|
|
237
|
-
|
|
|
209
|
+
| CustomEventTypeUnion;
|
|
210
|
+
|
|
211
|
+
// One member per key augmented into `CustomEventTypes`; `never` when none are declared.
|
|
212
|
+
type CustomEventTypeUnion = {
|
|
213
|
+
[K in keyof CustomEventTypes]: { type: K } & Omit<CustomEvent, 'type'> & {
|
|
214
|
+
received_at?: TimestampNS;
|
|
215
|
+
};
|
|
216
|
+
}[keyof CustomEventTypes];
|
|
238
217
|
export type EventType = Event['type'] | 'all';
|
|
239
218
|
|
|
240
|
-
export type EventHandler<T = string> = (event: Extract<Event, { type: T }>) => void;
|
|
241
|
-
|
|
242
219
|
/**
|
|
243
|
-
*
|
|
220
|
+
* A listener for events of type `T`. `'all'` (the default) receives every event, any other type the
|
|
221
|
+
* event members declaring it. Custom event types have to be declared by augmenting
|
|
222
|
+
* `CustomEventTypes`; an undeclared name is not an `EventType`.
|
|
244
223
|
*/
|
|
224
|
+
export type EventHandler<T extends EventType = 'all'> = (
|
|
225
|
+
event: T extends 'all' ? Event : Extract<Event, { type: T }>,
|
|
226
|
+
) => void;
|
|
245
227
|
|
|
246
228
|
export type ReactionFilters = NonNullable<QueryReactionsRequest['filter']>;
|
|
247
229
|
|
|
@@ -266,20 +248,16 @@ export type OGAttachment = RequireLiteral<Attachment, 'og_scrape_url'>;
|
|
|
266
248
|
export type PushProvider = CreateDeviceRequest['push_provider'];
|
|
267
249
|
|
|
268
250
|
/**
|
|
269
|
-
* Server-provided channel configuration, keyed by
|
|
270
|
-
*
|
|
271
|
-
*
|
|
251
|
+
* Server-provided channel configuration, keyed by cid (`messaging:general`). Keyed per channel
|
|
252
|
+
* because a channel's `config_overrides` can narrow its type's config. Read it via
|
|
253
|
+
* `channel.serverConfig`.
|
|
272
254
|
*/
|
|
273
255
|
export type Configs = Record<string, ChannelConfigWithInfo | undefined>;
|
|
274
256
|
|
|
275
257
|
export type ConnectionOpen = EventPayload<'health.check'> | EventPayload<'connection.ok'>;
|
|
276
258
|
|
|
277
259
|
/**
|
|
278
|
-
* The message `type` values the server can return.
|
|
279
|
-
*
|
|
280
|
-
* Hand-written because there is no generated equivalent: `MessageResponse['type']` is a bare
|
|
281
|
-
* `string`, so deriving it would widen rather than narrow. Both the React and React Native
|
|
282
|
-
* SDKs use this as a discriminant (RN types its SQLite message rows with it).
|
|
260
|
+
* The message `type` values the server can return (`MessageResponse['type']` is a bare `string`).
|
|
283
261
|
*/
|
|
284
262
|
export type MessageLabel =
|
|
285
263
|
| 'deleted'
|
|
@@ -309,13 +287,9 @@ export class StreamAPIError<T = APIError> extends Error {
|
|
|
309
287
|
status,
|
|
310
288
|
response,
|
|
311
289
|
}: {
|
|
312
|
-
/**
|
|
313
|
-
* Stream error code (`APIError.code`)
|
|
314
|
-
*/
|
|
290
|
+
/** Stream error code (`APIError.code`) */
|
|
315
291
|
code: StreamAPIError<T>['code'];
|
|
316
|
-
/**
|
|
317
|
-
* HTTP status code
|
|
318
|
-
*/
|
|
292
|
+
/** HTTP status code */
|
|
319
293
|
status: StreamAPIError<T>['status'];
|
|
320
294
|
response: StreamAPIError<T>['response'];
|
|
321
295
|
},
|
|
@@ -363,9 +337,6 @@ export class StreamAPIError<T = APIError> extends Error {
|
|
|
363
337
|
}
|
|
364
338
|
}
|
|
365
339
|
|
|
366
|
-
/**
|
|
367
|
-
* Poll vote visibility. Derived from the generated request shape so it tracks the spec.
|
|
368
|
-
*/
|
|
369
340
|
export type VotingVisibility = NonNullable<CreatePollRequest['voting_visibility']>;
|
|
370
341
|
|
|
371
342
|
export type PartialPollUpdate = {
|
|
@@ -373,10 +344,7 @@ export type PartialPollUpdate = {
|
|
|
373
344
|
unset?: Array<keyof UpdatePollRequest>;
|
|
374
345
|
};
|
|
375
346
|
|
|
376
|
-
/**
|
|
377
|
-
* Options accepted by `moderation.flagUser` / `moderation.flagMessage` on top of the
|
|
378
|
-
* entity they resolve and the `reason` they take positionally.
|
|
379
|
-
*/
|
|
347
|
+
/** Options of `moderation.flagUser` / `moderation.flagMessage` besides the entity and `reason`. */
|
|
380
348
|
export type ModerationFlagOptions = Omit<
|
|
381
349
|
FlagRequest,
|
|
382
350
|
'entity_id' | 'entity_type' | 'reason'
|
|
@@ -400,26 +368,17 @@ export const AIStates = {
|
|
|
400
368
|
Thinking: 'AI_STATE_THINKING',
|
|
401
369
|
} as const satisfies Record<string, AIState>;
|
|
402
370
|
|
|
403
|
-
/**
|
|
404
|
-
* An identifier containing information about the downstream SDK using stream-chat. It
|
|
405
|
-
* is used to resolve the user agent.
|
|
406
|
-
*/
|
|
371
|
+
/** The downstream SDK using stream-chat, used to resolve the user agent. */
|
|
407
372
|
export type SdkIdentifier = {
|
|
408
373
|
name: 'react' | 'react-native' | 'expo' | 'angular';
|
|
409
374
|
version: string;
|
|
410
375
|
};
|
|
411
376
|
|
|
412
|
-
/**
|
|
413
|
-
* An identifier containing information about the downstream device using stream-chat, if
|
|
414
|
-
* available. Is used by the react-native SDKs to enrich the user agent further.
|
|
415
|
-
*/
|
|
377
|
+
/** The downstream device, used by the React Native SDKs to enrich the user agent. */
|
|
416
378
|
export type DeviceIdentifier = { os: string; model?: string };
|
|
417
379
|
|
|
418
380
|
/**
|
|
419
|
-
*
|
|
420
|
-
* stream-chat, if available. `name` is reported as `app` and `version` as `app_version`
|
|
421
|
-
* in the user agent. Distinct from the SDK ({@link SdkIdentifier}) and device
|
|
422
|
-
* ({@link DeviceIdentifier}) identifiers.
|
|
381
|
+
* The downstream app: `name` is reported as `app` and `version` as `app_version` in the user agent.
|
|
423
382
|
*/
|
|
424
383
|
export type AppIdentifier = { name: string; version?: string };
|
|
425
384
|
|
|
@@ -481,10 +440,6 @@ export type DeleteMessageOptions = NonNullable<Parameters<ChatApi['deleteMessage
|
|
|
481
440
|
export type SendMessageAPIResponse = StreamResponse<SendMessageResponse>;
|
|
482
441
|
export type UpdateMessageOptions = Omit<UpdateMessageRequest, 'message'>;
|
|
483
442
|
export type UpdateMessageAPIResponse = StreamResponse<UpdateMessageResponse>;
|
|
484
|
-
/**
|
|
485
|
-
* The Giphy rendition names, derived from the generated `Images` shape so the two cannot
|
|
486
|
-
* drift. Consumed by the React and React Native SDKs to pick a rendition size.
|
|
487
|
-
*/
|
|
488
443
|
export type GiphyVersions = keyof Images;
|
|
489
444
|
export type TranslationLanguage = TranslateMessageRequest['language'];
|
|
490
445
|
|
|
@@ -497,8 +452,7 @@ export type FileReferenceBase = {
|
|
|
497
452
|
export type FileUploadInput = File | Blob | FileReferenceBase | string;
|
|
498
453
|
|
|
499
454
|
/**
|
|
500
|
-
* Structural subset of axios' `AxiosProgressEvent`,
|
|
501
|
-
* public surface does not depend on axios.
|
|
455
|
+
* Structural subset of axios' `AxiosProgressEvent`, so the public surface does not depend on axios.
|
|
502
456
|
*/
|
|
503
457
|
export type StreamProgressEvent = {
|
|
504
458
|
loaded: number;
|
|
@@ -511,9 +465,7 @@ export type StreamRequestOptions = {
|
|
|
511
465
|
signal?: AbortSignal;
|
|
512
466
|
/** Only meaningful for upload (multipart) requests; ignored everywhere else. */
|
|
513
467
|
onUploadProgress?: (event: StreamProgressEvent) => void;
|
|
514
|
-
/**
|
|
515
|
-
* Milliseconds before this request is aborted.
|
|
516
|
-
*/
|
|
468
|
+
/** Milliseconds before this request is aborted. */
|
|
517
469
|
timeout?: number;
|
|
518
470
|
};
|
|
519
471
|
|
package/src/types.utility.ts
CHANGED
|
@@ -3,9 +3,9 @@ export type DeepPartial<T> = {
|
|
|
3
3
|
};
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* The keys of every union member, not only those common to all
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* The keys of every union member, not only those common to all (`keyof (A | B)`). Distribution
|
|
7
|
+
* needs the naked type parameter: the same conditional inline over a concrete union yields the
|
|
8
|
+
* common keys.
|
|
9
9
|
*/
|
|
10
10
|
export type KeysOfUnion<T> = T extends unknown ? keyof T : never;
|
|
11
11
|
|
package/src/upload-utils.ts
CHANGED
|
@@ -9,17 +9,15 @@ const isFileReferenceBase = (value: unknown): value is FileReferenceBase =>
|
|
|
9
9
|
typeof (value as FileReferenceBase).uri === 'string';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* Wraps a bare URI string in a {@link FileReferenceBase}; `File`, `Blob` and picker objects pass
|
|
13
|
+
* through.
|
|
14
14
|
*/
|
|
15
15
|
export const normalizeUploadFile = (file?: FileUploadInput) =>
|
|
16
16
|
typeof file === 'string' ? { uri: file } : file;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Appends one request-body entry to a multipart form
|
|
20
|
-
*
|
|
21
|
-
* Callers must pass **raw** values - objects and arrays are JSON-encoded here (that is what
|
|
22
|
-
* the API expects for `user` and `upload_sizes`), so pre-stringifying them double-encodes.
|
|
19
|
+
* Appends one request-body entry to a multipart form. Pass **raw** values: objects and arrays are
|
|
20
|
+
* JSON-encoded here, so pre-stringifying them double-encodes.
|
|
23
21
|
*/
|
|
24
22
|
export function appendToFormData(data: FormData, key: string, value: unknown) {
|
|
25
23
|
if (value === undefined || value === null) return;
|
|
@@ -42,10 +40,7 @@ export function appendToFormData(data: FormData, key: string, value: unknown) {
|
|
|
42
40
|
}
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
/**
|
|
46
|
-
* Encodes a request body as `multipart/form-data`. Used by `ApiClient.sendRequest` for every
|
|
47
|
-
* generated operation declaring that content type.
|
|
48
|
-
*/
|
|
43
|
+
/** Encodes a request body as `multipart/form-data`. */
|
|
49
44
|
export function toFormData(body: Record<string, unknown>) {
|
|
50
45
|
const data = new FormData();
|
|
51
46
|
for (const [key, value] of Object.entries(body)) appendToFormData(data, key, value);
|
package/src/uploadManager.ts
CHANGED
|
@@ -9,48 +9,29 @@ import type { AttachmentManager, LocalAttachmentUploadMetadata } from '.';
|
|
|
9
9
|
const logger = chatLoggerSystem.getLogger('upload-manager');
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Whether an upload
|
|
13
|
-
*
|
|
14
|
-
* {@link UploadManager.deleteUploadRecord} and {@link UploadManager.cancelAllUploads} abort the
|
|
15
|
-
* request through its `AbortController`, which is what happens when an attachment is removed
|
|
16
|
-
* from the composer mid-upload or the client disconnects. Axios reports that as a
|
|
17
|
-
* `CanceledError` (`axios.isCancel`); a custom `doUploadRequest` on another transport
|
|
18
|
-
* conventionally throws a `DOMException` named `AbortError`.
|
|
19
|
-
*
|
|
20
|
-
* Callers use this to keep a deliberate cancellation from being reported as an error.
|
|
12
|
+
* Whether an upload was aborted (attachment removed, client disconnected) rather than failed: an
|
|
13
|
+
* axios `CanceledError`, or an `AbortError` from a custom `doUploadRequest`.
|
|
21
14
|
*/
|
|
22
15
|
export const isUploadCancellation = (error: unknown) =>
|
|
23
16
|
axios.isCancel(error) || (error instanceof Error && error.name === 'AbortError');
|
|
24
17
|
|
|
25
18
|
export type UploadRecord = {
|
|
26
|
-
/** The attachment's local
|
|
19
|
+
/** The attachment's local ID (`localMetadata.id`); also the key this record is held under. */
|
|
27
20
|
id: string;
|
|
28
21
|
/**
|
|
29
|
-
* `true` once every byte has been handed to the transport but the server has not responded
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* acknowledged, so it reaches 100% the moment the request body is flushed — then the
|
|
34
|
-
* connection sits idle while the CDN ingests the file and the response travels back. On a
|
|
35
|
-
* large file over a slow link that window is long, and a UI that renders 100% as "done"
|
|
36
|
-
* claims the upload is confirmed while it is not.
|
|
37
|
-
*
|
|
38
|
-
* Nothing measurable happens during that window, so it is the point at which a determinate
|
|
39
|
-
* progress bar should hand over to an indeterminate one. Confirmation is the record being
|
|
40
|
-
* removed, not progress reaching 100.
|
|
41
|
-
*
|
|
42
|
-
* Requires `AttachmentManagerConfig.trackUploadProgress`; without progress reporting there is
|
|
43
|
-
* no way to tell when the flush happened, and this stays `false`.
|
|
22
|
+
* `true` once every byte has been handed to the transport but the server has not responded yet.
|
|
23
|
+
* Progress reaches 100% when the request body is flushed, before the server confirms, so a
|
|
24
|
+
* determinate progress bar should turn indeterminate here. Confirmation is the record being
|
|
25
|
+
* removed. Stays `false` without `AttachmentManagerConfig.trackUploadProgress`.
|
|
44
26
|
*/
|
|
45
27
|
uploadConfirmationPending?: boolean;
|
|
46
28
|
uploadProgress?: number;
|
|
47
29
|
};
|
|
48
30
|
|
|
49
31
|
/**
|
|
50
|
-
* Whether every byte is sent but the server has not answered
|
|
51
|
-
* progress bar should go indeterminate. Reads
|
|
32
|
+
* Whether every byte is sent but the server has not answered. Reads
|
|
52
33
|
* {@link UploadRecord.uploadConfirmationPending} when present, else infers it from progress
|
|
53
|
-
* reaching 100. Takes `localMetadata`,
|
|
34
|
+
* reaching 100. Takes `localMetadata`, as carried by a message payload.
|
|
54
35
|
*/
|
|
55
36
|
export const isUploadConfirmationPending = (
|
|
56
37
|
localMetadata?: Pick<
|
|
@@ -69,14 +50,9 @@ export const isUploadConfirmationPending = (
|
|
|
69
50
|
|
|
70
51
|
export type UploadManagerState = {
|
|
71
52
|
/**
|
|
72
|
-
* In-flight uploads keyed by the attachment's local
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* transfer the composer already began rather than starting a second one.
|
|
76
|
-
*
|
|
77
|
-
* A record lives only for the request, removed on success and on failure alike. So this answers
|
|
78
|
-
* "is a request running now", never "did this upload" — for that read
|
|
79
|
-
* `localMetadata.uploadState`.
|
|
53
|
+
* In-flight uploads keyed by the attachment's local ID (`localMetadata.id`), which makes
|
|
54
|
+
* {@link UploadManager.upload} idempotent. A record lives only for the request (removed on
|
|
55
|
+
* success and failure alike), so for "did it upload" read `localMetadata.uploadState`.
|
|
80
56
|
*/
|
|
81
57
|
uploads: Record<string, UploadRecord>;
|
|
82
58
|
};
|
|
@@ -134,9 +110,8 @@ export class UploadManager {
|
|
|
134
110
|
getUpload = (id: string) => this.uploads[id];
|
|
135
111
|
|
|
136
112
|
/**
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* Aborts every in-flight upload request via its `UploadRequestOptions.abortSignal`.
|
|
113
|
+
* Aborts every in-flight upload (`UploadRequestOptions.abortSignal`) and clears all records, so a
|
|
114
|
+
* later session does not inherit them. Invoked on disconnect.
|
|
140
115
|
*/
|
|
141
116
|
reset = () => {
|
|
142
117
|
for (const { abortController } of this.inFlightUploads.values()) {
|
|
@@ -146,10 +121,7 @@ export class UploadManager {
|
|
|
146
121
|
this.state.next(initState());
|
|
147
122
|
};
|
|
148
123
|
|
|
149
|
-
/**
|
|
150
|
-
* Removes the upload record for `id` if present.
|
|
151
|
-
* If an upload is still in progress, aborts its `UploadRequestOptions.abortSignal`.
|
|
152
|
-
*/
|
|
124
|
+
/** Removes the record for `id` and aborts its upload if still in progress. */
|
|
153
125
|
deleteUploadRecord = (id: string) => {
|
|
154
126
|
const flight = this.inFlightUploads.get(id);
|
|
155
127
|
if (flight) {
|
|
@@ -166,8 +138,8 @@ export class UploadManager {
|
|
|
166
138
|
|
|
167
139
|
/**
|
|
168
140
|
* Starts an upload for `id`, or returns the existing in-flight promise if one is already running.
|
|
169
|
-
*
|
|
170
|
-
*
|
|
141
|
+
* Uploads through the `attachmentManager.doUploadRequest` of the channel `channelCid`, and
|
|
142
|
+
* rejects if that rejects (the record is removed from state either way).
|
|
171
143
|
*/
|
|
172
144
|
upload = ({
|
|
173
145
|
id,
|
|
@@ -192,9 +164,9 @@ export class UploadManager {
|
|
|
192
164
|
this.inFlightUploads.set(id, { promise, abortController });
|
|
193
165
|
|
|
194
166
|
void (async () => {
|
|
195
|
-
const attachmentManager = this.resolveAttachmentManager(channelCid);
|
|
196
|
-
const trackProgress = attachmentManager.config.trackUploadProgress;
|
|
197
167
|
try {
|
|
168
|
+
const attachmentManager = this.resolveAttachmentManager(channelCid);
|
|
169
|
+
const trackProgress = attachmentManager.config.trackUploadProgress;
|
|
198
170
|
this.upsertUpload({
|
|
199
171
|
uploadConfirmationPending: false,
|
|
200
172
|
id,
|
|
@@ -206,13 +178,9 @@ export class UploadManager {
|
|
|
206
178
|
this.updateUpload({
|
|
207
179
|
id,
|
|
208
180
|
uploadProgress: progress,
|
|
209
|
-
// Only a
|
|
210
|
-
//
|
|
211
|
-
//
|
|
212
|
-
// already gone indeterminate back to a determinate one with nothing to show.
|
|
213
|
-
//
|
|
214
|
-
// The record is removed in the `finally` below, so a record that still exists
|
|
215
|
-
// while reporting 100% can only mean "flushed, awaiting the response".
|
|
181
|
+
// Only a numeric report moves the flag (`undefined` means the transport cannot
|
|
182
|
+
// measure). The record is removed in `finally`, so 100% on a live record means
|
|
183
|
+
// "flushed, awaiting the response".
|
|
216
184
|
...(typeof progress === 'number'
|
|
217
185
|
? { uploadConfirmationPending: progress >= 100 }
|
|
218
186
|
: {}),
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
type Dispose<K, T> = (key: K, value: T) => void;
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @template K - The type of the keys.
|
|
7
|
-
* @template T - The type of the values.
|
|
3
|
+
* Least-recently-used cache holding at most `size` values. `add` and `get` mark a key as most
|
|
4
|
+
* recently used. Adding to a full cache evicts the least recently used entry, calling `dispose`.
|
|
8
5
|
*/
|
|
9
6
|
export class FixedSizeQueueCache<K, T> {
|
|
10
7
|
private keys: Array<K>;
|
|
@@ -21,7 +18,7 @@ export class FixedSizeQueueCache<K, T> {
|
|
|
21
18
|
}
|
|
22
19
|
|
|
23
20
|
/**
|
|
24
|
-
*
|
|
21
|
+
* Inserts or updates an entry as the most recently used one.
|
|
25
22
|
*
|
|
26
23
|
* @param key - The cache key.
|
|
27
24
|
* @param value - The value to associate with `key`.
|
|
@@ -30,17 +27,13 @@ export class FixedSizeQueueCache<K, T> {
|
|
|
30
27
|
const index = this.keys.indexOf(key);
|
|
31
28
|
|
|
32
29
|
if (index > -1) {
|
|
33
|
-
this.keys.splice(
|
|
30
|
+
this.keys.splice(index, 1);
|
|
34
31
|
} else if (this.keys.length >= this.size) {
|
|
35
32
|
const itemKey = this.keys.shift();
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (item) {
|
|
41
|
-
this.dispose?.(itemKey, item);
|
|
42
|
-
}
|
|
43
|
-
|
|
34
|
+
// Compared with `undefined` and checked with `has`, so falsy keys and values are evicted too.
|
|
35
|
+
if (itemKey !== undefined && this.map.has(itemKey)) {
|
|
36
|
+
this.dispose?.(itemKey, this.map.get(itemKey) as T);
|
|
44
37
|
this.map.delete(itemKey);
|
|
45
38
|
}
|
|
46
39
|
}
|
|
@@ -50,7 +43,7 @@ export class FixedSizeQueueCache<K, T> {
|
|
|
50
43
|
}
|
|
51
44
|
|
|
52
45
|
/**
|
|
53
|
-
* Retrieves
|
|
46
|
+
* Retrieves a value without marking it as recently used.
|
|
54
47
|
*
|
|
55
48
|
* @param key - The cache key.
|
|
56
49
|
* @returns The value, or `undefined` when the key is not cached.
|
|
@@ -62,16 +55,17 @@ export class FixedSizeQueueCache<K, T> {
|
|
|
62
55
|
}
|
|
63
56
|
|
|
64
57
|
/**
|
|
65
|
-
* Retrieves
|
|
58
|
+
* Retrieves a value and marks it as most recently used.
|
|
66
59
|
*
|
|
67
60
|
* @param key - The cache key.
|
|
68
61
|
* @returns The value, or `undefined` when the key is not cached.
|
|
69
62
|
*/
|
|
70
63
|
get(key: K) {
|
|
71
64
|
const foundItem = this.peek(key);
|
|
65
|
+
const index = this.keys.indexOf(key);
|
|
72
66
|
|
|
73
|
-
if (
|
|
74
|
-
this.keys.splice(
|
|
67
|
+
if (index > -1 && index !== this.keys.length - 1) {
|
|
68
|
+
this.keys.splice(index, 1);
|
|
75
69
|
this.keys.push(key);
|
|
76
70
|
}
|
|
77
71
|
|
|
@@ -83,9 +77,7 @@ export class FixedSizeQueueCache<K, T> {
|
|
|
83
77
|
return Array.from(this.map.values());
|
|
84
78
|
}
|
|
85
79
|
|
|
86
|
-
/**
|
|
87
|
-
* Clears queue entirely and disposes of each item individually.
|
|
88
|
-
*/
|
|
80
|
+
/** Empties the cache, calling `dispose` for each entry. */
|
|
89
81
|
clear() {
|
|
90
82
|
if (this.dispose) {
|
|
91
83
|
this.map.forEach((entry, key) => this.dispose?.(key, entry));
|