stream-chat 10.0.0-rc.21 → 10.0.0-rc.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/dist/cjs/index.browser.js +2196 -3902
  2. package/dist/cjs/index.browser.js.map +3 -3
  3. package/dist/cjs/index.node.js +2197 -3902
  4. package/dist/cjs/index.node.js.map +3 -3
  5. package/dist/esm/index.mjs +2199 -3905
  6. package/dist/esm/index.mjs.map +4 -4
  7. package/dist/types/ChannelManager.d.ts +120 -233
  8. package/dist/types/CooldownTimer.d.ts +8 -23
  9. package/dist/types/EventHandlerPipeline.d.ts +17 -37
  10. package/dist/types/LiveLocationManager.d.ts +22 -50
  11. package/dist/types/api-client.d.ts +9 -14
  12. package/dist/types/channel.d.ts +253 -448
  13. package/dist/types/channel_state.d.ts +48 -95
  14. package/dist/types/client.d.ts +245 -370
  15. package/dist/types/client_state.d.ts +1 -3
  16. package/dist/types/configuration/ConfigController.d.ts +30 -124
  17. package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +31 -123
  18. package/dist/types/configuration/keys.d.ts +5 -19
  19. package/dist/types/configuration/shape.d.ts +12 -29
  20. package/dist/types/configuration/types.d.ts +59 -87
  21. package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +13 -35
  22. package/dist/types/configuration/utils/copyConfigPatch.d.ts +8 -0
  23. package/dist/types/configuration/utils/declarativeSlices.d.ts +5 -16
  24. package/dist/types/configuration/utils/deepFreezeConfig.d.ts +3 -17
  25. package/dist/types/configuration/utils/serverAuthority.d.ts +9 -29
  26. package/dist/types/connection/ConnectionIdManager.d.ts +18 -40
  27. package/dist/types/connection/ConnectionRecoveryManager.d.ts +29 -120
  28. package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +32 -103
  29. package/dist/types/connection/networkConnection/reporters.d.ts +9 -32
  30. package/dist/types/connection/networkConnection/types.d.ts +12 -27
  31. package/dist/types/connection/wsConnection/StableWSConnection.d.ts +37 -116
  32. package/dist/types/connection/wsConnection/WSConnection.d.ts +41 -104
  33. package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +8 -16
  34. package/dist/types/connection/wsConnection/config.d.ts +8 -28
  35. package/dist/types/connection/wsConnection/types.d.ts +17 -70
  36. package/dist/types/entityStore/EntityStore.d.ts +153 -113
  37. package/dist/types/entityStore/StoreBackedItemIndex.d.ts +13 -46
  38. package/dist/types/errors.d.ts +7 -19
  39. package/dist/types/gen/chat/ChannelApi.d.ts +2 -1
  40. package/dist/types/gen/chat/ChatApi.d.ts +28 -14
  41. package/dist/types/gen/models/index.d.ts +769 -86
  42. package/dist/types/gen/moderation/ModerationApi.d.ts +4 -4
  43. package/dist/types/index.d.ts +2 -4
  44. package/dist/types/languageNames.d.ts +9 -24
  45. package/dist/types/logger.d.ts +1 -3
  46. package/dist/types/messageComposer/LocationComposer.d.ts +1 -1
  47. package/dist/types/messageComposer/attachmentIdentity.d.ts +1 -6
  48. package/dist/types/messageComposer/attachmentManager.d.ts +10 -32
  49. package/dist/types/messageComposer/attachmentUtils.d.ts +3 -14
  50. package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
  51. package/dist/types/messageComposer/configuration/types.d.ts +29 -56
  52. package/dist/types/messageComposer/linkPreviewsManager.d.ts +6 -9
  53. package/dist/types/messageComposer/messageComposer.d.ts +30 -164
  54. package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +4 -14
  55. package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +2 -9
  56. package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +2 -4
  57. package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +7 -19
  58. package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +9 -0
  59. package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +11 -18
  60. package/dist/types/messageComposer/middleware/textComposer/textMiddlewareUtils.d.ts +9 -3
  61. package/dist/types/messageComposer/middleware/textComposer/types.d.ts +1 -6
  62. package/dist/types/messageComposer/pollComposer.d.ts +8 -4
  63. package/dist/types/messageComposer/textComposer.d.ts +3 -9
  64. package/dist/types/messageComposer/types.d.ts +5 -8
  65. package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +25 -79
  66. package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +15 -82
  67. package/dist/types/messageOperations/FailedSendCache.d.ts +4 -9
  68. package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +10 -20
  69. package/dist/types/messageOperations/MessageOperations.d.ts +20 -40
  70. package/dist/types/messageOperations/applyReactionLocally.d.ts +5 -22
  71. package/dist/types/messageOperations/createMessageOperations.d.ts +3 -5
  72. package/dist/types/messageOperations/reflectReactionEvent.d.ts +5 -13
  73. package/dist/types/messageOperations/sendOrdering.d.ts +4 -7
  74. package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +7 -15
  75. package/dist/types/messageOperations/types.d.ts +15 -30
  76. package/dist/types/middleware.d.ts +7 -5
  77. package/dist/types/moderation.d.ts +21 -14
  78. package/dist/types/notifications/NotificationManager.d.ts +8 -31
  79. package/dist/types/notifications/types.d.ts +19 -59
  80. package/dist/types/offline-support/offline_support_api.d.ts +145 -539
  81. package/dist/types/offline-support/offline_sync_manager.d.ts +18 -42
  82. package/dist/types/offline-support/queueableOperations.d.ts +24 -52
  83. package/dist/types/offline-support/types.d.ts +24 -187
  84. package/dist/types/pagination/ItemIndex.d.ts +4 -12
  85. package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +13 -0
  86. package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -4
  87. package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +2 -3
  88. package/dist/types/pagination/paginators/BasePaginator.d.ts +235 -622
  89. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +67 -125
  90. package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +133 -292
  91. package/dist/types/pagination/paginators/MessagePaginator.d.ts +69 -118
  92. package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +7 -26
  93. package/dist/types/pagination/paginators/ReminderPaginator.d.ts +2 -2
  94. package/dist/types/pagination/paginators/ThreadPaginator.d.ts +15 -23
  95. package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +2 -6
  96. package/dist/types/pagination/sortCompiler.d.ts +11 -22
  97. package/dist/types/pagination/utility.normalization.d.ts +5 -23
  98. package/dist/types/pagination/utility.search.d.ts +3 -8
  99. package/dist/types/poll.d.ts +14 -14
  100. package/dist/types/poll_manager.d.ts +11 -2
  101. package/dist/types/poll_optimistic_votes.d.ts +10 -14
  102. package/dist/types/reminders/Reminder.d.ts +4 -4
  103. package/dist/types/reminders/ReminderManager.d.ts +7 -20
  104. package/dist/types/search/BaseSearchSource.d.ts +7 -12
  105. package/dist/types/search/ChannelSearchSource.d.ts +7 -7
  106. package/dist/types/search/MessageSearchSource.d.ts +7 -9
  107. package/dist/types/search/SearchController.d.ts +17 -22
  108. package/dist/types/search/types.d.ts +6 -10
  109. package/dist/types/signing.d.ts +12 -3
  110. package/dist/types/thread.d.ts +23 -71
  111. package/dist/types/thread_manager.d.ts +45 -70
  112. package/dist/types/token_manager.d.ts +8 -13
  113. package/dist/types/types.d.ts +64 -125
  114. package/dist/types/types.utility.d.ts +3 -3
  115. package/dist/types/upload-utils.d.ts +5 -10
  116. package/dist/types/uploadManager.d.ts +17 -45
  117. package/dist/types/utils/FixedSizeQueueCache.d.ts +6 -11
  118. package/dist/types/utils/WithSubscriptions.d.ts +5 -15
  119. package/dist/types/utils/concurrency.d.ts +11 -19
  120. package/dist/types/utils/mergeWith/mergeWith.d.ts +8 -11
  121. package/dist/types/utils/mergeWith/mergeWithCore.d.ts +5 -13
  122. package/dist/types/utils/mergeWith/mergeWithDiff.d.ts +22 -0
  123. package/dist/types/utils/objectPath.d.ts +6 -41
  124. package/dist/types/utils/retryable.d.ts +8 -12
  125. package/dist/types/utils/throttling/throttle.d.ts +8 -23
  126. package/dist/types/utils/time.d.ts +24 -64
  127. package/dist/types/utils.d.ts +40 -86
  128. package/package.json +7 -2
  129. package/src/ChannelManager.ts +159 -300
  130. package/src/CooldownTimer.ts +11 -29
  131. package/src/EventHandlerPipeline.ts +21 -44
  132. package/src/LiveLocationManager.ts +35 -74
  133. package/src/api-client.ts +43 -61
  134. package/src/campaign.ts +1 -1
  135. package/src/channel.ts +396 -749
  136. package/src/channel_batch_updater.ts +1 -1
  137. package/src/channel_state.ts +50 -105
  138. package/src/client.ts +360 -588
  139. package/src/client_state.ts +1 -6
  140. package/src/configuration/ConfigController.ts +41 -157
  141. package/src/configuration/InstanceConfigurationRegistry.ts +42 -171
  142. package/src/configuration/index.ts +1 -1
  143. package/src/configuration/keys.ts +13 -32
  144. package/src/configuration/shape.ts +67 -70
  145. package/src/configuration/types.ts +60 -100
  146. package/src/configuration/utils/applyInstanceConfiguration.ts +21 -53
  147. package/src/configuration/utils/copyConfigPatch.ts +11 -32
  148. package/src/configuration/utils/declarativeSlices.ts +9 -39
  149. package/src/configuration/utils/deepFreezeConfig.ts +3 -17
  150. package/src/configuration/utils/index.ts +2 -4
  151. package/src/configuration/utils/serverAuthority.ts +20 -68
  152. package/src/connection/ConnectionIdManager.ts +20 -49
  153. package/src/connection/ConnectionRecoveryManager.ts +51 -178
  154. package/src/connection/networkConnection/NetworkConnectionObserver.ts +37 -114
  155. package/src/connection/networkConnection/reporters.ts +9 -36
  156. package/src/connection/networkConnection/types.ts +12 -27
  157. package/src/connection/wsConnection/StableWSConnection.ts +73 -193
  158. package/src/connection/wsConnection/WSConnection.ts +56 -131
  159. package/src/connection/wsConnection/WSConnectionFallback.ts +22 -31
  160. package/src/connection/wsConnection/config.ts +13 -48
  161. package/src/connection/wsConnection/types.ts +17 -70
  162. package/src/constants.ts +4 -4
  163. package/src/entityStore/EntityStore.ts +162 -167
  164. package/src/entityStore/StoreBackedItemIndex.ts +14 -47
  165. package/src/errors.ts +7 -19
  166. package/src/formatMessageMemo.ts +3 -9
  167. package/src/gen/chat/ChannelApi.ts +19 -0
  168. package/src/gen/chat/ChatApi.ts +87 -13
  169. package/src/gen/models/index.ts +793 -71
  170. package/src/gen/moderation/ModerationApi.ts +0 -4
  171. package/src/index.ts +10 -14
  172. package/src/languageNames.ts +9 -24
  173. package/src/logger.ts +1 -3
  174. package/src/messageComposer/LocationComposer.ts +7 -23
  175. package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
  176. package/src/messageComposer/attachmentIdentity.ts +2 -13
  177. package/src/messageComposer/attachmentManager.ts +17 -63
  178. package/src/messageComposer/attachmentUtils.ts +3 -17
  179. package/src/messageComposer/configuration/configuration.ts +5 -8
  180. package/src/messageComposer/configuration/types.ts +29 -56
  181. package/src/messageComposer/fileUtils.ts +1 -1
  182. package/src/messageComposer/linkPreviewsManager.ts +8 -20
  183. package/src/messageComposer/messageComposer.ts +54 -222
  184. package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +4 -16
  185. package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +1 -2
  186. package/src/messageComposer/middleware/messageComposer/attachments.ts +14 -40
  187. package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +3 -4
  188. package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
  189. package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +4 -11
  190. package/src/messageComposer/middleware/pollComposer/state.ts +2 -2
  191. package/src/messageComposer/middleware/pollComposer/types.ts +2 -4
  192. package/src/messageComposer/middleware/pollComposer/validation.ts +8 -26
  193. package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +1 -6
  194. package/src/messageComposer/middleware/textComposer/commandUtils.ts +1 -2
  195. package/src/messageComposer/middleware/textComposer/commands.ts +11 -16
  196. package/src/messageComposer/middleware/textComposer/mentions.ts +32 -70
  197. package/src/messageComposer/middleware/textComposer/textMiddlewareUtils.ts +10 -4
  198. package/src/messageComposer/middleware/textComposer/types.ts +1 -6
  199. package/src/messageComposer/pollComposer.ts +11 -8
  200. package/src/messageComposer/textComposer.ts +9 -59
  201. package/src/messageComposer/types.ts +9 -12
  202. package/src/messageDelivery/MessageDeliveryReporter.ts +60 -113
  203. package/src/messageDelivery/MessageReceiptsTracker.ts +21 -105
  204. package/src/messageOperations/FailedSendCache.ts +4 -9
  205. package/src/messageOperations/MessageOperationStatePolicy.ts +40 -67
  206. package/src/messageOperations/MessageOperations.ts +33 -62
  207. package/src/messageOperations/applyReactionLocally.ts +9 -28
  208. package/src/messageOperations/createMessageOperations.ts +17 -33
  209. package/src/messageOperations/reflectReactionEvent.ts +5 -13
  210. package/src/messageOperations/sendOrdering.ts +4 -7
  211. package/src/messageOperations/settlePendingAttachmentUploads.ts +10 -21
  212. package/src/messageOperations/types.ts +15 -30
  213. package/src/middleware.ts +7 -10
  214. package/src/moderation.ts +25 -21
  215. package/src/notifications/NotificationManager.ts +11 -35
  216. package/src/notifications/types.ts +19 -59
  217. package/src/offline-support/offline_support_api.ts +178 -608
  218. package/src/offline-support/offline_sync_manager.ts +25 -69
  219. package/src/offline-support/queueableOperations.ts +31 -84
  220. package/src/offline-support/types.ts +25 -188
  221. package/src/pagination/ItemIndex.ts +4 -12
  222. package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
  223. package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +13 -62
  224. package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
  225. package/src/pagination/cursorDerivation/linearPaginationFlags.ts +4 -6
  226. package/src/pagination/filterCompiler.ts +11 -25
  227. package/src/pagination/paginators/BasePaginator.ts +422 -976
  228. package/src/pagination/paginators/ChannelPaginator.ts +130 -190
  229. package/src/pagination/paginators/MessageIntervalPaginator.ts +226 -457
  230. package/src/pagination/paginators/MessagePaginator.ts +135 -175
  231. package/src/pagination/paginators/PinnedMessagePaginator.ts +13 -38
  232. package/src/pagination/paginators/ReminderPaginator.ts +12 -15
  233. package/src/pagination/paginators/ThreadPaginator.ts +16 -26
  234. package/src/pagination/paginators/UserGroupPaginator.ts +6 -17
  235. package/src/pagination/paginators/stateThrottling.ts +5 -10
  236. package/src/pagination/sortCompiler.ts +23 -50
  237. package/src/pagination/utility.normalization.ts +8 -30
  238. package/src/pagination/utility.search.ts +4 -11
  239. package/src/poll.ts +19 -19
  240. package/src/poll_manager.ts +16 -20
  241. package/src/poll_optimistic_votes.ts +17 -22
  242. package/src/reminders/Reminder.ts +5 -6
  243. package/src/reminders/ReminderManager.ts +9 -34
  244. package/src/reminders/ReminderTimer.ts +1 -2
  245. package/src/search/BaseSearchSource.ts +14 -29
  246. package/src/search/ChannelSearchSource.ts +8 -8
  247. package/src/search/MessageSearchSource.ts +19 -25
  248. package/src/search/SearchController.ts +18 -24
  249. package/src/search/types.ts +6 -10
  250. package/src/segment.ts +1 -1
  251. package/src/signing.ts +23 -3
  252. package/src/thread.ts +72 -173
  253. package/src/thread_manager.ts +59 -76
  254. package/src/token_manager.ts +11 -21
  255. package/src/types.ts +78 -126
  256. package/src/types.utility.ts +3 -3
  257. package/src/upload-utils.ts +5 -10
  258. package/src/uploadManager.ts +22 -54
  259. package/src/utils/FixedSizeQueueCache.ts +13 -21
  260. package/src/utils/WithSubscriptions.ts +5 -15
  261. package/src/utils/concurrency.ts +16 -55
  262. package/src/utils/mergeWith/mergeWith.ts +10 -13
  263. package/src/utils/mergeWith/mergeWithCore.ts +24 -81
  264. package/src/utils/mergeWith/mergeWithDiff.ts +15 -33
  265. package/src/utils/objectPath.ts +6 -41
  266. package/src/utils/retryable.ts +10 -14
  267. package/src/utils/throttling/throttle.ts +9 -25
  268. package/src/utils/time.ts +26 -66
  269. package/src/utils.ts +72 -128
