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
@@ -1,4 +1,4 @@
1
- import type { Event } from '../types';
1
+ import type { Event, EventPayload } from '../types';
2
2
  import type { OfflineDBApi, OfflineDBState, PendingTask, PrepareBatchDBQueries } from './types';
3
3
  import type { StreamChat } from '../client';
4
4
  import { OfflineDBSyncManager } from './offline_sync_manager';
@@ -20,7 +20,6 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
20
20
  client: StreamChat;
21
21
  });
22
22
  /**
23
- * @abstract
24
23
  * Inserts a reaction into the DB.
25
24
  * Will write to:
26
25
  * - The reactions table with the new reaction
@@ -28,22 +27,22 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
28
27
  * - The users table with any users associated
29
28
  * Will return the prepared queries for delayed execution (even if they are
30
29
  * already executed).
30
+ *
31
31
  * @param {DBInsertReactionType} options
32
32
  * @returns {Promise<ExecuteBatchDBQueriesType>}
33
33
  */
34
34
  abstract insertReaction: OfflineDBApi['insertReaction'];
35
35
  /**
36
- * @abstract
37
36
  * Upserts the list of CIDs for a filter + sort query hash.
38
37
  * Will write to only the table containing the cids.
39
38
  * Will return the prepared queries for delayed execution (even if they are
40
39
  * already executed).
40
+ *
41
41
  * @param {DBUpsertCidsForQueryType} options
42
42
  * @returns {Promise<ExecuteBatchDBQueriesType>}
43
43
  */
44
44
  abstract upsertCidsForQuery: OfflineDBApi['upsertCidsForQuery'];
45
45
  /**
46
- * @abstract
47
46
  * Upserts the channels passed as an argument within the DB. Relies on
48
47
  * writing the properties we need from a ChannelResponse into the adequate
49
48
  * tables.
@@ -57,66 +56,66 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
57
56
  * - The reads table for each user
58
57
  * Will return the prepared queries for delayed execution (even if they are
59
58
  * already executed).
59
+ *
60
60
  * @param {DBUpsertChannelsType} options
61
61
  * @returns {Promise<ExecuteBatchDBQueriesType>}
62
62
  */
63
63
  abstract upsertChannels: OfflineDBApi['upsertChannels'];
64
64
  /**
65
- * @abstract
66
65
  * Upserts the current active user's sync status.
67
66
  * Will only write to the sync status table.
68
67
  * Will return the prepared queries for delayed execution (even if they are
69
68
  * already executed).
69
+ *
70
70
  * @param {DBUpsertUserSyncStatusType} options
71
71
  * @returns {Promise<ExecuteBatchDBQueriesType>}
72
72
  */
73
73
  abstract upsertUserSyncStatus: OfflineDBApi['upsertUserSyncStatus'];
74
74
  /**
75
- * @abstract
76
75
  * Upserts the app settings for the current Stream App into the DB. It
77
76
  * is only intended to be run once per lifecycle of the app.
78
77
  * Will only write to the respective app settings table.
79
78
  * Will return the prepared queries for delayed execution (even if they are
80
79
  * already executed).
80
+ *
81
81
  * @param {DBUpsertAppSettingsType} options
82
82
  * @returns {Promise<ExecuteBatchDBQueriesType>}
83
83
  */
84
84
  abstract upsertAppSettings: OfflineDBApi['upsertAppSettings'];
85
85
  /**
86
- * @abstract
87
86
  * Upserts a poll fully in the DB.
88
87
  * Will write to the polls table. It should not update the message
89
88
  * associated due to how the poll state works.
90
89
  * Will return the prepared queries for delayed execution (even if they are
91
90
  * already executed).
91
+ *
92
92
  * @param {DBUpsertPollType} options
93
93
  * @returns {Promise<ExecuteBatchDBQueriesType>}
94
94
  */
95
95
  abstract upsertPoll: OfflineDBApi['upsertPoll'];
