stream-chat 10.0.0-rc.8 → 10.0.0

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 (366) hide show
  1. package/README.md +7 -6
  2. package/dist/cjs/index.browser.js +22095 -22290
  3. package/dist/cjs/index.browser.js.map +4 -4
  4. package/dist/cjs/index.node.js +22143 -22298
  5. package/dist/cjs/index.node.js.map +4 -4
  6. package/dist/esm/index.mjs +22093 -22288
  7. package/dist/esm/index.mjs.map +4 -4
  8. package/dist/types/ChannelManager.d.ts +216 -135
  9. package/dist/types/CooldownTimer.d.ts +16 -27
  10. package/dist/types/EventHandlerPipeline.d.ts +18 -38
  11. package/dist/types/LiveLocationManager.d.ts +25 -47
  12. package/dist/types/api-client.d.ts +17 -5
  13. package/dist/types/channel.d.ts +435 -500
  14. package/dist/types/channel_state.d.ts +72 -112
  15. package/dist/types/client.d.ts +323 -440
  16. package/dist/types/client_state.d.ts +1 -3
  17. package/dist/types/configuration/ConfigController.d.ts +31 -125
  18. package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +32 -124
  19. package/dist/types/configuration/keys.d.ts +5 -19
  20. package/dist/types/configuration/shape.d.ts +12 -29
  21. package/dist/types/configuration/types.d.ts +64 -79
  22. package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +14 -36
  23. package/dist/types/configuration/utils/copyConfigPatch.d.ts +8 -0
  24. package/dist/types/configuration/utils/declarativeSlices.d.ts +5 -16
  25. package/dist/types/configuration/utils/deepFreezeConfig.d.ts +3 -17
  26. package/dist/types/configuration/utils/serverAuthority.d.ts +9 -29
  27. package/dist/types/connection/ConnectionIdManager.d.ts +45 -0
  28. package/dist/types/connection/ConnectionRecoveryManager.d.ts +84 -0
  29. package/dist/types/connection/index.d.ts +4 -0
  30. package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +82 -0
  31. package/dist/types/connection/networkConnection/index.d.ts +3 -0
  32. package/dist/types/connection/networkConnection/reporters.d.ts +20 -0
  33. package/dist/types/connection/networkConnection/types.d.ts +40 -0
  34. package/dist/types/connection/wsConnection/StableWSConnection.d.ts +137 -0
  35. package/dist/types/connection/wsConnection/WSConnection.d.ts +105 -0
  36. package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +47 -0
  37. package/dist/types/connection/wsConnection/config.d.ts +31 -0
  38. package/dist/types/connection/wsConnection/index.d.ts +4 -0
  39. package/dist/types/connection/wsConnection/types.d.ts +46 -0
  40. package/dist/types/constants.d.ts +3 -1
  41. package/dist/types/custom_types.d.ts +0 -2
  42. package/dist/types/entityStore/EntityStore.d.ts +226 -65
  43. package/dist/types/entityStore/StoreBackedItemIndex.d.ts +19 -33
  44. package/dist/types/entityStore/index.d.ts +0 -1
  45. package/dist/types/errors.d.ts +16 -19
  46. package/dist/types/formatMessageMemo.d.ts +5 -0
  47. package/dist/types/gen/chat/ChannelApi.d.ts +5 -1
  48. package/dist/types/gen/chat/ChatApi.d.ts +149 -105
  49. package/dist/types/gen/models/index.d.ts +2540 -698
  50. package/dist/types/gen/models/timestamp-guard.d.ts +22 -0
  51. package/dist/types/gen/moderation/ModerationApi.d.ts +37 -14
  52. package/dist/types/index.d.ts +10 -5
  53. package/dist/types/{i18n/languageNames.d.ts → languageNames.d.ts} +9 -24
  54. package/dist/types/logger.d.ts +1 -3
  55. package/dist/types/messageComposer/CustomDataManager.d.ts +7 -1
  56. package/dist/types/messageComposer/LocationComposer.d.ts +8 -2
  57. package/dist/types/messageComposer/attachmentIdentity.d.ts +24 -0
  58. package/dist/types/messageComposer/attachmentManager.d.ts +52 -24
  59. package/dist/types/messageComposer/attachmentUtils.d.ts +23 -0
  60. package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
  61. package/dist/types/messageComposer/configuration/types.d.ts +38 -50
  62. package/dist/types/messageComposer/index.d.ts +1 -0
  63. package/dist/types/messageComposer/linkPreviewsManager.d.ts +12 -9
  64. package/dist/types/messageComposer/messageComposer.d.ts +60 -123
  65. package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +10 -1
  66. package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +4 -0
  67. package/dist/types/messageComposer/middleware/messageComposer/commandInjection.d.ts +5 -0
  68. package/dist/types/messageComposer/middleware/messageComposer/index.d.ts +2 -0
  69. package/dist/types/messageComposer/middleware/messageComposer/pollOnly.d.ts +6 -0
  70. package/dist/types/messageComposer/middleware/messageComposer/userDataInjection.d.ts +5 -0
  71. package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +2 -4
  72. package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +7 -19
  73. package/dist/types/messageComposer/middleware/textComposer/commandUtils.d.ts +4 -0
  74. package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +11 -2
  75. package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +20 -19
  76. package/dist/types/messageComposer/middleware/textComposer/textMiddlewareUtils.d.ts +9 -3
  77. package/dist/types/messageComposer/middleware/textComposer/types.d.ts +1 -6
  78. package/dist/types/messageComposer/pollComposer.d.ts +15 -5
  79. package/dist/types/messageComposer/textComposer.d.ts +14 -7
  80. package/dist/types/messageComposer/types.d.ts +27 -7
  81. package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +27 -80
  82. package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +43 -73
  83. package/dist/types/messageOperations/FailedSendCache.d.ts +29 -0
  84. package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +16 -22
  85. package/dist/types/messageOperations/MessageOperations.d.ts +63 -34
  86. package/dist/types/messageOperations/applyReactionLocally.d.ts +15 -0
  87. package/dist/types/messageOperations/createMessageOperations.d.ts +9 -0
  88. package/dist/types/messageOperations/index.d.ts +6 -4
  89. package/dist/types/messageOperations/reflectReactionEvent.d.ts +16 -0
  90. package/dist/types/messageOperations/sendOrdering.d.ts +14 -0
  91. package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +20 -0
  92. package/dist/types/messageOperations/types.d.ts +43 -14
  93. package/dist/types/middleware.d.ts +10 -0
  94. package/dist/types/moderation.d.ts +21 -14
  95. package/dist/types/notifications/NotificationManager.d.ts +10 -23
  96. package/dist/types/notifications/types.d.ts +21 -57
  97. package/dist/types/offline-support/offline_support_api.d.ts +150 -528
  98. package/dist/types/offline-support/offline_sync_manager.d.ts +21 -42
  99. package/dist/types/offline-support/queueableOperations.d.ts +35 -37
  100. package/dist/types/offline-support/types.d.ts +40 -185
  101. package/dist/types/pagination/FilterBuilder.d.ts +1 -18
  102. package/dist/types/pagination/ItemIndex.d.ts +4 -12
  103. package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +13 -0
  104. package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +4 -5
  105. package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +19 -5
  106. package/dist/types/pagination/index.d.ts +1 -0
  107. package/dist/types/pagination/paginators/BasePaginator.d.ts +604 -550
  108. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +123 -106
  109. package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +576 -327
  110. package/dist/types/pagination/paginators/MessagePaginator.d.ts +237 -131
  111. package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +15 -26
  112. package/dist/types/pagination/paginators/ReminderPaginator.d.ts +4 -3
  113. package/dist/types/pagination/paginators/ThreadPaginator.d.ts +44 -0
  114. package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +5 -8
  115. package/dist/types/pagination/paginators/index.d.ts +1 -0
  116. package/dist/types/pagination/sortCompiler.d.ts +11 -22
  117. package/dist/types/pagination/utility.normalization.d.ts +8 -13
  118. package/dist/types/pagination/utility.search.d.ts +3 -8
  119. package/dist/types/poll.d.ts +35 -8
  120. package/dist/types/poll_manager.d.ts +12 -2
  121. package/dist/types/poll_optimistic_votes.d.ts +57 -0
  122. package/dist/types/reminders/Reminder.d.ts +17 -7
  123. package/dist/types/reminders/ReminderManager.d.ts +13 -25
  124. package/dist/types/search/BaseSearchSource.d.ts +10 -8
  125. package/dist/types/search/ChannelSearchSource.d.ts +16 -0
  126. package/dist/types/search/MessageSearchSource.d.ts +17 -0
  127. package/dist/types/search/SearchController.d.ts +26 -28
  128. package/dist/types/search/types.d.ts +6 -10
  129. package/dist/types/signing.d.ts +12 -3
  130. package/dist/types/thread.d.ts +67 -129
  131. package/dist/types/thread_manager.d.ts +95 -66
  132. package/dist/types/token_manager.d.ts +8 -13
  133. package/dist/types/types.d.ts +81 -197
  134. package/dist/types/types.utility.d.ts +3 -3
  135. package/dist/types/upload-utils.d.ts +5 -10
  136. package/dist/types/uploadManager.d.ts +31 -11
  137. package/dist/types/utils/FixedSizeQueueCache.d.ts +8 -11
  138. package/dist/types/utils/WithSubscriptions.d.ts +6 -16
  139. package/dist/types/utils/abort.d.ts +17 -0
  140. package/dist/types/utils/concurrency.d.ts +12 -20
  141. package/dist/types/utils/mergeWith/mergeWith.d.ts +8 -11
  142. package/dist/types/utils/mergeWith/mergeWithCore.d.ts +5 -13
  143. package/dist/types/utils/mergeWith/mergeWithDiff.d.ts +22 -0
  144. package/dist/types/utils/objectPath.d.ts +6 -41
  145. package/dist/types/utils/retryable.d.ts +8 -12
  146. package/dist/types/utils/throttling/throttle.d.ts +8 -23
  147. package/dist/types/utils/time.d.ts +45 -0
  148. package/dist/types/utils.d.ts +74 -93
  149. package/package.json +14 -40
  150. package/src/ChannelManager.ts +494 -303
  151. package/src/CooldownTimer.ts +46 -59
  152. package/src/EventHandlerPipeline.ts +22 -45
  153. package/src/LiveLocationManager.ts +99 -91
  154. package/src/api-client.ts +113 -50
  155. package/src/campaign.ts +1 -1
  156. package/src/channel.ts +1098 -1351
  157. package/src/channel_batch_updater.ts +1 -1
  158. package/src/channel_state.ts +81 -174
  159. package/src/client.ts +755 -970
  160. package/src/client_state.ts +3 -8
  161. package/src/configuration/ConfigController.ts +42 -158
  162. package/src/configuration/InstanceConfigurationRegistry.ts +43 -172
  163. package/src/configuration/index.ts +1 -1
  164. package/src/configuration/keys.ts +13 -32
  165. package/src/configuration/shape.ts +169 -59
  166. package/src/configuration/types.ts +69 -92
  167. package/src/configuration/utils/applyInstanceConfiguration.ts +22 -54
  168. package/src/configuration/utils/copyConfigPatch.ts +11 -32
  169. package/src/configuration/utils/declarativeSlices.ts +9 -39
  170. package/src/configuration/utils/deepFreezeConfig.ts +3 -17
  171. package/src/configuration/utils/index.ts +2 -4
  172. package/src/configuration/utils/serverAuthority.ts +20 -68
  173. package/src/connection/ConnectionIdManager.ts +111 -0
  174. package/src/connection/ConnectionRecoveryManager.ts +257 -0
  175. package/src/connection/index.ts +4 -0
  176. package/src/connection/networkConnection/NetworkConnectionObserver.ts +204 -0
  177. package/src/connection/networkConnection/index.ts +3 -0
  178. package/src/connection/networkConnection/reporters.ts +58 -0
  179. package/src/connection/networkConnection/types.ts +45 -0
  180. package/src/{connection.ts → connection/wsConnection/StableWSConnection.ts} +230 -231
  181. package/src/connection/wsConnection/WSConnection.ts +270 -0
  182. package/src/connection/wsConnection/WSConnectionFallback.ts +250 -0
  183. package/src/connection/wsConnection/config.ts +73 -0
  184. package/src/connection/wsConnection/index.ts +4 -0
  185. package/src/connection/wsConnection/types.ts +48 -0
  186. package/src/constants.ts +7 -5
  187. package/src/custom_types.ts +0 -1
  188. package/src/entityStore/EntityStore.ts +415 -79
  189. package/src/entityStore/StoreBackedItemIndex.ts +37 -41
  190. package/src/entityStore/index.ts +0 -1
  191. package/src/errors.ts +39 -20
  192. package/src/formatMessageMemo.ts +17 -0
  193. package/src/gen/chat/ChannelApi.ts +122 -36
  194. package/src/gen/chat/ChatApi.ts +578 -1752
  195. package/src/gen/models/index.ts +2566 -3440
  196. package/src/gen/models/timestamp-guard.ts +27 -0
  197. package/src/gen/moderation/ModerationApi.ts +183 -406
  198. package/src/index.ts +32 -10
  199. package/src/languageNames.ts +88 -0
  200. package/src/logger.ts +1 -3
  201. package/src/messageComposer/CustomDataManager.ts +19 -6
  202. package/src/messageComposer/LocationComposer.ts +49 -9
  203. package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
  204. package/src/messageComposer/attachmentIdentity.ts +54 -0
  205. package/src/messageComposer/attachmentManager.ts +170 -185
  206. package/src/messageComposer/attachmentUtils.ts +44 -0
  207. package/src/messageComposer/configuration/configuration.ts +15 -8
  208. package/src/messageComposer/configuration/types.ts +38 -50
  209. package/src/messageComposer/fileUtils.ts +1 -1
  210. package/src/messageComposer/index.ts +1 -0
  211. package/src/messageComposer/linkPreviewsManager.ts +18 -21
  212. package/src/messageComposer/messageComposer.ts +234 -179
  213. package/src/messageComposer/middleware/attachmentManager/postUpload/AttachmentPostUploadMiddlewareExecutor.ts +1 -1
  214. package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +46 -33
  215. package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +4 -1
  216. package/src/messageComposer/middleware/attachmentManager/preUpload/blockedUploadNotification.ts +1 -1
  217. package/src/messageComposer/middleware/messageComposer/MessageComposerMiddlewareExecutor.ts +6 -0
  218. package/src/messageComposer/middleware/messageComposer/attachments.ts +76 -5
  219. package/src/messageComposer/middleware/messageComposer/commandInjection.ts +10 -4
  220. package/src/messageComposer/middleware/messageComposer/customData.ts +17 -5
  221. package/src/messageComposer/middleware/messageComposer/index.ts +2 -0
  222. package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +22 -12
  223. package/src/messageComposer/middleware/messageComposer/pollOnly.ts +9 -1
  224. package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +7 -2
  225. package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
  226. package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +12 -12
  227. package/src/messageComposer/middleware/pollComposer/state.ts +2 -2
  228. package/src/messageComposer/middleware/pollComposer/types.ts +2 -4
  229. package/src/messageComposer/middleware/pollComposer/validation.ts +8 -26
  230. package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +8 -6
  231. package/src/messageComposer/middleware/textComposer/commandUtils.ts +10 -3
  232. package/src/messageComposer/middleware/textComposer/commands.ts +11 -16
  233. package/src/messageComposer/middleware/textComposer/mentions.ts +32 -70
  234. package/src/messageComposer/middleware/textComposer/textMiddlewareUtils.ts +10 -4
  235. package/src/messageComposer/middleware/textComposer/types.ts +1 -6
  236. package/src/messageComposer/pollComposer.ts +21 -9
  237. package/src/messageComposer/textComposer.ts +37 -57
  238. package/src/messageComposer/types.ts +39 -11
  239. package/src/messageDelivery/MessageDeliveryReporter.ts +86 -124
  240. package/src/messageDelivery/MessageReceiptsTracker.ts +122 -139
  241. package/src/messageOperations/FailedSendCache.ts +85 -0
  242. package/src/messageOperations/MessageOperationStatePolicy.ts +124 -116
  243. package/src/messageOperations/MessageOperations.ts +297 -175
  244. package/src/{entityStore → messageOperations}/applyReactionLocally.ts +13 -25
  245. package/src/messageOperations/createMessageOperations.ts +176 -0
  246. package/src/messageOperations/index.ts +6 -14
  247. package/src/messageOperations/reflectReactionEvent.ts +43 -0
  248. package/src/messageOperations/sendOrdering.ts +25 -0
  249. package/src/messageOperations/settlePendingAttachmentUploads.ts +98 -0
  250. package/src/messageOperations/types.ts +51 -13
  251. package/src/middleware.ts +13 -5
  252. package/src/moderation.ts +25 -21
  253. package/src/notifications/NotificationManager.ts +19 -28
  254. package/src/notifications/types.ts +21 -57
  255. package/src/offline-support/offline_support_api.ts +231 -681
  256. package/src/offline-support/offline_sync_manager.ts +51 -90
  257. package/src/offline-support/queueableOperations.ts +98 -73
  258. package/src/offline-support/types.ts +43 -185
  259. package/src/pagination/FilterBuilder.ts +1 -22
  260. package/src/pagination/ItemIndex.ts +4 -12
  261. package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
  262. package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +17 -62
  263. package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
  264. package/src/pagination/cursorDerivation/linearPaginationFlags.ts +53 -33
  265. package/src/pagination/filterCompiler.ts +11 -25
  266. package/src/pagination/index.ts +1 -0
  267. package/src/pagination/paginators/BasePaginator.ts +1415 -1041
  268. package/src/pagination/paginators/ChannelPaginator.ts +481 -219
  269. package/src/pagination/paginators/MessageIntervalPaginator.ts +1362 -775
  270. package/src/pagination/paginators/MessagePaginator.ts +521 -240
  271. package/src/pagination/paginators/PinnedMessagePaginator.ts +32 -40
  272. package/src/pagination/paginators/ReminderPaginator.ts +21 -16
  273. package/src/pagination/paginators/ThreadPaginator.ts +170 -0
  274. package/src/pagination/paginators/UserGroupPaginator.ts +18 -15
  275. package/src/pagination/paginators/index.ts +1 -0
  276. package/src/pagination/paginators/stateThrottling.ts +5 -10
  277. package/src/pagination/sortCompiler.ts +23 -50
  278. package/src/pagination/utility.normalization.ts +17 -24
  279. package/src/pagination/utility.search.ts +4 -11
  280. package/src/poll.ts +183 -102
  281. package/src/poll_manager.ts +24 -22
  282. package/src/poll_optimistic_votes.ts +335 -0
  283. package/src/reminders/Reminder.ts +33 -16
  284. package/src/reminders/ReminderManager.ts +23 -56
  285. package/src/reminders/ReminderTimer.ts +6 -6
  286. package/src/search/BaseSearchSource.ts +19 -25
  287. package/src/search/ChannelSearchSource.ts +43 -1
  288. package/src/search/MessageSearchSource.ts +77 -13
  289. package/src/search/SearchController.ts +39 -36
  290. package/src/search/types.ts +6 -10
  291. package/src/segment.ts +1 -1
  292. package/src/signing.ts +23 -3
  293. package/src/thread.ts +430 -712
  294. package/src/thread_manager.ts +300 -234
  295. package/src/token_manager.ts +12 -22
  296. package/src/types.ts +102 -214
  297. package/src/types.utility.ts +3 -3
  298. package/src/upload-utils.ts +5 -10
  299. package/src/uploadManager.ts +64 -18
  300. package/src/utils/FixedSizeQueueCache.ts +18 -21
  301. package/src/utils/WithSubscriptions.ts +6 -16
  302. package/src/utils/abort.ts +45 -0
  303. package/src/utils/concurrency.ts +16 -55
  304. package/src/utils/mergeWith/mergeWith.ts +10 -13
  305. package/src/utils/mergeWith/mergeWithCore.ts +24 -81
  306. package/src/utils/mergeWith/mergeWithDiff.ts +15 -33
  307. package/src/utils/objectPath.ts +6 -41
  308. package/src/utils/retryable.ts +10 -14
  309. package/src/utils/throttling/throttle.ts +9 -25
  310. package/src/utils/time.ts +64 -0
  311. package/src/utils.ts +227 -174
  312. package/codegen/i18n/callSites.ts +0 -126
  313. package/codegen/i18n/generate.ts +0 -226
  314. package/codegen/i18n/guards.ts +0 -178
  315. package/codegen/i18n/index.ts +0 -29
  316. package/codegen/i18n/stringMaps.ts +0 -91
  317. package/codegen/i18n/types.ts +0 -100
  318. package/dist/cjs/i18n.browser.js +0 -1131
  319. package/dist/cjs/i18n.browser.js.map +0 -7
  320. package/dist/cjs/i18n.node.js +0 -1160
  321. package/dist/cjs/i18n.node.js.map +0 -7
  322. package/dist/esm/i18n-codegen.mjs +0 -409
  323. package/dist/esm/i18n-codegen.mjs.map +0 -7
  324. package/dist/esm/i18n.mjs +0 -1098
  325. package/dist/esm/i18n.mjs.map +0 -7
  326. package/dist/types/ConnectionRecoveryManager.d.ts +0 -156
  327. package/dist/types/connection.d.ts +0 -139
  328. package/dist/types/entityStore/applyReactionLocally.d.ts +0 -26
  329. package/dist/types/gen/model-decoders/decoders.d.ts +0 -3
  330. package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +0 -6
  331. package/dist/types/i18n/Streami18n.d.ts +0 -168
  332. package/dist/types/i18n/TranslationBuilder.d.ts +0 -70
  333. package/dist/types/i18n/TranslationStore.d.ts +0 -57
  334. package/dist/types/i18n/dayjs.d.ts +0 -104
  335. package/dist/types/i18n/formatters.d.ts +0 -91
  336. package/dist/types/i18n/index.d.ts +0 -15
  337. package/dist/types/i18n/translator.d.ts +0 -29
  338. package/dist/types/i18n/types.d.ts +0 -262
  339. package/dist/types/i18n-codegen/callSites.d.ts +0 -10
  340. package/dist/types/i18n-codegen/generate.d.ts +0 -15
  341. package/dist/types/i18n-codegen/guards.d.ts +0 -61
  342. package/dist/types/i18n-codegen/index.d.ts +0 -29
  343. package/dist/types/i18n-codegen/stringMaps.d.ts +0 -14
  344. package/dist/types/i18n-codegen/types.d.ts +0 -94
  345. package/dist/types/insights.d.ts +0 -56
  346. package/dist/types/messageOperations/optimistic.d.ts +0 -118
  347. package/dist/types/messageOperations/persistence.d.ts +0 -21
  348. package/dist/types/pagination/utility.queryChannel.d.ts +0 -26
  349. package/dist/types/store.d.ts +0 -125
  350. package/src/ConnectionRecoveryManager.ts +0 -293
  351. package/src/gen/model-decoders/decoders.ts +0 -2710
  352. package/src/gen/model-decoders/event-decoder-mapping.ts +0 -198
  353. package/src/i18n/Streami18n.ts +0 -520
  354. package/src/i18n/TranslationBuilder.ts +0 -176
  355. package/src/i18n/TranslationStore.ts +0 -96
  356. package/src/i18n/dayjs.ts +0 -228
  357. package/src/i18n/formatters.ts +0 -461
  358. package/src/i18n/index.ts +0 -15
  359. package/src/i18n/languageNames.ts +0 -103
  360. package/src/i18n/translator.ts +0 -76
  361. package/src/i18n/types.ts +0 -375
  362. package/src/insights.ts +0 -82
  363. package/src/messageOperations/optimistic.ts +0 -249
  364. package/src/messageOperations/persistence.ts +0 -40
  365. package/src/pagination/utility.queryChannel.ts +0 -84
  366. package/src/store.ts +0 -304
