stream-chat 10.0.0-rc.9 → 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 (361) hide show
  1. package/README.md +7 -6
  2. package/dist/cjs/index.browser.js +21650 -19790
  3. package/dist/cjs/index.browser.js.map +4 -4
  4. package/dist/cjs/index.node.js +21690 -19798
  5. package/dist/cjs/index.node.js.map +4 -4
  6. package/dist/esm/index.mjs +21755 -19895
  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 +13 -27
  10. package/dist/types/EventHandlerPipeline.d.ts +18 -38
  11. package/dist/types/LiveLocationManager.d.ts +24 -52
  12. package/dist/types/api-client.d.ts +17 -5
  13. package/dist/types/channel.d.ts +432 -470
  14. package/dist/types/channel_state.d.ts +68 -112
  15. package/dist/types/client.d.ts +321 -435
  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 +2 -0
  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 +2528 -690
  50. package/dist/types/gen/models/timestamp-guard.d.ts +22 -0
  51. package/dist/types/gen/moderation/ModerationApi.d.ts +33 -14
  52. package/dist/types/index.d.ts +10 -6
  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 +7 -1
  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 -128
  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 +19 -18
  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 +40 -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 -186
  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 -334
  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 +5 -23
  118. package/dist/types/pagination/utility.search.d.ts +3 -8
  119. package/dist/types/poll.d.ts +34 -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 +11 -11
  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 +63 -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 -199
  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 +33 -57
  148. package/dist/types/utils.d.ts +72 -91
  149. package/package.json +14 -40
  150. package/src/ChannelManager.ts +494 -303
  151. package/src/CooldownTimer.ts +28 -38
  152. package/src/EventHandlerPipeline.ts +22 -45
  153. package/src/LiveLocationManager.ts +37 -76
  154. package/src/api-client.ts +113 -50
  155. package/src/campaign.ts +1 -1
  156. package/src/channel.ts +1067 -1276
  157. package/src/channel_batch_updater.ts +1 -1
  158. package/src/channel_state.ts +73 -168
  159. package/src/client.ts +744 -974
  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 -232
  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 +6 -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 -1540
  195. package/src/gen/models/index.ts +2498 -3383
  196. package/src/gen/models/timestamp-guard.ts +27 -0
  197. package/src/gen/moderation/ModerationApi.ts +170 -367
  198. package/src/index.ts +22 -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 +19 -23
  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 +223 -174
  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/textComposer.ts +1 -1
  225. package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +12 -12
  226. package/src/messageComposer/middleware/pollComposer/state.ts +2 -2
  227. package/src/messageComposer/middleware/pollComposer/types.ts +2 -4
  228. package/src/messageComposer/middleware/pollComposer/validation.ts +8 -26
  229. package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +8 -6
  230. package/src/messageComposer/middleware/textComposer/commandUtils.ts +10 -3
  231. package/src/messageComposer/middleware/textComposer/commands.ts +11 -16
  232. package/src/messageComposer/middleware/textComposer/mentions.ts +32 -70
  233. package/src/messageComposer/middleware/textComposer/textMiddlewareUtils.ts +10 -4
  234. package/src/messageComposer/middleware/textComposer/types.ts +1 -6
  235. package/src/messageComposer/pollComposer.ts +21 -9
  236. package/src/messageComposer/textComposer.ts +37 -57
  237. package/src/messageComposer/types.ts +39 -11
  238. package/src/messageDelivery/MessageDeliveryReporter.ts +86 -125
  239. package/src/messageDelivery/MessageReceiptsTracker.ts +88 -101
  240. package/src/messageOperations/FailedSendCache.ts +85 -0
  241. package/src/messageOperations/MessageOperationStatePolicy.ts +121 -112
  242. package/src/messageOperations/MessageOperations.ts +297 -175
  243. package/src/{entityStore → messageOperations}/applyReactionLocally.ts +9 -28
  244. package/src/messageOperations/createMessageOperations.ts +176 -0
  245. package/src/messageOperations/index.ts +6 -14
  246. package/src/messageOperations/reflectReactionEvent.ts +43 -0
  247. package/src/messageOperations/sendOrdering.ts +25 -0
  248. package/src/messageOperations/settlePendingAttachmentUploads.ts +98 -0
  249. package/src/messageOperations/types.ts +51 -13
  250. package/src/middleware.ts +13 -5
  251. package/src/moderation.ts +25 -21
  252. package/src/notifications/NotificationManager.ts +19 -28
  253. package/src/notifications/types.ts +21 -57
  254. package/src/offline-support/offline_support_api.ts +226 -669
  255. package/src/offline-support/offline_sync_manager.ts +51 -80
  256. package/src/offline-support/queueableOperations.ts +98 -73
  257. package/src/offline-support/types.ts +43 -186
  258. package/src/pagination/FilterBuilder.ts +1 -22
  259. package/src/pagination/ItemIndex.ts +4 -12
  260. package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
  261. package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +15 -63
  262. package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
  263. package/src/pagination/cursorDerivation/linearPaginationFlags.ts +53 -33
  264. package/src/pagination/filterCompiler.ts +11 -25
  265. package/src/pagination/index.ts +1 -0
  266. package/src/pagination/paginators/BasePaginator.ts +1415 -1041
  267. package/src/pagination/paginators/ChannelPaginator.ts +479 -217
  268. package/src/pagination/paginators/MessageIntervalPaginator.ts +1351 -772
  269. package/src/pagination/paginators/MessagePaginator.ts +513 -233
  270. package/src/pagination/paginators/PinnedMessagePaginator.ts +32 -40
  271. package/src/pagination/paginators/ReminderPaginator.ts +21 -16
  272. package/src/pagination/paginators/ThreadPaginator.ts +170 -0
  273. package/src/pagination/paginators/UserGroupPaginator.ts +16 -19
  274. package/src/pagination/paginators/index.ts +1 -0
  275. package/src/pagination/paginators/stateThrottling.ts +5 -10
  276. package/src/pagination/sortCompiler.ts +23 -50
  277. package/src/pagination/utility.normalization.ts +8 -30
  278. package/src/pagination/utility.search.ts +4 -11
  279. package/src/poll.ts +177 -98
  280. package/src/poll_manager.ts +24 -22
  281. package/src/poll_optimistic_votes.ts +335 -0
  282. package/src/reminders/Reminder.ts +16 -12
  283. package/src/reminders/ReminderManager.ts +22 -55
  284. package/src/reminders/ReminderTimer.ts +1 -2
  285. package/src/search/BaseSearchSource.ts +19 -25
  286. package/src/search/ChannelSearchSource.ts +43 -1
  287. package/src/search/MessageSearchSource.ts +77 -13
  288. package/src/search/SearchController.ts +39 -36
  289. package/src/search/types.ts +6 -10
  290. package/src/segment.ts +1 -1
  291. package/src/signing.ts +23 -3
  292. package/src/thread.ts +418 -703
  293. package/src/thread_manager.ts +300 -234
  294. package/src/token_manager.ts +12 -22
  295. package/src/types.ts +102 -216
  296. package/src/types.utility.ts +3 -3
  297. package/src/upload-utils.ts +5 -10
  298. package/src/uploadManager.ts +64 -18
  299. package/src/utils/FixedSizeQueueCache.ts +18 -21
  300. package/src/utils/WithSubscriptions.ts +6 -16
  301. package/src/utils/abort.ts +45 -0
  302. package/src/utils/concurrency.ts +16 -55
  303. package/src/utils/mergeWith/mergeWith.ts +10 -13
  304. package/src/utils/mergeWith/mergeWithCore.ts +24 -81
  305. package/src/utils/mergeWith/mergeWithDiff.ts +15 -33
  306. package/src/utils/objectPath.ts +6 -41
  307. package/src/utils/retryable.ts +10 -14
  308. package/src/utils/throttling/throttle.ts +9 -25
  309. package/src/utils/time.ts +40 -60
  310. package/src/utils.ts +181 -174
  311. package/codegen/i18n/callSites.ts +0 -126
  312. package/codegen/i18n/generate.ts +0 -226
  313. package/codegen/i18n/guards.ts +0 -178
  314. package/codegen/i18n/index.ts +0 -29
  315. package/codegen/i18n/stringMaps.ts +0 -91
  316. package/codegen/i18n/types.ts +0 -100
  317. package/dist/cjs/i18n.browser.js +0 -1131
  318. package/dist/cjs/i18n.browser.js.map +0 -7
  319. package/dist/cjs/i18n.node.js +0 -1160
  320. package/dist/cjs/i18n.node.js.map +0 -7
  321. package/dist/esm/i18n-codegen.mjs +0 -409
  322. package/dist/esm/i18n-codegen.mjs.map +0 -7
  323. package/dist/esm/i18n.mjs +0 -1098
  324. package/dist/esm/i18n.mjs.map +0 -7
  325. package/dist/types/ConnectionRecoveryManager.d.ts +0 -156
  326. package/dist/types/connection.d.ts +0 -139
  327. package/dist/types/entityStore/applyReactionLocally.d.ts +0 -32
  328. package/dist/types/i18n/Streami18n.d.ts +0 -168
  329. package/dist/types/i18n/TranslationBuilder.d.ts +0 -70
  330. package/dist/types/i18n/TranslationStore.d.ts +0 -57
  331. package/dist/types/i18n/dayjs.d.ts +0 -104
  332. package/dist/types/i18n/formatters.d.ts +0 -91
  333. package/dist/types/i18n/index.d.ts +0 -15
  334. package/dist/types/i18n/translator.d.ts +0 -29
  335. package/dist/types/i18n/types.d.ts +0 -262
  336. package/dist/types/i18n-codegen/callSites.d.ts +0 -10
  337. package/dist/types/i18n-codegen/generate.d.ts +0 -15
  338. package/dist/types/i18n-codegen/guards.d.ts +0 -61
  339. package/dist/types/i18n-codegen/index.d.ts +0 -29
  340. package/dist/types/i18n-codegen/stringMaps.d.ts +0 -14
  341. package/dist/types/i18n-codegen/types.d.ts +0 -94
  342. package/dist/types/insights.d.ts +0 -56
  343. package/dist/types/messageOperations/optimistic.d.ts +0 -118
  344. package/dist/types/messageOperations/persistence.d.ts +0 -21
  345. package/dist/types/pagination/utility.queryChannel.d.ts +0 -26
  346. package/dist/types/store.d.ts +0 -125
  347. package/src/ConnectionRecoveryManager.ts +0 -293
  348. package/src/i18n/Streami18n.ts +0 -520
  349. package/src/i18n/TranslationBuilder.ts +0 -176
  350. package/src/i18n/TranslationStore.ts +0 -96
  351. package/src/i18n/dayjs.ts +0 -228
  352. package/src/i18n/formatters.ts +0 -461
  353. package/src/i18n/index.ts +0 -15
  354. package/src/i18n/languageNames.ts +0 -103
  355. package/src/i18n/translator.ts +0 -76
  356. package/src/i18n/types.ts +0 -375
  357. package/src/insights.ts +0 -82
  358. package/src/messageOperations/optimistic.ts +0 -257
  359. package/src/messageOperations/persistence.ts +0 -40
  360. package/src/pagination/utility.queryChannel.ts +0 -84
  361. package/src/store.ts +0 -304