@@ -24,347 +24,198 @@ export type PrepareBatchDBQueries =
24
24
  | [string]
25
25
  | [string, Array<unknown> | Array<Array<unknown>>];
26
26
 
27
- /**
28
- * Options to insert a reaction into a message.
29
- */
30
27
  export type DBInsertReactionType = {
31
- /** MessageRequest to which the reaction is applied. */
32
28
  message: MessageResponse | LocalMessage;
33
- /** The reaction to insert. */
34
29
  reaction: ReactionResponse;
35
- /** Whether to immediately execute the operation. */
36
30
  execute?: boolean;
37
31
  };
38
32
 
39
- /**
40
- * Options to upsert channel IDs associated with a query.
41
- */
42
33
  export type DBUpsertCidsForQueryType = {
43
- /** Array of channel IDs. */
44
34
  cids: string[];
45
- /** Optional filters for the channels. */
46
35
  filters?: ChannelFilters;
47
- /** Optional full query options for the channels. */
48
36
  options?: ChannelOptions;
49
- /** Whether to immediately execute the operation. */
50
37
  execute?: boolean;
51
38
  /**
52
- * The predefined-filter metadata the backend resolved for this query, stored alongside the cid
53
- * order so a cache-seeded list can match and sort by the same rule that produced it. Absent for a
54
- * plain `filter_conditions` query, in which case any previously stored metadata is cleared.
39
+ * The predefined-filter metadata the backend resolved for this query, stored with the cid order
40
+ * so a cache-seeded list sorts and matches by the same rule. Absent for a plain
41
+ * `filter_conditions` query, which clears any stored metadata.
55
42
  */
56
43
  predefinedFilter?: ParsedPredefinedFilterResponse;
57
- /** Optional sorting applied to the channels. */
58
44
  sort?: SortParamRequest[];
59
45
  };
