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.
Files changed (242) hide show
  1. package/dist/cjs/index.browser.js +19798 -14472
  2. package/dist/cjs/index.browser.js.map +4 -4
  3. package/dist/cjs/index.node.js +19817 -14482
  4. package/dist/cjs/index.node.js.map +4 -4
  5. package/dist/esm/index.mjs +19795 -14469
  6. package/dist/esm/index.mjs.map +4 -4
  7. package/dist/types/ChannelManager.d.ts +221 -0
  8. package/dist/types/EventHandlerPipeline.d.ts +104 -0
  9. package/dist/types/api-client.d.ts +26 -0
  10. package/dist/types/campaign.d.ts +0 -44
  11. package/dist/types/channel.d.ts +454 -479
  12. package/dist/types/channel_batch_updater.d.ts +0 -93
  13. package/dist/types/channel_state.d.ts +53 -201
  14. package/dist/types/client.d.ts +451 -1920
  15. package/dist/types/client_state.d.ts +4 -4
  16. package/dist/types/configuration/InstanceConfigurationService.d.ts +26 -0
  17. package/dist/types/configuration/index.d.ts +1 -0
  18. package/dist/types/configuration/types.d.ts +53 -0
  19. package/dist/types/connection.d.ts +49 -41
  20. package/dist/types/connection_fallback.d.ts +6 -4
  21. package/dist/types/constants.d.ts +0 -4
  22. package/dist/types/custom_types.d.ts +2 -0
  23. package/dist/types/entityStore/EntityStore.d.ts +111 -0
  24. package/dist/types/entityStore/StoreBackedItemIndex.d.ts +60 -0
  25. package/dist/types/entityStore/applyReactionLocally.d.ts +26 -0
  26. package/dist/types/entityStore/index.d.ts +2 -0
  27. package/dist/types/errors.d.ts +10 -2
  28. package/dist/types/gen/chat/ChannelApi.d.ts +45 -0
  29. package/dist/types/gen/chat/ChatApi.d.ts +334 -0
  30. package/dist/types/gen/model-decoders/decoders.d.ts +3 -0
  31. package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +6 -0
  32. package/dist/types/gen/models/index.d.ts +8836 -0
  33. package/dist/types/gen/moderation/ModerationApi.d.ts +50 -0
  34. package/dist/types/gen-imports.d.ts +3 -0
  35. package/dist/types/index.d.ts +8 -7
  36. package/dist/types/insights.d.ts +9 -8
  37. package/dist/types/logger.d.ts +9 -0
  38. package/dist/types/messageComposer/LocationComposer.d.ts +7 -4
  39. package/dist/types/messageComposer/attachmentIdentity.d.ts +2 -2
  40. package/dist/types/messageComposer/attachmentManager.d.ts +8 -4
  41. package/dist/types/messageComposer/configuration/types.d.ts +11 -11
  42. package/dist/types/messageComposer/linkPreviewsManager.d.ts +25 -13
  43. package/dist/types/messageComposer/messageComposer.d.ts +10 -10
  44. package/dist/types/messageComposer/middleware/messageComposer/types.d.ts +3 -3
  45. package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +4 -7
  46. package/dist/types/messageComposer/middleware/textComposer/commandUtils.d.ts +3 -3
  47. package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +7 -7
  48. package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +218 -4
  49. package/dist/types/messageComposer/middleware/textComposer/types.d.ts +9 -4
  50. package/dist/types/messageComposer/pollComposer.d.ts +5 -4
  51. package/dist/types/messageComposer/textComposer.d.ts +8 -3
  52. package/dist/types/messageComposer/types.d.ts +6 -28
  53. package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +40 -25
  54. package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +53 -12
  55. package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +19 -0
  56. package/dist/types/messageOperations/MessageOperations.d.ts +17 -0
  57. package/dist/types/messageOperations/index.d.ts +3 -0
  58. package/dist/types/messageOperations/types.d.ts +49 -0
  59. package/dist/types/moderation.d.ts +21 -203
  60. package/dist/types/notifications/types.d.ts +8 -7
  61. package/dist/types/offline-support/offline_support_api.d.ts +111 -87
  62. package/dist/types/offline-support/offline_sync_manager.d.ts +0 -7
  63. package/dist/types/offline-support/types.d.ts +19 -23
  64. package/dist/types/offline-support/util.d.ts +4 -2
  65. package/dist/types/pagination/FilterBuilder.d.ts +1 -1
  66. package/dist/types/pagination/ItemIndex.d.ts +25 -0
  67. package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +9 -0
  68. package/dist/types/pagination/cursorDerivation/idAroundPaginationFlags.d.ts +6 -0
  69. package/dist/types/pagination/cursorDerivation/index.d.ts +1 -0
  70. package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +6 -0
  71. package/dist/types/pagination/filterCompiler.d.ts +7 -0
  72. package/dist/types/pagination/index.d.ts +1 -3
  73. package/dist/types/pagination/paginators/BasePaginator.d.ts +848 -0
  74. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +212 -0
  75. package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +282 -0
  76. package/dist/types/pagination/paginators/MessagePaginator.d.ts +208 -0
  77. package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +39 -0
  78. package/dist/types/pagination/paginators/ReminderPaginator.d.ts +19 -0
  79. package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +24 -0
  80. package/dist/types/pagination/paginators/index.d.ts +7 -0
  81. package/dist/types/pagination/paginators/stateThrottling.d.ts +2 -0
  82. package/dist/types/pagination/sortCompiler.d.ts +49 -0
  83. package/dist/types/pagination/types.normalization.d.ts +11 -0
  84. package/dist/types/pagination/utility.normalization.d.ts +18 -0
  85. package/dist/types/pagination/utility.queryChannel.d.ts +26 -0
  86. package/dist/types/pagination/utility.search.d.ts +13 -0
  87. package/dist/types/permissions.d.ts +1 -1
  88. package/dist/types/poll.d.ts +29 -32
  89. package/dist/types/poll_manager.d.ts +2 -2
  90. package/dist/types/reminders/Reminder.d.ts +2 -5
  91. package/dist/types/reminders/ReminderManager.d.ts +2 -9
  92. package/dist/types/search/MessageSearchSource.d.ts +4 -4
  93. package/dist/types/search/UserSearchSource.d.ts +1 -1
  94. package/dist/types/search/types.d.ts +3 -3
  95. package/dist/types/segment.d.ts +0 -34
  96. package/dist/types/signing.d.ts +105 -65
  97. package/dist/types/store.d.ts +1 -0
  98. package/dist/types/thread.d.ts +70 -34
  99. package/dist/types/thread_manager.d.ts +3 -3
  100. package/dist/types/token_manager.d.ts +15 -10
  101. package/dist/types/types.d.ts +197 -3404
  102. package/dist/types/utils/FixedSizeQueueCache.d.ts +12 -6
  103. package/dist/types/utils/WithSubscriptions.d.ts +2 -1
  104. package/dist/types/utils/concurrency.d.ts +4 -4
  105. package/dist/types/utils/mergeWith/mergeWith.d.ts +3 -3
  106. package/dist/types/utils/mergeWith/mergeWithCore.d.ts +8 -3
  107. package/dist/types/utils/retryable.d.ts +34 -0
  108. package/dist/types/utils/throttling/throttle.d.ts +36 -0
  109. package/dist/types/utils.d.ts +100 -194
  110. package/package.json +7 -3
  111. package/src/ChannelManager.ts +724 -0
  112. package/src/CooldownTimer.ts +2 -2
  113. package/src/EventHandlerPipeline.ts +228 -0
  114. package/src/LiveLocationManager.ts +12 -11
  115. package/src/api-client.ts +275 -0
  116. package/src/campaign.ts +1 -77
  117. package/src/channel.ts +1344 -1282
  118. package/src/channel_batch_updater.ts +1 -211
  119. package/src/channel_state.ts +144 -1013
  120. package/src/client.ts +936 -3995
  121. package/src/client_state.ts +4 -4
  122. package/src/configuration/InstanceConfigurationService.ts +73 -0
  123. package/src/configuration/index.ts +1 -0
  124. package/src/configuration/types.ts +81 -0
  125. package/src/connection.ts +145 -94
  126. package/src/connection_fallback.ts +29 -27
  127. package/src/constants.ts +1 -5
  128. package/src/custom_types.ts +4 -1
  129. package/src/entityStore/EntityStore.ts +208 -0
  130. package/src/entityStore/StoreBackedItemIndex.ts +115 -0
  131. package/src/entityStore/applyReactionLocally.ts +113 -0
  132. package/src/entityStore/index.ts +2 -0
  133. package/src/errors.ts +14 -2
  134. package/src/gen/chat/ChannelApi.ts +275 -0
  135. package/src/gen/chat/ChatApi.ts +2554 -0
  136. package/src/gen/model-decoders/decoders.ts +2680 -0
  137. package/src/gen/model-decoders/event-decoder-mapping.ts +198 -0
  138. package/src/gen/models/index.ts +12673 -0
  139. package/src/gen/moderation/ModerationApi.ts +607 -0
  140. package/src/gen-imports.ts +3 -0
  141. package/src/index.ts +11 -12
  142. package/src/insights.ts +6 -5
  143. package/src/logger.ts +28 -0
  144. package/src/messageComposer/LocationComposer.ts +9 -5
  145. package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -0
  146. package/src/messageComposer/attachmentIdentity.ts +16 -9
  147. package/src/messageComposer/attachmentManager.ts +13 -8
  148. package/src/messageComposer/configuration/types.ts +11 -11
  149. package/src/messageComposer/linkPreviewsManager.ts +9 -10
  150. package/src/messageComposer/messageComposer.ts +57 -53
  151. package/src/messageComposer/middleware/messageComposer/attachments.ts +1 -2
  152. package/src/messageComposer/middleware/messageComposer/cleanData.ts +1 -1
  153. package/src/messageComposer/middleware/messageComposer/compositionValidation.ts +2 -2
  154. package/src/messageComposer/middleware/messageComposer/messageComposerState.ts +2 -2
  155. package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +4 -3
  156. package/src/messageComposer/middleware/messageComposer/textComposer.ts +2 -2
  157. package/src/messageComposer/middleware/messageComposer/types.ts +3 -4
  158. package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +9 -5
  159. package/src/messageComposer/middleware/pollComposer/state.ts +0 -2
  160. package/src/messageComposer/middleware/pollComposer/types.ts +4 -7
  161. package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +10 -1
  162. package/src/messageComposer/middleware/textComposer/commandEffects.ts +4 -4
  163. package/src/messageComposer/middleware/textComposer/commandUtils.ts +3 -6
  164. package/src/messageComposer/middleware/textComposer/commands.ts +3 -3
  165. package/src/messageComposer/middleware/textComposer/mentionUtils.ts +1 -1
  166. package/src/messageComposer/middleware/textComposer/mentions.ts +31 -15
  167. package/src/messageComposer/middleware/textComposer/types.ts +9 -4
  168. package/src/messageComposer/pollComposer.ts +6 -8
  169. package/src/messageComposer/textComposer.ts +27 -2
  170. package/src/messageComposer/types.ts +6 -28
  171. package/src/messageDelivery/MessageDeliveryReporter.ts +101 -45
  172. package/src/messageDelivery/MessageReceiptsTracker.ts +294 -21
  173. package/src/messageOperations/MessageOperationStatePolicy.ts +77 -0
  174. package/src/messageOperations/MessageOperations.ts +212 -0
  175. package/src/messageOperations/index.ts +10 -0
  176. package/src/messageOperations/types.ts +64 -0
  177. package/src/moderation.ts +38 -431
  178. package/src/notifications/types.ts +8 -7
  179. package/src/offline-support/offline_support_api.ts +200 -133
  180. package/src/offline-support/offline_sync_manager.ts +23 -44
  181. package/src/offline-support/types.ts +23 -26
  182. package/src/offline-support/util.ts +5 -4
  183. package/src/pagination/FilterBuilder.ts +4 -1
  184. package/src/pagination/ItemIndex.ts +25 -0
  185. package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +73 -0
  186. package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +53 -0
  187. package/src/pagination/cursorDerivation/index.ts +1 -0
  188. package/src/pagination/cursorDerivation/linearPaginationFlags.ts +86 -0
  189. package/src/pagination/filterCompiler.ts +196 -0
  190. package/src/pagination/index.ts +1 -3
  191. package/src/pagination/paginators/BasePaginator.ts +2859 -0
  192. package/src/pagination/paginators/ChannelPaginator.ts +729 -0
  193. package/src/pagination/paginators/MessageIntervalPaginator.ts +1116 -0
  194. package/src/pagination/paginators/MessagePaginator.ts +508 -0
  195. package/src/pagination/paginators/PinnedMessagePaginator.ts +108 -0
  196. package/src/pagination/paginators/ReminderPaginator.ts +107 -0
  197. package/src/pagination/paginators/UserGroupPaginator.ts +127 -0
  198. package/src/pagination/paginators/index.ts +7 -0
  199. package/src/pagination/paginators/stateThrottling.ts +31 -0
  200. package/src/pagination/sortCompiler.ts +193 -0
  201. package/src/pagination/types.normalization.ts +14 -0
  202. package/src/pagination/utility.normalization.ts +106 -0
  203. package/src/pagination/utility.queryChannel.ts +84 -0
  204. package/src/pagination/utility.search.ts +80 -0
  205. package/src/permissions.ts +7 -8
  206. package/src/poll.ts +101 -110
  207. package/src/poll_manager.ts +14 -8
  208. package/src/reminders/Reminder.ts +2 -5
  209. package/src/reminders/ReminderManager.ts +19 -21
  210. package/src/search/BaseSearchSource.ts +0 -3
  211. package/src/search/ChannelMemberSearchSource.ts +7 -1
  212. package/src/search/ChannelSearchSource.ts +10 -3
  213. package/src/search/MessageSearchSource.ts +29 -30
  214. package/src/search/UserSearchSource.ts +12 -8
  215. package/src/search/types.ts +3 -4
  216. package/src/segment.ts +1 -95
  217. package/src/signing.ts +107 -67
  218. package/src/store.ts +2 -1
  219. package/src/thread.ts +562 -238
  220. package/src/thread_manager.ts +37 -16
  221. package/src/token_manager.ts +21 -10
  222. package/src/types.ts +364 -4533
  223. package/src/uploadManager.ts +8 -0
  224. package/src/utils/FixedSizeQueueCache.ts +12 -6
  225. package/src/utils/WithSubscriptions.ts +2 -1
  226. package/src/utils/concurrency.ts +4 -4
  227. package/src/utils/mergeWith/mergeWith.ts +3 -3
  228. package/src/utils/mergeWith/mergeWithCore.ts +140 -164
  229. package/src/utils/mergeWith/mergeWithDiff.ts +3 -3
  230. package/src/utils/retryable.ts +117 -0
  231. package/src/utils/throttling/throttle.ts +130 -0
  232. package/src/utils.ts +208 -754
  233. package/dist/types/channel_manager.d.ts +0 -122
  234. package/dist/types/events.d.ts +0 -72
  235. package/dist/types/pagination/BasePaginator.d.ts +0 -69
  236. package/dist/types/pagination/ReminderPaginator.d.ts +0 -16
  237. package/dist/types/pagination/UserGroupPaginator.d.ts +0 -21
  238. package/src/channel_manager.ts +0 -830
  239. package/src/events.ts +0 -75
  240. package/src/pagination/BasePaginator.ts +0 -184
  241. package/src/pagination/ReminderPaginator.ts +0 -56
  242. package/src/pagination/UserGroupPaginator.ts +0 -93