96
96
  /**
97
- * @abstract
98
97
  * Upserts only the channel.data for the provided channels in the DB.
99
98
  * Will only write to the channels table.
100
99
  * Will return the prepared queries for delayed execution (even if they are
101
100
  * already executed).
101
+ *
102
102
  * @param {DBUpsertChannelDataType} options
103
103
  * @returns {Promise<ExecuteBatchDBQueriesType>}
104
104
  */
105
105
  abstract upsertChannelData: OfflineDBApi['upsertChannelData'];
106
106
  /**
107
- * @abstract
108
107
  * Upserts the provided reads in the DB.
109
108
  * Will write to:
110
109
  * - The reads table
111
110
  * - The users table for each user associated with a read
112
111
  * Will return the prepared queries for delayed execution (even if they are
113
112
  * already executed).
113
+ *
114
114
  * @param {DBUpsertReadsType} options
115
115
  * @returns {Promise<ExecuteBatchDBQueriesType>}
116
116
  */
117
117
  abstract upsertReads: OfflineDBApi['upsertReads'];
118
118
  /**
119
- * @abstract
120
119
  * Upserts the messages in the DB.
121
120
  * Will write to:
122
121
  * - The messages table
@@ -126,274 +125,277 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
126
125
  * - The users table
127
126
  * Will return the prepared queries for delayed execution (even if they are
128
127
  * already executed).
128
+ *
129
129
  * @param {DBUpsertMessagesType} options
130
130
  * @returns {Promise<ExecuteBatchDBQueriesType>}
131
131
  */
132
132
  abstract upsertMessages: OfflineDBApi['upsertMessages'];
133
133
  /**
134
- * @abstract
135
134
  * Upserts the members in the DB.
136
135
  * Will write to:
137
136
  * - The users table (for each user associated with a member)
138
137
  * - The members table
139
138
  * Will return the prepared queries for delayed execution (even if they are
140
139
  * already executed).
140
+ *
141
141
  * @param {DBUpsertMembersType} options
142
142
  * @returns {Promise<ExecuteBatchDBQueriesType>}
143
143
  */
144
144
  abstract upsertMembers: OfflineDBApi['upsertMembers'];
145
145
  /**
146
- * @abstract
147
146
  * Updates a reaction in the DB. Will update the DB the same way
148
147
  * a reaction.updated event would (it assumes enforce_unique is true
149
148
  * and removes all other reactions associated with the user.
150
149
  * Will write to the reactions table.
151
150
  * Will return the prepared queries for delayed execution (even if they are
152
151
  * already executed).
152
+ *
153
153
  * @param {DBUpdateReactionType} options
154
154
  * @returns {Promise<ExecuteBatchDBQueriesType>}
155
155
  */
156
156
  abstract updateReaction: OfflineDBApi['updateReaction'];
157
157
  /**
158
- * @abstract
159
158
  * Updates a single message in the DB. This is used as a faster
160
159
  * alternative to upsertMessages with more optimized queries.
161
160
  * Will write to the messages table.
162
161
  * Will return the prepared queries for delayed execution (even if they are
163
162
  * already executed).
163
+ *
164
164
  * @param {DBUpdateMessageType} options
165
165
  * @returns {Promise<ExecuteBatchDBQueriesType>}
166
166
  */
167
167
  abstract updateMessage: OfflineDBApi['updateMessage'];
168
168
  /**
169
- * @abstract
170
169
  * Fetches the provided draft from the DB. Should return as close to
171
170
  * the server side DraftResponse as possible.
171
+ *
172
172
  * @param {DBGetDraftType} options
173
173
  * @returns {Promise<DraftResponse | null>}
174
174
  */
175
175
  abstract getDraft: OfflineDBApi['getDraft'];
176
176
  /**
177
- * @abstract
178
177
  * Upserts a draft in the DB.
179
178
  * Will write to the draft table upserting the draft.
180
179
  * Will return the prepared queries for delayed execution (even if they are
181
180
  * already executed).
181
+ *
182
182
  * @param {DBUpsertDraftType} options
183
183
  * @returns {Promise<ExecuteBatchDBQueriesType>}
184
184
  */