60
46
 
61
- /**
62
- * Options to upsert multiple channels.
63
- */
64
47
  export type DBUpsertChannelsType = {
65
- /** Array of channel API responses. */
66
48
  channels: ChannelStateResponseFields[];
67
- /** Whether to immediately execute the operation. */
68
49
  execute?: boolean;
69
50
  /** If true, marks that the latest messages are already set. */
70
51
  isLatestMessagesSet?: boolean;
71
52
  };
72
53
 
73
- /**
74
- * Options to upsert application settings for a user.
75
- */
76
54
  export type DBUpsertAppSettingsType = {
77
- /** App settings data. */
78
55
  appSettings: GetApplicationResponse;
79
- /** ID of the user the settings belong to. */
80
56
  userId: string;
81
- /** Whether to immediately execute the operation. */
82
57
  execute?: boolean;
83
58
  };
84
59
 
85
- /**
86
- * Sync status information for a user.
87
- */
88
60
  export type DBUpsertUserSyncStatusType = {
89
- /** ID of the user. */
90
61
  userId: string;
91
- /** ISO timestamp of the last sync. */
62
+ /** A date string `new Date()` can parse. */
92
63
  lastSyncedAt: string;
93
- /** Whether to immediately execute the operation. */
94
64
  execute?: boolean;
95
65
  };
