stream-chat 9.50.3 → 10.0.0-rc.2
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 +19798 -14472
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +19817 -14482
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +19795 -14469
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelManager.d.ts +221 -0
- package/dist/types/EventHandlerPipeline.d.ts +104 -0
- package/dist/types/api-client.d.ts +26 -0
- package/dist/types/campaign.d.ts +0 -44
- package/dist/types/channel.d.ts +454 -479
- package/dist/types/channel_batch_updater.d.ts +0 -93
- package/dist/types/channel_state.d.ts +53 -201
- package/dist/types/client.d.ts +451 -1920
- package/dist/types/client_state.d.ts +4 -4
- package/dist/types/configuration/InstanceConfigurationService.d.ts +26 -0
- package/dist/types/configuration/index.d.ts +1 -0
- package/dist/types/configuration/types.d.ts +53 -0
- package/dist/types/connection.d.ts +49 -41
- package/dist/types/connection_fallback.d.ts +6 -4
- package/dist/types/constants.d.ts +0 -4
- package/dist/types/custom_types.d.ts +2 -0
- package/dist/types/entityStore/EntityStore.d.ts +111 -0
- package/dist/types/entityStore/StoreBackedItemIndex.d.ts +60 -0
- package/dist/types/entityStore/applyReactionLocally.d.ts +26 -0
- package/dist/types/entityStore/index.d.ts +2 -0
- package/dist/types/errors.d.ts +10 -2
- package/dist/types/gen/chat/ChannelApi.d.ts +45 -0
- package/dist/types/gen/chat/ChatApi.d.ts +334 -0
- package/dist/types/gen/model-decoders/decoders.d.ts +3 -0
- package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +6 -0
- package/dist/types/gen/models/index.d.ts +8836 -0
- package/dist/types/gen/moderation/ModerationApi.d.ts +50 -0
- package/dist/types/gen-imports.d.ts +3 -0
- package/dist/types/index.d.ts +8 -7
- package/dist/types/insights.d.ts +9 -8
- package/dist/types/logger.d.ts +9 -0
- package/dist/types/messageComposer/LocationComposer.d.ts +7 -4
- package/dist/types/messageComposer/attachmentIdentity.d.ts +2 -2
- package/dist/types/messageComposer/attachmentManager.d.ts +8 -4
- package/dist/types/messageComposer/configuration/types.d.ts +11 -11
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +25 -13
- package/dist/types/messageComposer/messageComposer.d.ts +10 -10
- package/dist/types/messageComposer/middleware/messageComposer/types.d.ts +3 -3
- package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +4 -7
- package/dist/types/messageComposer/middleware/textComposer/commandUtils.d.ts +3 -3
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +7 -7
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +218 -4
- package/dist/types/messageComposer/middleware/textComposer/types.d.ts +9 -4
- package/dist/types/messageComposer/pollComposer.d.ts +5 -4
- package/dist/types/messageComposer/textComposer.d.ts +8 -3
- package/dist/types/messageComposer/types.d.ts +6 -28
- package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +40 -25
- package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +53 -12
- package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +19 -0
- package/dist/types/messageOperations/MessageOperations.d.ts +17 -0
- package/dist/types/messageOperations/index.d.ts +3 -0
- package/dist/types/messageOperations/types.d.ts +49 -0
- package/dist/types/moderation.d.ts +21 -203
- package/dist/types/notifications/types.d.ts +8 -7
- package/dist/types/offline-support/offline_support_api.d.ts +111 -87
- package/dist/types/offline-support/offline_sync_manager.d.ts +0 -7
- package/dist/types/offline-support/types.d.ts +19 -23
- package/dist/types/offline-support/util.d.ts +4 -2
- package/dist/types/pagination/FilterBuilder.d.ts +1 -1
- package/dist/types/pagination/ItemIndex.d.ts +25 -0
- package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +9 -0
- package/dist/types/pagination/cursorDerivation/idAroundPaginationFlags.d.ts +6 -0
- package/dist/types/pagination/cursorDerivation/index.d.ts +1 -0
- package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +6 -0
- package/dist/types/pagination/filterCompiler.d.ts +7 -0
- package/dist/types/pagination/index.d.ts +1 -3
- package/dist/types/pagination/paginators/BasePaginator.d.ts +848 -0
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +212 -0
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +282 -0
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +208 -0
- package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +39 -0
- package/dist/types/pagination/paginators/ReminderPaginator.d.ts +19 -0
- package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +24 -0
- package/dist/types/pagination/paginators/index.d.ts +7 -0
- package/dist/types/pagination/paginators/stateThrottling.d.ts +2 -0
- package/dist/types/pagination/sortCompiler.d.ts +49 -0
- package/dist/types/pagination/types.normalization.d.ts +11 -0
- package/dist/types/pagination/utility.normalization.d.ts +18 -0
- package/dist/types/pagination/utility.queryChannel.d.ts +26 -0
- package/dist/types/pagination/utility.search.d.ts +13 -0
- package/dist/types/permissions.d.ts +1 -1
- package/dist/types/poll.d.ts +29 -32
- package/dist/types/poll_manager.d.ts +2 -2
- package/dist/types/reminders/Reminder.d.ts +2 -5
- package/dist/types/reminders/ReminderManager.d.ts +2 -9
- package/dist/types/search/MessageSearchSource.d.ts +4 -4
- package/dist/types/search/UserSearchSource.d.ts +1 -1
- package/dist/types/search/types.d.ts +3 -3
- package/dist/types/segment.d.ts +0 -34
- package/dist/types/signing.d.ts +105 -65
- package/dist/types/store.d.ts +1 -0
- package/dist/types/thread.d.ts +70 -34
- package/dist/types/thread_manager.d.ts +3 -3
- package/dist/types/token_manager.d.ts +15 -10
- package/dist/types/types.d.ts +197 -3404
- package/dist/types/utils/FixedSizeQueueCache.d.ts +12 -6
- package/dist/types/utils/WithSubscriptions.d.ts +2 -1
- package/dist/types/utils/concurrency.d.ts +4 -4
- package/dist/types/utils/mergeWith/mergeWith.d.ts +3 -3
- package/dist/types/utils/mergeWith/mergeWithCore.d.ts +8 -3
- package/dist/types/utils/retryable.d.ts +34 -0
- package/dist/types/utils/throttling/throttle.d.ts +36 -0
- package/dist/types/utils.d.ts +100 -194
- package/package.json +7 -3
- package/src/ChannelManager.ts +724 -0
- package/src/CooldownTimer.ts +2 -2
- package/src/EventHandlerPipeline.ts +228 -0
- package/src/LiveLocationManager.ts +12 -11
- package/src/api-client.ts +275 -0
- package/src/campaign.ts +1 -77
- package/src/channel.ts +1344 -1282
- package/src/channel_batch_updater.ts +1 -211
- package/src/channel_state.ts +144 -1013
- package/src/client.ts +936 -3995
- package/src/client_state.ts +4 -4
- package/src/configuration/InstanceConfigurationService.ts +73 -0
- package/src/configuration/index.ts +1 -0
- package/src/configuration/types.ts +81 -0
- package/src/connection.ts +145 -94
- package/src/connection_fallback.ts +29 -27
- package/src/constants.ts +1 -5
- package/src/custom_types.ts +4 -1
- package/src/entityStore/EntityStore.ts +208 -0
- package/src/entityStore/StoreBackedItemIndex.ts +115 -0
- package/src/entityStore/applyReactionLocally.ts +113 -0
- package/src/entityStore/index.ts +2 -0
- package/src/errors.ts +14 -2
- package/src/gen/chat/ChannelApi.ts +275 -0
- package/src/gen/chat/ChatApi.ts +2554 -0
- package/src/gen/model-decoders/decoders.ts +2680 -0
- package/src/gen/model-decoders/event-decoder-mapping.ts +198 -0
- package/src/gen/models/index.ts +12673 -0
- package/src/gen/moderation/ModerationApi.ts +607 -0
- package/src/gen-imports.ts +3 -0
- package/src/index.ts +11 -12
- package/src/insights.ts +6 -5
- package/src/logger.ts +28 -0
- package/src/messageComposer/LocationComposer.ts +9 -5
- package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -0
- package/src/messageComposer/attachmentIdentity.ts +16 -9
- package/src/messageComposer/attachmentManager.ts +13 -8
- package/src/messageComposer/configuration/types.ts +11 -11
- package/src/messageComposer/linkPreviewsManager.ts +9 -10
- package/src/messageComposer/messageComposer.ts +57 -53
- package/src/messageComposer/middleware/messageComposer/attachments.ts +1 -2
- package/src/messageComposer/middleware/messageComposer/cleanData.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/compositionValidation.ts +2 -2
- package/src/messageComposer/middleware/messageComposer/messageComposerState.ts +2 -2
- package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +4 -3
- package/src/messageComposer/middleware/messageComposer/textComposer.ts +2 -2
- package/src/messageComposer/middleware/messageComposer/types.ts +3 -4
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +9 -5
- package/src/messageComposer/middleware/pollComposer/state.ts +0 -2
- package/src/messageComposer/middleware/pollComposer/types.ts +4 -7
- package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +10 -1
- package/src/messageComposer/middleware/textComposer/commandEffects.ts +4 -4
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +3 -6
- package/src/messageComposer/middleware/textComposer/commands.ts +3 -3
- package/src/messageComposer/middleware/textComposer/mentionUtils.ts +1 -1
- package/src/messageComposer/middleware/textComposer/mentions.ts +31 -15
- package/src/messageComposer/middleware/textComposer/types.ts +9 -4
- package/src/messageComposer/pollComposer.ts +6 -8
- package/src/messageComposer/textComposer.ts +27 -2
- package/src/messageComposer/types.ts +6 -28
- package/src/messageDelivery/MessageDeliveryReporter.ts +101 -45
- package/src/messageDelivery/MessageReceiptsTracker.ts +294 -21
- package/src/messageOperations/MessageOperationStatePolicy.ts +77 -0
- package/src/messageOperations/MessageOperations.ts +212 -0
- package/src/messageOperations/index.ts +10 -0
- package/src/messageOperations/types.ts +64 -0
- package/src/moderation.ts +38 -431
- package/src/notifications/types.ts +8 -7
- package/src/offline-support/offline_support_api.ts +200 -133
- package/src/offline-support/offline_sync_manager.ts +23 -44
- package/src/offline-support/types.ts +23 -26
- package/src/offline-support/util.ts +5 -4
- package/src/pagination/FilterBuilder.ts +4 -1
- package/src/pagination/ItemIndex.ts +25 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +73 -0
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +53 -0
- package/src/pagination/cursorDerivation/index.ts +1 -0
- package/src/pagination/cursorDerivation/linearPaginationFlags.ts +86 -0
- package/src/pagination/filterCompiler.ts +196 -0
- package/src/pagination/index.ts +1 -3
- package/src/pagination/paginators/BasePaginator.ts +2859 -0
- package/src/pagination/paginators/ChannelPaginator.ts +729 -0
- package/src/pagination/paginators/MessageIntervalPaginator.ts +1116 -0
- package/src/pagination/paginators/MessagePaginator.ts +508 -0
- package/src/pagination/paginators/PinnedMessagePaginator.ts +108 -0
- package/src/pagination/paginators/ReminderPaginator.ts +107 -0
- package/src/pagination/paginators/UserGroupPaginator.ts +127 -0
- package/src/pagination/paginators/index.ts +7 -0
- package/src/pagination/paginators/stateThrottling.ts +31 -0
- package/src/pagination/sortCompiler.ts +193 -0
- package/src/pagination/types.normalization.ts +14 -0
- package/src/pagination/utility.normalization.ts +106 -0
- package/src/pagination/utility.queryChannel.ts +84 -0
- package/src/pagination/utility.search.ts +80 -0
- package/src/permissions.ts +7 -8
- package/src/poll.ts +101 -110
- package/src/poll_manager.ts +14 -8
- package/src/reminders/Reminder.ts +2 -5
- package/src/reminders/ReminderManager.ts +19 -21
- package/src/search/BaseSearchSource.ts +0 -3
- package/src/search/ChannelMemberSearchSource.ts +7 -1
- package/src/search/ChannelSearchSource.ts +10 -3
- package/src/search/MessageSearchSource.ts +29 -30
- package/src/search/UserSearchSource.ts +12 -8
- package/src/search/types.ts +3 -4
- package/src/segment.ts +1 -95
- package/src/signing.ts +107 -67
- package/src/store.ts +2 -1
- package/src/thread.ts +562 -238
- package/src/thread_manager.ts +37 -16
- package/src/token_manager.ts +21 -10
- package/src/types.ts +364 -4533
- package/src/uploadManager.ts +8 -0
- package/src/utils/FixedSizeQueueCache.ts +12 -6
- package/src/utils/WithSubscriptions.ts +2 -1
- package/src/utils/concurrency.ts +4 -4
- package/src/utils/mergeWith/mergeWith.ts +3 -3
- package/src/utils/mergeWith/mergeWithCore.ts +140 -164
- package/src/utils/mergeWith/mergeWithDiff.ts +3 -3
- package/src/utils/retryable.ts +117 -0
- package/src/utils/throttling/throttle.ts +130 -0
- package/src/utils.ts +208 -754
- package/dist/types/channel_manager.d.ts +0 -122
- package/dist/types/events.d.ts +0 -72
- package/dist/types/pagination/BasePaginator.d.ts +0 -69
- package/dist/types/pagination/ReminderPaginator.d.ts +0 -16
- package/dist/types/pagination/UserGroupPaginator.d.ts +0 -21
- package/src/channel_manager.ts +0 -830
- package/src/events.ts +0 -75
- package/src/pagination/BasePaginator.ts +0 -184
- package/src/pagination/ReminderPaginator.ts +0 -56
- package/src/pagination/UserGroupPaginator.ts +0 -93
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { EventHandlerPipeline } from './EventHandlerPipeline';
|
|
2
|
+
import { WithSubscriptions } from './utils/WithSubscriptions';
|
|
3
|
+
import type { EventType } from './types';
|
|
4
|
+
import type { ChannelPaginator } from './pagination';
|
|
5
|
+
import type { StreamChat } from './client';
|
|
6
|
+
import type { Unsubscribe } from './store';
|
|
7
|
+
import { StateStore } from './store';
|
|
8
|
+
import type { EventHandlerPipelineHandler, FindEventHandlerParams, InsertEventHandlerPayload, LabeledEventHandler } from './EventHandlerPipeline';
|
|
9
|
+
import type { Channel } from './channel';
|
|
10
|
+
export type ChannelManagerEventHandlerContext = {
|
|
11
|
+
channelManager: ChannelManager;
|
|
12
|
+
};
|
|
13
|
+
type EventHandlerContext = ChannelManagerEventHandlerContext;
|
|
14
|
+
type SupportedEventType = EventType | (string & {});
|
|
15
|
+
/**
|
|
16
|
+
* Resolves which paginators should be the "owners" of a channel
|
|
17
|
+
* when the channel matches multiple paginator filters.
|
|
18
|
+
*
|
|
19
|
+
* Return a set of paginator ids that should keep/own the item.
|
|
20
|
+
* Returning an empty set means the channel will be removed everywhere.
|
|
21
|
+
*/
|
|
22
|
+
export type PaginatorOwnershipResolver = (args: {
|
|
23
|
+
channel: Channel;
|
|
24
|
+
matchingPaginators: ChannelPaginator[];
|
|
25
|
+
}) => string[];
|
|
26
|
+
/**
|
|
27
|
+
* Convenience factory for a priority-based ownership resolver.
|
|
28
|
+
* - Provide an ordered list of paginator ids from highest to lowest priority.
|
|
29
|
+
* - If two or more paginators match a channel, the one with the highest priority wins.
|
|
30
|
+
* - If none of the matching paginator ids are in the priority list, all matches are kept (back-compat).
|
|
31
|
+
*/
|
|
32
|
+
export declare const createPriorityOwnershipResolver: (priority?: string[]) => PaginatorOwnershipResolver;
|
|
33
|
+
export declare const ignoreEventsForUnknownChannels: EventHandlerPipelineHandler<EventHandlerContext>;
|
|
34
|
+
export type ChannelManagerState = {
|
|
35
|
+
paginators: ChannelPaginator[];
|
|
36
|
+
};
|
|
37
|
+
export type ChannelManagerEventHandlers = Partial<Record<SupportedEventType, LabeledEventHandler<EventHandlerContext>[]>>;
|
|
38
|
+
export type ChannelManagerOptions = {
|
|
39
|
+
client: StreamChat;
|
|
40
|
+
paginators?: ChannelPaginator[];
|
|
41
|
+
/**
|
|
42
|
+
* The complete set of event handlers to run, replacing the defaults rather than extending them.
|
|
43
|
+
* Start from `ChannelManager.getDefaultHandlers()` (a fresh copy) and enrich it, unless the
|
|
44
|
+
* intention really is to route events differently from scratch. Note that the manager the client
|
|
45
|
+
* instantiates (`client.channelManager`) is constructed without this option — customize that one
|
|
46
|
+
* through `addEventHandler` / `setEventHandlers` / `removeEventHandlers`.
|
|
47
|
+
*/
|
|
48
|
+
eventHandlers?: ChannelManagerEventHandlers;
|
|
49
|
+
/**
|
|
50
|
+
* Decide which paginator(s) should own a channel when multiple match.
|
|
51
|
+
* Defaults to keeping the channel in all matching paginators.
|
|
52
|
+
* Channels are kept only in the paginators that are listed in the ownershipResolver array.
|
|
53
|
+
* Empty ownershipResolver array means that the channel is kept in all matching paginators.
|
|
54
|
+
*/
|
|
55
|
+
ownershipResolver?: PaginatorOwnershipResolver | string[];
|
|
56
|
+
};
|
|
57
|
+
export declare class ChannelManager extends WithSubscriptions {
|
|
58
|
+
client: StreamChat;
|
|
59
|
+
state: StateStore<ChannelManagerState>;
|
|
60
|
+
protected _pipelines: Map<SupportedEventType, EventHandlerPipeline<ChannelManagerEventHandlerContext>>;
|
|
61
|
+
protected ownershipResolver?: PaginatorOwnershipResolver;
|
|
62
|
+
/**
|
|
63
|
+
* The `filterQueryResults` each registered paginator had before this manager wrapped it.
|
|
64
|
+
*
|
|
65
|
+
* A server query bypasses the manager — the paginator fetches and ingests a page on its own, and
|
|
66
|
+
* the backend knows nothing about client-side ownership — so a "Work" (`{ team: 'work' }`) channel
|
|
67
|
+
* comes back in a catch-all list's page too and would render in both. `wrapPaginatorFiltering`
|
|
68
|
+
* therefore composes the ownership check onto that hook, which every page passes through.
|
|
69
|
+
*
|
|
70
|
+
* Keys = already wrapped (so re-inserting does not wrap twice); values = what to restore on
|
|
71
|
+
* removal, since a detached paginator must stop applying rules resolved against lists it left.
|
|
72
|
+
* Weakly keyed so a dropped paginator is not kept alive by this manager.
|
|
73
|
+
*/
|
|
74
|
+
protected filterQueryResultsBeforeWrapping: WeakMap<ChannelPaginator, (items: Channel[]) => Channel[]>;
|
|
75
|
+
protected static readonly defaultEventHandlers: ChannelManagerEventHandlers;
|
|
76
|
+
constructor({ client, eventHandlers, paginators, ownershipResolver, }: ChannelManagerOptions);
|
|
77
|
+
get paginators(): ChannelPaginator[];
|
|
78
|
+
get pipelines(): Map<SupportedEventType, EventHandlerPipeline<EventHandlerContext>>;
|
|
79
|
+
private get ctx();
|
|
80
|
+
/**
|
|
81
|
+
* Returns deep copy of default handlers mapping.
|
|
82
|
+
* The defaults can be enriched with custom handlers or the custom handlers can be replaced.
|
|
83
|
+
*/
|
|
84
|
+
static getDefaultHandlers(): ChannelManagerEventHandlers;
|
|
85
|
+
/**
|
|
86
|
+
* Replace the rule deciding which paginator(s) own a channel matched by several of them. Pass an
|
|
87
|
+
* ordered array of paginator ids (highest priority first) for the built-in priority resolver, a
|
|
88
|
+
* custom resolver function, or `undefined` to go back to the default (a channel is kept in every
|
|
89
|
+
* paginator whose filter it matches).
|
|
90
|
+
*
|
|
91
|
+
* Available as a setter because the manager is constructed by the client, before the app has had
|
|
92
|
+
* a chance to create its paginators — their ids are therefore only known later.
|
|
93
|
+
*/
|
|
94
|
+
setOwnershipResolver(ownershipResolver?: PaginatorOwnershipResolver | string[]): void;
|
|
95
|
+
/**
|
|
96
|
+
* Which paginators should own the channel among the ones that matched.
|
|
97
|
+
* Default behavior keeps the channel in all matching paginators.
|
|
98
|
+
*/
|
|
99
|
+
resolveOwnership(channel: Channel, matchingPaginators: ChannelPaginator[]): Set<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Route a channel into the paginator(s) that should own it, and remove it from any list it
|
|
102
|
+
* no longer belongs to. Ownership is resolved exactly as for live WS updates — the channel is
|
|
103
|
+
* ingested into every paginator whose filter it matches (or, when an ownership resolver picks
|
|
104
|
+
* winners among several matches, only into the owner(s)).
|
|
105
|
+
*
|
|
106
|
+
* Use this to surface a channel the app just opened — a search result, a freshly created DM —
|
|
107
|
+
* in the list(s) without a full re-query. `ingestItem` dedupes by cid and inserts in sort
|
|
108
|
+
* order, so calling this repeatedly is safe.
|
|
109
|
+
*
|
|
110
|
+
* A channel that matches no paginator is not added anywhere. To have such channels still
|
|
111
|
+
* appear, register a catch-all paginator (empty filter) with the lowest ownership priority as
|
|
112
|
+
* a local fallback list.
|
|
113
|
+
*/
|
|
114
|
+
ingestChannel(channel: Channel): void;
|
|
115
|
+
/**
|
|
116
|
+
* Filter a page of query results for a specific paginator according to ownership rules.
|
|
117
|
+
* If no owners are specified by the resolver, all matching paginators keep the item.
|
|
118
|
+
*/
|
|
119
|
+
protected filterItemsByOwnership({ paginator, items, }: {
|
|
120
|
+
paginator: ChannelPaginator;
|
|
121
|
+
items: Channel[];
|
|
122
|
+
}): Channel[];
|
|
123
|
+
/**
|
|
124
|
+
* Makes a registered paginator apply this manager's ownership rules to the pages it fetches
|
|
125
|
+
* itself, by composing `filterItemsByOwnership` onto its `filterQueryResults`.
|
|
126
|
+
*
|
|
127
|
+
* A channel can enter a list through two doors, and only one of them goes through the manager:
|
|
128
|
+
* - **WS events / `ingestChannel`** — the manager routes the channel and consults
|
|
129
|
+
* `resolveOwnership` before ingesting, so exclusivity holds by construction.
|
|
130
|
+
* - **A server query** — `paginator.next()` (a `ChannelList` scrolling, `reload()`) queries and
|
|
131
|
+
* ingests on its own; the manager is not involved. Without this wrapper a page would land in
|
|
132
|
+
* every list whose *server-side* filter matched it, so a channel matching both
|
|
133
|
+
* `channels:archived` and `channels:default` would show up in both lists until some later event
|
|
134
|
+
* re-routed it — the exact duplication the resolver exists to prevent.
|
|
135
|
+
*
|
|
136
|
+
* Wrapping (rather than subclassing or a constructor hook) is what lets the manager inject this
|
|
137
|
+
* into paginators it does not construct: `filterQueryResults` is an instance property, so the
|
|
138
|
+
* original is captured here and handed back by `unwrapPaginatorFiltering` when the paginator is
|
|
139
|
+
* detached. The paginator's own filtering runs first and stays authoritative — ownership only ever
|
|
140
|
+
* removes further items, never adds any back.
|
|
141
|
+
*
|
|
142
|
+
* Idempotent: the `WeakMap` guard keeps a re-inserted paginator from being wrapped twice, which
|
|
143
|
+
* would filter the same page repeatedly and, worse, lose the reference to the true original.
|
|
144
|
+
*/
|
|
145
|
+
protected wrapPaginatorFiltering(paginator: ChannelPaginator): void;
|
|
146
|
+
/**
|
|
147
|
+
* Undo `wrapPaginatorFiltering` — restore the `filterQueryResults` the paginator had before this
|
|
148
|
+
* manager wrapped it. A paginator that has left the manager must not keep applying its ownership
|
|
149
|
+
* rules: those are resolved against the paginators the manager still holds, so a detached
|
|
150
|
+
* paginator would drop channels owned by lists it is no longer part of.
|
|
151
|
+
*/
|
|
152
|
+
protected unwrapPaginatorFiltering(paginator: ChannelPaginator): void;
|
|
153
|
+
getPaginatorById(id: string): ChannelPaginator | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* Replace the whole set of lists in a single state update — the primitive `insertPaginator` and
|
|
156
|
+
* `removePaginator` build on, and what to use for a wholesale swap instead of publishing an
|
|
157
|
+
* intermediate state per step. Paginators dropped from the set are detached exactly as
|
|
158
|
+
* `removePaginator` detaches them; a repeated id keeps only its first occurrence.
|
|
159
|
+
*
|
|
160
|
+
* @param paginators - The lists this manager should hold, in render order.
|
|
161
|
+
*/
|
|
162
|
+
setPaginators(paginators: ChannelPaginator[]): void;
|
|
163
|
+
/**
|
|
164
|
+
* Detach every list at once — the teardown counterpart of `setPaginators`. Each paginator is
|
|
165
|
+
* released exactly as `removePaginator` releases it (ownership-filtering wrapper removed,
|
|
166
|
+
* scheduled query canceled, loaded items kept), in a single state update.
|
|
167
|
+
*
|
|
168
|
+
* @returns The paginators the manager held, in the order it held them.
|
|
169
|
+
*/
|
|
170
|
+
clearPaginators(): ChannelPaginator[];
|
|
171
|
+
/**
|
|
172
|
+
* If paginator already exists → remove old, reinsert at new index.
|
|
173
|
+
* If index not provided → append at the end.
|
|
174
|
+
* If index provided → insert (or move) at that index.
|
|
175
|
+
*
|
|
176
|
+
* @param params - The insertion parameters.
|
|
177
|
+
* @param params.paginator - The paginator to insert or move.
|
|
178
|
+
* @param params.index - Target index; when omitted the paginator is appended.
|
|
179
|
+
*/
|
|
180
|
+
insertPaginator({ paginator, index }: {
|
|
181
|
+
paginator: ChannelPaginator;
|
|
182
|
+
index?: number;
|
|
183
|
+
}): void;
|
|
184
|
+
/**
|
|
185
|
+
* Remove a paginator from the manager. The paginator stops receiving WS-driven updates and
|
|
186
|
+
* disappears from `state.paginators` (so UIs rendering one list per paginator drop its list), and
|
|
187
|
+
* gets its own `filterQueryResults` back — from here on it is an independent paginator again.
|
|
188
|
+
*
|
|
189
|
+
* Its loaded items are left untouched: the paginator can be re-inserted later, or kept and
|
|
190
|
+
* queried on its own. Any query scheduled through `nextDebounced` is canceled, so a list that was
|
|
191
|
+
* just removed does not fire one more request.
|
|
192
|
+
*
|
|
193
|
+
* @param paginatorOrId - The paginator to remove, or its id.
|
|
194
|
+
* @returns The removed paginator, or `undefined` when this manager did not hold it.
|
|
195
|
+
*/
|
|
196
|
+
removePaginator(paginatorOrId: ChannelPaginator | string): ChannelPaginator | undefined;
|
|
197
|
+
/**
|
|
198
|
+
* Discard the loaded data of every registered list, keeping the registrations themselves: which
|
|
199
|
+
* lists exist is application configuration, while the channels in them belong to the connected
|
|
200
|
+
* user and become invalid on `disconnectUser`. Each paginator returns to "never queried"
|
|
201
|
+
* (`items: undefined`) with its debounced query canceled. Deliberately not named `resetState` —
|
|
202
|
+
* this manager's own `state` *is* the paginator list, which this must not touch.
|
|
203
|
+
*/
|
|
204
|
+
resetPaginatorStates(): void;
|
|
205
|
+
addEventHandler({ eventType, ...payload }: {
|
|
206
|
+
eventType: SupportedEventType;
|
|
207
|
+
} & InsertEventHandlerPayload<EventHandlerContext>): Unsubscribe;
|
|
208
|
+
setEventHandlers({ eventType, handlers, }: {
|
|
209
|
+
eventType: SupportedEventType;
|
|
210
|
+
handlers: LabeledEventHandler<EventHandlerContext>[];
|
|
211
|
+
}): void;
|
|
212
|
+
removeEventHandlers({ eventType, handlers, }: {
|
|
213
|
+
eventType: SupportedEventType;
|
|
214
|
+
handlers: FindEventHandlerParams<EventHandlerContext>[];
|
|
215
|
+
}): void;
|
|
216
|
+
/** Subscribe to WS (and more buses via attachBus) */
|
|
217
|
+
registerSubscriptions(): Unsubscribe;
|
|
218
|
+
ensurePipeline(eventType: SupportedEventType): EventHandlerPipeline<EventHandlerContext>;
|
|
219
|
+
reload: () => Promise<PromiseSettledResult<void>[]>;
|
|
220
|
+
}
|
|
221
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { ChannelResponse, Event, EventType, MessageResponse, ReactionResponse, UserResponse } from './types';
|
|
2
|
+
import type { Unsubscribe } from './store';
|
|
3
|
+
/**
|
|
4
|
+
* Flat routing view of an event, as seen by pipeline handlers. The public `Event` type is now a
|
|
5
|
+
* discriminated union (each WS event exposes only its own fields) and also admits bare custom-event
|
|
6
|
+
* name strings — neither is convenient for the generic routers here, which only read a bounded set of
|
|
7
|
+
* common optional fields. Dispatched event *values* are always objects, so the pipeline casts to
|
|
8
|
+
* this view at the boundary (see `processOne`).
|
|
9
|
+
*/
|
|
10
|
+
export type PipelineEvent = {
|
|
11
|
+
type: EventType | (string & {});
|
|
12
|
+
channel?: ChannelResponse;
|
|
13
|
+
channel_id?: string;
|
|
14
|
+
channel_type?: string;
|
|
15
|
+
cid?: string;
|
|
16
|
+
created_at?: string | Date;
|
|
17
|
+
hard_delete?: boolean;
|
|
18
|
+
message?: MessageResponse;
|
|
19
|
+
reaction?: ReactionResponse;
|
|
20
|
+
user?: UserResponse;
|
|
21
|
+
};
|
|
22
|
+
type MatchById = {
|
|
23
|
+
id: string | RegExp;
|
|
24
|
+
regexMatch?: boolean;
|
|
25
|
+
};
|
|
26
|
+
export type FindEventHandlerParams<CTX extends Record<string, unknown>> = {
|
|
27
|
+
handler?: LabeledEventHandler<CTX> | EventHandlerPipelineHandler<CTX>;
|
|
28
|
+
idMatch?: MatchById;
|
|
29
|
+
};
|
|
30
|
+
export type EventHandlerResult = {
|
|
31
|
+
action: 'stop';
|
|
32
|
+
};
|
|
33
|
+
export type InsertEventHandlerPayload<CTX extends Record<string, unknown>> = {
|
|
34
|
+
handle: EventHandlerPipelineHandler<CTX>;
|
|
35
|
+
index?: number;
|
|
36
|
+
id?: string;
|
|
37
|
+
replace?: boolean;
|
|
38
|
+
revertOnUnsubscribe?: boolean;
|
|
39
|
+
};
|
|
40
|
+
export type EventHandlerPipelineHandler<CTX extends Record<string, unknown>> = (payload: {
|
|
41
|
+
event: PipelineEvent;
|
|
42
|
+
ctx: CTX;
|
|
43
|
+
}) => EventHandlerResult | void | Promise<EventHandlerResult | void>;
|
|
44
|
+
export type LabeledEventHandler<CTX extends Record<string, unknown>> = {
|
|
45
|
+
handle: EventHandlerPipelineHandler<CTX>;
|
|
46
|
+
id?: string;
|
|
47
|
+
};
|
|
48
|
+
export declare class EventHandlerPipeline<CTX extends Record<string, unknown> = {}> {
|
|
49
|
+
id: string;
|
|
50
|
+
protected handlers: LabeledEventHandler<CTX>[];
|
|
51
|
+
private runnerExecutionPromise;
|
|
52
|
+
constructor({ id }: {
|
|
53
|
+
id: string;
|
|
54
|
+
});
|
|
55
|
+
get size(): number;
|
|
56
|
+
findIndex({ handler, idMatch }: FindEventHandlerParams<CTX>): number;
|
|
57
|
+
/**
|
|
58
|
+
* Insert a handler into the pipeline at the given index.
|
|
59
|
+
*
|
|
60
|
+
* - If `replace` is `true` and the index is within bounds, the existing handler
|
|
61
|
+
* at that position will be replaced by the new one.
|
|
62
|
+
* - If `revertOnUnsubscribe` is also `true`, then calling the returned
|
|
63
|
+
* unsubscribe will both remove the inserted handler *and* restore the
|
|
64
|
+
* previously replaced handler at the same index.
|
|
65
|
+
* - If `replace` is `false` (default), the new handler is inserted at the index
|
|
66
|
+
* (or appended if the index is greater than the pipeline size). Unsubscribe
|
|
67
|
+
* will only remove this handler.
|
|
68
|
+
*
|
|
69
|
+
* @param payload - Insertion options.
|
|
70
|
+
* @param payload.handle - The handler function to insert.
|
|
71
|
+
* @param payload.index - Target index in the pipeline (clamped to valid range).
|
|
72
|
+
* @param payload.replace - If true, replace existing handler at index instead of inserting.
|
|
73
|
+
* @param payload.revertOnUnsubscribe - If true, restore the replaced handler when unsubscribing.
|
|
74
|
+
* @returns An unsubscribe function that removes (and optionally restores) the handler.
|
|
75
|
+
*/
|
|
76
|
+
insert({ handle, id, index, replace, revertOnUnsubscribe, }: InsertEventHandlerPayload<CTX>): Unsubscribe;
|
|
77
|
+
/**
|
|
78
|
+
* Remove handler by:
|
|
79
|
+
* - handler function identity or
|
|
80
|
+
* - by id that could be an exact match or
|
|
81
|
+
* - match by regexp.
|
|
82
|
+
*
|
|
83
|
+
* @param params - {FindEventHandlerParams}
|
|
84
|
+
*/
|
|
85
|
+
remove(params: FindEventHandlerParams<CTX>): void;
|
|
86
|
+
replaceAll(handlers: LabeledEventHandler<CTX>[]): void;
|
|
87
|
+
clear(): void;
|
|
88
|
+
/**
|
|
89
|
+
* Queue an event for processing. Events are processed serially, in the order
|
|
90
|
+
* `run` is called. Returns a promise that resolves/rejects for this specific
|
|
91
|
+
* event’s processing, while the internal chain continues (errors won’t break it).
|
|
92
|
+
*/
|
|
93
|
+
run(event: Event, ctx: CTX): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Wait until all queued events have been processed.
|
|
96
|
+
*/
|
|
97
|
+
drain(): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Process a single event through a stable snapshot of handlers to avoid
|
|
100
|
+
* mid-iteration mutations (insert/remove) affecting this run.
|
|
101
|
+
*/
|
|
102
|
+
private processOne;
|
|
103
|
+
}
|
|
104
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AxiosRequestConfig, Method } from 'axios';
|
|
2
|
+
import type { RequestMetadata, SendFileAPIResponse, UserResponse } from './types';
|
|
3
|
+
import type { StreamChat } from './client';
|
|
4
|
+
export declare class ApiClient {
|
|
5
|
+
client: StreamChat;
|
|
6
|
+
private nextRequestAbortController;
|
|
7
|
+
constructor(client?: StreamChat);
|
|
8
|
+
_getToken(): string | undefined;
|
|
9
|
+
createAbortControllerForNextRequest(): AbortController;
|
|
10
|
+
sendRequest<T>(method: Method, url: string, pathParams?: Record<string, string>, queryParams?: Record<string, unknown>, body?: unknown, requestContentType?: string): Promise<{
|
|
11
|
+
body: T;
|
|
12
|
+
metadata: RequestMetadata;
|
|
13
|
+
}>;
|
|
14
|
+
doAxiosRequest<T>(type: string, url: string, data?: unknown, options?: AxiosRequestConfig): Promise<T>;
|
|
15
|
+
get<T>(url: string, params?: AxiosRequestConfig['params']): Promise<T>;
|
|
16
|
+
put<T>(url: string, data?: unknown): Promise<T>;
|
|
17
|
+
post<T>(url: string, data?: unknown): Promise<T>;
|
|
18
|
+
patch<T>(url: string, data?: unknown): Promise<T>;
|
|
19
|
+
delete<T>(url: string, params?: AxiosRequestConfig['params']): Promise<T>;
|
|
20
|
+
sendFile(url: string, uri: string | NodeJS.ReadableStream | Buffer | File, name?: string, contentType?: string, user?: UserResponse, axiosRequestConfig?: AxiosRequestConfig): Promise<SendFileAPIResponse>;
|
|
21
|
+
private resolveUrl;
|
|
22
|
+
private getNextAbortSignal;
|
|
23
|
+
populateRequestConfigWithDefaults(additonalConfig: AxiosRequestConfig): AxiosRequestConfig;
|
|
24
|
+
private extractMetadata;
|
|
25
|
+
private _doRequest;
|
|
26
|
+
}
|
package/dist/types/campaign.d.ts
CHANGED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { StreamChat } from './client';
|
|
2
|
-
import type { CampaignData, GetCampaignOptions } from './types';
|
|
3
|
-
export declare class Campaign {
|
|
4
|
-
id: string | null;
|
|
5
|
-
data?: CampaignData;
|
|
6
|
-
client: StreamChat;
|
|
7
|
-
constructor(client: StreamChat, id: string | null, data?: CampaignData);
|
|
8
|
-
create(): Promise<{
|
|
9
|
-
campaign: import("./types").CampaignResponse;
|
|
10
|
-
users: {
|
|
11
|
-
next?: string;
|
|
12
|
-
prev?: string;
|
|
13
|
-
};
|
|
14
|
-
} & import("./types").APIResponse>;
|
|
15
|
-
verifyCampaignId(): void;
|
|
16
|
-
start(options?: {
|
|
17
|
-
scheduledFor?: string;
|
|
18
|
-
stopAt?: string;
|
|
19
|
-
}): Promise<{
|
|
20
|
-
campaign: import("./types").CampaignResponse;
|
|
21
|
-
users: {
|
|
22
|
-
next?: string;
|
|
23
|
-
prev?: string;
|
|
24
|
-
};
|
|
25
|
-
} & import("./types").APIResponse>;
|
|
26
|
-
update(data: Partial<CampaignData>): Promise<{
|
|
27
|
-
campaign: import("./types").CampaignResponse;
|
|
28
|
-
users: {
|
|
29
|
-
next?: string;
|
|
30
|
-
prev?: string;
|
|
31
|
-
};
|
|
32
|
-
}>;
|
|
33
|
-
delete(): Promise<import("./types").APIResponse>;
|
|
34
|
-
stop(): Promise<{
|
|
35
|
-
campaign: import("./types").CampaignResponse;
|
|
36
|
-
}>;
|
|
37
|
-
get(options?: GetCampaignOptions): Promise<{
|
|
38
|
-
campaign: import("./types").CampaignResponse;
|
|
39
|
-
users: {
|
|
40
|
-
next?: string;
|
|
41
|
-
prev?: string;
|
|
42
|
-
};
|
|
43
|
-
} & import("./types").APIResponse>;
|
|
44
|
-
}
|