@@ -1,8 +1,9 @@
1
- import type { BasePaginatorConfig, PaginationDirection, PaginationQueryParams, PaginatorState } from './BasePaginator';
1
+ import type { BasePaginatorConfig, DoRequestResponse, ExecuteQueryReturnValue, Interval, PaginationDirection, PaginationQueryParams, PaginatorState, QueryPagePlacement } from './BasePaginator';
2
2
  import { BasePaginator, type PaginationQueryReturnValue, type PaginatorOptions } from './BasePaginator';
3
- import type { LocalMessage, MessagePaginationParams, MessageResponse, PinnedMessagePaginationOptions, ReactionResponse, SortParamRequest, UserResponse } from '../../types';
3
+ import type { ChannelStateResponse, GetRepliesResponse, LocalMessage, MessagePaginationParams, PinnedMessagePaginationOptions, SortParamRequest, StreamResponse, TimestampNS, UserResponse } from '../../types';
4
4
  import type { Channel } from '../../channel';
5
- import { StateStore } from '../../store';
5
+ import type { Thread } from '../../thread';
6
+ import { StateStore } from '@stream-io/state-store';
6
7
  import type { ItemIndexApi } from '../ItemIndex';
7
8
  import type { EntityStoreChangeBatch } from '../../entityStore/EntityStore';