185
185
  abstract upsertDraft: OfflineDBApi['upsertDraft'];
186
186
  /**
187
- * @abstract
188
187
  * Deletes a draft from the DB.
189
188
  * Will write to the draft table removing the draft.
190
189
  * Will return the prepared queries for delayed execution (even if they are
191
190
  * already executed).
191
+ *
192
192
  * @param {DBDeleteDraftType} options
193
193
  * @returns {Promise<ExecuteBatchDBQueriesType>}
194
194
  */
195
195
  abstract deleteDraft: OfflineDBApi['deleteDraft'];
196
196
  /**
197
- * @abstract
198
197
  * Fetches the provided channels from the DB and aggregates all data associated
199
- * with them in a single ChannelAPIResponse. The implementation itself is responsible
198
+ * with them in a single ChannelStateResponseFields. The implementation itself is responsible
200
199
  * for aggregating and serialization of all of the data. Should return as close to
201
- * the server side ChannelAPIResponse as possible.
200
+ * the server side ChannelStateResponseFields as possible.
201
+ *
202
202
  * @param {DBGetChannelsType} options
203
- * @returns {Promise<Omit<ChannelAPIResponse, 'duration'>[] | null>}
203
+ * @returns {Promise<Omit<ChannelStateResponseFields, 'duration'>[] | null>}
204
204
  */
205
205
  abstract getChannels: OfflineDBApi['getChannels'];
206
206
  /**
207
- * @abstract
208
207
  * Fetches the channels from the DB that were the last known response to a filters & sort
209
- * hash as a query and aggregates all data associated with them in a single ChannelAPIResponse.
208
+ * hash as a query and aggregates all data associated with them in a single ChannelStateResponseFields.
210
209
  * The implementation itself is responsible for aggregating and serialization of all of the data.
211
- * Should return as close to the server side ChannelAPIResponse as possible.
210
+ * Should return as close to the server side ChannelStateResponseFields as possible.
211
+ *
212
212
  * @param {DBGetChannelsForQueryType} options
213
- * @returns {Promise<Omit<ChannelAPIResponse, 'duration'>[] | null>}
213
+ * @returns {Promise<Omit<ChannelStateResponseFields, 'duration'>[] | null>}
214
214
  */
215
215
  abstract getChannelsForQuery: OfflineDBApi['getChannelsForQuery'];
216
216
  /**
217
- * @abstract
218
217
  * Will return a list of all available CIDs in the DB. The same can be achieved
219
218
  * by fetching all channels, however this is meant to be much faster as a query.
219
+ *
220
220
  * @returns {Promise<string[]>}
221
221
  */
222
222
  abstract getAllChannelCids: OfflineDBApi['getAllChannelCids'];
223
223
  /**
224
- * @abstract
225
224
  * Fetches the timestamp of the last sync of the DB.
225
+ *
226
226
  * @param {DBGetLastSyncedAtType} options
227
227
  * @returns {Promise<string | undefined>}
228
228
  */
229
229
  abstract getLastSyncedAt: OfflineDBApi['getLastSyncedAt'];
230
230
  /**
231
- * @abstract
232
231
  * Fetches all pending tasks from the DB. It will return them in an
233
232
  * ordered fashion by the time they were created.
233
+ *
234
234
  * @param {DBGetPendingTasksType} [conditions]
235
235
  * @returns {Promise<PendingTask[]>}
236
236
  */
237
237
  abstract getPendingTasks: OfflineDBApi['getPendingTasks'];
238
238
  /**
239
- * @abstract
240
239
  * Fetches the app settings stored in the DB. Is mainly meant to be used
241
240
  * only while offline and opening the application, as we only update the
242
241
  * app settings whenever they are fetched again so it has the potential to
243
242
  * be stale.
243
+ *
244
244
  * @param {DBGetAppSettingsType} options
245
- * @returns {Promise<AppSettingsAPIResponse | null>}
245
+ * @returns {Promise<GetApplicationResponse | null>}
246
246
  */
247
247
  abstract getAppSettings: OfflineDBApi['getAppSettings'];
