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,8 +1,3 @@
1
- /**
2
- * Core utility functions and types for mergeWith functionality.
3
- * This file contains shared logic used by both mergeWith and mergeWithDiff functions.
4
- */
5
-
6
1
  export type MergeWithCustomizer<T extends object> = (
7
2
  objValue: unknown,
8
3
  srcValue: unknown,
@@ -28,19 +23,15 @@ export interface DiffNode {
28
23
  oldValue?: unknown;
29
24
  }
30
25
 
26
+ /** True for objects of a class other than `Object`. Arrays and plain objects are not. */
31
27
  export const isClassInstance = (value: unknown): boolean => {
32
28
  if (!value || typeof value !== 'object') return false;
33
29
 
34
- // Arrays are not class instances
35
30
  if (Array.isArray(value)) return false;
36
31
 
37
- // Get the prototype chain
38
32
  const proto = Object.getPrototypeOf(value);
39
-
40
- // If it's null or Object.prototype, it's a plain object
41
33
  if (proto === null || proto === Object.prototype) return false;
42
34
 
43
- // Check if it has a constructor that's not Object
44
35
  return value.constructor && value.constructor !== Object;
45
36
  };
46
37
 
@@ -55,18 +46,15 @@ function memoHasOrAdd(memo: PairMemo, a: object, b: object): boolean {
55
46
  }
56
47
 
57
48
  /**
58
- * Deep semantic equality with cycle safety and symbol-key support.
59
- * Keeps your existing semantics:
60
- * - Dates/RegExps compared by value
61
- * - "Class instances" are treated atomically (unequal unless ===)
62
- * - NaN equals NaN; -0 equals 0 (same as ===)
49
+ * Deep equality that is cycle-safe and covers symbol keys. Dates and RegExps compare by value, Sets
50
+ * and Maps by content, other class instances only by `===`. `NaN` equals `NaN`, `-0` equals `0`.
63
51
  */
64
52
  export const isEqual = (
65
53
  value1: unknown,
66
54
  value2: unknown,
67
55
  pairMemo: PairMemo = new WeakMap(),
68
56
  ): boolean => {
69
- if (value1 === value2) return true; // includes -0 === 0
57
+ if (value1 === value2) return true;
70
58
  if (value1 == null || value2 == null) return false;
71
59
 
72
60
  const t1 = typeof value1;
@@ -74,21 +62,18 @@ export const isEqual = (
74
62
  if (t1 !== t2) return false;
75
63
 
76
64
  if (t1 !== 'object') {
77
- // NaN handling
78
65
  // eslint-disable-next-line no-self-compare
79
66
  return value1 !== value1 && value2 !== value2 ? true : value1 === value2;
80
67
  }
81
68
 
82
- // Objects
83
69
  const o1 = value1 as object;
84
70
  const o2 = value2 as object;
85
71
 
86
- // Fast path for tag mismatch
87
72
  const tag1 = Object.prototype.toString.call(o1);
88
73
  const tag2 = Object.prototype.toString.call(o2);
89
74
  if (tag1 !== tag2) return false;
90
75
 
91
- // Special cases before instance test
76
+ // Dates and RegExps are class instances: compare them before that test.
92
77
  if (o1 instanceof Date && o2 instanceof Date) {
93
78
  return (o1 as Date).getTime() === (o2 as Date).getTime();
94
79
  }
@@ -98,11 +83,7 @@ export const isEqual = (
98
83
  return r1.source === r2.source && r1.flags === r2.flags;
99
84
  }
100
85
 
101
- // Handle Set comparison
102
- // Two sets are equal if they have the same size and
103
- // every value in one has an equivalent value in the
104
- // other (using deep equality).
105
- // Cannot use the same item for multiple matches in another set.
86
+ // Sets are equal when every value matches a distinct deep-equal value in the other.
106
87
  if (value1 instanceof Set && value2 instanceof Set) {
107
88
  if (value1.size !== value2.size) return false;
108
89
  if (memoHasOrAdd(pairMemo, value1, value2)) return true;
@@ -113,7 +94,7 @@ export const isEqual = (
113
94
  let matched = false;
114
95
  for (const v2 of unmatched) {
115
96
  if (isEqual(v1, v2, pairMemo)) {
116
- unmatched.delete(v2); // consume the match
97
+ unmatched.delete(v2);
117
98
  matched = true;
118
99
  break;
119
100
  }
@@ -124,13 +105,12 @@ export const isEqual = (
124
105
  return unmatched.size === 0;
125
106
  }
126
107
 
127
- // Handle Map comparison
128
108
  if (value1 instanceof Map && value2 instanceof Map) {
129
109
  if (value1.size !== value2.size) return false;
130
110
 
131
111
  if (memoHasOrAdd(pairMemo, value1, value2)) return true;
132
112
 
133
- const unmatched = new Set(value2); // tracks entries in map2 not yet matched
113
+ const unmatched = new Set(value2);
134
114
 
135
115
  for (const [k1, v1] of value1) {
136
116
  let matchedEntry: [unknown, unknown] | null = null;
@@ -143,20 +123,19 @@ export const isEqual = (
143
123
  }
144
124
  }
145
125
 
146
- if (!matchedEntry) return false; // nothing matched this entry
147
- unmatched.delete(matchedEntry); // consume it
126
+ if (!matchedEntry) return false;
127
+ unmatched.delete(matchedEntry);
148
128
  }
149
129
 
150
130
  return unmatched.size === 0;
151
131
  }
152
132
 
153
- // Treat non-plain instances atomically (your current rule)
154
133
  if (isClassInstance(o1) || isClassInstance(o2)) return false;
155
134
 
156
- // Cycle guard (pairwise)
135
+ // Cycle guard: a pair already being compared counts as equal.
157
136
  if (memoHasOrAdd(pairMemo, o1, o2)) return true;
158
137
 
159
- // Arrays (respect holes vs undefined)
138
+ // A hole differs from `undefined`.
160
139
  if (Array.isArray(o1)) {
161
140
  const a1 = value1 as unknown[],
162
141
  a2 = value2 as unknown[];
@@ -167,7 +146,6 @@ export const isEqual = (
167
146
  if (has1 !== has2) return false;
168
147
  if (has1 && !isEqual(a1[i], a2[i], pairMemo)) return false;
169
148
  }
170
- // Compare enumerable non-index props as well (to align with objects)
171
149
  const extraKeys1 = Reflect.ownKeys(o1)
172
150
  .filter((k) => typeof k !== 'string' || isNaN(+k))
173
151
  .filter((k) => Object.prototype.propertyIsEnumerable.call(o1, k));
@@ -183,7 +161,6 @@ export const isEqual = (
183
161
  return true;
184
162
  }
185
163
 
186
- // Plain objects (string + symbol enumerable own keys)
187
164
  const keys1 = Reflect.ownKeys(o1).filter((k) =>
188
165
  Object.prototype.propertyIsEnumerable.call(o1, k),
189
166
  );
@@ -192,7 +169,7 @@ export const isEqual = (
192
169
  );
193
170
  if (keys1.length !== keys2.length) return false;
194
171
 
195
- // enforce same prototype to avoid {} == Object.create(null, ...)
172
+ // Same prototype, so `{}` differs from `Object.create(null)`.
196
173
  if (Object.getPrototypeOf(o1) !== Object.getPrototypeOf(o2)) return false;
197
174
 
198
175
  for (const k of keys1) {
@@ -203,42 +180,27 @@ export const isEqual = (
203
180
  return true;
204
181
  };
205
182
 
206
- /**
207
- * Generates a diff between original and modified objects.
208
- * This is used after the merge operation to track what has changed.
209
- */
183
+ /** Diff of the keys added or updated in `modified`, or `null` when there are none. */
210
184
  export function generateDiff(original: unknown, modified: unknown): DiffNode | null {
211
- // Root diff node
212
185
  const diffRoot: DiffNode = { children: {} };
213
186
 
214
- // Compare the objects and build the diff tree
215
187
  compareAndBuildDiff(original, modified, diffRoot);
216
188
 
217
- // Clean up the diff tree (remove empty nodes)
218
189
  return cleanupDiffTree(diffRoot);
219
190
  }
220
191
 
221
- /**
222
- * Helper function to compare and build the diff tree
223
- */
224
192
  function compareAndBuildDiff(
225
193
  original: unknown,
226
194
  modified: unknown,
227
195
  parentDiffNode: DiffNode,
228
196
  key?: string | symbol,
229
197
  pairMemo: PairMemo = new WeakMap(),
230
- /**
231
- * Tracks individual objects that are being processed in the current traversal path
232
- * - It's used to detect when we encounter the same object multiple times in a single traversal path
233
- * - This helps identify self-referential or circular structures within a single object (e.g., when an object references itself)
234
- * - When an object appears in `objectStack` again, we know it's a circular reference within the same object
235
- */
198
+ /** Objects on the current traversal path, to detect an object that references itself. */
236
199
  objectStack = new Set<unknown>(),
237
200
  ): void {
238
- // If values are equal, no diff to record
239
201
  if (isEqual(original, modified)) return;
240
202
 
241
- // Handle additions (value in modified but not in original)
203
+ // A null/undefined original counts as an addition.
242
204
  if (original === undefined || original === null) {
243
205
  if (key !== undefined) {
244
206
  parentDiffNode.children[String(key)] = {
@@ -250,7 +212,6 @@ function compareAndBuildDiff(
250
212
  return;
251
213
  }
252
214
 
253
- // Check for circular references in objects
254
215
  if (typeof original === 'object' && original !== null) {
255
216
  if (objectStack.has(original)) {
256
217
  if (key !== undefined) {
@@ -266,7 +227,6 @@ function compareAndBuildDiff(
266
227
  objectStack.add(original);
267
228
  }
268
229
 
269
- // Check if we're dealing with non-objects or special object types that should be treated atomically
270
230
  const shouldTreatAtomically =
271
231
  typeof original !== 'object' ||
272
232
  typeof modified !== 'object' ||
@@ -286,18 +246,15 @@ function compareAndBuildDiff(
286
246
  };
287
247
  }
288
248
 
289
- // Remove from object stack if it was added
290
249
  if (typeof original === 'object' && original !== null) {
291
250
  objectStack.delete(original);
292
251
  }
293
252
  return;
294
253
  }
295
254
 
296
- // Handle objects
297
255
  const originalObj = original as Record<string | symbol, unknown>;
298
256
  const modifiedObj = modified as Record<string | symbol, unknown>;
299
257
 
300
- // Create a diff node for this level if we're processing a property
301
258
  const currentDiffNode =
302
259
  key !== undefined
303
260
  ? {
@@ -312,7 +269,7 @@ function compareAndBuildDiff(
312
269
  parentDiffNode.children[String(key)] = currentDiffNode;
313
270
  }
314
271
 
315
- // Pairwise cycle check (prevents infinite recursion across the *pair*)
272
+ // Pairwise cycle check.
316
273
  if (
317
274
  typeof original === 'object' &&
318
275
  original !== null &&
@@ -320,14 +277,11 @@ function compareAndBuildDiff(
320
277
  modified !== null
321
278
  ) {
322
279
  if (memoHasOrAdd(pairMemo, original as object, modified as object)) {
323
- // already visited this exact pair in this diff traversal
324
- // (prevents infinite recursion), so stop here
325
280
  if (typeof original === 'object') objectStack.delete(original);
326
281
  return;
327
282
  }
328
283
  }
329
284
 
330
- // Process all keys from both objects
331
285
  const allKeys = new Set([
332
286
  ...Object.keys(originalObj),
333
287
  ...Object.getOwnPropertySymbols(originalObj),
@@ -339,13 +293,11 @@ function compareAndBuildDiff(
339
293
  const originalValue = originalObj[childKey];
340
294
  const modifiedValue = modifiedObj[childKey];
341
295
 
342
- // Handle deleted properties (they exist in original but not in modified)
296
+ // Deletions are not tracked.
343
297
  if (!(childKey in modifiedObj)) {
344
- // Currently we don't track deletions, but could be added here if needed
345
298
  continue;
346
299
  }
347
300
 
348
- // Handle added properties (they exist in modified but not in original)
349
301
  if (!(childKey in originalObj)) {
350
302
  currentDiffNode.children[String(childKey)] = {
351
303
  type: 'added',
@@ -355,7 +307,6 @@ function compareAndBuildDiff(
355
307
  continue;
356
308
  }
357
309
 
358
- // Process properties that exist in both but may have changed
359
310
  compareAndBuildDiff(
360
311
  originalValue,
361
312
  modifiedValue,
@@ -383,7 +334,6 @@ export function createMergeCore<T extends object>(options: { trackDiff?: boolean
383
334
  }): { result: T; diff: DiffNode | null } {
384
335
  const sources = Array.isArray(source) ? source : [source];
385
336
 
386
- // Store the original target if we need to track diffs
387
337
  const originalTarget = trackDiff ? structuredClone(target) : undefined;
388
338
 
389
339
  function handleCustomizer(
@@ -422,21 +372,18 @@ export function createMergeCore<T extends object>(options: { trackDiff?: boolean
422
372
  return srcValue;
423
373
  }
424
374
  if (targetValue && typeof targetValue === 'object') {
425
- // Check if it's a class instance (not a plain object)
426
375
  const isTargetClassInstance = isClassInstance(targetValue);
427
376
  const isSourceClassInstance = isClassInstance(srcValue);
428
377
 
429
- // If either is a class instance, don't try to merge them
378
+ // A class instance on either side is not merged: the source one wins, else the target
379
+ // stays.
430
380
  if (isTargetClassInstance || isSourceClassInstance) {
431
- // If source is a class instance, use it
432
381
  if (isSourceClassInstance) {
433
382
  return srcValue as object;
434
383
  }
435
- // Otherwise preserve the target
436
384
  return targetValue;
437
385
  }
438
386
 
439
- // For plain objects, use normal merging
440
387
  return Array.isArray(targetValue) ? [...targetValue] : { ...targetValue };
441
388
  }
442
389
  return Array.isArray(srcValue) ? [] : {};
@@ -501,10 +448,8 @@ export function createMergeCore<T extends object>(options: { trackDiff?: boolean
501
448
  pendingMerges: PendingMerge[],
502
449
  ): void {
503
450
  if (stack.has(source)) {
504
- // We've detected a circular reference in the source object
505
- // Just skip this merge to avoid infinite recursion
506
-
507
- // If we're tracking diffs, we need to mark this as a circular reference
451
+ // Circular reference in the source: skip the merge. With diff tracking the target is re-set
452
+ // on the parent.
508
453
  if (trackDiff && sourceKey && parentTarget) {
509
454
  Object.defineProperty(parentTarget, sourceKey, {
510
455
  value: target,
@@ -526,7 +471,7 @@ export function createMergeCore<T extends object>(options: { trackDiff?: boolean
526
471
  }
527
472
 
528
473
  function baseMerge(object: T, source: object, stack = new Set<unknown>()): T {
529
- // prevent infinite recursion
474
+ // Prevents infinite recursion.
530
475
  if (stack.has(object) || stack.has(source)) {
531
476
  return { ...object };
532
477
  }
@@ -553,7 +498,6 @@ export function createMergeCore<T extends object>(options: { trackDiff?: boolean
553
498
  ...target,
554
499
  } as T);
555
500
 
556
- // If diff tracking is enabled, generate the diff after the merge is complete
557
501
  const diff =
558
502
  trackDiff && originalTarget ? generateDiff(originalTarget, result) : null;
559
503
 
@@ -561,7 +505,7 @@ export function createMergeCore<T extends object>(options: { trackDiff?: boolean
561
505
  };
562
506
  }
563
507
 
564
- // Utility function to clean up the diff tree by removing empty child nodes
508
+ /** Prunes nodes that have no type and no children. Returns `null` for an empty tree. */
565
509
  export function cleanupDiffTree(diffNode: DiffNode): DiffNode | null {
566
510
  const cleanChildren: Record<string | symbol, DiffNode> = {};
567
511
  let hasChildren = false;
@@ -574,7 +518,6 @@ export function cleanupDiffTree(diffNode: DiffNode): DiffNode | null {
574
518
  }
575
519
  }
576
520
 
577
- // If this node has a type (added/updated) or has children, keep it
578
521
  if (diffNode.type || hasChildren) {
579
522
  return {
580
523
  ...diffNode,
@@ -1,44 +1,28 @@
1
+ import { cleanupDiffTree, createMergeCore } from './mergeWithCore';
2
+ import type { DiffNode, MergeWithCustomizer } from './mergeWithCore';
3
+
1
4
  /**
2
- * This method is like `mergeWith` except that it also returns information about
3
- * which keys have been added or updated during the merge operation.
5
+ * Like `mergeWith`, and also returns a hierarchical diff of the keys that were added or
6
+ * updated.
4
7
  *
5
- * @category Object
6
- * @param object - The destination object.
7
- * @param source - A single source object or an array of objects to be merged into the object.
8
+ * @param target - The destination object. It is not mutated.
9
+ * @param source - A single source object or an array of objects to be merged into `target`.
8
10
  * @param customizer - The function to customize assigned values.
9
- * @returns Returns an object containing the merged result and a hierarchical diff object.
11
+ * @returns The merged result and a hierarchical diff object.
10
12
  * @example
11
13
  *
12
- * function customizer(objValue, srcValue) {
13
- * if (Array.isArray(objValue)) {
14
- * return objValue.concat(srcValue);
15
- * }
16
- * }
17
- *
18
- * var object = {
19
- * 'fruits': ['apple'],
20
- * 'vegetables': ['beet']
21
- * };
22
- *
23
- * var other = {
24
- * 'fruits': ['banana'],
25
- * 'vegetables': ['carrot'],
26
- * 'grains': ['wheat']
27
- * };
28
- *
29
- * const { result, diff } = mergeWithDiff({ target: object, source: other, customizer });
30
- * // result => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'], 'grains': ['wheat'] }
14
+ * const { result, diff } = mergeWithDiff({ a: 1, b: { c: 2 } }, { b: { c: 3 }, d: 4 });
15
+ * // result => { a: 1, b: { c: 3 }, d: 4 }
31
16
  * // diff => {
32
17
  * // children: {
33
- * // 'fruits': { type: 'updated', value: ['banana'], oldValue: ['apple'], children: {} },
34
- * // 'vegetables': { type: 'updated', value: ['carrot'], oldValue: ['beet'], children: {} },
35
- * // 'grains': { type: 'added', value: ['wheat'], children: {} }
18
+ * // b: {
19
+ * // type: 'updated', value: { c: 3 }, oldValue: { c: 2 },
20
+ * // children: { c: { type: 'updated', value: 3, oldValue: 2, children: {} } }
21
+ * // },
22
+ * // d: { type: 'added', value: 4, children: {} }
36
23
  * // }
37
24
  * // }
38
25
  */
39
- import { cleanupDiffTree, createMergeCore } from './mergeWithCore';
40
- import type { DiffNode, MergeWithCustomizer } from './mergeWithCore';
41
-
42
26
  export function mergeWithDiff<T extends object>(
43
27
  target: T,
44
28
  source: object | object[],
@@ -47,7 +31,5 @@ export function mergeWithDiff<T extends object>(
47
31
  const mergeCore = createMergeCore<T>({ trackDiff: true });
48
32
  const { result, diff } = mergeCore({ target, source, customizer });
49
33
 
50
- // Clean up the diff tree to remove empty nodes
51
-
52
34
  return { result, diff: cleanupDiffTree(diff ?? { children: {} }) || { children: {} } };
53
35
  }
@@ -1,52 +1,20 @@
1
1
  /**
2
- * Dot-path access over **plain-object trees**, with presence and value as separate questions.
2
+ * Dot-path access over plain-object trees. `hasPath` tells an explicit `undefined` from an absent
3
+ * key, which `getPath` cannot.
3
4
  *
4
- * The pair exists because {@link getPath} alone cannot answer "was this path registered?". A configuration
5
- * patch may carry an explicit `undefined` — `{ messagePaginator: { initialCursor: undefined } }` — and a
6
- * caller that has to tell that apart from an absent key needs {@link hasPath}, since both read back as
7
- * `undefined`. That distinction is the whole reason the construction-only diagnostic in
8
- * `InstanceConfigurationRegistry` can report a late registration at all.
9
- *
10
- * **Descends into plain objects only**, deliberately. A configuration tree holds class instances
11
- * (`itemIndex`), functions and arrays as leaf *values*, and walking into their internals would be both
12
- * meaningless and slow — `hasPath(config, 'messagePaginator.initialCursor')` must not start indexing an
13
- * `ItemIndex`.
14
- *
15
- * **Three other dot-path walkers exist in this package and none is a drop-in replacement**, which is worth
16
- * knowing before adding a fourth:
17
- *
18
- * - `get` in `src/utils.ts` (module-private, backs `uniqBy`) returns `undefined` for a missing path *and* for
19
- * a present-but-undefined one, so it cannot express `hasPath`. It also descends on
20
- * `typeof acc === 'object'`, which includes arrays and class instances.
21
- * - `resolveDotPathValue` in `src/pagination/utility.normalization.ts` (backs the filter compiler)
22
- * short-circuits on any falsy intermediate value, so `''.length` resolves to `undefined` rather than `0`.
23
- * Its declared return type is `unknown[]` while it returns `unknown`.
24
- * - `examples/vite`'s Configuration tab carries a segment-array variant identical in behaviour to this one.
25
- *
26
- * Consolidating those is a separate change: two of them are load-bearing for unrelated subsystems, and the
27
- * filter compiler's falsy short-circuit is a behaviour difference rather than a refactor.
5
+ * Descends into plain objects only: arrays, class instances and functions are leaf values.
28
6
  *
29
7
  * @internal
30
8
  */
31
9
 
32
- /**
33
- * A record this module is willing to walk into: an object literal or `Object.create(null)`, and nothing
34
- * else. Arrays, `Date`s, `RegExp`s and class instances are configuration *values*, not interiors.
35
- *
36
- * The prototype check is what makes that true. A `typeof value === 'object' && !Array.isArray(value)` test —
37
- * which is what this and the three sibling walkers all used — happily descends into a class instance, so
38
- * `hasPath(config, 'itemIndex.length')` answered `true` for a path that is not configuration at all.
39
- */
10
+ /** An object literal or `Object.create(null)`. Arrays, Dates and class instances are leaves. */
40
11
  export const isWalkableRecord = (value: unknown): value is Record<string, unknown> => {
41
12
  if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;
42
13
  const prototype = Object.getPrototypeOf(value);
43
14
  return prototype === Object.prototype || prototype === null;
44
15
  };
45
16
 
46
- /**
47
- * Whether a dot-path is present. A key explicitly set to `undefined` counts as present — that is the point
48
- * of having this alongside {@link getPath}.
49
- */
17
+ /** Whether a dot-path is present. A key set to `undefined` counts as present. */
50
18
  export const hasPath = (source: Record<string, unknown>, path: string): boolean => {
51
19
  const [head, ...rest] = path.split('.');
52
20
  if (!(head in source)) return false;
@@ -55,10 +23,7 @@ export const hasPath = (source: Record<string, unknown>, path: string): boolean
55
23
  return isWalkableRecord(next) ? hasPath(next, rest.join('.')) : false;
56
24
  };
57
25
 
58
- /**
59
- * The value at a dot-path, or `undefined` when the path is absent. Pair with {@link hasPath} when the two
60
- * cases have to be told apart.
61
- */
26
+ /** The value at a dot-path, or `undefined` when absent. Use {@link hasPath} to tell them apart. */
62
27
  export const getPath = (source: Record<string, unknown>, path: string): unknown => {
63
28
  const [head, ...rest] = path.split('.');
64
29
  const next = source[head];
@@ -2,7 +2,6 @@ type FunctionToRetry<T = any> = (...functionArguments: any[]) => PromiseLike<T>;
2
2
 
3
3
  enum RetryErrorType {
4
4
  ABORT,
5
- ATTEMPT_LIMIT_REACHED,
6
5
  }
7
6
 
8
7
  export class RetryError extends Error {
@@ -10,7 +9,6 @@ export class RetryError extends Error {
10
9
 
11
10
  private static errorMap = {
12
11
  [RetryErrorType.ABORT]: 'Value changed, retry handler aborted',
13
- [RetryErrorType.ATTEMPT_LIMIT_REACHED]: 'Reached maximum amount of retry attempts',
14
12
  } satisfies Record<RetryErrorType, string>;
15
13
 
16
14
  constructor({ type }: { type: RetryErrorType }) {
@@ -49,17 +47,14 @@ export type RunWithRetryOptions<T extends FunctionToRetry> = {
49
47
  };
50
48
 
51
49
  /**
52
- * Function which wraps asynchronous functions with retry mechanism which'll keep executing said
53
- * function pre-defined number of times until it resolves, rejects or the retry mechanism runs out of available attempts.
50
+ * Wraps `f` so a failed call is retried. Throws the error when it is not retryable, else the last
51
+ * attempt's error once the retries run out. A falsy result counts as a failure and is retried.
54
52
  *
55
- * #### Available options:
56
- * - `didValueChange` - check function with initial argument value to check against new values, return `true` to abort next attempt
57
- *
58
- * - `isRetryable` - error evaluation function which determines whether to retry the execution
59
- *
60
- * - `delayBetweenRetries` - accepts either fixed numeric value or function which provides retry attempt as the argument, expects number as return value
61
- *
62
- * - `retryAttempts` - number of attempts to try out before rejecting the promise
53
+ * - `retryAttempts`: retries after the first attempt. Defaults to 3.
54
+ * - `isRetryable`: whether an error is worth retrying. Defaults to always.
55
+ * - `delayBetweenRetries`: ms, or a function of the 0-based retry number.
56
+ * - `didValueChange`: called with the call arguments before each attempt, `true` aborts with a
57
+ * `RetryError`.
63
58
  */
64
59
  export const runWithRetry = <T extends FunctionToRetry>(
65
60
  f: T,
@@ -73,10 +68,11 @@ export const runWithRetry = <T extends FunctionToRetry>(
73
68
  async function retryable(...functionArguments: Parameters<T>) {
74
69
  // starting with -1 as first attempt is not considered a retry
75
70
  let retryAttempt = -1;
71
+ let error: unknown = null;
76
72
 
77
73
  do {
78
74
  let data: Awaited<ReturnType<T>> | null = null;
79
- let error: unknown = null;
75
+ error = null;
80
76
 
81
77
  if (await didValueChange?.(...functionArguments)) {
82
78
  throw new RetryError({ type: RetryErrorType.ABORT });
@@ -113,5 +109,5 @@ export const runWithRetry = <T extends FunctionToRetry>(
113
109
  }
114
110
  } while (retryAttempt < retryAttempts);
115
111
 
116
- throw new RetryError({ type: RetryErrorType.ATTEMPT_LIMIT_REACHED });
112
+ throw error;
117
113
  };
@@ -1,40 +1,25 @@
1
1
  export type ThrottledCallback = (...args: unknown[]) => unknown;
2
2
 
3
3
  export type ThrottleOptions = {
4
- /** Call on the leading edge (default: true). */
4
+ /** Call on the leading edge. Defaults to `true`. */
5
5
  leading?: boolean;
6
- /** Call once at the end of the window with the latest args (default: false). */
6
+ /** Call once at the end of the window with the latest args. Defaults to `false`. */
7
7
  trailing?: boolean;
8
8
  };
9
9
 
10
10
  export type Throttled<T extends unknown[]> = {
11
- /**
12
- * The throttled function — call it as often as you like; it invokes `fn` at most once per window
13
- * (leading and/or trailing per options).
14
- */
11
+ /** Invokes `fn` at most once per window (leading and/or trailing, per options). */
15
12
  throttledFn: (...args: T) => void;
16
- /** Clear a pending trailing invocation WITHOUT firing it. */
13
+ /** Clears a pending trailing invocation without firing it. */
17
14
  cancelTimer: () => void;
18
- /**
19
- * Fire a pending trailing invocation immediately (with the latest stored args), clearing the timer.
20
- * No-op when nothing is pending. Use to bypass the throttle delay for updates that must land now.
21
- */
15
+ /** Fires a pending trailing invocation now with the latest args. No-op when none is pending. */
22
16
  flush: () => void;
23
17
  };
24
18
 
25
19
  /**
26
- * Throttle a function so it runs at most once per `timeout` ms.
27
- *
28
- * - `leading`: fire immediately when the window opens
29
- * - `trailing`: remember the latest args/this and fire once when the window closes
30
- *
31
- * defaults: `{ leading: true, trailing: false }`
32
- *
33
- * Copied verbatim from the Feeds client (`packages/feeds-client/src/utils/throttling/throttle.ts`)
34
- * and extended with a `flush()` method (the Feeds version only exposes `cancelTimer()`).
35
- *
36
- * notes:
37
- * - make one throttled instance and reuse it; re-creating it resets internal state
20
+ * Runs `fn` at most once per `timeout` ms. `leading` fires when the window opens, `trailing` fires
21
+ * once at its end with the latest args and `this` (see {@link ThrottleOptions}). Create one
22
+ * instance and reuse it: recreating it resets the window. `timeout` defaults to 200.
38
23
  */
39
24
  export const throttle = <T extends unknown[]>(
40
25
  fn: (...args: T) => void,
@@ -110,8 +95,7 @@ export const throttle = <T extends unknown[]>(
110
95
  clearTimeout(timer);
111
96
  timer = null;
112
97
  }
113
- // We discard the pending trailing too, otherwise a later flush() would refire
114
- // the invocation this cancel was meant to drop.
98
+ // Also drops the stored args, so a later `flush()` cannot refire them.
115
99
  storedArgs = null;
116
100
  storedThis = null;
117
101
  },