8
9
  export type MessageFocusReason = 'jump-to-message' | 'jump-to-first-unread' | 'jump-to-latest';
@@ -18,20 +19,19 @@ export type MessageFocusSignalState = {
18
19
  };
19
20
  export type JumpToMessageOptions = {
20
21
  pageSize?: number;
21
- /**
22
- * Optional reason attached to emitted focus signal.
23
- * Defaults to `jump-to-message`.
24
- */
22
+ /** Reason attached to the emitted focus signal. Defaults to `jump-to-message`. */
25
23
  focusReason?: MessageFocusReason;
26
- /**
27
- * TTL for the emitted focus signal in milliseconds.
28
- * Defaults to `3000`.
29
- */
24
+ /** TTL of the emitted focus signal in milliseconds. Defaults to `3000`. */
30
25
  focusSignalTtlMs?: number;
26
+ /** Suppresses the focus signal after a successful jump. */
27
+ suppressFocusSignal?: boolean;
31
28
  /**
32
- * If true, suppresses focus signal emission after a successful jump.
29
+ * Also watches the channel (so it receives events) when it is not watched yet. The request that
30
+ * loads the interval around the message asks to watch too, so it stays one request, and a message
31
+ * already loaded is loaded again. Ignored for a thread's reply list (its request cannot watch)
32
+ * and when the paginator's `doRequest` loads the messages.
33
33
  */
34
- suppressFocusSignal?: boolean;
34
+ watchChannel?: boolean;
35
35
  };
36
36
  export type MessagePaginatorSort = SortParamRequest[];