248
248
  /**
249
- * @abstract
250
249
  * Fetches reactions from the DB for a given filter & sort hash and
251
250
  * for a given message ID.
251
+ *
252
252
  * @param {DBGetReactionsType} options
253
253
  * @returns {Promise<ReactionResponse[] | null>}
254
254
  */
255
255
  abstract getReactions: OfflineDBApi['getReactions'];
256
256
  /**
257
- * @abstract
258
257
  * Executes multiple queries in a batched fashion. It will also be done
259
258
  * within a transaction.
259
+ *
260
260
  * @param {ExecuteBatchDBQueriesType} queries
261
261
  * @returns {Promise<unknown>}
262
262
  */
263
263
  abstract executeSqlBatch: OfflineDBApi['executeSqlBatch'];
264
264
  /**
265
- * @abstract
266
265
  * Adds a pending task to the pending tasks table. Can only be one of the
267
266
  * supported types of pending tasks, otherwise its execution will throw.
268
267
  * Will return the prepared queries for delayed execution (even if they are
269
268
  * already executed).
269
+ *
270
270
  * @param {PendingTask} task
271
271
  * @returns {Promise<() => Promise<void>>}
272
272
  */
273
273
  abstract addPendingTask: OfflineDBApi['addPendingTask'];
274
274
  /**
275
- * @abstract
276
275
  * Updates a pending task in the DB, given its ID.
277
276
  * Will return the prepared queries for delayed execution (even if they are
278
277
  * already executed).
278
+ *
279
279
  * @param {DBUpdatePendingTaskType} options
280
280
  * @returns {Promise<ExecuteBatchDBQueriesType>}
281
281
  */
282
282
  abstract updatePendingTask: OfflineDBApi['updatePendingTask'];
283
283
  /**
284
- * @abstract
285
284
  * Deletes a pending task from the DB, given its ID.
286
285
  * Will return the prepared queries for delayed execution (even if they are
287
286
  * already executed).
287
+ *
288
288
  * @param {DBDeletePendingTaskType} options
289
289
  * @returns {Promise<ExecuteBatchDBQueriesType>}
290
290
  */
291
291
  abstract deletePendingTask: OfflineDBApi['deletePendingTask'];
292
292
  /**
293
- * @abstract
294
293
  * Deletes a reaction from the DB.
295
294
  * Will write to the reactions table removing the reaction.
296
295
  * Will return the prepared queries for delayed execution (even if they are
297
296
  * already executed).
297
+ *
298
298
  * @param {DBDeleteReactionType} options
299
299
  * @returns {Promise<ExecuteBatchDBQueriesType>}
300
300
  */
301
301
  abstract deleteReaction: OfflineDBApi['deleteReaction'];
302
302
  /**
303
- * @abstract
304
303
  * Deletes a member from the DB.
305
304
  * Will only write to the members table.
306
305
  * Will return the prepared queries for delayed execution (even if they are
307
306
  * already executed).
307
+ *
308
308
  * @param {DBDeleteMemberType} options
309
309
  * @returns {Promise<ExecuteBatchDBQueriesType>}
310
310
  */
311
311
  abstract deleteMember: OfflineDBApi['deleteMember'];
312
312
  /**
313
- * @abstract
314
313
  * Deletes a channel from the DB.
315
314
  * It will also delete all other entities associated with the channel in
316
315
  * a cascading fashion (messages, reactions, members etc.).
317
316
  * Will return the prepared queries for delayed execution (even if they are
318
317
  * already executed).
318
+ *
319
319
  * @param {DBDeleteChannelType} options
320
320
  * @returns {Promise<ExecuteBatchDBQueriesType>}
321
321
  */
322
322
  abstract deleteChannel: OfflineDBApi['deleteChannel'];
323
323
  /**
324
- * @abstract
325
324
  * Deletes multiple messages for a given channel. Works as `channel.truncated` would.
326
325
  * Should remove entities primarily from the messages table and then from all associated
327
326
  * tables in a cascading fashion (reactions, polls etc.).
328
327
  * Will return the prepared queries for delayed execution (even if they are
329
328
  * already executed).
329
+ *
330
330
  * @param {DBDeleteMessagesForChannelType} options
331
331
  * @returns {Promise<ExecuteBatchDBQueriesType>}
332
332
  */