package/src/events.ts DELETED
@@ -1,75 +0,0 @@
1
- export const EVENT_MAP = {
2
- 'channel.created': true,
3
- 'channel.deleted': true,
4
- 'channel.hidden': true,
5
- 'channel.kicked': true,
6
- 'channel.muted': true,
7
- 'channel.truncated': true,
8
- 'channel.unmuted': true,
9
- 'channel.updated': true,
10
- 'channel.visible': true,
11
- 'draft.deleted': true,
12
- 'draft.updated': true,
13
- 'health.check': true,
14
- 'member.added': true,
15
- 'member.removed': true,
16
- 'member.updated': true,
17
- 'message.deleted': true,
18
- 'message.new': true,
19
- 'message.read': true,
20
- 'message.updated': true,
21
- 'message.undeleted': true,
22
- 'notification.added_to_channel': true,
23
- 'notification.channel_deleted': true,
24
- 'message.delivered': true,
25
- 'notification.channel_mutes_updated': true,
26
- 'notification.channel_truncated': true,
27
- 'notification.invite_accepted': true,
28
- 'notification.invite_rejected': true,
29
- 'notification.invited': true,
30
- 'notification.mark_read': true,
31
- 'notification.mark_unread': true,
32
- 'notification.message_new': true,
33
- 'notification.mutes_updated': true,
34
- 'notification.reminder_due': true,
35
- 'notification.removed_from_channel': true,
36
- 'notification.thread_message_new': true,
37
- 'poll.closed': true,
38
- 'poll.updated': true,
39
- 'poll.vote_casted': true,
40
- 'poll.vote_changed': true,
41
- 'poll.vote_removed': true,
42
- 'reaction.deleted': true,
43
- 'reaction.new': true,
44
- 'reaction.updated': true,
45
- 'reminder.created': true,
46
- 'reminder.deleted': true,
47
- 'reminder.updated': true,
48
- 'thread.updated': true,
49
- 'typing.start': true,
50
- 'typing.stop': true,
51
- 'user.banned': true,
52
- 'user.deleted': true,
53
- 'user.messages.deleted': true,
54
- 'user.presence.changed': true,
55
- 'user.unbanned': true,
56
- 'user.unread_message_reminder': true,
57
- 'user.updated': true,
58
- 'user.watching.start': true,
59
- 'user.watching.stop': true,
60
- // AI events
61
- 'ai_indicator.update': true,
62
- 'ai_indicator.stop': true,
63
- 'ai_indicator.clear': true,
64
-
65
- // local events
66
- 'message.read_locally': true,
67
- 'channels.queried': true,
68
- 'offline_reactions.queried': true,
69
- 'connection.changed': true,
70
- 'connection.recovered': true,
71
- 'transport.changed': true,
72
- 'capabilities.changed': true,
73
- 'live_location_sharing.started': true,
74
- 'live_location_sharing.stopped': true,
75
- };
@@ -1,184 +0,0 @@
1
- import { StateStore } from '../store';
2
- import { debounce, type DebouncedFunc } from '../utils';
3
-
4
- type PaginationDirection = 'next' | 'prev';
5
- type Cursor = { next: string | null; prev: string | null };
6
- export type PaginationQueryParams = { direction: PaginationDirection };
7
- export type PaginationQueryReturnValue<T> = { items: T[] } & {
8
- next?: string;
9
- prev?: string;
10
- };
11
- export type PaginatorDebounceOptions = {
12
- debounceMs: number;
13
- };
14
- type DebouncedExecQueryFunction = DebouncedFunc<
15
- (params: { direction: PaginationDirection }) => Promise<void>
16
- >;
17
-
18
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- export type PaginatorState<T = any> = {
20
- hasNext: boolean;
21
- hasPrev: boolean;
22
- isLoading: boolean;
23
- items: T[] | undefined;
24
- lastQueryError?: Error;
25
- cursor?: Cursor;
26
- offset?: number;
27
- };
28
-
29
- export type PaginatorOptions = {
30
- /** The number of milliseconds to debounce the search query. The default interval is 300ms. */
31
- debounceMs?: number;
32
- pageSize?: number;
33
- };
34
- export const DEFAULT_PAGINATION_OPTIONS: Required<PaginatorOptions> = {
35
- debounceMs: 300,
36
- pageSize: 10,
37
- } as const;
38
-
39
- export abstract class BasePaginator<T> {
40
- state: StateStore<PaginatorState<T>>;
41
- pageSize: number;
42
- protected _executeQueryDebounced!: DebouncedExecQueryFunction;
43
- protected _isCursorPagination = false;
44
-
45
- protected constructor(options?: PaginatorOptions) {
46
- const { debounceMs, pageSize } = { ...DEFAULT_PAGINATION_OPTIONS, ...options };
47
- this.pageSize = pageSize;
48
- this.state = new StateStore<PaginatorState<T>>(this.initialState);
49
- this.setDebounceOptions({ debounceMs });
50
- }
51
-
52
- get lastQueryError() {
53
- return this.state.getLatestValue().lastQueryError;
54
- }
55
-
56
- get hasNext() {
57
- return this.state.getLatestValue().hasNext;
58
- }
59
-
60
- get hasPrev() {
61
- return this.state.getLatestValue().hasPrev;
62
- }
63
-
64
- get hasResults() {
65
- return Array.isArray(this.state.getLatestValue().items);
66
- }
67
-
68
- get isLoading() {
69
- return this.state.getLatestValue().isLoading;
70
- }
71
-
72
- get initialState(): PaginatorState {
73
- return {
74
- hasNext: true,
75
- hasPrev: true, //todo: check if optimistic value does not cause problems in UI
76
- isLoading: false,
77
- items: undefined,
78
- lastQueryError: undefined,
79
- cursor: undefined,
80
- offset: 0,
81
- };
82
- }
83
-
84
- get items() {
85
- return this.state.getLatestValue().items;
86
- }
87
-
88
- get cursor() {
89
- return this.state.getLatestValue().cursor;
90
- }
91
-
92
- get offset() {
93
- return this.state.getLatestValue().offset;
94
- }
95
-
96
- abstract query(params: PaginationQueryParams): Promise<PaginationQueryReturnValue<T>>;
97
-
98
- abstract filterQueryResults(items: T[]): T[] | Promise<T[]>;
99
-
100
- setDebounceOptions = ({ debounceMs }: PaginatorDebounceOptions) => {
101
- this._executeQueryDebounced = debounce(this.executeQuery.bind(this), debounceMs);
102
- };
103
-
104
- canExecuteQuery = (direction: PaginationDirection) =>
105
- (!this.isLoading && direction === 'next' && this.hasNext) ||
106
- (direction === 'prev' && this.hasPrev);
107
-
108
- protected getStateBeforeFirstQuery(): PaginatorState<T> {
109
- return {
110
- ...this.initialState,
111
- isLoading: true,
112
- };
113
- }
114
-
115
- protected getStateAfterQuery(
116
- stateUpdate: Partial<PaginatorState<T>>,
117
- isFirstPage: boolean,
118
- ): PaginatorState<T> {
119
- const current = this.state.getLatestValue();
120
- return {
121
- ...current,
122
- lastQueryError: undefined, // reset lastQueryError that can be overridden by the stateUpdate
123
- ...stateUpdate,
124
- isLoading: false,
125
- items: isFirstPage
126
- ? stateUpdate.items
127
- : [...(this.items ?? []), ...(stateUpdate.items || [])],
128
- };
129
- }
130
-
131
- async executeQuery({ direction }: { direction: PaginationDirection }) {
132
- if (!this.canExecuteQuery(direction)) return;
133
- const isFirstPage = typeof this.items === 'undefined';
134
- if (isFirstPage) {
135
- this.state.next(this.getStateBeforeFirstQuery());
136
- } else {
137
- this.state.partialNext({ isLoading: true });
138
- }
139
-
140
- const stateUpdate: Partial<PaginatorState<T>> = {};
141
- try {
142
- const results = await this.query({ direction });
143
- if (!results) return;
144
- const { items, next, prev } = results;
145
- if (isFirstPage && (next || prev)) {
146
- this._isCursorPagination = true;
147
- }
148
-
149
- if (this._isCursorPagination) {
150
- stateUpdate.cursor = { next: next || null, prev: prev || null };
151
- stateUpdate.hasNext = !!next;
152
- stateUpdate.hasPrev = !!prev;
153
- } else {
154
- stateUpdate.offset = (this.offset ?? 0) + items.length;
155
- stateUpdate.hasNext = items.length === this.pageSize;
156
- }
157
-
158
- stateUpdate.items = await this.filterQueryResults(items);
159
- } catch (e) {
160
- stateUpdate.lastQueryError = e as Error;
161
- } finally {
162
- this.state.next(this.getStateAfterQuery(stateUpdate, isFirstPage));
163
- }
164
- }
165
-
166
- cancelScheduledQuery() {
167
- this._executeQueryDebounced.cancel();
168
- }
169
-
170
- resetState() {
171
- this.state.next(this.initialState);
172
- }
173
-
174
- next = () => this.executeQuery({ direction: 'next' });
175
-
176
- prev = () => this.executeQuery({ direction: 'prev' });
177
-
178
- nextDebounced = () => {
179
- this._executeQueryDebounced({ direction: 'next' });
180
- };
181
- prevDebounced = () => {
182
- this._executeQueryDebounced({ direction: 'prev' });
183
- };
184
- }
@@ -1,56 +0,0 @@
1
- import { BasePaginator } from './BasePaginator';
2
- import type {
3
- PaginationQueryParams,
4
- PaginationQueryReturnValue,
5
- PaginatorOptions,
6
- } from './BasePaginator';
7
- import type { ReminderFilters, ReminderResponse, ReminderSort } from '../types';
8
- import type { StreamChat } from '../client';
9
-
10
- export class ReminderPaginator extends BasePaginator<ReminderResponse> {
11
- private client: StreamChat;
12
- protected _filters: ReminderFilters | undefined;
13
- protected _sort: ReminderSort | undefined;
14
-
15
- get filters(): ReminderFilters | undefined {
16
- return this._filters;
17
- }
18
-
19
- get sort(): ReminderSort | undefined {
20
- return this._sort;
21
- }
22
-
23
- set filters(filters: ReminderFilters | undefined) {
24
- this._filters = filters;
25
- this.resetState();
26
- }
27
-
28
- set sort(sort: ReminderSort | undefined) {
29
- this._sort = sort;
30
- this.resetState();
31
- }
32
-
33
- constructor(client: StreamChat, options?: PaginatorOptions) {
34
- super(options);
35
- this.client = client;
36
- }
37
-
38
- query = async ({
39
- direction,
40
- }: PaginationQueryParams): Promise<PaginationQueryReturnValue<ReminderResponse>> => {
41
- const cursor = this.cursor?.[direction];
42
- const {
43
- reminders: items,
44
- next,
45
- prev,
46
- } = await this.client.queryReminders({
47
- filter: this.filters,
48
- sort: this.sort,
49
- limit: this.pageSize,
50
- [direction]: cursor,
51
- });
52
- return { items, next, prev };
53
- };
54
-
55
- filterQueryResults = (items: ReminderResponse[]) => items;
56
- }
@@ -1,93 +0,0 @@
1
- import { BasePaginator } from './BasePaginator';
2
- import type {
3
- PaginationQueryParams,
4
- PaginationQueryReturnValue,
5
- PaginatorOptions,
6
- PaginatorState,
7
- } from './BasePaginator';
8
- import type { QueryUserGroupsOptions, UserGroupResponse } from '../types';
9
- import type { StreamChat } from '../client';
10
-
11
- type UserGroupListCursor = {
12
- created_at_gt: string;
13
- id_gt: string;
14
- };
15
-
16
- const isRecord = (value: unknown): value is Record<string, unknown> =>
17
- typeof value === 'object' && value !== null;
18
-
19
- const decodeCursor = <TCursor extends object>(cursor: string | null | undefined) => {
20
- if (!cursor) return undefined;
21
-
22
- try {
23
- const parsed = JSON.parse(cursor);
24
- return isRecord(parsed) ? (parsed as TCursor) : undefined;
25
- } catch {
26
- return undefined;
27
- }
28
- };
29
-
30
- /**
31
- * Paginates user-group listing through `/usergroups`.
32
- *
33
- * This entity only supports forward cursor pagination via `created_at_gt` and `id_gt`.
34
- * Previous-page pagination is not available because the API does not expose a backward cursor.
35
- */
36
- export class UserGroupPaginator extends BasePaginator<UserGroupResponse> {
37
- private client: StreamChat;
38
- protected _teamId: string | undefined;
39
-
40
- constructor(client: StreamChat, options?: PaginatorOptions) {
41
- super(options);
42
- this.client = client;
43
- }
44
-
45
- get initialState(): PaginatorState<UserGroupResponse> {
46
- return {
47
- ...super.initialState,
48
- hasPrev: false,
49
- };
50
- }
51
-
52
- get teamId() {
53
- return this._teamId;
54
- }
55
-
56
- set teamId(teamId: string | undefined) {
57
- if (teamId === this._teamId) return;
58
- this._teamId = teamId;
59
- this.resetState();
60
- }
61
-
62
- private buildNextCursor = (items: UserGroupResponse[]) => {
63
- if (items.length < this.pageSize) return undefined;
64
- const lastItem = items[items.length - 1];
65
- if (!lastItem) return undefined;
66
-
67
- return JSON.stringify({
68
- created_at_gt: lastItem.created_at,
69
- id_gt: lastItem.id,
70
- } satisfies UserGroupListCursor);
71
- };
72
-
73
- query = async ({
74
- direction,
75
- }: PaginationQueryParams): Promise<PaginationQueryReturnValue<UserGroupResponse>> => {
76
- if (direction === 'prev') {
77
- return { items: [] };
78
- }
79
-
80
- const cursor = decodeCursor<UserGroupListCursor>(this.cursor?.next);
81
- const options: QueryUserGroupsOptions = {
82
- limit: this.pageSize,
83
- ...(this.teamId ? { team_id: this.teamId } : {}),
84
- ...(cursor?.id_gt ? { id_gt: cursor.id_gt } : {}),
85
- ...(cursor?.created_at_gt ? { created_at_gt: cursor.created_at_gt } : {}),
86
- };
87
-
88
- const { user_groups: items } = await this.client.queryUserGroups(options);
89
- return { items, next: this.buildNextCursor(items) };
90
- };
91
-
92
- filterQueryResults = (items: UserGroupResponse[]) => items;
93
- }