@@ -1,6 +1,6 @@
1
1
  import type {
2
2
  BasePaginatorConfig,
3
- PaginatorCursor,
3
+ DoRequestResponse,
4
4
  PaginatorOptions,
5
5
  } from './BasePaginator';
6
6
  import {
@@ -33,25 +33,18 @@ export type PinnedMessagePaginatorOptions = {
33
33
  const PINNED_AT_SORT: SortParamRequest[] = [{ field: 'pinned_at', direction: 1 }];
34
34
 
35
35
  /**
36
- * Pinned-message list paginator.
36
+ * The channel's pinned messages, ordered by `pinned_at` ascending (oldest-pinned first). Extends
37
+ * {@link MessageIntervalPaginator} rather than {@link MessagePaginator}: pinned messages are a subset
38
+ * of the channel and take no part in read/unread or delivery-receipt tracking.
37
39
  *
38
- * Extends the unread-free {@link MessageIntervalPaginator} base — pinned messages are a subset of
39
- * the channel and MUST NOT participate in read/unread or delivery-receipt tracking (that belongs to
40
- * the channel and thread message timelines). By extending the base rather than {@link MessagePaginator}
41
- * it simply never gets the unread surface.
42
- *
43
- * Differences from the main list:
44
- * - fetches from the `/pinned_messages` endpoint (`channel.getPinnedMessages`) rather than
45
- * `channel.query({ messages })`;
46
- * - includes only pinned, non-shadowed messages (`shouldIncludeMessageInInterval`), and filters on
47
- * `{ cid, pinned: true }` so `ingestItem` auto-adds on pin and auto-removes on unpin;
48
- * - orders by `pinned_at` ascending (oldest-pinned first), matching the legacy
49
- * `channel.state.pinnedMessages` order.
50
- *
51
- * Navigation (`jumpToMessage` / `jumpToTheLatestMessage`) is inherited and meaningful — the endpoint
52
- * supports `id_around` — but no unread-coupled navigation exists.
40
+ * Fetches through `channel.getPinnedMessages`, includes only pinned, non-shadowed messages and
41
+ * matches `{ cid, pinned: true }`, so `ingestItem` adds on pin and removes on unpin.
53
42
  */
54
43
  export class PinnedMessagePaginator extends MessageIntervalPaginator {
44
+ protected get holderName() {
45
+ return 'pinned-message-paginator';
46
+ }
47
+
55
48
  constructor({
56
49
  channel,
57
50
  id,
@@ -61,9 +54,7 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
61
54
  super({
62
55
  channel,
63
56
  id: id ?? `pinned-message-paginator-${generateUUIDv4()}`,
64
- // No explicit index: inherit the store-backed item index from MessageIntervalPaginator so a
65
- // pinned message shares the single canonical copy with the main list / thread and reflects
66
- // reactions & edits applied elsewhere. A caller may still inject a custom `itemIndex`.
57
+ // Omitted: the inherited store-backed index shares one copy of each message with the main list.
67
58
  itemIndex,
68
59
  paginatorOptions,
69
60
  });
@@ -71,11 +62,7 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
71
62
  this.installPinnedMessageBehaviour();
72
63
  }
73
64
 
74
- /**
75
- * Memoized for the reason {@link MessageIntervalPaginator}'s overlay is: the base derivation folds
76
- * this in and skips the publish when nothing moved, which needs stable references. Both close over
77
- * `this` and over a fixed `pinned_at` sort, so there is nothing to rebuild.
78
- */
65
+ /** Memoized: stable references let the base derivation skip a publish when nothing moved. */
79
66
  private pinnedBehaviour?: Partial<BasePaginatorConfig<LocalMessage, MessageQueryShape>>;
80
67
 
81
68
  private buildPinnedBehaviour(): Partial<
@@ -89,12 +76,11 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
89
76
  tiebreaker: this.pinnedTiebreaker,
90
77
  }),
91
78
 
92
- // Fetch from the pinned-messages endpoint. The base `query` feeds the resolved query shape
93
- // (including `id_around` jumps) here as `options`; we return both cursors and let the base gate
94
- // them by direction.
79
+ // The base passes the resolved shape (including `id_around` jumps) as `options`. Both
80
+ // cursors are returned and the base `extractQueryPage` gates them by direction.
95
81
  doRequest: async (
96
82
  options: MessageQueryShape,
97
- ): Promise<{ cursor?: PaginatorCursor; items: LocalMessage[] }> => {
83
+ ): Promise<DoRequestResponse<LocalMessage>> => {
98
84
  const { messages } = await this.channel.getPinnedMessages({
99
85
  ...(options as PinnedMessagePaginationOptions),
100
86
  sort: PINNED_AT_SORT,
@@ -113,11 +99,7 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
113
99
  return leftId < rightId ? -1 : leftId > rightId ? 1 : 0;
114
100
  };
115
101
 
116
- /**
117
- * The ordering and request behaviour that makes this a *pinned*-message paginator, contributed to the
118
- * base derivation so a re-derivation cannot drop it and does not need a second write to restore it.
119
- * Spread over the interval overlay, so this class's `pinned_at` comparator wins.
120
- */
102
+ /** Adds the pinned ordering and request behaviour to the derivation, over the interval overlay. */
121
103
  protected override getBehaviourOverrides(): Partial<
122
104
  BasePaginatorConfig<LocalMessage, MessageQueryShape>
123
105
  > {
@@ -125,12 +107,9 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
125
107
  }
126
108
 
127
109
  private installPinnedMessageBehaviour(): void {
128
- // Order by pinned_at (ascending), overriding the base's created_at comparators. Ascending keeps
129
- // the head edge (most-recently-pinned) at the end of an interval, matching the base's interval
130
- // direction getters (which are shared with created_at-asc semantics).
131
- //
132
- // A plain field rather than config, so a re-derivation never touches it — which is why only the
133
- // constructor sets it.
110
+ // Ascending `pinned_at` keeps the head edge (most recently pinned) at the end of an interval,
111
+ // like the base's `created_at` ascending. A plain field rather than config, so a re-derivation
112
+ // never touches it and only the constructor sets it.
134
113
  this.sortComparator = makeComparator<LocalMessage>({
135
114
  sort: PINNED_AT_SORT,
136
115
  resolvePathValue: resolveDotPathValue,
@@ -139,6 +118,19 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
139
118
  this.updateConfig(this.buildPinnedBehaviour());
140
119
  }
141
120
 
121
+ /**
122
+ * The newest page (no cursor, not around a message) holds the most recently pinned messages, so
123
+ * it reaches the head: its interval becomes the only newest interval, and an older interval that
124
+ * was the newest one can load newer pins (see `makeOnlyHead`). A newest page comes from this
125
+ * paginator's own query or with a channel response.
126
+ */
127
+ protected override pageReachesHead(
128
+ _page: LocalMessage[],
129
+ queryShape: MessageQueryShape | undefined,
130
+ ): boolean | undefined {
131
+ return this.isHeadPageQueryShape(queryShape) ? true : undefined;
132
+ }
133
+
142
134
  buildMatchFilters = (): PinnedMessagePaginatorFilter => ({
143
135
  cid: this.channel.cid,
144
136
  pinned: true,
@@ -15,12 +15,10 @@ import { StoreBackedItemIndex } from '../../entityStore/StoreBackedItemIndex';
15
15
  import { makeComparator } from '../sortCompiler';
16
16
  import { resolveDotPathValue } from '../utility.normalization';
17
17
 
18
- // Reminders are keyed by the message they belong to; used for interval dedup and index addressing.
18
+ // Reminders are keyed by the message they belong to.
19
19
  const getReminderId = (reminder: ReminderResponseData) => reminder.message_id;
20
20
 
21
- // Fallback order for interval placement when no explicit sort is set. Order is not a pinned contract
22
- // (ReminderManager stores reminders in a message_id-keyed Map), but interval storage needs a total
23
- // order, so default to a deterministic one.
21
+ // Interval storage needs a total order, so default to a deterministic one when no sort is set.
24
22
  const DEFAULT_SORT: SortParamRequest[] = [{ direction: 1, field: 'created_at' }];
25
23
 
26
24
  export class ReminderPaginator extends BasePaginator<
@@ -58,6 +56,7 @@ export class ReminderPaginator extends BasePaginator<
58
56
  initialCursor: ZERO_PAGE_CURSOR,
59
57
  itemIndex: new StoreBackedItemIndex<ReminderResponseData>({
60
58
  getEntityId: getReminderId,
59
+ holderName: 'reminder-paginator',
61
60
  }),
62
61
  ...options,
63
62
  });
@@ -69,8 +68,7 @@ export class ReminderPaginator extends BasePaginator<
69
68
  return getReminderId(item);
70
69
  }
71
70
 
72
- // Interval storage needs a total order. Derive it from the requested sort (rebuilt when `sort`
73
- // changes, which also resets the accumulated pages), with a message_id tiebreaker.
71
+ // Total order for interval storage: the requested sort, with a message_id tiebreaker.
74
72
  private buildSortComparator() {
75
73
  return makeComparator<ReminderResponseData>({
76
74
  sort: this._sort ?? DEFAULT_SORT,
@@ -80,28 +78,35 @@ export class ReminderPaginator extends BasePaginator<
80
78
  });
81
79
  }
82
80
 
83
- protected getNextQueryShape({
84
- direction,
85
- }: Required<
86
- Pick<PaginationQueryParams<QueryRemindersRequest>, 'direction'>
87
- >): QueryRemindersRequest {
88
- const cursor = this.cursor?.[direction];
81
+ protected getNextQueryShape(): QueryRemindersRequest {
89
82
  return {
90
83
  filter: this.filters,
91
84
  sort: this.sort,
92
85
  limit: this.pageSize,
93
- [direction]: cursor,
94
86
  };
95
87
  }
96
88
 
97
- query = async ({
89
+ protected override fetchQueryResponse = async ({
90
+ direction,
98
91
  queryShape,
99
92
  }: PaginationQueryParams<QueryRemindersRequest>): Promise<
100
93
  PaginationQueryReturnValue<ReminderResponseData>
101
94
  > => {
102
- const { reminders: items, next, prev } = await this.client.queryReminders(queryShape);
95
+ const cursor = direction ? (this.cursor?.[direction] ?? undefined) : undefined;
96
+ const request: QueryRemindersRequest = {
97
+ ...(queryShape ?? this.getNextQueryShape()),
98
+ // The request names its cursors after the response's `next` / `prev`, not after the direction.
99
+ ...(cursor ? { [direction === 'tailward' ? 'next' : 'prev']: cursor } : {}),
100
+ };
101
+ const { reminders: items, next, prev } = await this.client.queryReminders(request);
103
102
  return { items, headward: prev, tailward: next };
104
103
  };
105
104
 
106
- filterQueryResults = (items: ReminderResponseData[]) => items;
105
+ /** The extracting step of the query pipeline: the response is the page. */
106
+ protected override extractQueryPage(
107
+ response: PaginationQueryReturnValue<ReminderResponseData>,
108
+ _params: PaginationQueryParams<QueryRemindersRequest>,
109
+ ) {
110
+ return response;
111
+ }
107
112
  }
@@ -0,0 +1,170 @@
1
+ import { BasePaginator, ZERO_PAGE_CURSOR } from './BasePaginator';
2
+ import type {
3
+ PaginationQueryParams,
4
+ PaginationQueryReturnValue,
5
+ PaginationQueryShapeChangeIdentifier,
6
+ PaginatorOptions,
7
+ PaginatorState,
8
+ } from './BasePaginator';
9
+ import type { StreamChat } from '../../client';
10
+ import { EntityStore } from '../../entityStore/EntityStore';
11
+ import { StoreBackedItemIndex } from '../../entityStore/StoreBackedItemIndex';
12
+ import type { Thread } from '../../thread';
13
+ import type { QueryThreadsRequest } from '../../types';
14
+ import { isEqual } from '../../utils/mergeWith/mergeWithCore';
15
+
16
+ export const DEFAULT_THREAD_PAGE_SIZE = 25;
17
+
18
+ /** Default query options for every page of the thread list. */
19
+ export const DEFAULT_THREAD_QUERY: QueryThreadsRequest = {
20
+ participant_limit: 10,
21
+ reply_limit: 10,
22
+ watch: true,
23
+ };
24
+
25
+ /** What identifies the query, as opposed to which page of it is requested. */
26
+ const getQueryIdentity = (queryShape: QueryThreadsRequest | undefined) => {
27
+ if (!queryShape) return queryShape;
28
+ const { limit: _, next: __, prev: ___, ...identity } = queryShape;
29
+ return identity;
30
+ };
31
+
32
+ const hasPaginationQueryShapeChanged: PaginationQueryShapeChangeIdentifier<
33
+ QueryThreadsRequest
34
+ > = (prevQueryShape, nextQueryShape) =>
35
+ !isEqual(getQueryIdentity(prevQueryShape), getQueryIdentity(nextQueryShape));
36
+
37
+ export type ThreadPaginatorOptions = {
38
+ client: StreamChat;
39
+ /** Store holding the list's threads (`client.threads`' thread store). Omitted: a private one. */
40
+ store?: EntityStore<Thread>;
41
+ paginatorOptions?: PaginatorOptions<Thread, QueryThreadsRequest>;
42
+ };
43
+
44
+ /**
45
+ * The thread list, in the order `queryThreads` returns it. There is no client-side sort: the server
46
+ * order (unread first, then latest reply) depends on state a `Thread` mutates in place, so a
47
+ * comparator would corrupt interval storage. Pages append in server order and
48
+ * {@link ThreadPaginator.reload} replaces the list.
49
+ */
50
+ export class ThreadPaginator extends BasePaginator<Thread, QueryThreadsRequest> {
51
+ private readonly client: StreamChat;
52
+ private readonly store: EntityStore<Thread>;
53
+
54
+ constructor({
55
+ client,
56
+ store = new EntityStore<Thread>({ getEntityId: (thread) => thread.id }),
57
+ paginatorOptions,
58
+ }: ThreadPaginatorOptions) {
59
+ super({
60
+ hasPaginationQueryShapeChanged,
61
+ initialCursor: ZERO_PAGE_CURSOR,
62
+ itemIndex: new StoreBackedItemIndex<Thread>({
63
+ getEntityId: (thread) => thread.id,
64
+ holderName: 'thread-paginator',
65
+ store,
66
+ }),
67
+ pageSize: DEFAULT_THREAD_PAGE_SIZE,
68
+ ...paginatorOptions,
69
+ });
70
+ this.client = client;
71
+ this.store = store;
72
+ }
73
+
74
+ /** No next page until a load has landed, so `toTail()` is a no-op before the first reload. */
75
+ get initialState(): PaginatorState<Thread> {
76
+ return {
77
+ ...super.initialState,
78
+ hasMoreTail: false,
79
+ };
80
+ }
81
+
82
+ getItemId(thread: Thread): string {
83
+ return thread.id;
84
+ }
85
+
86
+ protected getNextQueryShape({
87
+ direction,
88
+ }: Required<
89
+ Pick<PaginationQueryParams<QueryThreadsRequest>, 'direction'>
90
+ >): QueryThreadsRequest {
91
+ const cursor = this.cursor?.[direction] ?? undefined;
92
+ return {
93
+ ...DEFAULT_THREAD_QUERY,
94
+ limit: this.pageSize,
95
+ ...(cursor ? { [direction === 'tailward' ? 'next' : 'prev']: cursor } : {}),
96
+ };
97
+ }
98
+
99
+ protected override fetchQueryResponse = async ({
100
+ queryShape,
101
+ }: PaginationQueryParams<QueryThreadsRequest>): Promise<
102
+ PaginationQueryReturnValue<Thread>
103
+ > => {
104
+ const { threads, next } = await this.client.queryThreadsAndHydrate(queryShape);
105
+ return {
106
+ items: threads.map((thread) => this.store.get(thread.id) ?? thread),
107
+ tailward: next,
108
+ };
109
+ };
110
+
111
+ /** The extracting step of the query pipeline: the response is the page. */
112
+ protected override extractQueryPage(
113
+ response: PaginationQueryReturnValue<Thread>,
114
+ _params: PaginationQueryParams<QueryThreadsRequest>,
115
+ ) {
116
+ return response;
117
+ }
118
+
119
+ /**
120
+ * Re-queries the first page and replaces the list in server order; also the first load. The
121
+ * current threads stay until the response lands. A failed query leaves them and records
122
+ * `lastQueryError`; a success clears it. Only the first load publishes `isLoading` (with items it
123
+ * would mean the next page).
124
+ */
125
+ reload = async ({ limit = this.pageSize }: { limit?: number } = {}) => {
126
+ const isFirstLoad = !this.hasResults;
127
+ if (isFirstLoad) this.state.partialNext({ isLoading: true });
128
+ let replaced = false;
129
+ try {
130
+ const fetchParams = {
131
+ queryShape: { ...DEFAULT_THREAD_QUERY, limit },
132
+ retryCount: this.config.retryCount,
133
+ };
134
+ const response = await this.fetchQueryResponseWithRetries(fetchParams);
135
+ if (!response) return;
136
+ // The query pipeline's steps (see `executeQuery`) with a placing step of its own, below. A
137
+ // thread list's response is its page, so nothing else is left to apply.
138
+ const results = this.extractQueryPage(response, fetchParams);
139
+
140
+ // Replace rather than merge (the order is server-driven): IDs absent from the response go.
141
+ const nextIds = new Set(results.items.map((thread) => thread.id));
142
+ this.setIntervals([]);
143
+ this.setActiveInterval(undefined);
144
+ for (const [id] of this._itemIndex.entries()) {
145
+ if (!nextIds.has(id)) this._itemIndex.remove(id);
146
+ }
147
+ this.setItems({
148
+ cursor: { headward: undefined, tailward: results.tailward },
149
+ isFirstPage: true,
150
+ isLastPage: !results.tailward,
151
+ valueOrFactory: results.items,
152
+ });
153
+ replaced = true;
154
+ } finally {
155
+ const clearError = replaced && this.lastQueryError;
156
+ if (isFirstLoad || clearError) {
157
+ this.state.partialNext({
158
+ ...(isFirstLoad ? { isLoading: false } : {}),
159
+ ...(clearError ? { lastQueryError: undefined } : {}),
160
+ });
161
+ }
162
+ }
163
+ };
164
+
165
+ /** Also clears the item index (the base reset keeps it), before the base publishes. */
166
+ resetState() {
167
+ this._itemIndex.clear();
168
+ super.resetState();
169
+ }
170
+ }
@@ -30,12 +30,8 @@ const decodeCursor = <TCursor extends object>(cursor: string | null | undefined)
30
30
  };
31
31
 
32
32
  /**
33
- * Paginates user-group listing through `/usergroups`.
34
- *
35
- * This entity only supports forward (tailward) cursor pagination via
36
- * `created_at_gt` and `id_gt`. Backward (headward) pagination is not available
37
- * because the API does not expose a backward cursor, so the headward cursor is
38
- * initialized as exhausted (`null`).
33
+ * Paginates `/usergroups` forward (tailward) only, via `created_at_gt` and `id_gt`. The API has no
34
+ * backward cursor, so the headward cursor starts exhausted (`null`).
39
35
  */
40
36
  export class UserGroupPaginator extends BasePaginator<
41
37
  UserGroupResponse,
@@ -52,13 +48,12 @@ export class UserGroupPaginator extends BasePaginator<
52
48
  initialCursor: { ...ZERO_PAGE_CURSOR, headward: null },
53
49
  itemIndex: new StoreBackedItemIndex<UserGroupResponse>({
54
50
  getEntityId: (group) => group.id,
51
+ holderName: 'user-group-paginator',
55
52
  }),
56
53
  ...options,
57
54
  });
58
55
  this.client = client;
59
- // Interval storage needs a total order for its placement/merge math. The listing is ordered by
60
- // the forward cursor (`created_at_gt`, `id_gt`), i.e. ascending `created_at` then `id` — mirror
61
- // that here so the visible order matches the server's.
56
+ // Total order for interval storage, mirroring the server's ascending (`created_at`, `id`).
62
57
  this.sortComparator = (a, b) => {
63
58
  if (a.created_at !== b.created_at) return a.created_at < b.created_at ? -1 : 1;
64
59
  return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
@@ -88,19 +83,15 @@ export class UserGroupPaginator extends BasePaginator<
88
83
  if (!lastItem) return undefined;
89
84
 
90
85
  return JSON.stringify({
91
- // The cursor is a request value, so it has to go back out as RFC3339 rather than as the
92
- // wire number the item carries. `nsToRfc3339` and not `nsToDate(...).toISOString()`:
93
- // `Date` holds only milliseconds, so flooring the boundary item's timestamp would put the
94
- // cursor below it and a strict `created_at_gt` could hand that same item back on the next
95
- // page.
86
+ // `nsToRfc3339` keeps the nanoseconds: a `Date` would floor the boundary timestamp and the
87
+ // strict `created_at_gt` could return that same item on the next page.
96
88
  created_at_gt: nsToRfc3339(lastItem.created_at),
97
89
  id_gt: lastItem.id,
98
90
  } satisfies UserGroupListCursor);
99
91
  };
100
92
 
101
- // The query shape must stay stable across pages: the paginator resets its
102
- // accumulated list when the query shape changes ('auto' reset policy), so the
103
- // forward cursor is NOT part of the shape — it is applied per request in `query`.
93
+ // The cursor stays out of the shape (a shape change resets the list): `fetchQueryResponse`
94
+ // applies it.
104
95
  protected getNextQueryShape(): ListUserGroupsOptions {
105
96
  return {
106
97
  limit: this.pageSize,
@@ -108,7 +99,7 @@ export class UserGroupPaginator extends BasePaginator<
108
99
  };
109
100
  }
110
101
 
111
- query = async ({
102
+ protected override fetchQueryResponse = async ({
112
103
  direction,
113
104
  queryShape,
114
105
  }: PaginationQueryParams<ListUserGroupsOptions>): Promise<
@@ -129,5 +120,11 @@ export class UserGroupPaginator extends BasePaginator<
129
120
  return { items, tailward: this.buildNextCursor(items) };
130
121
  };
131
122
 
132
- filterQueryResults = (items: UserGroupResponse[]) => items;
123
+ /** The extracting step of the query pipeline: the response is the page. */
124
+ protected override extractQueryPage(
125
+ response: PaginationQueryReturnValue<UserGroupResponse>,
126
+ _params: PaginationQueryParams<ListUserGroupsOptions>,
127
+ ) {
128
+ return response;
129
+ }
133
130
  }
@@ -5,3 +5,4 @@ export * from './MessagePaginator';
5
5
  export * from './PinnedMessagePaginator';
6
6
  export * from './ReminderPaginator';
7
7
  export * from './UserGroupPaginator';
8
+ export * from './ThreadPaginator';
@@ -1,13 +1,3 @@
1
- /**
2
- * Global switch for the message-list `state` publish throttle (see `BasePaginator.scheduleWindowPublish`).
3
- *
4
- * Auto-disabled under test runners (Vitest / Jest) so the existing unit suites keep their synchronous,
5
- * un-throttled behavior with zero per-test changes: with throttling off, every live mutation publishes
6
- * to `state` immediately, exactly as before this feature. A dedicated throttle test flips it on
7
- * (around fake timers) via {@link setStateThrottlingEnabled} and restores it afterwards.
8
- *
9
- * Production (an app bundle) defaults ON.
10
- */
11
1
  const isTestRunner = (): boolean => {
12
2
  try {
13
3
  return (
@@ -22,6 +12,11 @@ const isTestRunner = (): boolean => {
22
12
  }
23
13
  };
24
14
 
15
+ /**
16
+ * Global switch for the `state` publish throttle (see `BasePaginator.scheduleActiveIntervalPublish`). On by
17
+ * default, off under test runners (Vitest / Jest) so every mutation publishes synchronously. Tests
18
+ * of the throttle itself turn it on with {@link setStateThrottlingEnabled}.
19
+ */
25
20
  let enabled = !isTestRunner();
26
21
 
27
22
  export const isStateThrottlingEnabled = (): boolean => enabled;
@@ -12,15 +12,10 @@ export type ItemLocation = {
12
12
  };
13
13
 
14
14
  /**
15
- * Generic binary-search + plateau lookup over an abstract sorted array.
16
- *
17
- * The array is represented by:
18
- * - its length
19
- * - a getter `getItemAt(index)` that returns the item (or undefined)
20
- *
21
- * It returns:
22
- * - current: actual index of the item in the array
23
- * - expected: lower-bound position where the item belongs according to compare function
15
+ * Binary search over an abstract sorted array. Returns the needle's `currentIndex` (`-1` if absent)
16
+ * and the `insertionIndex` where `compare` places it (after items that compare equal). With
17
+ * `plateauScan`, a needle not at the insertion index is looked for by identity, scanning outward
18
+ * from it.
24
19
  */
25
20
  export function binarySearch<T>({
26
21
  needle,
@@ -30,43 +25,32 @@ export function binarySearch<T>({
30
25
  compare,
31
26
  plateauScan,
32
27
  }: {
33
- /** Target item in the searched array */
34
28
  needle: T;
35
29
  length: number;
36
- /** Retrieves the item from an array. The array could be just an array of reference by id to an index.
37
- * Therefore, we do not access the array directly but allow to determine, how the item is constructed.
38
- */
30
+ /** Reads the item at an index (the array may hold IDs resolved through an index). */
39
31
  getItemAt: (index: number) => T | undefined;
40
- /** Used to determine identity, not equality based on sort / comparator rules */
32
+ /** Identity, not equality under the sort order. */
41
33
  itemIdentityEquals: (item1: T, item2: T) => boolean;
42
- /** Used to determine equality from the sort order point of view. */
43
34
  compare: Comparator<T>;
44
35
  plateauScan?: boolean;
45
36
  }): ItemLocation {
46
- // empty array
47
37
  if (length === 0) return { currentIndex: -1, insertionIndex: 0 };
48
38
 
49
- // --- 1) Binary search to find lower bound (insertionIndex) ---
50
39
  let lo = 0;
51
40
  let hi = length;
52
41
 
53
42
  while (lo < hi) {
54
- const mid = (lo + hi) >> 1; // fast floor((low+high)/2)
43
+ const mid = (lo + hi) >> 1;
55
44
  const midItem = getItemAt(mid);
56
45
  if (!midItem) {
57
- // Corruption: we have an ID but no backing item.
58
- // Bail out with "not found".
46
+ // An ID without a backing item: report not found.
59
47
  return { currentIndex: -1, insertionIndex: -1 };
60
48
  }
61
49
 
62
50
  if (itemIdentityEquals(midItem, needle) && mid > 0) {
63
- // The probe landed on the needle's own slot, where `compare` is 0 by definition and says
64
- // nothing about where it belongs. That matters when relocating an item whose sort value just
65
- // changed: the array is sorted EXCEPT at this slot, because items held by reference (a
66
- // `Channel` mutated in place before the paginator is told) already carry the new value.
67
- // Walking right on that 0 reports "insert just after where you are" — read downstream as
68
- // "already in place" — so the item never moves. The left neighbour is the reliable signal;
69
- // otherwise fall through, keeping the established end-of-plateau result.
51
+ // The needle's own slot compares 0 and says nothing about where it belongs, and its value may
52
+ // have just changed in place (items held by reference): use the left neighbour, or it never
53
+ // moves.
70
54
  const leftItem = getItemAt(mid - 1);
71
55
  if (leftItem && compare(leftItem, needle) > 0) {
72
56
  hi = mid;
@@ -75,17 +59,14 @@ export function binarySearch<T>({
75
59
  }
76
60
 
77
61
  if (compare(midItem, needle) <= 0) {
78
- // midItem < needle ⇒ go right
79
62
  lo = mid + 1;
80
63
  } else {
81
- // midItem ≥ needle ⇒ go left
82
64
  hi = mid;
83
65
  }
84
66
  }
85
67
 
86
68
  const insertionIndex = lo;
87
69
 
88
- // item is located where it is expected to be according to the sort
89
70
  const itemAtExpectedIndex = getItemAt(insertionIndex);
90
71
  if (itemAtExpectedIndex && itemIdentityEquals(itemAtExpectedIndex, needle)) {
91
72
  return { currentIndex: insertionIndex, insertionIndex };
@@ -95,8 +76,6 @@ export function binarySearch<T>({
95
76
  return { currentIndex: -1, insertionIndex };
96
77
  }
97
78
 
98
- // --- 2) Plateau scan around insertionIndex ---
99
-
100
79
  const checkSide = (atIndex: number) => {
101
80
  const result = { exhausted: false, found: false };
102
81
  const item = getItemAt(atIndex);
@@ -105,9 +84,8 @@ export function binarySearch<T>({
105
84
  return result;
106
85
  };
107
86
 
108
- // Alternating left/right scan
109
87
  let iLeft = insertionIndex - 1;
110
- let iRight = insertionIndex + 1; // we've already checked insertionIndex
88
+ let iRight = insertionIndex + 1; // insertionIndex itself is already checked
111
89
  let leftDone = iLeft < 0;
112
90
  let rightDone = iRight >= length;
113
91
 
@@ -125,22 +103,19 @@ export function binarySearch<T>({
125
103
  }
126
104
  }
127
105
 
128
- // Not found in plateau; insertion index is still the correct lower bound.
129
106
  return { currentIndex: -1, insertionIndex };
130
107
  }
131
108
 
132
109
  /**
133
- * Negative number (< 0) → a comes before b
134
- *
135
- * Zero (0) → leave a and b unchanged relative to each other
136
- * (but they can still move relative to others — sort in JS is not guaranteed stable in older engines, though modern V8/Node/Chrome/Firefox make it stable)
137
- *
138
- * Positive number (> 0) → a comes after b
110
+ * Builds a comparator from a sort spec: terms apply in order, then `tiebreaker`.
111
+ * `null`/`undefined` values sort last whatever the direction.
139
112
  *
140
113
  * @param params - Comparator configuration.
141
114
  * @param params.sort - The sort specification defining fields and directions.
142
115
  * @param params.resolvePathValue - Resolver used to read a field value from an item.
143
- * @param params.tiebreaker - Comparator applied when all sort terms are equal.
116
+ * @param params.tiebreaker - Comparator applied when all sort terms are equal. Defaults to
117
+ * comparing `cid`.
118
+ * @returns The comparator.
144
119
  */
145
120
  export function makeComparator<T>({
146
121
  sort,
@@ -165,17 +140,15 @@ export function makeComparator<T>({
165
140
  comparison = compare(normalized.a, normalized.b);
166
141
  break;
167
142
  default: {
168
- // Null/undefined always sort to the tail, INDEPENDENT of `direction`. Return here so the
169
- // result bypasses the direction flip below — otherwise a descending sort (e.g.
170
- // `{ last_message_at: -1 }`) negates "null last" into "null first" and floats value-less
171
- // items (e.g. channels with no last message) to the head of the list.
143
+ // Return before the direction flip below, which would turn "null last" into "null first"
144
+ // on a descending sort.
172
145
  if (leftValue == null && rightValue == null) {
173
- comparison = 0; // tie on this term; fall through to the next term / tiebreaker
146
+ comparison = 0;
174
147
  break;
175
148
  }
176
- if (leftValue == null) return 1; // a (null) sorts after b
177
- if (rightValue == null) return -1; // b (null) sorts after a
178
- // Both non-null but not normalizable: deterministic string compare (respects direction).
149
+ if (leftValue == null) return 1;
150
+ if (rightValue == null) return -1;
151
+ // Both non-null but not normalizable: compare as strings (respects direction).
179
152
  const stringLeftValue = String(leftValue),
180
153
  stringRightValue = String(rightValue);
181
154
  comparison =