333
333
  abstract deleteMessagesForChannel: OfflineDBApi['deleteMessagesForChannel'];
334
334
  /**
335
- * @abstract
336
335
  * Deletes all pending tasks from the DB.
337
336
  * Will only update the pending tasks table.
338
337
  * Will return the prepared queries for delayed execution (even if they are
339
338
  * already executed).
339
+ *
340
340
  * @param {DBDropPendingTasksType} options
341
341
  * @returns {Promise<ExecuteBatchDBQueriesType>}
342
342
  */
343
343
  abstract dropPendingTasks: OfflineDBApi['dropPendingTasks'];
344
344
  /**
345
- * @abstract
346
345
  * Deletes a message from the DB.
347
346
  * All other entities associated with the message will also be deleted
348
347
  * in a cascading fashion (reactions, polls etc.).
349
348
  * Will return the prepared queries for delayed execution (even if they are
350
349
  * already executed).
350
+ *
351
351
  * @param {DBDeleteMessageType} options
352
352
  * @returns {Promise<ExecuteBatchDBQueriesType>}
353
353
  */
354
354
  abstract hardDeleteMessage: OfflineDBApi['hardDeleteMessage'];
355
355
  /**
356
- * @abstract
357
356
  * Updates a message with a deleted_at value in the DB.
358
357
  * Will only update the messages table, as the message is simply marked
359
358
  * as deleted and not removed from the DB.
360
359
  * Will return the prepared queries for delayed execution (even if they are
361
360
  * already executed).
361
+ *
362
362
  * @param {DBDeleteMessageType} options
363
363
  * @returns {Promise<ExecuteBatchDBQueriesType>}
364
364
  */
365
365
  abstract softDeleteMessage: OfflineDBApi['softDeleteMessage'];
366
366
  /**
367
- * @abstract
368
367
  * Drops all tables and reinitializes the connection to the DB.
368
+ *
369
369
  * @returns {Promise<unknown>}
370
370
  */
371
371
  abstract resetDB: OfflineDBApi['resetDB'];
372
372
  /**
373
- * @abstract
374
373
  * A utility query that checks whether a specific channel exists in the DB.
375
374
  * Technically the same as actually fetching that channel through other queries,
376
375
  * but much faster.
376
+ *
377
377
  * @param {DBChannelExistsType} options
378
378
  * @returns {Promise<boolean>}
379
379
  */
380
380
  abstract channelExists: OfflineDBApi['channelExists'];
381
381
  /**
382
- * @abstract
383
382
  * Initializes the DB (typically creating a simple file handle as a connection pointer for
384
383
  * SQLite and likely similar for other DBs).
384
+ *
385
385
  * @returns {Promise<boolean>}
386
386
  */
387
387
  abstract initializeDB: OfflineDBApi['initializeDB'];
388
388
  /**
389
389
  * Initializes the DB as well as its syncManager for a given userId.
390
390
  * It will update the DBs reactive state with initialization values.
391
+ *
391
392
  * @param userId - the user ID for which we want to initialize
392
393
  */
393
394
  init: (userId: string) => Promise<void>;
394
395
  /**
395
396
  * Checks whether the DB should be initialized or if it has been initialized already.
396
- * @param {string} userId - the user ID for which we want to check initialization
397
+ *
398
+ * @param userId - the user ID for which we want to check initialization
397
399
  */
398
400
  shouldInitialize(userId: string): boolean;