96
66
 
97
- /**
98
- * Options to upsert a poll.
99
- */
100
67
  export type DBUpsertPollType = {
101
- /** Poll data to be stored. */
102
68
  poll: PollResponseData;
103
- /** Whether to immediately execute the operation. */
104
69
  execute?: boolean;
105
70
  };
106
71
 
107
- /**
108
- * Options to upsert individual channel data.
109
- */
110
72
  export type DBUpsertChannelDataType = {
111
- /** Channel data. */
112
73
  channel: ChannelResponse;
113
- /** Whether to immediately execute the operation. */
114
74
  execute?: boolean;
115
75
  };
116
76
 
117
- /**
118
- * Options to upsert read statuses for a channel.
119
- */
120
77
  export type DBUpsertReadsType = {
121
- /** Channel ID. */
122
78
  cid: string;
123
- /** Array of read statuses. */
124
79
  reads: ReadStateResponse[];
125
- /** Whether to immediately execute the operation. */
126
80
  execute?: boolean;
127
81
  };
128
82
 
129
- /**
130
- * Options to upsert multiple messages.
131
- */
132
83
  export type DBUpsertMessagesType = {
133
- /** Array of message responses. */
134
84
  messages: MessageResponse[];
135
- /** Whether to immediately execute the operation. */
136
85
  execute?: boolean;
137
86
  };
138
87
 
139
- /**
140
- * Options to upsert members in a channel.
141
- */
142
88
  export type DBUpsertMembersType = {
143
- /** Channel ID. */
144
89
  cid: string;
145
- /** Array of channel members. */
146
90
  members: ChannelMemberResponse[];
147
- /** Whether to immediately execute the operation. */
148
91
  execute?: boolean;
149
92
  };
150
93
 
151
- /**
152
- * Options to update a reaction.
153
- */
154
94
  export type DBUpdateReactionType = {
155
- /** MessageRequest associated with the reaction. */
156
95
  message: MessageResponse | LocalMessage;
157
- /** The updated reaction. */
158
96
  reaction: ReactionResponse;
159
- /** Whether to immediately execute the operation. */
160
97
  execute?: boolean;
161
98
  };