37
37
  export type MessagePaginatorFilter = {
@@ -40,157 +40,177 @@ export type MessagePaginatorFilter = {
40
40
  };
41
41
  export type MessagePaginatorState = PaginatorState<LocalMessage>;
42
42
  export type MessageQueryShape = MessagePaginationParams | PinnedMessagePaginationOptions;
43
- export declare const getMessageCreatedAtTimestamp: (message: LocalMessage) => number | null;
43
+ /** A message's `created_at` (unix nanoseconds), or `null` when absent or not finite. */
44
+ export declare const getMessageCreatedAtTimestamp: (message: LocalMessage | null | undefined) => TimestampNS | null;
44
45
  export type MessagePaginatorOptions = {
45
46
  channel: Channel;
46
47
  id?: string;
47
48
  itemIndex?: ItemIndexApi<LocalMessage>;
48
49
  parentMessageId?: string;
49
- /**
50
- * Sort passed to backend message/replies query.
51
- * Does not affect in-memory item ordering.
52
- */
50
+ /** Sort sent to the backend messages/replies query. Does not affect in-memory ordering. */
53
51
  requestSort?: MessagePaginatorSort;
54
52
  /**
55
53
  * @deprecated Use `requestSort` instead.
56
54
  */
57
55
  sort?: MessagePaginatorSort;
58
- /**
59
- * In-memory ordering for items exposed by paginator state.
60
- */
56
+ /** In-memory ordering of the items exposed by paginator state. */
61
57
  itemOrder?: MessagePaginatorSort;
58
+ /** The thread whose replies this paginator lists; without it, it lists the channel's messages. */
59
+ thread?: Thread;
62
60
  paginatorOptions?: PaginatorOptions<LocalMessage, MessageQueryShape>;
63
61
  };
64
62
  /**
65
- * Options for {@link MessageIntervalPaginator.mergeNewestPage} that enable destructive
66
- * reconciliation — removing messages that were hard-deleted (by anyone) while the client was
67
- * offline. A hard delete emits no event to other clients, and the merge is otherwise additive, so
68
- * without this such a message lingers as a ghost after reconnect.
69
- *
70
- * Throughout, `page` is the newest window the server returned for `mergeNewestPage`, and "`page`'s
71
- * newest / oldest message" are its bounds by `created_at`. With NO options, `mergeNewestPage` prunes
72
- * any loaded message that falls WITHIN `page`'s `created_at` span but is absent from it —
73
- * unconditionally safe (a message that arrived live during the caller's fetch is always strictly
74
- * newer than `page`'s newest message, so it can never fall in that span). `candidateIds` widens the
75
- * reconcilable window at the TOP edge; `requestedLimit` only tunes the `hasMoreTail` affordance and
76
- * can never remove a message:
63
+ * Options for {@link MessageIntervalPaginator.reconcileNewestMessages} that enable reconciling
64
+ * messages hard-deleted while the client received no events (no event reaches other clients). With
65
+ * no options it prunes loaded messages inside `page`'s `created_at` span that are absent from it,
66
+ * which is always safe: a live arrival is newer than `page`'s newest message.
67
+ * `headIntervalItemIdsAtRequest` widens reconciliation at the top edge; `requestedLimit` says
68
+ * whether the page reached the channel start.
77
69
  */
78
- export type MergeNewestPageOptions = {
79
- /**
80
- * The `limit` the caller passed to the query that produced `page`. Used ONLY to derive
81
- * `hasMoreTail` — whether `page` reached the channel's own oldest message — by comparing it to
82
- * `page.length`. It NEVER removes a message (reconciliation stays window-only regardless), so the
83
- * worst a wrong value can do is show/hide the "load older" affordance for one settle. Trusted only
84
- * when no larger than the paginator's own `pageSize` (see
85
- * {@link MessageIntervalPaginator.pageReachedChannelStart}); a larger over-request — e.g.
86
- * `channel.reload` re-fetching the whole loaded window to reconcile as much as possible — may have
87
- * been silently server-capped, so its short page is ignored rather than mistaken for reaching the
88
- * start.
70
+ export type ReconcileNewestMessagesOptions = {
71
+ /**
72
+ * The `limit` the caller passed to the query that produced `page`. Compared to `page.length`, it
73
+ * says whether `page` reached the channel start (see
74
+ * {@link MessageIntervalPaginator.pageReachedChannelStart}, which ignores a limit above
75
+ * `pageSize`), deciding `hasMoreTail`, whether `page` can be separated from the head interval by
76
+ * a gap, and whether a reload asks the server about messages deleted below the page (see
77
+ * {@link MessageIntervalPaginator.removeIdsTailwardOfPageIfNothingOlder}). On its own it never
78
+ * removes a message. Pass the limit actually sent: a larger one makes a short page look like the
79
+ * channel start, welding it to the head interval across a real gap.
89
80
  */
90
81
  requestedLimit?: number;
91
82
  /**
92
- * A snapshot of the loaded message ids taken BEFORE the caller's fetch await. Required to prune
93
- * messages NEWER than `page`'s newest message (a hard-deleted newest message) and to reconcile an
94
- * empty `page` (a fully-emptied channel): at/above that top edge a just-deleted message and a
95
- * message that arrived live during the fetch are indistinguishable by timestamp — only the pre-fetch
96
- * snapshot separates them (a live arrival is not in it). Must be captured before the await; the
97
- * paginator's own items at merge time already include any live arrival.
83
+ * The IDs of the head interval's server-confirmed items when the request for `page` went out,
84
+ * taken with {@link MessageIntervalPaginator.getHeadIntervalItemIdsAtRequest} before the request
85
+ * is awaited. Only these prove what `page` says about the head interval:
86
+ *
87
+ * - deletion: at or above `page`'s newest message, and for an empty `page`, only this snapshot
88
+ * tells a just-deleted message from one that arrived live, or was sent, during the request;
89
+ * - contiguity: `page` starts inside the head interval only if its oldest message the head
90
+ * interval could hold is in this snapshot (see `isSeparatedFromHeadByGap`).
91
+ *
92
+ * Only the head interval receives live messages, so only its IDs are needed.
98
93
  */
99
- candidateIds?: ReadonlySet<string>;
94
+ headIntervalItemIdsAtRequest?: ReadonlySet<string>;
95
+ };
96
+ /** An external query prepared by {@link MessageIntervalPaginator.prepareExternalQuery}. */
97
+ export type PreparedExternalQuery = {
98
+ messagePaginationParams: MessagePaginationParams;
99
+ isNewestPage: boolean;
100
+ placePage: (page: LocalMessage[]) => boolean;
100
101
  };
101
102
  /**
102
- * Options for {@link MessageIntervalPaginator.seedFirstPageSync}, the synchronous channel-open seed.
103
+ * What one of the message paginator's own queries got back, before its page is extracted (see
104
+ * {@link MessageIntervalPaginator.fetchQueryResponse}), by where it came from.
103
105
  */
104
- export type SeedFirstPageOptions = {
105
- /**
106
- * When true and the paginator has already been seeded once, fold the fresh page via
107
- * {@link MessageIntervalPaginator.mergeNewestPage} — merge in place, reconcile offline hard-deletes,
108
- * re-derive the tail cursor, rebuild on a disjoint window, and skip when jumped away from the head —
109
- * instead of a plain first-page ingest. Lets callers (channel.reload, the channel-list hydrate,
110
- * connection recovery) share one reconciling seed path. Left false for the differently-sorted
111
- * pinned list, and a no-op on a cold open (nothing loaded to fold).
112
- */
113
- reconcile?: boolean;
114
- /**
115
- * Pre-fetch snapshot of loaded message ids (captured before the caller's network await), forwarded
116
- * to {@link MergeNewestPageOptions.candidateIds} so a hard-deleted NEWEST message is reconciled
117
- * without mistaking a message that arrived live during the fetch for a delete. Only consulted when
118
- * {@link reconcile} is set and a window is already loaded.
119
- */
120
- candidateIds?: ReadonlySet<string>;
106
+ export type MessageQueryResponse = {
107
+ /** what a custom `doRequest` returned: the page, used as is */
108
+ doRequestResponse: DoRequestResponse<LocalMessage>;
109
+ source: 'doRequest';
110
+ } | {
111
+ /** the replies endpoint's response for a thread's reply list */
112
+ repliesResponse: GetRepliesResponse;
113
+ source: 'replies';
114
+ } | {
115
+ /** the response of a channel query: its messages, and the rest, applied once they are placed */
116
+ channelResponse: StreamResponse<ChannelStateResponse>;
117
+ source: 'channel';
118
+ /** whether the query watched the channel, which applying the response records */
119
+ watch: boolean;
121
120
  };
122
121
  /**
123
- * MessageIntervalPaginator allows configuring backend request sort, while keeping internal item ordering stable.
124
- * Filtering of ingested items is still limited to local predicates (`filterQueryResults`).
122
+ * A message list with a configurable backend request sort and a stable in-memory item order.
123
+ * Ingested items are filtered only by local predicates (`filterQueryResults`).
125
124
  */
126
- export declare class MessageIntervalPaginator extends BasePaginator<LocalMessage, MessageQueryShape> {
125
+ export declare class MessageIntervalPaginator extends BasePaginator<LocalMessage, MessageQueryShape, MessageQueryResponse> {
126
+ /**
127
+ * Holder name of this list's index in the message store. A getter, so a subclass's value is in
128
+ * place while the base constructor builds the index.
129
+ */
130
+ protected get holderName(): string;
127
131
  state: StateStore<MessagePaginatorState>;
128
132
  private readonly _id;
129
- protected channel: Channel;
130
- protected parentMessageId?: string;
133
+ /** The channel this list belongs to. A thread's reply list holds its parent channel. */
134
+ readonly channel: Channel;
135
+ /** See {@link MessagePaginatorOptions.thread}. */
136
+ readonly thread?: Thread;
137
+ /** Set when this is a thread's reply list, to the parent message's ID. */
138
+ readonly parentMessageId?: string;
131
139
  readonly messageFocusSignal: StateStore<MessageFocusSignalState>;
132
140
  private clearMessageFocusSignalTimeoutId;
133
141
  private messageFocusSignalToken;
134
142
  protected _requestSort: MessagePaginatorSort;
135
143
  protected _itemOrder: MessagePaginatorSort;
136
- protected _nextQueryShape: MessageQueryShape | undefined;
137
- /** Pending below-window reached-start probe (exposed for deterministic test awaiting). */
138
- private _belowWindowReconcile?;
144
+ /** The pending {@link removeIdsTailwardOfPageIfNothingOlder} (kept so tests can await it). */
145
+ private _pendingTailwardOfPageRemoval?;
146
+ /**
147
+ * The ID of the newest server-confirmed message of the interval whose head mark was cleared last
148
+ * (see {@link unmarkedHeadInterval}). Forgotten once a newest page is reconciled with no head
149
+ * interval loaded, and when the loaded intervals are cleared.
150
+ */
151
+ private unmarkedHeadEdgeId;
139
152
  sortComparator: (a: LocalMessage, b: LocalMessage) => number;
140
153
  /**
141
- * Single source of truth for whether a message should be included in paginator intervals/state.
142
- * Keep this consistent with `filterQueryResults` AND cursor flag derivation.
154
+ * Whether a message belongs in intervals and state. Keep it consistent with `filterQueryResults`
155
+ * and with the page the linear cursor flag derivation reads (see {@link deriveCursorFromPage}).
143
156
  */
144
157
  shouldIncludeMessageInInterval(message: LocalMessage): boolean;
145
158
  /**
146
- * Entity-store adapter (this paginator is an `EntityStoreSubscriber`): the `EntityStore` calls this
147
- * on each holder with the subset of its watched ids that changed. Unwraps the batch and delegates to
148
- * the base's store-agnostic {@link BasePaginator.reconcileChangedIds}. Lives here, not on the generic
149
- * `BasePaginator`, so the base stays free of `EntityStore` types — only message paginators are
150
- * store-backed.
159
+ * Reconciles the held messages that changed in the entity store.
160
+ *
161
+ * @internal
162
+ * @param batch - The change batch from the store.
163
+ * @param batch.changedIds - IDs of the watched messages that changed.
151
164
  */
152
165
  onEntitiesChanged({ changedIds }: EntityStoreChangeBatch): void;
153
166
  /**
154
- * Entity-store subscriber flush (the optional `EntityStoreSubscriber.flushState`): the `EntityStore`
155
- * calls this after an optimistic (local-user) write so the change renders without throttle delay.
156
- * Delegates to the base's generic {@link BasePaginator.flushPendingPublishes}.
167
+ * Drops a message from this paginator's intervals after the entity store removed it.
168
+ *
169
+ * @internal
170
+ * @param id - ID of the removed message.
171
+ * @param message - The removed message.
157
172
  */
173
+ onEntityRemoved(id: string, message: unknown): void;
174
+ /** Entity-store subscriber flush after an optimistic (local-user) write: skips the throttle. */
158
175
  flushState(): void;
176
+ /** UI-driven "hold off on pruning" signal ({@link setPruningSuspended}). Off by default. */
177
+ protected get isPruningSuspended(): boolean;
178
+ private _pruningSuspended;
179
+ /**
180
+ * Holds off dropping the oldest loaded messages, so pruning does not pull content from under a user
181
+ * reading near them: the interval may grow past `maxLoadedItems` until they scroll back. A plain
182
+ * field, not a `StateStore`: nothing observes it and a scroll-driven signal must not cost a render.
183
+ */
184
+ setPruningSuspended: (suspended: boolean) => void;
185
+ /**
186
+ * A message anchors pagination once the server has acknowledged it. This keeps an unsent message
187
+ * out of both halves of a prune and stops its ID from becoming the tailward cursor (`id_lt`).
188
+ */
189
+ protected isPaginationAnchorable(item: LocalMessage | undefined): boolean;
159
190
  protected get intervalItemIdsAreHeadFirst(): boolean;
160
191
  protected get intervalSortDirection(): 'asc' | 'desc';
161
- constructor({ channel, id, itemIndex, parentMessageId, requestSort, sort, itemOrder, paginatorOptions, }: MessagePaginatorOptions, builtInDefaults?: Partial<BasePaginatorConfig<LocalMessage, MessageQueryShape>>);
192
+ constructor({ channel, id, itemIndex, parentMessageId, requestSort, sort, itemOrder, paginatorOptions, thread, }: MessagePaginatorOptions, builtInDefaults?: Partial<BasePaginatorConfig<LocalMessage, MessageQueryShape>>);
162
193
  /**
163
- * Memoized so every derivation sees the *same* two functions. `initializeConfig` folds this into the
164
- * config it publishes and skips the publish when nothing moved — which only works if these references
165
- * are stable.
166
- *
167
- * Safe to build once: both close over `this` and read `_itemOrder`, which is assigned in the
168
- * constructor and has no setter.
194
+ * Memoized: `initializeConfig` folds it in and skips the publish when nothing moved, which needs
195
+ * stable references. Safe to build once: `_itemOrder` is set in the constructor, with no setter.
169
196
  */
170
197
  private intervalBehaviour?;
171
198
  private buildIntervalBehaviour;
172
199
  /**
173
- * Cursor derivation and in-memory item ordering, which this class installs on `config` rather than
174
- * passing as constructor options.
175
- *
176
- * Contributed to the base derivation rather than written after it — see
177
- * {@link BasePaginator.getBehaviourOverrides}. That is what keeps one re-derivation to one publish,
178
- * and stops the intermediate publish that had these two stripped.
200
+ * Installs cursor derivation and item ordering on `config` through the base derivation
201
+ * ({@link BasePaginator.getBehaviourOverrides}), so one re-derivation is one publish.
179
202
  */
180
203
  protected getBehaviourOverrides(): Partial<BasePaginatorConfig<LocalMessage, MessageQueryShape>>;
181
204
  /**
182
- * The constructor's route to the same overlay. Deliberately calls the private builder rather than the
183
- * overridable hook: this runs inside the constructor, and a subclass override would execute before its
184
- * own fields were initialized.
205
+ * The constructor's route to the same overlay. It calls the private builder, not the overridable
206
+ * hook, which would run a subclass override before its fields are initialized.
185
207
  */
186
208
  protected installIntervalBehaviour(): void;
187
209
  get id(): string;
188
210
  get sort(): MessagePaginatorSort;
189
211
  get requestSort(): MessagePaginatorSort;
190
212
  get itemOrder(): MessagePaginatorSort;
191
- /**
192
- * Even though we do not send filters object to the server, we need to have filters for client-side item ingestion logic.
193
- */
213
+ /** Not sent to the server: drives client-side item ingestion. */
194
214
  buildMatchFilters: () => MessagePaginatorFilter;
195
215
  protected getNextQueryShape({ direction, }: Omit<PaginationQueryParams<MessageQueryShape>, 'isFirstPageQuery'>): MessageQueryShape;
196
216
  getCursorFromQueryResults: ({ direction, items, }: {
@@ -200,168 +220,430 @@ export declare class MessageIntervalPaginator extends BasePaginator<LocalMessage
200
220
  tailward: string | undefined;
201
221
  headward: string | undefined;
202
222
  };
203
- query: ({ direction, }: PaginationQueryParams<MessageQueryShape>) => Promise<PaginationQueryReturnValue<LocalMessage>>;
204
223
  /**
205
- * Seed the paginator with the page a channel-open query just fetched (`Channel.query` for
206
- * `watch`/`create`, and `client.hydrateActiveChannels`).
224
+ * Runs the query pipeline (see `BasePaginator.executeQuery`). A query that goes to the channel —
225
+ * not a thread's reply list, not a custom `doRequest` — runs as a tracked query of the channel
226
+ * (`Channel.runTrackedQuery`), so the channel store keeps the channel until the query ends. A
227
+ * disposed channel's query is not tracked: its fetch step is refused, and fails as any failed
228
+ * request does.
229
+ */
230
+ executeQuery(params?: PaginationQueryParams<MessageQueryShape>): Promise<ExecuteQueryReturnValue<LocalMessage> | void>;
231
+ /**
232
+ * The fetching step of the query pipeline: requests a page through a custom `doRequest`, the
233
+ * replies endpoint for a thread's reply list, or the channel query otherwise, which takes in what
234
+ * the response says about the channel itself and leaves the rest for the last step (see
235
+ * `Channel.requestChannelState`). Reads `requestOptions.watch`: `true` also watches the channel
236
+ * with the request. Ignored for a thread's reply list and with `doRequest`.
237
+ */
238
+ protected fetchQueryResponse: ({ direction, queryShape, requestOptions, }: PaginationQueryParams<MessageQueryShape>) => Promise<MessageQueryResponse>;
239
+ /**
240
+ * The extracting step of the query pipeline: the messages in item order and their cursors, which
241
+ * a custom `doRequest` reports and which are derived from the messages otherwise.
242
+ */
243
+ protected extractQueryPage(response: MessageQueryResponse, { direction }: PaginationQueryParams<MessageQueryShape>): PaginationQueryReturnValue<LocalMessage>;
244
+ /**
245
+ * The last step of the query pipeline: the rest of a channel query's response, applied once its
246
+ * page is placed (see `Channel.applyChannelStateFromResponse`). The other sources return nothing
247
+ * else.
248
+ */
249
+ protected applyQueryResponseRest(response: MessageQueryResponse, _placeParams: QueryPagePlacement<MessageQueryShape>): void;
250
+ /**
251
+ * Whether this paginator is active: the thread it lists is active (see `Thread.activate()`), or,
252
+ * without a thread, its channel is (see `Channel.activate()`). A page from a query an active
253
+ * paginator did not run leaves its active interval active; an inactive paginator shows a fresh
254
+ * newest page instead, also one separated from the loaded messages by a gap (see
255
+ * {@link reconcileNewestMessages}).
256
+ */
257
+ private isActivePaginator;
258
+ /**
259
+ * Places a page from an external query — one this paginator did not run, whose page the caller
260
+ * chose — in the intervals it belongs to, never removing anything loaded. Bringing the loaded
261
+ * newest messages up to date with a fresh newest page, removals included, is
262
+ * {@link reconcileNewestMessages}'s job instead.
263
+ *
264
+ * External queries are a channel query (`watch()`, see {@link prepareExternalQuery}), the
265
+ * channel list's query (`client.hydrateChannels`), and the channel state the pinned list's first
266
+ * page comes with. `messagePaginationParams` are the
267
+ * options the page was queried with; they decide where it goes:
268
+ *
269
+ * - The newest page: when no interval is active yet (nothing loaded, or only live messages), its
270
+ * interval becomes the active one, as the channel's first page. When the active interval is the
271
+ * newest interval, the page lands in it.
272
+ * - Any other page — a page at a cursor or around a message, or the newest page while an older
273
+ * interval is active — is only stored, as a separate interval merged only with an interval it
274
+ * overlaps.
275
+ *
276
+ * The active interval stays active: changing it is this paginator's own methods' job
277
+ * (`jumpToMessage()` and the like). The exception is an inactive paginator (see
278
+ * {@link isActivePaginator}), where the newest page is shown as when no interval is
279
+ * active. A newest
280
+ * page for loaded messages goes to {@link reconcileNewestMessages} instead
281
+ * (`prepareExternalQuery`, the channel list's query). When a page lands in the active interval,
282
+ * overlaps it, or takes in an active interval of live messages only, that interval is shown again
283
+ * with the page. The paginator's own queries are left alone too: a running one keeps its loading
284
+ * flag, and its last query error and query shape stay.
207
285
  *
208
- * These paths hydrate the channel read state in the SAME synchronous tick they add messages
209
- * (`Channel._initializeState`), and the read patch drives `MessageReceiptsTracker`, which resolves
210
- * read/delivered cursors against this paginator (`findItemByTimestamp`) whenever the server omits
211
- * the `last_read_message_id` / `last_delivered_message_id`. `postQueryReconcile` is fully
212
- * synchronous (filtering is a local predicate), so seeding here guarantees the paginator is
213
- * populated before the reconcile runs. First-page reconciliation also takes the unread snapshot.
286
+ * It runs synchronously, so a caller can apply the rest of the response right after with the page
287
+ * in place, as it has to: read and delivery positions that come without a message id are looked
288
+ * up among the loaded messages.
214
289
  *
215
- * The fetched page is NOT always the latest window: a channel can be opened AROUND a message
216
- * (`messages: { id_around }` / `{ created_at_around }`), so the original pagination options are
217
- * threaded through as the query shape. For an around/jump open this lets `postQueryReconcile`
218
- * apply jump semantics (no forced head/tail; cursor flags derived from the around position)
219
- * instead of wrongly flagging the window as the head (newest) page.
290
+ * Returns whether it showed the page as a first page.
220
291
  */
221
- seedFirstPageSync(messages: LocalMessage[], requestedPageSize: number, messagePaginationOptions?: MessagePaginationParams, options?: SeedFirstPageOptions): void;
292
+ placeExternalQueryPage(page: LocalMessage[], requestedPageSize: number, messagePaginationParams?: MessagePaginationParams): boolean;
293
+ /**
294
+ * Whether messages are loaded for {@link reconcileNewestMessages} to bring up to date. A list
295
+ * loaded empty has none (no interval, not even live messages), so a fresh newest page is placed
296
+ * as a first page instead ({@link placeExternalQueryPage}); reconciling would find nothing to
297
+ * merge it into and drop it.
298
+ */
299
+ get canReconcileNewestMessages(): boolean;
300
+ /**
301
+ * The snapshot a newest page is reconciled against (see
302
+ * {@link ReconcileNewestMessagesOptions.headIntervalItemIdsAtRequest}): the IDs of the head
303
+ * interval's server-confirmed messages. Take it right before the request goes out. Unsent messages
304
+ * are left out: one confirmed during the request proves neither that the page connects to the
305
+ * head interval nor, when the page lacks it, that it was deleted. `undefined` while no head
306
+ * interval is loaded.
307
+ *
308
+ * @internal
309
+ */
310
+ getHeadIntervalItemIdsAtRequest(): ReadonlySet<string> | undefined;
311
+ /**
312
+ * Whether the loaded message with this ID is server-confirmed
313
+ * (see {@link isServerConfirmedMessage}).
314
+ */
315
+ private isServerConfirmedItemId;
316
+ /**
317
+ * Prepares an external query for a page of these messages: the watch query the channel sends
318
+ * (`channel.watch()`, `channel.reload()`) with the `messages` options its caller gave. Call it
319
+ * before sending the query, and place the returned page with `placePage` before the response's
320
+ * read state is applied: the read state is resolved against the loaded messages.
321
+ *
322
+ * - `messagePaginationParams`: the options to send as the query's `messages`, with `limit` set to
323
+ * the page size when not given.
324
+ * - `isNewestPage`: whether the query asks for the newest page — no cursor, not around a message,
325
+ * and some messages.
326
+ * - `placePage`: places the returned page. The newest page goes to
327
+ * {@link placeExternalNewestPage}, reconciled against the messages loaded when the query was
328
+ * prepared; any other page is placed by {@link placeExternalQueryPage}. A query for no messages
329
+ * (`limit: 0`) places nothing. Returns whether it showed a first page.
330
+ */
331
+ prepareExternalQuery(messages?: MessagePaginationParams): PreparedExternalQuery;
332
+ /**
333
+ * Places the newest page of an external query (a channel query, the channel list's query): it
334
+ * reconciles the loaded newest messages ({@link reconcileNewestMessages}), or is placed as a
335
+ * first page when none are loaded ({@link placeExternalQueryPage}). A query for no messages
336
+ * (`requestedLimit: 0`) places nothing. Returns whether it showed a first page.
337
+ *
338
+ * @internal
339
+ */
340
+ placeExternalNewestPage(page: LocalMessage[], { headIntervalItemIdsAtRequest, requestedLimit, }: ReconcileNewestMessagesOptions & {
341
+ requestedLimit: number;
342
+ }): boolean;
222
343
  isJumpQueryShape(queryShape: MessageQueryShape): boolean;
223
- jumpToMessage: (messageId: string, { focusReason, focusSignalTtlMs, pageSize, suppressFocusSignal, }?: JumpToMessageOptions) => Promise<boolean>;
344
+ /** Only a query without a cursor and not around a message returns the newest page. */
345
+ protected isHeadPageQueryShape(queryShape: MessageQueryShape | undefined): boolean;
346
+ /** A jump sends its own `limit`: head/tail flags are derived against it, not `pageSize`. */
347
+ protected getRequestedPageSize(queryShape: MessageQueryShape | undefined): number;
348
+ /**
349
+ * Makes the interval holding the message the active one, querying the page around it when it is
350
+ * not loaded. Resolves `false` when the message cannot be shown, or when a later claim on the
351
+ * active interval (see `claimActiveInterval`) was made before the page arrived.
352
+ */
353
+ jumpToMessage: (messageId: string, { focusReason, focusSignalTtlMs, pageSize, suppressFocusSignal, watchChannel, }?: JumpToMessageOptions) => Promise<boolean>;
354
+ /**
355
+ * Shows a loaded interval as it is: its items, its own pagination flags and the cursor continuing
356
+ * it. Claiming the active interval is the caller's choice (see `claimActiveInterval`).
357
+ */
358
+ protected showLoadedInterval(interval: Interval): void;
359
+ /** Makes `interval` the active interval and publishes `state` for it in one update. */
360
+ private showInterval;
361
+ /**
362
+ * Shows the interval holding the latest message and jumps to that message. Without a loaded head
363
+ * interval (see {@link latestHeadInterval}), the newest page is queried first: no cursor, so it
364
+ * holds the latest message however many pages are missing. The page merges with an interval it
365
+ * overlaps and is an interval of its own otherwise, and is shown either way. Resolves `false` when
366
+ * the latest message cannot be shown, or when a later claim on the active interval (see
367
+ * `claimActiveInterval`) was made before the page arrived: that page is then only stored.
368
+ */
224
369
  jumpToTheLatestMessage: (options?: JumpToMessageOptions) => Promise<boolean>;
225
370
  /**
226
- * Fold an already fetched newest (head) page into the currently loaded items without issuing a
227
- * query. The caller supplies a page it obtained on its own and this reconciles it against what is
228
- * loaded, instead of rerunning the first page query, so the loaded set is updated in place rather
229
- * than blanked and reloaded. Two cases, decided by whether the incoming page overlaps the loaded
230
- * head:
231
- *
232
- * 1. OVERLAP - the incoming page shares at least one id with the loaded head (fewer than a full
233
- * page is new). Merge in place: existing items are reconciled by id (edits, soft deletes), new
234
- * items are appended and every already loaded item (including older pages already paged in) is
235
- * kept. The tail boundary (`hasMoreTail`/`cursor.tailward`) is set from whether the page reached
236
- * the channel start ({@link pageReachedChannelStart}): a bounded page that came back short means
237
- * no more older, otherwise "load older" stays enabled and the cursor re-anchors to the true loaded
238
- * oldest (which also clears a stale offline-DB cursor). Then destructive reconciliation
239
- * ({@link reconcileHeadAgainstPage}) removes any loaded message
240
- * that the authoritative page proves was hard-deleted while offline (see that method + the
241
- * {@link MergeNewestPageOptions} for the exact, safe window).
242
- *
243
- * 2. DISJOINT - the incoming page shares no id with the loaded head (at least a full page is new).
244
- * Merging would weld the two across the gap (the interval merge treats two head intervals as
245
- * overlapping when one reaches further headward), hiding the items in between with no way to
246
- * reach them. Instead the loaded set is discarded and rebuilt from the incoming page as a fresh
247
- * contiguous head (`hasMoreTail: true`, cursor reanchored to the page's oldest item) so the
248
- * gap and older history load again when paginating older. No separate reconciliation is needed:
249
- * the rebuilt window IS the server truth, so any hard-deleted message is simply absent from it.
250
- *
251
- * Never blanks the loaded set. Noop unless the newest slice is both loaded AND the interval
252
- * currently in view (the head interval is anchored at the head and active); when the caller has
253
- * jumped to a separate older window the merge is skipped so their position is preserved, and the
254
- * incoming page is picked up on a later load. An empty page never wipes the list on its own, but
255
- * — given a pre-fetch snapshot via `options.candidateIds` — is reconciled as "the channel has no
256
- * messages" (every server-confirmed loaded message removed).
257
- *
258
- * @param page - The fetched newest window (may be empty). `created_at` order is normalized on ingest.
259
- * @param options - See {@link MergeNewestPageOptions}. Omit to prune only within the page's own span.
260
- */
261
- mergeNewestPage: (page: LocalMessage[], options?: MergeNewestPageOptions) => void;
262
- /**
263
- * Whether `page` proves it reached the channel's own oldest message: the caller's request was
264
- * bounded by this paginator's OWN `pageSize` AND `page` came back shorter than that request.
265
- *
266
- * `pageSize <= the server's max page size` is already the invariant normal pagination
267
- * (`executeQuery`) relies on — `page.length < pageSize` ⟹ reached the end — so a request no larger
268
- * than `pageSize` returns exactly what was asked unless the channel ended. This needs no hardcoded
269
- * max page size and is per-paginator, so a thread reply paginator uses its own `pageSize`.
270
- *
271
- * An OVER-request (larger than `pageSize`, e.g. `channel.reload` re-fetching the whole loaded window
272
- * to reconcile as much as possible) may have been silently capped by the server, so a short page
273
- * there is NOT proof of reaching the start — return `false` and stay conservative. This only ever
274
- * gates the `hasMoreTail` affordance; it never removes a message.
371
+ * The head interval when it is the newest loaded interval, so its newest message is the latest
372
+ * one; `undefined` while no head interval is loaded or live messages newer than it are.
373
+ */
374
+ private get latestHeadInterval();
375
+ /**
376
+ * Reconciles the loaded newest messages with a fresh newest page, without issuing a query: they
377
+ * are brought up to date in place — messages added and updated, those the page proves were
378
+ * hard-deleted removed — rather than blanked and reloaded. The page comes from an external query
379
+ * (a reload, a channel-list query, connection recovery). In an active paginator (see
380
+ * {@link isActivePaginator}) the active interval stays active, the head interval included
381
+ * (changing it is `jumpToTheLatestMessage()`'s job); in an inactive one, the head interval is
382
+ * shown.
383
+ *
384
+ * Where the page goes depends on the head interval, the loaded interval reaching the newest
385
+ * message:
386
+ *
387
+ * 1. NO HEAD INTERVAL (only live messages, a jumped-to interval, or a cleared head mark, see
388
+ * {@link unmarkHead}) - the page becomes the head interval, merging with the intervals it
389
+ * overlaps, live messages included, minus what it proves was hard-deleted. It is shown if the
390
+ * live messages it absorbed were active; an active interval that it overlaps grows. A
391
+ * page separated by a gap from the interval whose head mark was cleared is placed as in 2.
392
+ *
393
+ * 2. SEPARATED BY A GAP (see {@link isSeparatedFromHeadByGap}) - merging would weld the two
394
+ * across the gap, hiding the messages in between, so the page takes the place of the head
395
+ * interval (see {@link placeNewestPageAcrossGap}): stored beside the active interval when that
396
+ * is an older interval, shown in place of the loaded intervals otherwise.
397
+ *
398
+ * 3. OTHERWISE - the page merges into the head interval, which keeps every loaded message and
399
+ * drops what the page proves was hard-deleted (see {@link reconcileHeadAgainstPage}). An
400
+ * active head interval gets its tail boundary from the page (see {@link showHeadInterval});
401
+ * otherwise the active interval stays active, and grows into the head interval if the page
402
+ * overlaps it.
403
+ *
404
+ * Only a gap drops loaded intervals, never an older active interval, and with nothing loaded it
405
+ * does nothing: placing a first page is {@link placeQueryPage}'s job. An empty page changes
406
+ * nothing on its own but, given a pre-fetch snapshot (`options.headIntervalItemIdsAtRequest`), is
407
+ * reconciled as "the channel has no messages": every server-confirmed message of the head interval
408
+ * is removed.
409
+ *
410
+ * The query shape of the loaded interval is recorded on every exit (see
411
+ * `recordLoadedIntervalQueryShape`): an interval left without one loses itself on the next
412
+ * pagination.
413
+ *
414
+ * @param page - The fetched newest interval (may be empty). `created_at` order is normalized on
415
+ * ingest.
416
+ * @param options - See {@link ReconcileNewestMessagesOptions}. Omit to prune only within the
417
+ * page's own span.
418
+ */
419
+ reconcileNewestMessages: (page: LocalMessage[], options?: ReconcileNewestMessagesOptions) => void;
420
+ private _reconcileNewestMessages;
421
+ /**
422
+ * Shows the head interval a fresh newest page merged into, with no newer messages to load. It has
423
+ * older ones unless the page reached the channel start (see {@link pageReachedChannelStart});
424
+ * `isTail` follows, which also clears a stale offline-DB `isTail: true` that would let
425
+ * `intervalsOverlap` weld a far page across a gap.
426
+ */
427
+ private showHeadInterval;
428
+ /**
429
+ * Whether a fresh newest page and the head interval (or the interval whose head mark was cleared,
430
+ * see {@link unmarkedHeadInterval}) are separated by a gap, with messages between them possibly
431
+ * not loaded. They are not when the two together form one unbroken stretch of the channel:
432
+ *
433
+ * - the page starts inside the head interval (see {@link pageStartsInsideHead});
434
+ * - the page covers the head interval (see {@link pageCoversHead});
435
+ * - the page reached the channel start (see {@link pageReachedChannelStart}), so nothing older
436
+ * than it exists to be missing.
437
+ *
438
+ * Sharing a message is not enough on its own: a message the user sent while offline is confirmed
439
+ * by the server before the reconnect's newest page is requested, so it sits at the top of the
440
+ * head interval and in the page, with the messages missed below it in neither. For example, the
441
+ * interval holds m1–m100 and the user's queued "hello"; the server got m101–m210 meanwhile. A page
442
+ * of 25 holds m187–m210 and "hello": it does not start inside the interval (m187 was never loaded)
443
+ * nor cover it (m1 is not in it), so it is past a gap. When the user wrote the last 10 loaded
444
+ * messages and others sent 20 since, a page of 25 holds the user's last 5 and the 20 new ones:
445
+ * its oldest was loaded, so it starts inside the interval.
446
+ *
447
+ * A message missed while the socket was down comes with connection recovery's newest page.
448
+ */
449
+ private isSeparatedFromHeadByGap;
450
+ /**
451
+ * Whether the page's oldest message the head interval could hold (see
452
+ * {@link getPageOldestHoldableMessage}) was in the head interval when the request went out. The
453
+ * page runs unbroken from that message to the newest and the interval is taken to run unbroken
454
+ * below it, so nothing between them is missing.
455
+ *
456
+ * With a snapshot of the request (`options.headIntervalItemIdsAtRequest`), the message must be
457
+ * in it and held by no interval other than the head interval: a message that reached the interval
458
+ * during the request, live or as a send confirmed meanwhile, may sit above messages the interval
459
+ * never loaded. One no longer loaded at all still counts: if the head interval holds messages
460
+ * older than it, the interval ran unbroken through it and it was removed (e.g. hard-deleted);
461
+ * if not, the page covers the interval anyway. Without a snapshot, the message must be in the
462
+ * head interval and server-confirmed now.
463
+ *
464
+ * The interval is not unbroken below a send the server confirmed while the channel received no
465
+ * events, such as one replayed from the offline queue before the reconnect's newest page is
466
+ * requested. If that send is exactly the page's oldest (as many newer messages as the page has
467
+ * room for were sent after it), the page is taken to start inside the interval although messages
468
+ * below the send were missed. The page and the interval cannot tell this apart from a send
469
+ * confirmed while events were arriving.
470
+ */
471
+ private pageStartsInsideHead;
472
+ /**
473
+ * Whether the page spans the whole head interval: the interval holds no server-confirmed message
474
+ * older than the page. What the interval holds beyond the page is newer (it arrived as an event
475
+ * after the page was produced) or unsent (it carries the device's clock).
476
+ */
477
+ private pageCoversHead;
478
+ /**
479
+ * The page's oldest message that the head interval could have loaded: server-confirmed and kept
480
+ * in intervals (see {@link filterQueryResults}). A message the interval filters out, such as a
481
+ * shadowed one, would never be found in it. {@link pageCoversHead} compares with the page's
482
+ * oldest message of any kind instead: it only needs the page's span.
483
+ */
484
+ private getPageOldestHoldableMessage;
485
+ /**
486
+ * The interval whose head mark was cleared last (see {@link unmarkHead}), while it is still
487
+ * loaded. It reached the newest message until then, so a newest page is judged against it while
488
+ * no head interval is loaded.
489
+ */
490
+ private get unmarkedHeadInterval();
491
+ /**
492
+ * Remembers the interval by a message that stays in it: a server-confirmed one, as an unsent one
493
+ * may be deleted or retried; the raw newest item only when the interval holds none.
494
+ */
495
+ protected unmarkHead(interval: Interval): void;
496
+ protected clearItemStorage(): void;
497
+ resetState(): void;
498
+ private getPageOldestMessage;
499
+ /**
500
+ * Places a fresh newest page separated by a gap from `headInterval` (the head interval, or the
501
+ * interval whose head mark was cleared, see {@link isSeparatedFromHeadByGap}). The page becomes
502
+ * the head interval either way, and the intervals nothing brought up to date are dropped, as a
503
+ * message deleted meanwhile would come back with them:
504
+ *
505
+ * - an active interval other than the head interval (see {@link getActiveIntervalApartFromHead})
506
+ * stays active, and the page is stored beside it (see
507
+ * {@link storeNewestPageBesideActiveInterval});
508
+ * - otherwise the page replaces the loaded intervals and is shown (see
509
+ * {@link replaceIntervalsWithNewestPage}).
510
+ */
511
+ private placeNewestPageAcrossGap;
512
+ /**
513
+ * The active loaded interval when it is not `headInterval`, such as an interval jumped to;
514
+ * `undefined` when `headInterval` or live messages only are active, and in an inactive paginator
515
+ * (see {@link isActivePaginator}).
516
+ */
517
+ private getActiveIntervalApartFromHead;
518
+ /**
519
+ * Replaces the loaded intervals with a fresh newest page separated from the head interval by a gap
520
+ * (see {@link placeNewestPageAcrossGap}) and shows it. The page's interval keeps the loaded
521
+ * messages that must not be lost (see {@link getMessagesKeptAcrossGap}) and has older messages
522
+ * to load.
523
+ */
524
+ private replaceIntervalsWithNewestPage;
525
+ /**
526
+ * Stores a fresh newest page separated from the head interval by a gap (see
527
+ * {@link placeNewestPageAcrossGap}) as the head interval, beside `activeInterval`, which stays
528
+ * active and shown as it is. Every other loaded interval is dropped and loads again on
529
+ * demand. The page's interval keeps the messages of the dropped intervals that must not be lost
530
+ * (see {@link getMessagesKeptAcrossGap}) and has older messages to load.
531
+ *
532
+ * The active interval keeps all its messages, unsent ones included, so nothing moves in the
533
+ * shown list, and it is not brought up to date: a message deleted or edited meanwhile stays as it was
534
+ * loaded. It can load newer messages, up to the head interval it then joins.
535
+ */
536
+ private storeNewestPageBesideActiveInterval;
537
+ /**
538
+ * Ingests a fresh newest page placed across a gap, with `keptMessages`, as the head interval,
539
+ * which has older messages to load, and removes from it what the page proves was hard-deleted (see
540
+ * {@link reconcileHeadAgainstPage}). Returns the interval the page landed in.
541
+ */
542
+ private ingestPageAsHeadInterval;
543
+ /**
544
+ * Drops `intervals` from storage and releases their messages, except those with `keepingIds`,
545
+ * which the caller ingests again.
546
+ */
547
+ private dropIntervals;
548
+ /**
549
+ * Marks the active interval, which does not reach the newest message, as able to load newer
550
+ * messages. Publishes the flag and cursor only when they changed, so the interval shown stays as
551
+ * it is.
552
+ */
553
+ private markActiveIntervalBelowHead;
554
+ /**
555
+ * The messages of `intervals`, missing from a newest page placed across a gap, that the page's
556
+ * interval keeps:
557
+ *
558
+ * - unsent messages (see {@link isServerConfirmedMessage});
559
+ * - messages from the page's oldest on: those that arrived during the request stay, and
560
+ * reconciling removes those the page proves were hard-deleted.
561
+ */
562
+ private getMessagesKeptAcrossGap;
563
+ /**
564
+ * Merges a fresh newest page, not separated by a gap, into the head interval while another
565
+ * interval is shown. That interval stays active and grows into the head interval if the page
566
+ * overlaps it. In an inactive paginator (see {@link isActivePaginator}), the head interval is
567
+ * shown instead.
568
+ */
569
+ private mergePageIntoInactiveHead;
570
+ /** Publishes the active interval once a newest page grew it into the head interval. */
571
+ private publishActiveIntervalGrownIntoHead;
572
+ /**
573
+ * Whether `page` proves it reached the channel's oldest message: the request was bounded by this
574
+ * paginator's own `pageSize` and `page` came back shorter. A larger over-request (e.g.
575
+ * `channel.reload`) may have been server-capped and never proves it. Gates `hasMoreTail` and the
576
+ * gap rule ({@link isSeparatedFromHeadByGap}), never removing a message.
275
577
  */
276
578
  private pageReachedChannelStart;
277
579
  /**
278
- * Settle the below-window leftovers {@link reconcileHeadAgainstPage} handed back (loaded messages
279
- * older than `anchorId` — the returned page's oldest — and absent from the page). From the page alone
280
- * they're ambiguous: a hard-deleted oldest vs a server-capped over-request. Ask the server "anything
281
- * older than `anchorId`?" — the only cap-free way to tell. Nothing older ⇒ genuine deletes ⇒ remove
282
- * them and settle the tail. A probe failure or a head change across the await keeps them (never a false
283
- * delete). The caller decides WHEN this runs.
580
+ * Settles the loaded messages {@link reconcileHeadAgainstPage} found tailward of the page (older
581
+ * than `pageTailId`, the page's oldest, and absent from it): from the page alone a hard-deleted
582
+ * oldest message looks like one the page was too short to include. It asks the server whether
583
+ * anything is older than `pageTailId`. When nothing is, those messages were deleted: they are
584
+ * removed and the head interval becomes the tail. A failed request, or a head interval replaced
585
+ * while waiting, keeps them. The caller decides when this runs.
284
586
  */
285
- private pruneBelowWindowIfReachedStart;
587
+ private removeIdsTailwardOfPageIfNothingOlder;
286
588
  /** One `limit: 1` fetch of messages older than `id` (channel main list or thread replies). */
287
589
  private hasMessagesOlderThan;
288
590
  /**
289
- * Whether a loaded message is server-confirmed and therefore eligible to be reconciled away when
290
- * absent from an authoritative page. Excludes local-only messages the server has never
291
- * acknowledged — optimistic (`sending`) and `failed` sends, and client-side `error` placeholders —
292
- * so a legitimately-unsent message is never mistaken for a hard delete.
591
+ * Whether a loaded message is server-confirmed, so it may be reconciled away when absent from an
592
+ * authoritative page. Optimistic (`sending`), `failed` and client-side `error` messages are not, so
593
+ * an unsent message is never mistaken for a hard delete.
293
594
  */
294
595
  protected isServerConfirmedMessage(message: LocalMessage): boolean;
295
596
  /**
296
- * Destructive half of {@link mergeNewestPage}: remove messages in the loaded head interval that
297
- * `page` proves were hard-deleted while offline (a hard delete emits no event to other clients, and
298
- * the merge is additive, so they would otherwise linger forever).
299
- *
300
- * Here `page` is the freshly-fetched newest window the server returned for the query that produced
301
- * it. Its two bounds are its NEWEST message (`page`'s last item by `created_at`) and its OLDEST
302
- * message (`page`'s first item). Reconciliation removes ONLY messages `page` actually covers — no
303
- * hardcoded page size is involved — in two regions, by a loaded message's `created_at`:
304
- *
305
- * - WITHIN `page` (strictly between `page`'s oldest and newest message): a server-confirmed loaded
306
- * message absent from `page` was hard-deleted. Safe with no snapshot — a message that arrived live
307
- * during the caller's fetch is always strictly newer than `page`'s newest message, so it can never
308
- * fall in this span.
309
- * - AT/ABOVE `page`'s newest message (a hard-deleted newest message), and the empty-`page` case:
310
- * only reconcilable with a pre-fetch `candidateIds` snapshot, which alone tells a just-deleted
311
- * message from one that arrived live during the fetch at that top edge.
312
- *
313
- * A loaded message BELOW `page`'s oldest is NOT removed here (window-only) — from the page alone a
314
- * hard-deleted oldest is indistinguishable from a server-capped over-request. Those messages are
315
- * instead RETURNED (the below-window leftovers) so {@link pruneBelowWindowIfReachedStart} can settle
316
- * them with a `limit: 1` "anything older?" probe — the only cap-free proof — and remove them only if
317
- * the server confirms nothing older exists. Absent that proof they are kept (a later cold/fresh query
318
- * omits any real delete).
319
- *
320
- * Removal goes through {@link removeItem} (batched) so the item index, intervals, shared message
321
- * store and — via the {@link MessagePaginator} override — the tracked last message all stay correct;
322
- * the active window is then re-emitted once.
323
- *
324
- * @returns the below-window leftover ids (loaded, server-confirmed, older than `page`'s oldest, absent
325
- * from it) for the caller's reached-start probe. Empty for the no-head / empty-page paths.
326
- */
327
- protected reconcileHeadAgainstPage(page: LocalMessage[], options?: MergeNewestPageOptions): string[];
328
- /**
329
- * Remove a set of reconciled (hard-deleted) ids from this paginator's loaded state in one coalesced
330
- * batch. Each id goes through {@link removeItem}, which drops it from THREE places — not a single
331
- * interval:
332
- *
333
- * 1. the item index — unlinks this paginator's membership from the shared entity store (GC'ing the
334
- * content if this was the last holder);
335
- * 2. the interval that holds it — located by id, so it is NOT head-specific in general; in practice
336
- * it is always the head interval, because the sole caller ({@link reconcileHeadAgainstPage})
337
- * sources these ids from `headInterval.itemIds` and an item has single-interval membership;
338
- * 3. the active window (`state.items`) if visible — blanking to `[]` when the window empties, per
339
- * {@link flushWindowPublish}.
340
- *
341
- * The coalesced batch collapses all of that into a single `state.items` publish. Then mirror the
342
- * removal into the offline DB (see {@link purgeReconciledFromOfflineDb}) so a cold start does not
343
- * re-seed the ghosts from SQLite. No-op for an empty set, so an unaffected merge does not touch
344
- * state a second time.
597
+ * Whether this list holds `message`: it passes the filter and, in a channel's main list (no
598
+ * `parentMessageId`), is not a reply only its thread lists (see `isThreadOnlyReply`).
345
599
  */
346
- private removeReconciledItems;
600
+ private isListedMessage;
347
601
  /**
348
- * Mirror a destructive reconciliation into the offline DB. A hard delete performed while the client
349
- * was offline reaches it via no event, so the offline store never ran its own hard-delete for these
350
- * ids; the reconnect query re-hydrates the DB by UPSERT (which never removes what is absent from the
351
- * page), so without this the ghosts survive in SQLite and a cold start would re-seed them after the
352
- * in-memory list already dropped them.
602
+ * The failed messages a reload restores with {@link restoreFailedMessages}: those of the shown
603
+ * interval and the head interval, and those of `persisted` (e.g. the offline database's rows of
604
+ * the channel) this list holds (see {@link isListedMessage}). The loaded copy wins, as it is at
605
+ * least as fresh. Take them before the reload's request.
606
+ *
607
+ * @internal
608
+ */
609
+ getFailedMessagesToRestore(persisted?: LocalMessage[]): LocalMessage[];
610
+ /**
611
+ * Ingests again each failed message taken before a reload (see
612
+ * {@link getFailedMessagesToRestore}) that no interval holds after it, so a reload never loses the
613
+ * user's unsent work. One an interval holds is left as it is: it may have been resent.
614
+ *
615
+ * @internal
616
+ */
617
+ restoreFailedMessages(failedMessages: LocalMessage[]): void;
618
+ /**
619
+ * Destructive half of {@link reconcileNewestMessages}: removes loaded head-interval messages
620
+ * that `page` (the fresh newest interval) proves were hard-deleted while the client received no
621
+ * events, by `created_at`:
622
+ *
623
+ * - within `page`'s span: a server-confirmed message absent from `page` was deleted (a live
624
+ * arrival is newer than `page`'s newest, so this needs no snapshot);
625
+ * - at or above `page`'s newest, and for an empty `page`: only IDs in the pre-fetch
626
+ * `headIntervalItemIdsAtRequest` snapshot, which tells a just-deleted message from a live
627
+ * arrival or a send confirmed during the request.
628
+ *
629
+ * Messages below `page`'s oldest are kept (a hard-deleted oldest looks like a server-capped
630
+ * over-request) and returned for {@link removeIdsTailwardOfPageIfNothingOlder}. Removal goes through
631
+ * {@link removeItem}, so the index, intervals, message store and any subclass bookkeeping (e.g.
632
+ * the latest message of {@link MessagePaginator}) stay correct.
353
633
  *
354
- * Owned by the state layer, NOT the SDK: the SDK only supplies the platform `offlineDb`
355
- * implementation and never orchestrates DB writes for reconciliation. Fire-and-forget and
356
- * best-effort — the in-memory removal is the source of truth for the live list, so a failed/absent
357
- * DB write is no worse than before (the ghost merely re-appears on a cold start until the next
358
- * reconcile). No-op when offline support is off (`client.offlineDb` undefined). The ids are already
359
- * server-confirmed (the reconcile excludes pending/failed/optimistic), so a plain hard delete —
360
- * without the pending-task teardown of a local failed message — is correct.
634
+ * @returns The below-interval leftover IDs. Empty for the no-head and empty-page paths.
635
+ */
636
+ protected reconcileHeadAgainstPage(page: LocalMessage[], options?: ReconcileNewestMessagesOptions): string[];
637
+ /** Removes reconciled IDs in one coalesced batch (one publish), then mirrors it offline. */
638
+ private removeReconciledItems;
639
+ /**
640
+ * Mirrors a reconciliation into the offline DB: a hard delete done while offline reaches it via no
641
+ * event and the reconnect query upserts (never removing absent rows), so a cold start would re-seed
642
+ * the ghosts. Fire-and-forget, no-op without offline support.
361
643
  */
362
644
  private purgeReconciledFromOfflineDb;
363
645
  protected resolveUnreadBoundaryIdsByTimestamp: ({ lastReadAt, messages, }: {
364
- lastReadAt: Date;
646
+ lastReadAt: TimestampNS;
365
647
  messages: LocalMessage[];
366
648
  }) => {
367
649
  firstUnreadMessageId: string | null;
@@ -373,10 +655,9 @@ export declare class MessageIntervalPaginator extends BasePaginator<LocalMessage
373
655
  ttlMs?: number;
374
656
  }) => MessageFocusSignal;
375
657
  /**
376
- * Starts the auto-dismissal countdown for the currently active focus signal. Call this once the
377
- * focused message has been viewed (rendered and visible), so the highlight's lifetime is measured
378
- * from when the user could actually see it rather than from when the jump resolved. No-op if the
379
- * signal has already been cleared or superseded (guarded by `token`).
658
+ * Starts the auto-dismiss countdown for the active focus signal. Call it once the focused message
659
+ * is viewed, so the highlight lasts from when the user could see it. No-op if the signal was
660
+ * cleared or superseded (guarded by `token`).
380
661
  */
381
662
  scheduleMessageFocusSignalClear: ({ token, ttlMs, }?: {
382
663
  token?: number;
@@ -387,92 +668,60 @@ export declare class MessageIntervalPaginator extends BasePaginator<LocalMessage
387
668
  }) => void;
388
669
  clearStateAndCache(): void;
389
670
  /**
390
- * Partial truncation for `channel.truncated` carrying a `truncated_at`: drop every loaded
391
- * message strictly older than the cutoff (keeping newer ones) across all loaded windows,
392
- * mirroring the legacy per-message-set pruning. For a full truncation (no `truncated_at`) use
393
- * {@link MessageIntervalPaginator.clearStateAndCache} instead.
394
- *
395
- * Batched and edge-classified: because messages are chronological, each interval is classified by
396
- * its `tail` (oldest) and `head` (newest) edges, so only the single interval that *straddles* the
397
- * cutoff is scanned member-by-member — the rest are kept or dropped wholesale. The straddling
398
- * interval becomes the new global tail (nothing older than the cutoff exists anymore), so its
399
- * `isTail`/`hasMoreTail` are set; intervals entirely newer keep their flags (unloaded older
400
- * messages may still sit between them and the cutoff). The active window is re-emitted once.
671
+ * Partial truncation for `channel.truncated` with a `truncated_at`: drops every loaded message
672
+ * strictly older than the cutoff across all intervals (a full truncation uses
673
+ * {@link MessageIntervalPaginator.clearStateAndCache}). Only the interval straddling the cutoff is
674
+ * scanned member by member and becomes the new global tail; intervals entirely newer keep their
675
+ * flags, since unloaded older messages may sit between them and the cutoff. The active interval is
676
+ * re-emitted once.
677
+ */
678
+ truncate({ truncatedAt }: {
679
+ truncatedAt: TimestampNS;
680
+ }): void;
681
+ /**
682
+ * Deletes `userId`'s loaded messages (removes them on a hard delete) and marks the quotes of them
683
+ * as deleted. Returns the messages it deleted, as they were before.
401
684
  */
402
- truncate: ({ truncatedAt }: {
403
- truncatedAt: Date;
404
- }) => void;
405
685
  applyMessageDeletionForUser: ({ userId, hardDelete, deletedAt, }: {
406
686
  userId: string;
407
687
  hardDelete?: boolean;
408
- deletedAt: Date;
409
- }) => void;
688
+ deletedAt: TimestampNS;
689
+ }) => LocalMessage[];
690
+ /** Updates the quoted-message snapshot of every cached message that quotes `message`. */
691
+ reflectQuotedMessageUpdate: (message: LocalMessage) => void;
410
692
  /**
411
- * Ensures quoted-message snapshots across loaded paginator cache are in sync
412
- * with the provided message.
413
- *
414
- * Scans cached messages and updates any item where `quoted_message_id`
415
- * matches `message.id`.
693
+ * Reflects an updated `user` onto every cached message authored by that user (not
694
+ * `quoted_message.user`). Patches the shared item index in one batch and re-emits the active
695
+ * interval once, if it held an affected message.
416
696
  */
417
- reflectQuotedMessageUpdate: (message: LocalMessage) => void;
697
+ reflectUserUpdate(user: UserResponse): void;
418
698
  /**
419
- * Reflect an updated `user` object onto every cached message authored by that user, mirroring
420
- * the legacy `ChannelState.updateUserMessages` for the main message list (does not touch
421
- * `quoted_message.user` — that is not part of the legacy behavior).
422
- *
423
- * Batched: a user rename can affect many messages, so this patches the shared item index and
424
- * re-emits the active window a single time (if it held an affected message) rather than one
425
- * `ingestItem` re-emit per message.
426
- */
427
- reflectUserUpdate: (user: UserResponse) => void;
428
- /**
429
- * Apply a reaction WS event (`reaction.new` / `reaction.updated` / `reaction.deleted`) to the
430
- * cached message. The event's `message` already carries the server-updated
431
- * `reaction_groups` / `latest_reactions`; only `own_reactions` needs local preservation so a
432
- * cross-user reaction does not wipe the current user's reactions. This re-homes what
433
- * `ChannelState.addReaction` / `removeReaction` used to do off the now-removed
434
- * `channel.state.messages` / `channel.state.threads` caches (the same logic backs the thread
435
- * paginator via `Thread.messagePaginator`).
436
- *
437
- * `own_reactions` is seeded from the currently cached item (so another user's reaction keeps ours),
438
- * falling back to the event's own_reactions when the message is not loaded — matching the legacy
439
- * behavior where `_updateMessage` only mutated a message that existed locally.
440
- *
441
- * @param params - The reaction event payload.
442
- * @param params.message - The reaction event's message, carrying the
443
- * server-computed `reaction_groups` / `latest_reactions`. Ingested as-is except for `own_reactions`.
444
- * @param params.reaction - The reaction from the event. Only added to/removed from
445
- * `own_reactions` when its `user_id` is the current user; otherwise the current user's
446
- * `own_reactions` are left untouched.
447
- * @param [params.removed=false] - `true` for `reaction.deleted` (remove the reaction from
448
- * `own_reactions`); `false` for `reaction.new` / `reaction.updated` (add it).
449
- * @param [params.enforceUnique=false] - When adding, first clear the current user's existing
450
- * `own_reactions` so only the incoming one remains (used by `reaction.updated`, where a user's
451
- * reaction replaces their previous one).
452
- *
453
- * TODO(reactive-store): reflect reactions ONCE at the store level, not per-paginator. Both the
454
- * channel handler (channel.ts) and the thread handler (thread.ts) call this on every reaction.*
455
- * event, so a message held in more than one collection (a show_in_channel reply, or the thread
456
- * parent) is reflected TWICE: two writes to the same canonical slot, each fanning out to the
457
- * other holder (double re-projection) and minting a fresh ref that defeats the reconcile
458
- * ref-equality bail. Idempotent (counts come wholesale from the event) so the result is correct,
459
- * just wasteful. The store already fans out to every holder, so reflect once (by id, if held) and
460
- * retire the per-collection reflect calls + parent path + enforce_unique branch.
461
- */
462
- reflectReaction: ({ enforceUnique, message, reaction, removed, }: {
463
- message: MessageResponse | LocalMessage;
464
- reaction: ReactionResponse;
465
- enforceUnique?: boolean;
466
- removed?: boolean;
467
- }) => void;
699
+ * The last loaded message created at or before `timestamp` (a floor), or `null` when it precedes
700
+ * every loaded message. With `exactTsMatch`, only a message created exactly at `timestamp` matches.
701
+ * Searches the loaded intervals from the head down (each already sorted, O(log n) per interval):
702
+ * the first holding a message at or before `timestamp` holds the answer. Used by the receipts
703
+ * tracker to resolve read/delivered cursors.
704
+ */
705
+ findItemByTimestamp: (timestamp: TimestampNS, exactTsMatch?: boolean) => LocalMessage | null;
468
706
  /**
469
- * Map a timestamp to a loaded message — the first message in the latest (head) window whose
470
- * `created_at` is >= `timestampMs` (mirrors the legacy `ChannelState.findMessageByTimestamp`
471
- * lower-bound search), or the newest loaded message when the timestamp is beyond it. Used by the
472
- * receipts tracker to resolve read/delivered cursors. Searches the newest loaded window — where
473
- * read cursors live — which is already sorted, so this is O(log n) with no re-sort.
707
+ * {@link findItemByTimestamp} within one interval (`items` ascending by `created_at`). `undefined`
708
+ * when every item is newer than `timestamp`, so an older interval has to be searched.
474
709
  */
475
- findItemByTimestamp: (timestampMs: number, exactTsMatch?: boolean) => LocalMessage | null;
476
- filterQueryResults: (items: LocalMessage[]) => LocalMessage[];
710
+ private findItemByTimestampIn;
711
+ filterQueryResults(items: LocalMessage[]): LocalMessage[];
712
+ /**
713
+ * The sort of a replies request. A page newer than a cursor (`id_gt`, `created_at_after`, ...)
714
+ * must hold the replies right after the cursor, so it is requested oldest first: newest first
715
+ * returns the newest replies and skips the ones in between. The page is put in item order
716
+ * afterwards, so the request sort only decides which replies the page holds.
717
+ */
718
+ private getRepliesRequestSort;
477
719
  private getCanonicalQueryItems;
720
+ /**
721
+ * The cursor and more-messages flags after a page is placed (`deriveCursor`). A page around a
722
+ * point counts the messages the server returned on each side of it. Any other page is compared
723
+ * with the interval's outermost server-known messages (see {@link getServerKnownEdges}): a page
724
+ * never holds an unsent message, so one at an edge must not hide that the page reached the edge.
725
+ */
726
+ private deriveCursorFromPage;
478
727
  }