399
401
  /**
@@ -401,6 +403,7 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
401
403
  * passed uses a reference to the DB itself and will handle errors gracefully
402
404
  * and silently. Only really meant to be used for write queries that need to
403
405
  * be run in synchronous functions.
406
+ *
404
407
  * @param queryCallback - a callback wrapping all query logic that is to be executed
405
408
  * @param method - a utility parameter used for proper logging (will make sure the method
406
409
  * is logged on failure)
@@ -421,13 +424,19 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
421
424
  * If both fail, it will not execute the query as it would result in a foreign key constraint
422
425
  * error.
423
426
  *
424
- * @param event - the WS event we are trying to process
425
- * @param execute - whether to immediately execute the operation.
426
- * @param forceUpdate - whether to upsert the channel data anyway
427
- * @param createQueries - a callback function to creation of the queries that we want to execute
427
+ * @param event - The WS event we are trying to process.
428
+ * @param event.execute - Whether to immediately execute the operation (optional, defaults to `true`).
429
+ * @param event.forceUpdate - Whether to upsert the channel data anyway (optional, defaults to `false`).
430
+ * @param createQueries - A callback that creates the queries to execute.
431
+ * @returns The list of prepared queries (executed when `execute` is `true`).
428
432
  */
429
433
  queriesWithChannelGuard: ({ event, execute, forceUpdate, }: {
430
- event: Event;
434
+ event: Extract<Event, {
435
+ channel?: any;
436
+ cid?: any;
437
+ channel_type?: any;
438
+ channel_id?: any;
439
+ }>;
431
440
  execute?: boolean;
432
441
  forceUpdate?: boolean;
433
442
  }, createQueries: (executeOverride?: boolean) => Promise<PrepareBatchDBQueries[]>) => Promise<PrepareBatchDBQueries[]>;
@@ -436,29 +445,32 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
436
445
  * and it is going to make sure that both messages and reads are upserted. It will not
437
446
  * try to fetch the reads from the DB first and it will rely on channel.state to handle
438
447
  * the number of unreads.
439
- * @param event - the WS event we are trying to process
440
- * @param execute - whether to immediately execute the operation.
448
+ *
449
+ * @param payload.event - the WS event we are trying to process
450
+ * @param payload.execute - Whether to immediately execute the operation (optional, defaults to `true`).
441
451
  */
442
452
  handleNewMessage: ({ event, execute, }: {
443
- event: Event;
453
+ event: EventPayload<"message.new">;
444
454
  execute?: boolean;
445
455
  }) => Promise<PrepareBatchDBQueries[]>;
446
456
  /**
447
457
  * A handler for message deletion. It provides a channel guard and determines whether
448
458
  * it should hard delete or soft delete the message.
449
- * @param event - the WS event we are trying to process
450
- * @param execute - whether to immediately execute the operation.
459
+ *
460
+ * @param payload.event - the WS event we are trying to process
461
+ * @param payload.execute - Whether to immediately execute the operation (optional, defaults to `true`).
451
462
  */
452
463
  handleDeleteMessage: ({ event, execute, }: {
453
- event: Event;
464
+ event: EventPayload<"message.deleted">;
454
465
  execute?: boolean;
455
466
  }) => Promise<PrepareBatchDBQueries[]>;
456
467
  /**
457
468
  * A utility method used for removing a message that has already failed from the
458
469
  * state as well as the DB. We want to drop all pending tasks and finally hard
459
470
  * delete the message from the DB.
460
- * @param messageId - the message id of the message we want to remove
461
- * @param execute - whether to immediately execute the operation.
471
+ *
472
+ * @param payload.messageId - The ID of the message we want to remove.
473
+ * @param payload.execute - Whether to immediately execute the operation (optional, defaults to `true`).
462
474
  */