162
99
 
163
- /**
164
- * Options to update a message.
165
- */
166
100
  export type DBUpdateMessageType = {
167
- /** MessageRequest to update. */
168
101
  message: MessageResponse | LocalMessage;
169
- /** Whether to immediately execute the operation. */
170
102
  execute?: boolean;
171
103
  };
172
104
 
173
- /**
174
- * Options to get channels by their IDs.
175
- */
176
105
  export type DBGetChannelsType = {
177
- /** Array of channel IDs. */
178
106
  cids: string[];
179
- /** ID of the user. */
180
107
  userId: string;
181
108
  };
182
109
 
183
- /**
184
- * Options to get channels based on filters.
185
- */
186
110
  export type DBGetChannelsForQueryType = {
187
- /** ID of the user. */
188
111
  userId: string;
189
- /** Optional filters for channels. */
190
112
  options?: QueryChannelsRequest;
191
113
  };
192
114
 
193
115
  /**
194
- * A cached channel query: the channels in the order the query produced them, plus the rule that
195
- * produced that order. Returned as one value because the two are written as one cache row - reading
196
- * the order without the rule is what lets a cache-seeded list sort and match by the wrong one.
116
+ * A cached channel query: its channels in query order, and the predefined-filter metadata that
117
+ * produced that order. They are written as one cache row, so they are read together.
197
118
  */
198
119
  export type DBGetChannelsForQueryResult = {
199
- /** Channels in cached query order. */
200
120
  channels: Omit<ChannelStateResponseFields, 'duration'>[];
201
- /** The predefined-filter metadata this query was cached with, if it was a predefined-filter query. */
121
+ /** Set when the query was cached from a predefined-filter query. */
202
122
  predefinedFilter?: ParsedPredefinedFilterResponse;
203
123
  };
204
124
 
205
- /**
206
- * Payload for retrieving the last sync timestamp for a user.
207
- */
208
125
  export type DBGetLastSyncedAtType = {
209
- /** ID of the user. */
210
126
  userId: string;
211
127
  };
212
128
 
213
- /**
214
- * Options to fetch pending tasks for a specific message.
215
- */
216
129
  export type DBGetPendingTasksType = {
217
- /** Optional message ID to filter tasks. */
130
+ /** Returns only this message's tasks. */
218
131
  messageId?: string;
219
132
  };
220
133
 
221
- /**
222
- * Payload for retrieving application settings for a user.
223
- */
224
134
  export type DBGetAppSettingsType = {
225
- /** ID of the user. */
226
135
  userId: string;
227
136
  };
228
137
 
229
- /**
230
- * Options to retrieve reactions for a message.
231
- */
232
138
  export type DBGetReactionsType = {
233
- /** ID of the message. */
234
139
  messageId: string;
235
- /** Optional filter to apply to reactions. */
236
140
  filters?: ReactionFilters;
237
- /** Optional sorting for reactions. */
238
141
  sort?: SortParamRequest[];
239
- /** Optional maximum number of reactions to return. */
240
142
  limit?: number;
241
143
  };
242
144
 
243
- /**
244
- * Payload for deleting a pending task by ID.
245
- */
246
145
  export type DBDeletePendingTaskType = {
247
- /** ID of the pending task. */
248
146
  id: number;
249
147
  };
250
148
 
251
- /**
252
- * Payload for updating a pending task by ID.
253
- */
254
149
  export type DBUpdatePendingTaskType = {
255
- /** ID of the pending task. */
256
150
  id: number;
257
- /** The next task payload to persist. */
258
151
  task: PendingTask;
259
152
  };
260
153
 
261
- /**
262
- * Options to delete a reaction from a message.
263
- */
264
154
  export type DBDeleteReactionType = {
265
- /** The reaction to delete. */
266
155
  reaction: ReactionResponse;
267
- /** Optional message associated with the reaction. */
268
156
  message?: MessageResponse | LocalMessage;
269
- /** Whether to immediately execute the operation. */
270
157
  execute?: boolean;
271
158
  };
272
159
 
273
- /**
274
- * Options to delete a channel member.
275
- */
276
160
  export type DBDeleteMemberType = {
277
- /** Channel ID. */
278
161
  cid: string;
279
- /** Member to remove. */
280
162
  member: ChannelMemberResponse;
281
- /** Whether to immediately execute the operation. */
282
163
  execute?: boolean;
283
164
  };
284
165
 
285
- /**
286
- * Options to drop all pending tasks for a message.
287
- */
288
166
  export type DBDropPendingTasksType = {
289
- /** ID of the message. */
290
167
  messageId: string;
291
- /** Whether to immediately execute the operation. */
292
168
  execute?: boolean;
293
169
  };
294
170
 
295
- /**
296
- * Options to delete a message.
297
- */
298
171
  export type DBDeleteMessageType = {
299
- /** ID of the message. */
300
172
  id: string;
301
- /** Whether to delete the message for the user only. */
173
+ /** Delete for the current user only. */
302
174
  deleteForMe?: boolean;
303
- /** Whether to immediately execute the operation. */
304
175
  execute?: boolean;
305
176
  };
306
177
 
307
- /**
308
- * Options to delete a channel.
309
- */
310
178
  export type DBDeleteChannelType = {
311
- /** Channel ID. */
312
179
  cid: string;
313
- /** Whether to immediately execute the operation. */
314
180
  execute?: boolean;
315
181
  };
316
182
 
317
- /**
318
- * Options to delete messages in a channel.
319
- */
320
183
  export type DBDeleteMessagesForChannelType = {
321
- /** Channel ID. */
322
184
  cid: string;
323
- /** Timestamp before which messages are deleted. */
324
- /** Unix nanoseconds, as the API sends it. */
185
+ /** Messages before this timestamp are deleted (unix nanoseconds, as the API sends it). */
325
186
  truncated_at?: TimestampNS;
326
- /** Whether to immediately execute the operation. */
327
187
  execute?: boolean;
328
188
  };
329
189
 
330
- /**
331
- * Payload for checking whether a channel exists by ID.
332
- */
333
190
  export type DBChannelExistsType = {
334
- /** Channel ID. */
335
191
  cid: string;
336
192
  };
337
193
 
338
194
  export type DBUpsertDraftType = {
339
- /** Draft message to upsert. */
340
195
  draft: DraftResponse;
341
- /** Whether to immediately execute the operation. */
342
196
  execute?: boolean;
343
197
  };
344
198
 
345
199
  export type DBGetDraftType = {
346
- /** Channel ID for which to get the draft. */
347
200
  cid: string;
348
- /** ID of the user requesting the draft. */
349
201
  userId: string;
350
- /** Optional parent ID for the parent message in thread, if applicable. */
202
+ /** The thread's parent message ID, for a thread draft. */
351
203
  parent_id?: string;
352
204
  };
353
205
 
354
206
  export type DBDeleteDraftType = {
355
- /** Channel ID for which to delete the draft. */
356
207
  cid: string;
357
- /** Optional parent ID for the parent message in thread, if applicable. */
208
+ /** The thread's parent message ID, for a thread draft. */
358
209
  parent_id?: string;
359
- /** Whether to immediately execute the operation. */
360
210
  execute?: boolean;
361
211
  };
362
212
 
363
- /**
364
- * Represents a list of batch SQL queries to be executed.
365
- */
366
213
  export type ExecuteBatchDBQueriesType = PrepareBatchDBQueries[];
367
214
 