463
475
  handleRemoveMessage: ({ messageId, execute, }: {
464
476
  messageId: string;
@@ -470,12 +482,13 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
470
482
  * The unreadMessages argument is useful for cases where we know the exact number of unreads
471
483
  * (for example reading an entire channel), but `unread_messages` might not necessarily exist
472
484
  * in the event (or it exists with a stale value if we know what we want to ultimately update to).
473
- * @param event - the WS event we are trying to process
474
- * @param unreadMessages - an override of unread_messages that will be preferred when upserting reads
475
- * @param execute - whether to immediately execute the operation.
485
+ *
486
+ * @param payload.event - The WS event we are trying to process.
487
+ * @param payload.unreadMessages - An override of `unread_messages` that will be preferred when upserting reads.
488
+ * @param payload.execute - Whether to immediately execute the operation (optional, defaults to `true`).
476
489
  */
477
490
  handleRead: ({ event, unreadMessages, execute, }: {
478
- event: Event;
491
+ event: EventPayload<"message.read" | "message.read_locally" | "notification.mark_read" | "notification.mark_unread">;
479
492
  unreadMessages?: number;
480
493
  execute?: boolean;
481
494
  }) => Promise<PrepareBatchDBQueries[]>;
@@ -483,21 +496,23 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
483
496
  * A utility method used to handle member events. It guards the processing
484
497
  * of each event with a channel guard and also forces an update of member_count
485
498
  * for the respective channel if applicable.
486
- * @param event - the WS event we are trying to process
487
- * @param execute - whether to immediately execute the operation.
499
+ *
500
+ * @param payload.event - the WS event we are trying to process
501
+ * @param payload.execute - Whether to immediately execute the operation (optional, defaults to `true`).
488
502
  */
489
503
  handleMemberEvent: ({ event, execute, }: {
490
- event: Event;
504
+ event: EventPayload<`member.${string}`>;
491
505
  execute?: boolean;
492
506
  }) => Promise<PrepareBatchDBQueries[]>;
493
507
  /**
494
508
  * A utility method used to handle message.updated events. It guards each
495
509
  * event handler within a channel guard.
496
- * @param event - the WS event we are trying to process
497
- * @param execute - whether to immediately execute the operation.
510
+ *
511
+ * @param payload.event - the WS event we are trying to process
512
+ * @param payload.execute - Whether to immediately execute the operation (optional, defaults to `true`).
498
513
  */
499
514
  handleMessageUpdatedEvent: ({ event, execute, }: {
500
- event: Event;
515
+ event: EventPayload<"message.updated" | "message.undeleted">;
501
516
  execute?: boolean;
502
517
  }) => Promise<PrepareBatchDBQueries[]>;
503
518
  /**
@@ -506,22 +521,24 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
506
521
  * simple upsertion is not enough.
507
522
  * It will update the hidden property of a channel to true if handling the `channel.hidden`
508
523
  * event and to false if handling `channel.visible`.
509
- * @param event - the WS event we are trying to process
510
- * @param execute - whether to immediately execute the operation.
524
+ *
525
+ * @param payload. - the WS event we are trying to process
526
+ * @param payload.execute - Whether to immediately execute the operation (optional, defaults to `true`).
511
527
  */
512
528
  handleChannelVisibilityEvent: ({ event, execute, }: {
513
- event: Event;
529
+ event: EventPayload<"channel.visible" | "channel.hidden">;
514
530
  execute?: boolean;
515
531
  }) => Promise<import("./types").ExecuteBatchDBQueriesType>;
516
532
  /**
517
533
  * A utility handler used to handle channel.truncated events. It handles both
518
534
  * removing all messages and relying on truncated_at as well. It will also upsert
519
535
  * reads adequately (and calculate the correct unread messages when truncating).
520
- * @param event - the WS event we are trying to process
521
- * @param execute - whether to immediately execute the operation.
536
+ *
537
+ * @param payload.event - the WS event we are trying to process
538
+ * @param payload.execute - Whether to immediately execute the operation (optional, defaults to `true`).
522
539
  */
523
540
  handleChannelTruncatedEvent: ({ event, execute, }: {
524
- event: Event;
541
+ event: EventPayload<"channel.truncated">;
525
542
  execute?: boolean;
526
543
  }) => Promise<PrepareBatchDBQueries[]>;
527
544
  /**
@@ -530,30 +547,33 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
530
547
  * - reaction.new -> insertReaction
531
548
  * - reaction.updated -> updateReaction
532
549
  * - reaction.deleted -> deleteReaction
533
- * @param event - the WS event we are trying to process
534
- * @param execute - whether to immediately execute the operation.
550
+ *
551
+ * @param payload.event - the WS event we are trying to process
552
+ * @param payload.execute - Whether to immediately execute the operation (optional, defaults to `true`).
535
553
  */
536
554
  handleReactionEvent: ({ event, execute, }: {
537
- event: Event;
555
+ event: EventPayload<`reaction.${string}`>;
538
556
  execute?: boolean;
539
557
  }) => Promise<PrepareBatchDBQueries[]>;
540
558
  /**
541
559
  * A utility handler for all draft events:
542
560
  * - draft.updated -> updateDraft
543
561
  * - draft.deleted -> deleteDraft
544
- * @param event - the WS event we are trying to process
545
- * @param execute - whether to immediately execute the operation.
562
+ *
563
+ * @param payload.event - the WS event we are trying to process
564
+ * @param payload.execute - Whether to immediately execute the operation (optional, defaults to `true`).
546
565
  */
547
566
  handleDraftEvent: ({ event, execute, }: {
548
- event: Event;
567
+ event: EventPayload<`draft.${string}`>;
549
568
  execute?: boolean;
550
569
  }) => Promise<import("./types").ExecuteBatchDBQueriesType>;
551
570
  /**
552
571
  * A generic event handler that decides which DB API to invoke based on
553
572
  * event.type for all events we are currently handling. It is used to both
554
573
  * react on WS events as well as process the sync API events.
555
- * @param event - the WS event we are trying to process
556
- * @param execute - whether to immediately execute the operation.
574
+ *
575
+ * @param payload.event - the WS event we are trying to process
576
+ * @param payload.execute - Whether to immediately execute the operation (optional, defaults to `true`).
557
577
  */
558
578
  handleEvent: ({ event, execute, }: {
559
579
  event: Event;
@@ -568,17 +588,20 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
568
588
  * 3. If it is, it will insert the task in the pending tasks table
569
589
  *
570
590
  * It will return the response from the execution if it succeeded.
591
+ *
571
592
  * @param task - the pending task we want to execute
572
593
  */
573
594
  queueTask: <T>({ task }: {
574
595
  task: PendingTask;
575
596
  }) => Promise<T>;
576
597
  /**
577
- * A utility method that determines if a failed task should be added to the
578
- * queue based on its error.
579
- * Error code 4 - bad request data
580
- * Error code 17 - missing own_capabilities to execute the task
581
- * @param error
598
+ * A utility method that determines if a failed task should be skipped (NOT added to the queue) -
599
+ * i.e. the failure is a definitive rejection rather than an ephemeral/retryable one. A task is
600
+ * kept in the queue only when its error is {@link isEphemeral} (connection/network error or a
601
+ * retryable server code). A non retryable server response (i.e bad request, not allowed etc) is
602
+ * skipped since retrying it would never succeed.
603
+ *
604
+ * @param error - The error thrown while executing the failed task.
582
605
  */
583
606
  private shouldSkipQueueingTask;
584
607
  private mergeFailedMessageUpdateIntoPendingSendMessage;
@@ -602,6 +625,7 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
602
625
  * - Creating a draft
603
626
  * - Deleting a draft
604
627
  * It will throw if we try to execute a pending task that is not supported.
628
+ *
605
629
  * @param task - The task we want to execute
606
630
  * @param isPendingTask - a control value telling us if it's an actual pending task being executed
607
631
  * or delayed execution
@@ -58,13 +58,6 @@ export declare class OfflineDBSyncManager {
58
58
  private sync;
59
59
  /**
60
60
  * Executes any tasks that were queued while offline and then performs a sync.
61
- *
62
- * Each step is isolated so a failure in one does not prevent the other, and
63
- * neither can escape to the callers (init + the connection.changed handler).
64
- * This guarantees the subsequent invokeSyncStatusListeners(true) always runs,
65
- * so syncStatus recovers to true and gated channel queries are unblocked.
66
- * Failed syncs degrade to "possibly stale data until the next query" rather
67
- * than freezing all future queries. See issue #1816.
68
61
  */
69
62
  private syncAndExecutePendingTasks;
70
63
  }