215
+ /**
216
+ * The storage contract. A member taking `execute` returns its prepared queries whether or not it
217
+ * already ran them.
218
+ */
368
219
  export interface OfflineDBApi {
369
220
  insertReaction: (options: DBInsertReactionType) => Promise<ExecuteBatchDBQueriesType>;
370
221
  upsertCidsForQuery: (
@@ -442,15 +293,12 @@ export type PendingTaskTypes = {
442
293
  };
443
294
 
444
295
  /**
445
- * Every operation the offline queue can replay, declared as the method that performs it.
446
- *
447
- * This map is the single definition of what a queueable operation IS. `PendingTask`'s payload union is
448
- * derived from it, and `QUEUEABLE_OPERATIONS` has to supply a resolver for each key — so a new task
449
- * type is a compile error until both its signature and its resolver exist, rather than a runtime
450
- * "Tried to execute invalid pending task type" the first time somebody queues one.
296
+ * Every operation the offline queue can replay, as the method that performs it. `PendingTask` is
297
+ * derived from it and `QUEUEABLE_OPERATIONS` needs an entry per key, so a new task type does not
298
+ * compile until both exist.
451
299
  *
452
- * Each resolves to a method that only sends the request — a queueing one would make a replay queue
453
- * itself again instead of hitting the server. Hence the drafts' `_`-prefixed forms.
300
+ * Each method only sends the request (a queueing one would re-queue on replay), hence the drafts'
301
+ * `_`-prefixed forms.
454
302
  *
455
303
  * @internal
456
304
  */
@@ -467,7 +315,7 @@ export type QueueableOperationSignatures = {
467
315
  export type QueueableType = keyof QueueableOperationSignatures;
468
316
 
469
317
  /**
470
- * The argument list of a queueable operation — what a task carries as its `payload`.
318
+ * The argument list of a queueable operation, which a task carries as its `payload`.
471
319
  *
472
320
  * @internal
473
321
  */
@@ -475,19 +323,12 @@ export type QueueablePayload<T extends QueueableType> = Parameters<
475
323
  QueueableOperationSignatures[T]
476
324
  >;
477
325
 
478
- /**
479
- * What a queueable operation resolves with.
480
- *
481
- * @internal
482
- */
326
+ /** @internal */
483
327
  export type QueueableResult<T extends QueueableType> = Awaited<
484
328
  ReturnType<QueueableOperationSignatures[T]>
485
329
  >;
486
330
 
487
- /**
488
- * A queued request: which operation, and the arguments to replay it with. The payload is the argument
489
- * list of the method named in {@link QueueableOperationSignatures}, so the two cannot drift.
490
- */
331
+ /** A queued request: the operation and the arguments to replay it with. */
491
332
  export type PendingTask = {
492
333
  channelId?: string;
493
334
  channelType?: string;
@@ -498,11 +339,7 @@ export type PendingTask = {
498
339
  [T in QueueableType]: { payload: QueueablePayload<T>; type: T };
499
340
  }[QueueableType];
500
341
 
501
- /**
502
- * A task narrowed to one operation.
503
- *
504
- * @internal
505
- */
342
+ /** @internal */
506
343
  export type PendingTaskOf<T extends QueueableType> = Extract<PendingTask, { type: T }>;
507
344
 
508
345
  export type OfflineErrorType = 'connection:lost';
@@ -1,12 +1,7 @@
1
1
  /**
2
- * The minimal CRUD surface a paginator relies on from its item index.
3
- *
4
- * The sole implementation is {@link StoreBackedItemIndex}: backed by a shared, client-global store
5
- * it dedupes content across collections and fans changes out to every holder; backed by a private
6
- * store (the default, owner-less mode) it behaves as a plain per-instance index. Keeping this as an
7
- * interface lets `BasePaginator` stay agnostic to which backing a given paginator uses.
8
- *
9
- * @template T The domain item type managed by the index.
2
+ * The CRUD surface a paginator relies on from its item index. The only implementation is
3
+ * `StoreBackedItemIndex`: on a shared client store it dedupes items across collections and fans
4
+ * changes out to every holder, on a private store it is a plain per-instance index.
10
5
  */
11
6
  export interface ItemIndexApi<T> {
12
7
  setMany(items: T[]): void;
@@ -17,9 +12,6 @@ export interface ItemIndexApi<T> {
17
12
  clear(): void;
18
13
  entries(): [string, T][];
19
14
  values(): T[];
20
- /**
21
- * Runs `fn`, coalescing any change notifications it produces into a single flush. A private-store
22
- * (owner-less) index has nothing to fan out and simply runs `fn`.
23
- */
15
+ /** Runs `fn`, coalescing the change notifications it produces into a single flush. */
24
16
  batch<R>(fn: () => R): R;
25
17
  }
@@ -0,0 +1,29 @@
1
+ import type { Interval, PaginationFlags } from '../paginators';
2
+
3
+ /**
4
+ * Flags for a page centred on a point (`id_around` / `created_at_around`). The server splits the
5
+ * limit evenly around the point and fills a side that runs out from the other, so on a full page a
6
+ * side with less than the smaller half is exhausted. A page shorter than the limit holds everything.
7
+ */
8
+ export const deriveAroundPaginationFlags = ({
9
+ interval,
10
+ newerCount,
11
+ olderCount,
12
+ pageLength,
13
+ requestedPageSize,
14
+ }: {
15
+ interval: Interval;
16
+ newerCount: number;
17
+ olderCount: number;
18
+ pageLength: number;
19
+ requestedPageSize: number;
20
+ }): PaginationFlags => {
21
+ const isPageFull = pageLength >= requestedPageSize;
22
+ // The smaller half, so the odd slot the server gives either side does not matter.
23
+ const minShare = Math.floor((olderCount + newerCount) / 2);
24
+ // An interval already known to reach the dataset head or tail stays there.
25
+ return {
26
+ hasMoreHead: !interval.isHead && isPageFull && newerCount >= minShare,
27
+ hasMoreTail: !interval.isTail && isPageFull && olderCount >= minShare,
28
+ };
29
+ };
@@ -1,77 +1,28 @@
1
- import { binarySearch } from '../sortCompiler';
1
+ import { deriveAroundPaginationFlags } from './aroundPaginationFlags';
2
2
  import { dateToNs } from '../../utils/time';
3
3
  import type { TimestampNS } from '../../types';
4
- import type { BasePaginator, CursorDeriveContext, PaginationFlags } from '../paginators';
5
- import { ComparisonResult } from '../types.normalization';
4
+ import type { CursorDeriveContext, PaginationFlags } from '../paginators';
6
5
 
7
6
  export const deriveCreatedAtAroundPaginationFlags = <
8
7
  T extends { id: string; created_at: TimestampNS },
9
8
  Q extends { created_at_around?: Date | string },
10
- P extends BasePaginator<T, Q>,
11
9
  >({
12
10
  hasMoreHead,
13
11
  hasMoreTail,
14
12
  interval,
15
13
  page,
16
- paginator,
17
14
  queryShape,
18
15
  requestedPageSize,
19
- }: CursorDeriveContext<T, Q> & { paginator: P }): PaginationFlags => {
20
- let flags: PaginationFlags = { hasMoreHead, hasMoreTail };
21
- if (!queryShape?.created_at_around) return flags;
22
- // `created_at_around` is a REQUEST field, so it is still a `Date` (or an ISO string). Items carry
23
- // the wire unit, so bring the bound into that unit before comparing the two.
16
+ }: CursorDeriveContext<T, Q>): PaginationFlags => {
17
+ if (!queryShape?.created_at_around) return { hasMoreHead, hasMoreTail };
18
+ // The bound is a `Date` or ISO string but items carry nanoseconds: convert before comparing.
24
19
  const createdAtAround = dateToNs(new Date(queryShape.created_at_around));
25
- const [firstPageItem, lastPageItem] = [page[0], page.slice(-1)[0]];
26
-
27
- // expect ASC order (from oldest to newest)
28
- const isAboveHeadBound =
29
- paginator.sortComparator({ created_at: createdAtAround } as T, lastPageItem) ===
30
- ComparisonResult.A_PRECEDES_B;
31
- const isBelowTailBound =
32
- paginator.sortComparator(firstPageItem, { created_at: createdAtAround } as T) ===
33
- ComparisonResult.A_PRECEDES_B;
34
-
35
- const requestedPageSizeNotMet =
36
- requestedPageSize > interval.itemIds.length && requestedPageSize > page.length;
37
- const noMoreMessages =
38
- (requestedPageSize > interval.itemIds.length ||
39
- interval.itemIds.length >= page.length) &&
40
- requestedPageSize > page.length;
41
-
42
- if (isAboveHeadBound) {
43
- flags.hasMoreHead = false;
44
- if (requestedPageSizeNotMet) {
45
- flags.hasMoreTail = false;
46
- }
47
- } else if (isBelowTailBound) {
48
- flags.hasMoreTail = false;
49
- if (requestedPageSizeNotMet) {
50
- flags.hasMoreHead = false;
51
- }
52
- } else if (noMoreMessages) {
53
- flags = { hasMoreHead: false, hasMoreTail: false };
54
- } else {
55
- const [firstPageMsgIsFirstInSet, lastPageMsgIsLastInSet] = [
56
- firstPageItem?.id && firstPageItem.id === interval.itemIds[0],
57
- lastPageItem?.id && lastPageItem.id === interval.itemIds.slice(-1)[0],
58
- ];
59
-
60
- const midPointByCount = Math.floor(page.length / 2);
61
- const { insertionIndex } = binarySearch({
62
- needle: { created_at: createdAtAround } as T,
63
- length: page.length,
64
- getItemAt: (index) => page[index],
65
- compare: (a, b) => a.created_at - b.created_at,
66
- itemIdentityEquals: (a, b) => a.created_at === b.created_at,
67
- plateauScan: false,
68
- });
69
-
70
- if (insertionIndex !== -1) {
71
- if (firstPageMsgIsFirstInSet) flags.hasMoreTail = midPointByCount <= insertionIndex;
72
- if (lastPageMsgIsLastInSet) flags.hasMoreHead = midPointByCount >= insertionIndex;
73
- }
74
- }
75
-
76
- return flags;
20
+ const olderCount = page.filter((item) => item.created_at < createdAtAround).length;
21
+ return deriveAroundPaginationFlags({
22
+ interval,
23
+ newerCount: page.length - olderCount,
24
+ olderCount,
25
+ pageLength: page.length,
26
+ requestedPageSize,
27
+ });
77
28
  };
@@ -1,3 +1,4 @@
1
+ import { deriveAroundPaginationFlags } from './aroundPaginationFlags';
1
2
  import type { CursorDeriveContext, PaginationFlags } from '../paginators';
2
3
 
3
4
  export const deriveIdAroundPaginationFlags = <
@@ -11,43 +12,14 @@ export const deriveIdAroundPaginationFlags = <
11
12
  queryShape,
12
13
  requestedPageSize,
13
14
  }: CursorDeriveContext<T, Q>): PaginationFlags => {
14
- let flags: PaginationFlags = { hasMoreHead, hasMoreTail };
15
- if (!queryShape?.id_around) return flags;
16
- const { id_around } = queryShape;
17
-
18
- const [firstPageMsg, lastPageMsg] = [page[0], page.slice(-1)[0]];
19
- const [firstPageMsgIsFirstInSet, lastPageMsgIsLastInSet] = [
20
- firstPageMsg?.id === interval.itemIds[0],
21
- lastPageMsg?.id === interval.itemIds.slice(-1)[0],
22
- ];
23
-
24
- const midPoint = Math.floor(page.length / 2);
25
- const noMoreMessages =
26
- (requestedPageSize > interval.itemIds.length ||
27
- interval.itemIds.length >= page.length) &&
28
- requestedPageSize > page.length;
29
-
30
- if (noMoreMessages) {
31
- flags = { hasMoreHead: false, hasMoreTail: false };
32
- } else if (!page[midPoint]) {
33
- return flags;
34
- } else if (page[midPoint].id === id_around) {
35
- flags = { hasMoreHead: true, hasMoreTail: true };
36
- } else {
37
- const halves = [page.slice(0, midPoint), page.slice(midPoint)];
38
- if (firstPageMsgIsFirstInSet) {
39
- const targetMsg = halves[0].find((message) => message.id === id_around);
40
- if (targetMsg) {
41
- flags.hasMoreTail = false;
42
- }
43
- }
44
- if (lastPageMsgIsLastInSet) {
45
- const targetMsg = halves[1].find((message) => message.id === id_around);
46
- if (targetMsg) {
47
- flags.hasMoreHead = false;
48
- }
49
- }
50
- }
51
-
52
- return flags;
15
+ const targetIndex = page.findIndex((item) => item.id === queryShape?.id_around);
16
+ // Without the target in the page, the page says nothing about where it sits.
17
+ if (!queryShape?.id_around || targetIndex === -1) return { hasMoreHead, hasMoreTail };
18
+ return deriveAroundPaginationFlags({
19
+ interval,
20
+ newerCount: page.length - 1 - targetIndex,
21
+ olderCount: targetIndex,
22
+ pageLength: page.length,
23
+ requestedPageSize,
24
+ });
53
25
  };
@@ -2,9 +2,8 @@ import type { CursorDeriveContext, PaginationFlags } from '../paginators';
2
2
  import type { MessagePaginationParams, TimestampNS } from '../../types';
3
3
 
4
4
  /**
5
- * The query keys this helper understands when deriving a cursor direction. Not a request
6
- * shape — `MessagePaginationParams` and `PinnedMessagePaginationOptions` are both assignable
7
- * to it, and `offset` is present because the pinned-messages endpoint accepts one.
5
+ * The query keys understood when deriving a cursor direction. `MessagePaginationParams` and
6
+ * `PinnedMessagePaginationOptions` are both assignable to it (`offset` is for pinned messages).
8
7
  */
9
8
  type LinearPaginationQueryShape = {
10
9
  created_at_after?: Date;
@@ -85,9 +84,8 @@ export const deriveLinearPaginationFlags = <
85
84
  typeof queriedMessagesTowardsTail !== 'undefined' ||
86
85
  containsUnrecognizedOptionsOnly
87
86
  ) {
88
- // Without the isFirstPage branch, a partial first page (e.g. an
89
- // offline prehydrate returning fewer than `requestedPageSize`) latches `hasMoreTail`
90
- // to `false` and a subsequent full network first page can never restore it.
87
+ // A partial first page (e.g. an offline prehydrate) must not latch `hasMoreTail` to `false`:
88
+ // a later full network first page has to be able to restore it.
91
89
  hasMoreTail = isFirstPage ? hasMore : !hasMoreTail ? false : hasMore;
92
90
  }
93
91
  if (typeof queriedMessagesTowardsHead !== 'undefined') {