stream-chat 10.0.0-rc.8 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (366) hide show
  1. package/README.md +7 -6
  2. package/dist/cjs/index.browser.js +22095 -22290
  3. package/dist/cjs/index.browser.js.map +4 -4
  4. package/dist/cjs/index.node.js +22143 -22298
  5. package/dist/cjs/index.node.js.map +4 -4
  6. package/dist/esm/index.mjs +22093 -22288
  7. package/dist/esm/index.mjs.map +4 -4
  8. package/dist/types/ChannelManager.d.ts +216 -135
  9. package/dist/types/CooldownTimer.d.ts +16 -27
  10. package/dist/types/EventHandlerPipeline.d.ts +18 -38
  11. package/dist/types/LiveLocationManager.d.ts +25 -47
  12. package/dist/types/api-client.d.ts +17 -5
  13. package/dist/types/channel.d.ts +435 -500
  14. package/dist/types/channel_state.d.ts +72 -112
  15. package/dist/types/client.d.ts +323 -440
  16. package/dist/types/client_state.d.ts +1 -3
  17. package/dist/types/configuration/ConfigController.d.ts +31 -125
  18. package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +32 -124
  19. package/dist/types/configuration/keys.d.ts +5 -19
  20. package/dist/types/configuration/shape.d.ts +12 -29
  21. package/dist/types/configuration/types.d.ts +64 -79
  22. package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +14 -36
  23. package/dist/types/configuration/utils/copyConfigPatch.d.ts +8 -0
  24. package/dist/types/configuration/utils/declarativeSlices.d.ts +5 -16
  25. package/dist/types/configuration/utils/deepFreezeConfig.d.ts +3 -17
  26. package/dist/types/configuration/utils/serverAuthority.d.ts +9 -29
  27. package/dist/types/connection/ConnectionIdManager.d.ts +45 -0
  28. package/dist/types/connection/ConnectionRecoveryManager.d.ts +84 -0
  29. package/dist/types/connection/index.d.ts +4 -0
  30. package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +82 -0
  31. package/dist/types/connection/networkConnection/index.d.ts +3 -0
  32. package/dist/types/connection/networkConnection/reporters.d.ts +20 -0
  33. package/dist/types/connection/networkConnection/types.d.ts +40 -0
  34. package/dist/types/connection/wsConnection/StableWSConnection.d.ts +137 -0
  35. package/dist/types/connection/wsConnection/WSConnection.d.ts +105 -0
  36. package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +47 -0
  37. package/dist/types/connection/wsConnection/config.d.ts +31 -0
  38. package/dist/types/connection/wsConnection/index.d.ts +4 -0
  39. package/dist/types/connection/wsConnection/types.d.ts +46 -0
  40. package/dist/types/constants.d.ts +3 -1
  41. package/dist/types/custom_types.d.ts +0 -2
  42. package/dist/types/entityStore/EntityStore.d.ts +226 -65
  43. package/dist/types/entityStore/StoreBackedItemIndex.d.ts +19 -33
  44. package/dist/types/entityStore/index.d.ts +0 -1
  45. package/dist/types/errors.d.ts +16 -19
  46. package/dist/types/formatMessageMemo.d.ts +5 -0
  47. package/dist/types/gen/chat/ChannelApi.d.ts +5 -1
  48. package/dist/types/gen/chat/ChatApi.d.ts +149 -105
  49. package/dist/types/gen/models/index.d.ts +2540 -698
  50. package/dist/types/gen/models/timestamp-guard.d.ts +22 -0
  51. package/dist/types/gen/moderation/ModerationApi.d.ts +37 -14
  52. package/dist/types/index.d.ts +10 -5
  53. package/dist/types/{i18n/languageNames.d.ts → languageNames.d.ts} +9 -24
  54. package/dist/types/logger.d.ts +1 -3
  55. package/dist/types/messageComposer/CustomDataManager.d.ts +7 -1
  56. package/dist/types/messageComposer/LocationComposer.d.ts +8 -2
  57. package/dist/types/messageComposer/attachmentIdentity.d.ts +24 -0
  58. package/dist/types/messageComposer/attachmentManager.d.ts +52 -24
  59. package/dist/types/messageComposer/attachmentUtils.d.ts +23 -0
  60. package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
  61. package/dist/types/messageComposer/configuration/types.d.ts +38 -50
  62. package/dist/types/messageComposer/index.d.ts +1 -0
  63. package/dist/types/messageComposer/linkPreviewsManager.d.ts +12 -9
  64. package/dist/types/messageComposer/messageComposer.d.ts +60 -123
  65. package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +10 -1
  66. package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +4 -0
  67. package/dist/types/messageComposer/middleware/messageComposer/commandInjection.d.ts +5 -0
  68. package/dist/types/messageComposer/middleware/messageComposer/index.d.ts +2 -0
  69. package/dist/types/messageComposer/middleware/messageComposer/pollOnly.d.ts +6 -0
  70. package/dist/types/messageComposer/middleware/messageComposer/userDataInjection.d.ts +5 -0
  71. package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +2 -4
  72. package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +7 -19
  73. package/dist/types/messageComposer/middleware/textComposer/commandUtils.d.ts +4 -0
  74. package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +11 -2
  75. package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +20 -19
  76. package/dist/types/messageComposer/middleware/textComposer/textMiddlewareUtils.d.ts +9 -3
  77. package/dist/types/messageComposer/middleware/textComposer/types.d.ts +1 -6
  78. package/dist/types/messageComposer/pollComposer.d.ts +15 -5
  79. package/dist/types/messageComposer/textComposer.d.ts +14 -7
  80. package/dist/types/messageComposer/types.d.ts +27 -7
  81. package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +27 -80
  82. package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +43 -73
  83. package/dist/types/messageOperations/FailedSendCache.d.ts +29 -0
  84. package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +16 -22
  85. package/dist/types/messageOperations/MessageOperations.d.ts +63 -34
  86. package/dist/types/messageOperations/applyReactionLocally.d.ts +15 -0
  87. package/dist/types/messageOperations/createMessageOperations.d.ts +9 -0
  88. package/dist/types/messageOperations/index.d.ts +6 -4
  89. package/dist/types/messageOperations/reflectReactionEvent.d.ts +16 -0
  90. package/dist/types/messageOperations/sendOrdering.d.ts +14 -0
  91. package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +20 -0
  92. package/dist/types/messageOperations/types.d.ts +43 -14
  93. package/dist/types/middleware.d.ts +10 -0
  94. package/dist/types/moderation.d.ts +21 -14
  95. package/dist/types/notifications/NotificationManager.d.ts +10 -23
  96. package/dist/types/notifications/types.d.ts +21 -57
  97. package/dist/types/offline-support/offline_support_api.d.ts +150 -528
  98. package/dist/types/offline-support/offline_sync_manager.d.ts +21 -42
  99. package/dist/types/offline-support/queueableOperations.d.ts +35 -37
  100. package/dist/types/offline-support/types.d.ts +40 -185
  101. package/dist/types/pagination/FilterBuilder.d.ts +1 -18
  102. package/dist/types/pagination/ItemIndex.d.ts +4 -12
  103. package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +13 -0
  104. package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +4 -5
  105. package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +19 -5
  106. package/dist/types/pagination/index.d.ts +1 -0
  107. package/dist/types/pagination/paginators/BasePaginator.d.ts +604 -550
  108. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +123 -106
  109. package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +576 -327
  110. package/dist/types/pagination/paginators/MessagePaginator.d.ts +237 -131
  111. package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +15 -26
  112. package/dist/types/pagination/paginators/ReminderPaginator.d.ts +4 -3
  113. package/dist/types/pagination/paginators/ThreadPaginator.d.ts +44 -0
  114. package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +5 -8
  115. package/dist/types/pagination/paginators/index.d.ts +1 -0
  116. package/dist/types/pagination/sortCompiler.d.ts +11 -22
  117. package/dist/types/pagination/utility.normalization.d.ts +8 -13
  118. package/dist/types/pagination/utility.search.d.ts +3 -8
  119. package/dist/types/poll.d.ts +35 -8
  120. package/dist/types/poll_manager.d.ts +12 -2
  121. package/dist/types/poll_optimistic_votes.d.ts +57 -0
  122. package/dist/types/reminders/Reminder.d.ts +17 -7
  123. package/dist/types/reminders/ReminderManager.d.ts +13 -25
  124. package/dist/types/search/BaseSearchSource.d.ts +10 -8
  125. package/dist/types/search/ChannelSearchSource.d.ts +16 -0
  126. package/dist/types/search/MessageSearchSource.d.ts +17 -0
  127. package/dist/types/search/SearchController.d.ts +26 -28
  128. package/dist/types/search/types.d.ts +6 -10
  129. package/dist/types/signing.d.ts +12 -3
  130. package/dist/types/thread.d.ts +67 -129
  131. package/dist/types/thread_manager.d.ts +95 -66
  132. package/dist/types/token_manager.d.ts +8 -13
  133. package/dist/types/types.d.ts +81 -197
  134. package/dist/types/types.utility.d.ts +3 -3
  135. package/dist/types/upload-utils.d.ts +5 -10
  136. package/dist/types/uploadManager.d.ts +31 -11
  137. package/dist/types/utils/FixedSizeQueueCache.d.ts +8 -11
  138. package/dist/types/utils/WithSubscriptions.d.ts +6 -16
  139. package/dist/types/utils/abort.d.ts +17 -0
  140. package/dist/types/utils/concurrency.d.ts +12 -20
  141. package/dist/types/utils/mergeWith/mergeWith.d.ts +8 -11
  142. package/dist/types/utils/mergeWith/mergeWithCore.d.ts +5 -13
  143. package/dist/types/utils/mergeWith/mergeWithDiff.d.ts +22 -0
  144. package/dist/types/utils/objectPath.d.ts +6 -41
  145. package/dist/types/utils/retryable.d.ts +8 -12
  146. package/dist/types/utils/throttling/throttle.d.ts +8 -23
  147. package/dist/types/utils/time.d.ts +45 -0
  148. package/dist/types/utils.d.ts +74 -93
  149. package/package.json +14 -40
  150. package/src/ChannelManager.ts +494 -303
  151. package/src/CooldownTimer.ts +46 -59
  152. package/src/EventHandlerPipeline.ts +22 -45
  153. package/src/LiveLocationManager.ts +99 -91
  154. package/src/api-client.ts +113 -50
  155. package/src/campaign.ts +1 -1
  156. package/src/channel.ts +1098 -1351
  157. package/src/channel_batch_updater.ts +1 -1
  158. package/src/channel_state.ts +81 -174
  159. package/src/client.ts +755 -970
  160. package/src/client_state.ts +3 -8
  161. package/src/configuration/ConfigController.ts +42 -158
  162. package/src/configuration/InstanceConfigurationRegistry.ts +43 -172
  163. package/src/configuration/index.ts +1 -1
  164. package/src/configuration/keys.ts +13 -32
  165. package/src/configuration/shape.ts +169 -59
  166. package/src/configuration/types.ts +69 -92
  167. package/src/configuration/utils/applyInstanceConfiguration.ts +22 -54
  168. package/src/configuration/utils/copyConfigPatch.ts +11 -32
  169. package/src/configuration/utils/declarativeSlices.ts +9 -39
  170. package/src/configuration/utils/deepFreezeConfig.ts +3 -17
  171. package/src/configuration/utils/index.ts +2 -4
  172. package/src/configuration/utils/serverAuthority.ts +20 -68
  173. package/src/connection/ConnectionIdManager.ts +111 -0
  174. package/src/connection/ConnectionRecoveryManager.ts +257 -0
  175. package/src/connection/index.ts +4 -0
  176. package/src/connection/networkConnection/NetworkConnectionObserver.ts +204 -0
  177. package/src/connection/networkConnection/index.ts +3 -0
  178. package/src/connection/networkConnection/reporters.ts +58 -0
  179. package/src/connection/networkConnection/types.ts +45 -0
  180. package/src/{connection.ts → connection/wsConnection/StableWSConnection.ts} +230 -231
  181. package/src/connection/wsConnection/WSConnection.ts +270 -0
  182. package/src/connection/wsConnection/WSConnectionFallback.ts +250 -0
  183. package/src/connection/wsConnection/config.ts +73 -0
  184. package/src/connection/wsConnection/index.ts +4 -0
  185. package/src/connection/wsConnection/types.ts +48 -0
  186. package/src/constants.ts +7 -5
  187. package/src/custom_types.ts +0 -1
  188. package/src/entityStore/EntityStore.ts +415 -79
  189. package/src/entityStore/StoreBackedItemIndex.ts +37 -41
  190. package/src/entityStore/index.ts +0 -1
  191. package/src/errors.ts +39 -20
  192. package/src/formatMessageMemo.ts +17 -0
  193. package/src/gen/chat/ChannelApi.ts +122 -36
  194. package/src/gen/chat/ChatApi.ts +578 -1752
  195. package/src/gen/models/index.ts +2566 -3440
  196. package/src/gen/models/timestamp-guard.ts +27 -0
  197. package/src/gen/moderation/ModerationApi.ts +183 -406
  198. package/src/index.ts +32 -10
  199. package/src/languageNames.ts +88 -0
  200. package/src/logger.ts +1 -3
  201. package/src/messageComposer/CustomDataManager.ts +19 -6
  202. package/src/messageComposer/LocationComposer.ts +49 -9
  203. package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
  204. package/src/messageComposer/attachmentIdentity.ts +54 -0
  205. package/src/messageComposer/attachmentManager.ts +170 -185
  206. package/src/messageComposer/attachmentUtils.ts +44 -0
  207. package/src/messageComposer/configuration/configuration.ts +15 -8
  208. package/src/messageComposer/configuration/types.ts +38 -50
  209. package/src/messageComposer/fileUtils.ts +1 -1
  210. package/src/messageComposer/index.ts +1 -0
  211. package/src/messageComposer/linkPreviewsManager.ts +18 -21
  212. package/src/messageComposer/messageComposer.ts +234 -179
  213. package/src/messageComposer/middleware/attachmentManager/postUpload/AttachmentPostUploadMiddlewareExecutor.ts +1 -1
  214. package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +46 -33
  215. package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +4 -1
  216. package/src/messageComposer/middleware/attachmentManager/preUpload/blockedUploadNotification.ts +1 -1
  217. package/src/messageComposer/middleware/messageComposer/MessageComposerMiddlewareExecutor.ts +6 -0
  218. package/src/messageComposer/middleware/messageComposer/attachments.ts +76 -5
  219. package/src/messageComposer/middleware/messageComposer/commandInjection.ts +10 -4
  220. package/src/messageComposer/middleware/messageComposer/customData.ts +17 -5
  221. package/src/messageComposer/middleware/messageComposer/index.ts +2 -0
  222. package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +22 -12
  223. package/src/messageComposer/middleware/messageComposer/pollOnly.ts +9 -1
  224. package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +7 -2
  225. package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
  226. package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +12 -12
  227. package/src/messageComposer/middleware/pollComposer/state.ts +2 -2
  228. package/src/messageComposer/middleware/pollComposer/types.ts +2 -4
  229. package/src/messageComposer/middleware/pollComposer/validation.ts +8 -26
  230. package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +8 -6
  231. package/src/messageComposer/middleware/textComposer/commandUtils.ts +10 -3
  232. package/src/messageComposer/middleware/textComposer/commands.ts +11 -16
  233. package/src/messageComposer/middleware/textComposer/mentions.ts +32 -70
  234. package/src/messageComposer/middleware/textComposer/textMiddlewareUtils.ts +10 -4
  235. package/src/messageComposer/middleware/textComposer/types.ts +1 -6
  236. package/src/messageComposer/pollComposer.ts +21 -9
  237. package/src/messageComposer/textComposer.ts +37 -57
  238. package/src/messageComposer/types.ts +39 -11
  239. package/src/messageDelivery/MessageDeliveryReporter.ts +86 -124
  240. package/src/messageDelivery/MessageReceiptsTracker.ts +122 -139
  241. package/src/messageOperations/FailedSendCache.ts +85 -0
  242. package/src/messageOperations/MessageOperationStatePolicy.ts +124 -116
  243. package/src/messageOperations/MessageOperations.ts +297 -175
  244. package/src/{entityStore → messageOperations}/applyReactionLocally.ts +13 -25
  245. package/src/messageOperations/createMessageOperations.ts +176 -0
  246. package/src/messageOperations/index.ts +6 -14
  247. package/src/messageOperations/reflectReactionEvent.ts +43 -0
  248. package/src/messageOperations/sendOrdering.ts +25 -0
  249. package/src/messageOperations/settlePendingAttachmentUploads.ts +98 -0
  250. package/src/messageOperations/types.ts +51 -13
  251. package/src/middleware.ts +13 -5
  252. package/src/moderation.ts +25 -21
  253. package/src/notifications/NotificationManager.ts +19 -28
  254. package/src/notifications/types.ts +21 -57
  255. package/src/offline-support/offline_support_api.ts +231 -681
  256. package/src/offline-support/offline_sync_manager.ts +51 -90
  257. package/src/offline-support/queueableOperations.ts +98 -73
  258. package/src/offline-support/types.ts +43 -185
  259. package/src/pagination/FilterBuilder.ts +1 -22
  260. package/src/pagination/ItemIndex.ts +4 -12
  261. package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
  262. package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +17 -62
  263. package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
  264. package/src/pagination/cursorDerivation/linearPaginationFlags.ts +53 -33
  265. package/src/pagination/filterCompiler.ts +11 -25
  266. package/src/pagination/index.ts +1 -0
  267. package/src/pagination/paginators/BasePaginator.ts +1415 -1041
  268. package/src/pagination/paginators/ChannelPaginator.ts +481 -219
  269. package/src/pagination/paginators/MessageIntervalPaginator.ts +1362 -775
  270. package/src/pagination/paginators/MessagePaginator.ts +521 -240
  271. package/src/pagination/paginators/PinnedMessagePaginator.ts +32 -40
  272. package/src/pagination/paginators/ReminderPaginator.ts +21 -16
  273. package/src/pagination/paginators/ThreadPaginator.ts +170 -0
  274. package/src/pagination/paginators/UserGroupPaginator.ts +18 -15
  275. package/src/pagination/paginators/index.ts +1 -0
  276. package/src/pagination/paginators/stateThrottling.ts +5 -10
  277. package/src/pagination/sortCompiler.ts +23 -50
  278. package/src/pagination/utility.normalization.ts +17 -24
  279. package/src/pagination/utility.search.ts +4 -11
  280. package/src/poll.ts +183 -102
  281. package/src/poll_manager.ts +24 -22
  282. package/src/poll_optimistic_votes.ts +335 -0
  283. package/src/reminders/Reminder.ts +33 -16
  284. package/src/reminders/ReminderManager.ts +23 -56
  285. package/src/reminders/ReminderTimer.ts +6 -6
  286. package/src/search/BaseSearchSource.ts +19 -25
  287. package/src/search/ChannelSearchSource.ts +43 -1
  288. package/src/search/MessageSearchSource.ts +77 -13
  289. package/src/search/SearchController.ts +39 -36
  290. package/src/search/types.ts +6 -10
  291. package/src/segment.ts +1 -1
  292. package/src/signing.ts +23 -3
  293. package/src/thread.ts +430 -712
  294. package/src/thread_manager.ts +300 -234
  295. package/src/token_manager.ts +12 -22
  296. package/src/types.ts +102 -214
  297. package/src/types.utility.ts +3 -3
  298. package/src/upload-utils.ts +5 -10
  299. package/src/uploadManager.ts +64 -18
  300. package/src/utils/FixedSizeQueueCache.ts +18 -21
  301. package/src/utils/WithSubscriptions.ts +6 -16
  302. package/src/utils/abort.ts +45 -0
  303. package/src/utils/concurrency.ts +16 -55
  304. package/src/utils/mergeWith/mergeWith.ts +10 -13
  305. package/src/utils/mergeWith/mergeWithCore.ts +24 -81
  306. package/src/utils/mergeWith/mergeWithDiff.ts +15 -33
  307. package/src/utils/objectPath.ts +6 -41
  308. package/src/utils/retryable.ts +10 -14
  309. package/src/utils/throttling/throttle.ts +9 -25
  310. package/src/utils/time.ts +64 -0
  311. package/src/utils.ts +227 -174
  312. package/codegen/i18n/callSites.ts +0 -126
  313. package/codegen/i18n/generate.ts +0 -226
  314. package/codegen/i18n/guards.ts +0 -178
  315. package/codegen/i18n/index.ts +0 -29
  316. package/codegen/i18n/stringMaps.ts +0 -91
  317. package/codegen/i18n/types.ts +0 -100
  318. package/dist/cjs/i18n.browser.js +0 -1131
  319. package/dist/cjs/i18n.browser.js.map +0 -7
  320. package/dist/cjs/i18n.node.js +0 -1160
  321. package/dist/cjs/i18n.node.js.map +0 -7
  322. package/dist/esm/i18n-codegen.mjs +0 -409
  323. package/dist/esm/i18n-codegen.mjs.map +0 -7
  324. package/dist/esm/i18n.mjs +0 -1098
  325. package/dist/esm/i18n.mjs.map +0 -7
  326. package/dist/types/ConnectionRecoveryManager.d.ts +0 -156
  327. package/dist/types/connection.d.ts +0 -139
  328. package/dist/types/entityStore/applyReactionLocally.d.ts +0 -26
  329. package/dist/types/gen/model-decoders/decoders.d.ts +0 -3
  330. package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +0 -6
  331. package/dist/types/i18n/Streami18n.d.ts +0 -168
  332. package/dist/types/i18n/TranslationBuilder.d.ts +0 -70
  333. package/dist/types/i18n/TranslationStore.d.ts +0 -57
  334. package/dist/types/i18n/dayjs.d.ts +0 -104
  335. package/dist/types/i18n/formatters.d.ts +0 -91
  336. package/dist/types/i18n/index.d.ts +0 -15
  337. package/dist/types/i18n/translator.d.ts +0 -29
  338. package/dist/types/i18n/types.d.ts +0 -262
  339. package/dist/types/i18n-codegen/callSites.d.ts +0 -10
  340. package/dist/types/i18n-codegen/generate.d.ts +0 -15
  341. package/dist/types/i18n-codegen/guards.d.ts +0 -61
  342. package/dist/types/i18n-codegen/index.d.ts +0 -29
  343. package/dist/types/i18n-codegen/stringMaps.d.ts +0 -14
  344. package/dist/types/i18n-codegen/types.d.ts +0 -94
  345. package/dist/types/insights.d.ts +0 -56
  346. package/dist/types/messageOperations/optimistic.d.ts +0 -118
  347. package/dist/types/messageOperations/persistence.d.ts +0 -21
  348. package/dist/types/pagination/utility.queryChannel.d.ts +0 -26
  349. package/dist/types/store.d.ts +0 -125
  350. package/src/ConnectionRecoveryManager.ts +0 -293
  351. package/src/gen/model-decoders/decoders.ts +0 -2710
  352. package/src/gen/model-decoders/event-decoder-mapping.ts +0 -198
  353. package/src/i18n/Streami18n.ts +0 -520
  354. package/src/i18n/TranslationBuilder.ts +0 -176
  355. package/src/i18n/TranslationStore.ts +0 -96
  356. package/src/i18n/dayjs.ts +0 -228
  357. package/src/i18n/formatters.ts +0 -461
  358. package/src/i18n/index.ts +0 -15
  359. package/src/i18n/languageNames.ts +0 -103
  360. package/src/i18n/translator.ts +0 -76
  361. package/src/i18n/types.ts +0 -375
  362. package/src/insights.ts +0 -82
  363. package/src/messageOperations/optimistic.ts +0 -249
  364. package/src/messageOperations/persistence.ts +0 -40
  365. package/src/pagination/utility.queryChannel.ts +0 -84
  366. package/src/store.ts +0 -304
@@ -11,62 +11,40 @@ import type {
11
11
  InstanceSetupTearDownFunction,
12
12
  } from '../types';
13
13
  import type { DeepPartial } from '../../types.utility';
14
- import type { Unsubscribe } from '../../store';
14
+ import type { Unsubscribe } from '@stream-io/state-store';
15
15
 
16
16
  const logger = chatLoggerSystem.getLogger('instance-configuration');
17
17
 
18
18
  /** @internal */
19
19
  export type ApplyInstanceConfigurationParams<K extends InstanceSetupKey> = {
20
- /** The instance's argument for its setup function — `{ channel }`, `{ composer }`, and so on. */
20
+ /** The instance's argument for its setup function, such as `{ channel }`. */
21
21
  args: InstanceSetupFunctionArgsOf<K>;
22
- /** The client's configuration registry, i.e. `client.config`. */
23
22
  config: InstanceConfigurationRegistry;
24
23
  key: K;
25
24
  /**
26
- * Other keys this instance derives from. `Channel` and `Thread` both read the shared `messagePaginator`
27
- * and `messageOperations` keys, so a change there has to re-run this instance's own cycle rather than
28
- * only re-deriving: re-deriving alone would drop the setup function's overrides, since tier 2 is
29
- * applied after tier 1.
30
- *
31
- * Keys rather than stores, which buys two things beyond brevity. The instance is registered as a
32
- * live instance of each, so `hasLiveInstances` is true for a shared key and its construction-only paths get
33
- * same late-registration warning the per-parent slices already got. And there is no longer a structural
34
- * store type needed to work around `StateStore`'s invariance.
25
+ * Other keys this instance derives from (`Channel` and `Thread` read `messagePaginator` and
26
+ * `messageOperations`). A change there re-runs the whole cycle, so the setup function is re-applied
27
+ * over the new values. The instance is also registered as live under each.
35
28
  */
36
29
  alsoWatch?: readonly InstanceConfigKey[];
37
30
  /**
38
- * Applies a declarative configuration slice to the instance. Omit it if the instance has no
39
- * declarative surface and only wants the setup function.
40
- *
41
- * Called on every cycle, **including when this key has no configuration of its own** — an instance may
42
- * derive from other inputs too (`alsoWatch`, or the server), so it has to be told to re-derive rather
43
- * than being skipped. Hence the optional argument.
31
+ * Applies the declarative slice to the instance. Omit it if the instance only wants the setup function.
32
+ * Called on every cycle, with `undefined` when the key has no configuration, since the instance may
33
+ * derive from other inputs too.
44
34
  */
45
35
  applyConfig?: (config?: DeepPartial<InstanceConfigOf<K>>) => void;
46
36
  /**
47
- * The instance's own `initializeConfig`, bound. Invoked by `config.reset()` after both slots are
48
- * cleared, so the instance re-derives its configuration from current inputs. Omit it to get
49
- * clear-registrations-only reset semantics.
37
+ * The instance's `initializeConfig`, bound. `reset` calls it after clearing both slots. Without it,
38
+ * reset only clears registrations.
50
39
  */
51
40
  reinitializeConfig?: () => void;
52
41
  };
53
42
 
54
43
  /**
55
- * Subscribes one instance to the configuration registered for its key, and returns the unsubscribe.
56
- *
57
- * This is the single place the *subscription* semantics live, so every configured instance behaves
58
- * identically:
59
- *
60
- * - applies whatever is already registered, immediately;
61
- * - re-applies on every change to either slot, declarative configuration first and the setup function
62
- * second, so a setup function always wins for the same field;
63
- * - runs the previous setup function's teardown before re-applying, and again on unsubscribe;
64
- * - contains errors — a throwing setup function, teardown or applier is logged and never propagates,
65
- * so it cannot break `client.channel()` or a `Thread` construction.
66
- *
67
- * Not exported from the package. It only does anything for a key in {@link InstanceSetupKey}, and those
68
- * keys all belong to classes this package constructs, so there is no caller outside it. `ConfigController`
69
- * _is_ exported, because resolution is reusable on its own — see `docs/instance-configuration.md` §6.
44
+ * Subscribes one instance to the configuration registered for its key and returns the unsubscribe.
45
+ * Applies what is registered immediately, then on every change: declarative configuration first and the
46
+ * setup function second (so it wins), running the previous teardown before each re-apply and on
47
+ * unsubscribe. A throwing setup function, teardown or applier is logged, never propagated.
70
48
  *
71
49
  * @internal
72
50
  */
@@ -115,22 +93,16 @@ export const applyInstanceConfiguration = <K extends InstanceSetupKey>({
115
93
  }
116
94
  };
117
95
 
118
- // One handle, shared by every key this instance registers under. `reset` de-duplicates by object
119
- // identity, so a handle allocated per key would defeat it — a `Channel` registered under `channel`,
120
- // `messagePaginator` and `messageOperations` would re-derive three times for one reset.
96
+ // One handle for every key: `reset` de-duplicates by identity, so the instance re-derives once.
121
97
  const instanceHandle: ConfiguredInstance = { reinitializeConfig };
122
98
 
123
99
  const unregisterInstance = service.registerInstance(key, instanceHandle);
124
100
 
125
- // `StateStore.subscribe` fires immediately, and we subscribe to two stores — so suppress while
126
- // wiring and apply exactly once afterwards.
101
+ // `subscribe` fires immediately: suppress while wiring, then apply once.
127
102
  let suppress = true;
128
103
 
129
- // `reset` clears every slot and *then* re-derives each live instance exactly once. An instance that
130
- // supplied a `reinitializeConfig` is therefore covered already, so reacting to the individual clears
131
- // would re-derive it once per populated key — and against a tree still half-cleared, since the
132
- // notifications fire synchronously inside reset's loop. An instance without one has no other route, so
133
- // it keeps reacting.
104
+ // An instance with `reinitializeConfig` is re-derived once by reset's final pass, so it ignores the
105
+ // per-key clears, which fire synchronously against a half-cleared tree.
134
106
  const coveredByResetsOwnPass = () => !!reinitializeConfig && service.isResetting;
135
107
 
136
108
  const onConfigChange = () => {
@@ -140,8 +112,7 @@ export const applyInstanceConfiguration = <K extends InstanceSetupKey>({
140
112
 
141
113
  const onSetupChange = () => {
142
114
  if (suppress) return;
143
- // Teardown is not reset's to run: it lives in this closure, so `reinitializeConfig` cannot reach it.
144
- // Run it here and leave the re-derivation to reset's final phase.
115
+ // Teardown lives in this closure, out of reset's reach: run it here, leave re-derivation to reset.
145
116
  if (coveredByResetsOwnPass()) {
146
117
  runTearDown();
147
118
  return;
@@ -155,17 +126,14 @@ export const applyInstanceConfiguration = <K extends InstanceSetupKey>({
155
126
  const unsubscribeSetup = service
156
127
  .getSetupState(key)
157
128
  .subscribeWithSelector(({ setupFunction }) => ({ setupFunction }), onSetupChange);
158
- // Selector-based like the two above, so a store that publishes without its `config` moving — `reset`
159
- // clearing an already-empty slot does exactly that, since `partialNext` always allocates — does not
160
- // trigger a cycle.
129
+ // Selector-based so a publish that leaves `config` unchanged (`reset` clearing an empty slot) does
130
+ // not trigger a cycle.
161
131
  const unsubscribeExtra = (alsoWatch ?? []).map((watchedKey) =>
162
132
  service
163
133
  .getConfigState(watchedKey)
164
134
  .subscribeWithSelector(({ config }) => ({ config }), onConfigChange),
165
135
  );
166
- // Registering against the watched keys too is what makes `hasLiveInstances` true for them. The shared
167
- // `instanceHandle` is what lets `reset()` de-duplicate across keys, so being registered under several
168
- // does not multiply re-derives.
136
+ // Registered under the watched keys too, so `hasLiveInstances` is true for them.
169
137
  const unregisterExtra = (alsoWatch ?? []).map((watchedKey) =>
170
138
  service.registerInstance(watchedKey, instanceHandle),
171
139
  );
@@ -1,47 +1,18 @@
1
1
  import { isWalkableRecord } from '../../utils/objectPath';
2
2
 
3
- /**
4
- * Copies a caller-supplied configuration patch, so the value the SDK stores shares no mutable object with
5
- * the caller.
6
- *
7
- * **Why this exists.** `mergeWith` reuses a source subtree verbatim when the target has nothing at that key
8
- * (`createNewTarget` returns `srcValue`), and the declarative registry's target starts empty — so the first
9
- * `client.config.set({ messageComposer: patch })` left `getConfig('messageComposer').text === patch.text`.
10
- * Two consequences, both silent: mutating `patch.text` afterwards changed resolved configuration behind
11
- * every live instance's back with no notification, and the registry held the caller's objects for the
12
- * client's lifetime.
13
- *
14
- * **Why not `structuredClone`.** Configuration is not JSON — `commands.sendValidator`,
15
- * `attachments.fileUploadFilter`, `linkPreviews.findURLFn`, `location.getDeviceId`,
16
- * `messagePaginator.hasPaginationQueryShapeChanged` and every `requestHandlers` entry are functions, and
17
- * `structuredClone` throws on them.
18
- *
19
- * So: plain objects and arrays are copied, and everything else is passed through by reference —
20
- * functions, `Date`s, `RegExp`s, class instances. Those are values a caller *hands over* rather than a
21
- * structure the SDK merges into, and copying them would be wrong as well as impossible: a cloned
22
- * `ItemIndex` would not be the index the paginator loaded items into.
23
- *
24
- * **Repeated objects are copied once.** Every object copied is remembered, so a graph that points back at
25
- * itself terminates instead of overflowing the stack — reachable from `client.config.set()` and
26
- * `updateConfig`, both of which take an object an integrator built. The same bookkeeping keeps two
27
- * references to one object as two references to one copy, rather than duplicating it.
28
- *
29
- * @internal
30
- */
3
+ /** `copies` maps each source object to its copy, so cycles and shared references survive. */
31
4
  const copyInto = <T>(value: T, copies: WeakMap<object, unknown>): T => {
32
5
  if (Array.isArray(value)) {
33
6
  if (copies.has(value)) return copies.get(value) as T;
34
7
 
35
8
  const copy: unknown[] = [];
36
- // Registered before the entries are walked, so an entry pointing back at this array finds the copy
37
- // instead of recursing forever.
9
+ // Registered before walking the entries, so a cycle finds the copy.
38
10
  copies.set(value, copy);
39
11
  for (const entry of value) copy.push(copyInto(entry, copies));
40
12
  return copy as unknown as T;
41
13
  }
42
14
 
43
- // Plain objects only. A class instance, a Date or a RegExp is an opaque value here — see
44
- // `isWalkableRecord`, which draws the same line for dot-path access.
15
+ // Plain objects only: class instances, Dates and RegExps are opaque (see `isWalkableRecord`).
45
16
  if (typeof value === 'object' && value !== null) {
46
17
  if (!isWalkableRecord(value)) return value;
47
18
  if (copies.has(value)) return copies.get(value) as T;
@@ -58,4 +29,12 @@ const copyInto = <T>(value: T, copies: WeakMap<object, unknown>): T => {
58
29
  return value;
59
30
  };
60
31
 
32
+ /**
33
+ * Copies a caller-supplied configuration patch so the stored value shares no mutable object with the
34
+ * caller (`mergeWith` reuses source subtrees verbatim). Plain objects and arrays are copied; everything
35
+ * else (functions, `Date`s, class instances) passes through by reference. Not `structuredClone`, which
36
+ * throws on the functions configuration holds. Cycles terminate and shared references stay shared.
37
+ *
38
+ * @internal
39
+ */
61
40
  export const copyConfigPatch = <T>(value: T): T => copyInto(value, new WeakMap());
@@ -3,29 +3,10 @@ import type { MessageOperationsConfig } from '../../messageOperations/MessageOpe
3
3
  import type { DeclarativeMessagePaginatorConfig } from '../types';
4
4
 
5
5
  /**
6
- * How a declarative subtree is combined before it reaches the object that owns it.
7
- *
8
- * Two shared keys (`messagePaginator`, `messageOperations`) are also offered nested under `channel` and
9
- * `thread`, so an owner has to layer the general registration and its own override — and, for the
10
- * paginator, split off the one member of the subtree that is a construction argument rather than
11
- * configuration.
12
- */
13
-
14
- /**
15
- * Layers a per-parent slice of a **shared** configuration key over the shared one, field by field.
16
- *
17
- * Two keys are shared between `Channel` and `Thread` — `messagePaginator` and `messageOperations`
18
- * (**DEC-25**, **DV-15**) — because both entities own one of each and most of the settings mean the same
19
- * thing under either parent. The shared key carries what is common; the per-parent slice overrides only the
20
- * fields it names.
21
- *
22
- * Fields the specific slice does not mention — including ones it sets to `undefined` explicitly — fall
23
- * through to the shared slice, so `{ messagePaginator: { pageSize: 50 } }` is not undone by a
24
- * `channel.messagePaginator` slice that only names `stateThrottleMs`. That `undefined` skip is the whole
25
- * reason this is not a plain object spread.
26
- *
27
- * One level deep on purpose: every field on both config types is a scalar or a function, so there is no
28
- * nested object for a deep merge to reach. Use `mergeWith` if that stops being true.
6
+ * Layers a per-parent slice of a shared key (`messagePaginator`, `messageOperations`) over the shared
7
+ * one, field by field. Fields the specific slice omits or sets to `undefined` fall through to the shared
8
+ * slice, which is why this is not a plain spread. One level deep: an object field such as
9
+ * `initialCursor` replaces the shared one whole.
29
10
  */
30
11
  const mergeDeclarativeSlice = <TConfig extends object>(
31
12
  general?: TConfig,
@@ -42,14 +23,14 @@ const mergeDeclarativeSlice = <TConfig extends object>(
42
23
  return merged;
43
24
  };
44
25
 
45
- /** Layers `channel.messageOperations` / `thread.messageOperations` over the shared `messageOperations` key. */
26
+ /** Layers a per-parent `messageOperations` slice (channel or thread) over the shared key. */
46
27
  export const mergeDeclarativeMessageOperationsConfig = (
47
28
  general?: Partial<MessageOperationsConfig>,
48
29
  specific?: Partial<MessageOperationsConfig>,
49
30
  ): Partial<MessageOperationsConfig> | undefined =>
50
31
  mergeDeclarativeSlice(general, specific);
51
32
 
52
- /** Layers `channel.messagePaginator` / `thread.messagePaginator` over the shared `messagePaginator` key. */
33
+ /** Layers a per-parent `messagePaginator` slice (channel or thread) over the shared key. */
53
34
  export const mergeDeclarativePaginatorConfig = (
54
35
  general?: DeclarativeMessagePaginatorConfig,
55
36
  specific?: DeclarativeMessagePaginatorConfig,
@@ -57,20 +38,9 @@ export const mergeDeclarativePaginatorConfig = (
57
38
  mergeDeclarativeSlice(general, specific);
58
39
 
59
40
  /**
60
- * Drops the construction-only arguments from a message-paginator slice, leaving only what is actually
61
- * paginator *configuration*.
62
- *
63
- * `unreadReferencePolicy` rides in the same subtree for the integrator's convenience, but it is not a
64
- * `BasePaginatorConfig` field — `MessagePaginator` reads it once into a private member. Passed through to
65
- * `initializeConfig` it landed in the published `config` as an untyped key that nothing reads, and a
66
- * registration arriving after construction made resolved configuration *contradict* behaviour: the
67
- * construction-only warning correctly said the value would not apply, and then
68
- * `paginator.config.unreadReferencePolicy` reported it as though it had. A settings UI reading resolved
69
- * config showed `read-state-only` for a paginator behaving as `snapshot`.
70
- *
71
- * So the owning `Channel` / `Thread` splits the slice: the constructor argument goes to the constructor,
72
- * and only this half reaches the paginator's configuration. Both already read the policy separately, so
73
- * nothing is lost.
41
+ * Drops `unreadReferencePolicy` from a message-paginator slice. `MessagePaginator` reads it once as a
42
+ * constructor argument, so leaving it in would make the resolved `config` report a value that does not
43
+ * apply.
74
44
  */
75
45
  export const toDeclarativePaginatorConfig = (
76
46
  slice?: DeclarativeMessagePaginatorConfig,
@@ -1,21 +1,7 @@
1
1
  /**
2
- * Recursively freezes a package-level default configuration object.
3
- *
4
- * **Why a runtime guard rather than a type.** Resolved configuration is built by deep-merging over these
5
- * constants, and the merge only *copies* a subtree that some layer actually touches — so a subtree nobody
6
- * configured stays identical by reference to the module-level default, and is reachable through the
7
- * instance's public `config` getter. A write through it therefore changed the default for every instance
8
- * of every client in the process, including ones created afterwards. `Readonly<T>` cannot catch that: it
9
- * is shallow, so it rejects `config.pageSize = 5` but accepts `config.drafts.enabled = true` — and the
10
- * nested form is the one that reaches shared state. In ESM, which is always strict, a write to a frozen
11
- * object throws a `TypeError` at the offending line instead of silently succeeding somewhere else.
12
- *
13
- * Deliberately lives in its own module rather than `src/utils.ts`: that barrel is `vi.mock`ed wholesale by
14
- * some suites, and a default-config constant must not depend on which of its exports a test happens to
15
- * stub.
16
- *
17
- * Functions are frozen as values but not walked — a function's `prototype` is not configuration. Freezing
18
- * is idempotent and stops at anything already frozen, so shared sub-configs cost one visit.
2
+ * Recursively freezes a package-level default configuration. Resolved config shares untouched subtrees
3
+ * with these defaults, so an unfrozen nested write through `config` would change them for every instance
4
+ * in the process (`Readonly<T>` is shallow and cannot catch it). Functions are left as they are.
19
5
  *
20
6
  * @internal
21
7
  */
@@ -1,5 +1,3 @@
1
- // Only the modules that were already public belong here — `src/configuration/index.ts` re-exports this
2
- // barrel wholesale, so anything added becomes public API. `applyInstanceConfiguration`,
3
- // `copyConfigPatch`, `deepFreezeConfig` and `declarativeSlices` are `@internal` and are imported by path
4
- // instead.
1
+ // `src/configuration/index.ts` re-exports this barrel wholesale, so anything added becomes public API.
2
+ // Helpers marked `@internal` are imported by path instead.
5
3
  export * from './serverAuthority';
@@ -3,58 +3,32 @@ import type { MergeWithCustomizer } from '../../utils/mergeWith/mergeWithCore';
3
3
  import type { DeepPartial } from '../../types.utility';
4
4
 
5
5
  /**
6
- * The fields a server decides for some configurable object — a partial configuration holding *only* those
7
- * fields, with the value the server currently reports.
8
- *
9
- * Only server-decided fields may appear. The merge below lets any scalar on this side win, so an
10
- * unrelated field smuggled in here would override the caller's value while looking like a server
11
- * restriction.
6
+ * The fields a server decides, with the values it reports. Include only those: a non-boolean scalar
7
+ * here overrides the caller's, and a boolean is ANDed with it.
12
8
  */
13
9
  export type ServerRestrictions<TConfig extends object> = DeepPartial<TConfig>;
14
10
 
15
11
  /**
16
- * Merges a set of server restrictions over a requested configuration under two rules:
17
- *
18
- * 1. **Booleans are ANDed.** A flag the *client* turned off stays off even where the server would allow it —
19
- * asking for less than you are granted is always legitimate — and a flag the server turned off stays off
20
- * whatever the client asked. Either side may narrow; neither may widen.
21
- * 2. **Any other scalar: the server wins.** This is what makes "client configuration can only narrow what
22
- * the server grants" true rather than aspirational.
23
- *
24
- * Objects are left to the normal deep merge, so the rules apply leaf by leaf.
25
- *
26
- * A third rule lives in {@link ServerUpperBounds}, passed separately because a ceiling narrows rather than
27
- * replaces.
28
- *
29
- * **Rule 1 is deliberately not keyed on a field name.** It used to read `key === 'enabled'`, which happened
30
- * to be correct because `location.enabled` was the only boolean restriction — and was a trap for whoever
31
- * added the next one. A gate named anything else (`text.publishTypingEvents` for `typing_events`, say) would
32
- * have fallen through to rule 2, and a client's deliberate `false` would have been overwritten by a
33
- * permissive server: exactly the widening **DV-16** was about, reintroduced one field at a time. Boolean
34
- * restrictions are gates, and the conjunction of two gates is the rule for all of them.
12
+ * Booleans are ANDed (either side may narrow, neither may widen); any other scalar takes the server's
13
+ * value. Objects deep-merge, so this applies per leaf. Not keyed on field names: every boolean
14
+ * restriction is a gate.
35
15
  */
36
16
  const serverRestrictionCustomizer: MergeWithCustomizer<object> = (
37
17
  requestedValue,
38
18
  restrictionValue,
39
19
  ) => {
40
- // Not a leaf — hand it back to the deep merge and decide further down.
41
- //
42
- // `typeof null === 'object'`, so `null` is excluded explicitly: it has no interior to descend into. The
43
- // upper-bound customizer below has always guarded this and this one did not; the two disagreeing was a
44
- // latent difference rather than a live bug, since no configuration field is nullable today.
20
+ // Not a leaf: let the deep merge descend. `null` is excluded because `typeof null === 'object'`.
45
21
  const isInterior = (value: unknown) => typeof value === 'object' && value !== null;
46
22
  if (isInterior(requestedValue)) return undefined;
47
- // Nothing requested here but the server describes a subtree — descend so it lands, rather than answering
48
- // with the absent request and dropping it. Deliberately *not* extended to a requested scalar under an
49
- // object restriction: rule 2 refuses that below, which is the point of its scalar check.
23
+ // Nothing requested but the server describes a subtree: descend so it lands.
50
24
  if (requestedValue == null && isInterior(restrictionValue)) return undefined;
51
25
 
52
- // Rule 1: both sides are gates, so the stricter one wins whichever side it is on.
26
+ // Both gates: the stricter side wins.
53
27
  if (typeof requestedValue === 'boolean' && typeof restrictionValue === 'boolean') {
54
28
  return requestedValue && restrictionValue;
55
29
  }
56
30
 
57
- // Rule 2: the server had the last word.
31
+ // Any other scalar: the server wins.
58
32
  if (
59
33
  ['string', 'number', 'bigint', 'boolean', 'symbol'].includes(typeof restrictionValue)
60
34
  ) {
@@ -66,54 +40,32 @@ const serverRestrictionCustomizer: MergeWithCustomizer<object> = (
66
40
  };
67
41
 
68
42
  /**
69
- * Numeric ceilings the server imposes — a partial configuration holding only fields where the server states
70
- * a *maximum*, such as a channel type's `max_message_length`.
71
- *
72
- * Separate from {@link ServerRestrictions} because the two combine differently, and putting a ceiling in the
73
- * wrong bucket is a silent bug rather than a type error: a restriction *replaces* the requested value, which
74
- * for a limit would widen a caller who deliberately asked for something stricter.
43
+ * Fields where the server states a maximum (e.g. `max_message_length`). Separate from
44
+ * {@link ServerRestrictions} because a restriction replaces the value, which would widen a stricter
45
+ * caller.
75
46
  */
76
47
  export type ServerUpperBounds<TConfig extends object> = DeepPartial<TConfig>;
77
48
 
78
- /**
79
- * Tightest wins. A ceiling can only lower the requested value, never raise it — and it applies in full when
80
- * the caller asked for no limit at all, which is the common case and the reason the server's maximum is
81
- * worth reading: an unlimited composer otherwise lets a message be written that the API will reject.
82
- */
49
+ /** Tightest wins. A ceiling applies in full when the caller asked for no limit. */
83
50
  const upperBoundCustomizer: MergeWithCustomizer<object> = (
84
51
  requestedValue,
85
52
  boundValue,
86
53
  ) => {
87
- // Not a leaf — hand it back to the deep merge and decide at the leaves.
54
+ // Not a leaf: let the deep merge descend.
88
55
  if (typeof requestedValue === 'object' && requestedValue !== null) return undefined;
89
- // The server states no ceiling for this field, so the request stands.
56
+ // No ceiling stated: the request stands.
90
57
  if (typeof boundValue !== 'number') return requestedValue;
91
- // No client limit — the server's is the effective one. For `undefined` the deep merge would reach the
92
- // same answer on its own; the branch earns its place on a value that is neither, where delegating
93
- // would keep the nonsense and drop the ceiling.
58
+ // No client limit (or a non-number): the server's ceiling applies.
94
59
  if (typeof requestedValue !== 'number') return boundValue;
95
60
 
96
61
  return Math.min(requestedValue, boundValue);
97
62
  };
98
63
 
99
64
  /**
100
- * Applies a server's restrictions to a configuration a caller asked for, so the result never claims more
101
- * than the server allows.
102
- *
103
- * **Why this is a named function rather than an inline merge.** It has to run on *every* route by which a
104
- * configuration can change — construction, the declarative tree, a setup function, a direct
105
- * `updateConfig` — because a restriction applied only at construction holds until the first time anything
106
- * updates the configuration and then silently stops holding. `MessageComposer` learned this the hard way:
107
- * only its `deriveConfig` applied the restrictions, so registering `location.enabled: true` on a running
108
- * app widened past a `shared_locations: false` server and produced a composer offering a feature the API
109
- * rejects (**DV-16**).
110
- *
111
- * **What it deliberately does not do.** It knows nothing about *where* restrictions come from. Reading
112
- * them is the entity's job, because only the entity knows what to ask — a composer reads its channel's
113
- * `serverConfig`, something else might read capabilities — and the answer depends on an instance that
114
- * exists. That is also why this does not live in `InstanceConfigurationRegistry`: that service merges
115
- * declarative layers before any instance exists, and its merges follow the opposite rule (a more specific
116
- * layer *may* re-enable what a broader one disabled), which rule 1 would break.
65
+ * Applies server restrictions to a requested configuration, so the result never claims more than the
66
+ * server allows. Call it on every route that changes a configuration (construction, declarative tree,
67
+ * setup function, `updateConfig`), or the restrictions stop holding at the first update. Reading the
68
+ * restrictions is the entity's job.
117
69
  *
118
70
  * @example
119
71
  * ```ts
@@ -0,0 +1,111 @@
1
+ import { waitUnlessAborted } from '../utils/abort';
2
+ import { chatLoggerSystem } from '../logger';
3
+
4
+ const logger = chatLoggerSystem.getLogger('connection');
5
+
6
+ /**
7
+ * Holds the connection ID (the WebSocket's, or the long-poll's after an `enableWSFallback` switch)
8
+ * and lets callers await one that is still being negotiated.
9
+ *
10
+ * The server keys channel watches and presence subscriptions by connection ID and answers `200`
11
+ * while registering nothing when a request that needs one carries none (see `requiresConnectionId`
12
+ * in `api-client.ts`), so such requests wait for the handshake. The ID lives only here, so a
13
+ * replaced socket cannot leave a stale copy behind.
14
+ *
15
+ * Driven by {@link StableWSConnection}, or by `WSConnectionFallback` after a fallback switch.
16
+ */
17
+ export class ConnectionIdManager {
18
+ connectionId?: string;
19
+ loadConnectionIdPromise?: Promise<string>;
20
+ private resolve?: (connectionId: string) => void;
21
+ private reject?: (reason: unknown) => void;
22
+
23
+ /** Creates the deferred a connection attempt settles, so mid-handshake requests can await it. */
24
+ arm = () => {
25
+ if (this.connectionId || this.loadConnectionIdPromise) return;
26
+
27
+ this.loadConnectionIdPromise = new Promise<string>((resolve, reject) => {
28
+ this.resolve = resolve;
29
+ this.reject = reject;
30
+ });
31
+ // Keeps an unawaited rejection from surfacing as unhandled. Awaiters still see it.
32
+ this.loadConnectionIdPromise.catch(() => undefined);
33
+ };
34
+
35
+ /**
36
+ * Publishes the ID from the `connection.ok` event and releases anything waiting on one.
37
+ *
38
+ * @param connectionId - The connection ID carried by the `connection.ok` event.
39
+ */
40
+ resolveConnectionId = (connectionId: string) => {
41
+ this.connectionId = connectionId;
42
+ this.resolve?.(connectionId);
43
+ this.settle();
44
+ };
45
+
46
+ /**
47
+ * Rejects pending waiters, for a connection attempt that will not be retried.
48
+ *
49
+ * @param reason - The error to reject pending waiters with.
50
+ */
51
+ rejectConnectionId = (reason: unknown) => {
52
+ this.connectionId = undefined;
53
+ this.reject?.(reason);
54
+ this.settle();
55
+ };
56
+
57
+ /** Drops the ID for a socket that died but will be retried. New requests wait for the reconnect. */
58
+ invalidate = () => {
59
+ if (!this.connectionId) return;
60
+
61
+ logger
62
+ .withExtraTags('invalidate')
63
+ .debug('Dropping the connection id; the socket is no longer up.');
64
+
65
+ this.connectionId = undefined;
66
+ this.arm();
67
+ };
68
+
69
+ /** Drops the ID and rejects any pending waiter with a "connection closed" error. */
70
+ reset = () => {
71
+ logger.withExtraTags('reset').debug('Dropping the connection id.');
72
+
73
+ this.rejectConnectionId(
74
+ new Error(
75
+ 'The WebSocket connection was closed before a connection id could be resolved. Call `client.openConnection()` to open a new one, or `client.connectUser()` if the user was disconnected.',
76
+ ),
77
+ );
78
+ };
79
+
80
+ /**
81
+ * Returns the connection ID, waiting for the handshake when one is in flight.
82
+ *
83
+ * @param signal - Abandons the wait. Only the waiting path honours it; an ID already in hand is
84
+ * returned either way.
85
+ * @returns The current connection ID, or a promise for it while the handshake is in flight.
86
+ * @throws When no socket is open or being opened.
87
+ */
88
+ getConnectionId = (signal?: AbortSignal): string | Promise<string> => {
89
+ if (this.connectionId) return this.connectionId;
90
+
91
+ const pending = this.loadConnectionIdPromise;
92
+
93
+ if (!pending) {
94
+ throw new Error(
95
+ 'No connection id is available: there is no WebSocket connection, and none is being established. A request that watches a channel or subscribes to presence needs one. Call `client.connectUser()` if no user is connected, or `client.openConnection()` if the socket was closed with `client.closeConnection()`.',
96
+ );
97
+ }
98
+
99
+ return waitUnlessAborted({
100
+ abortMessage: 'The wait for a connection id was aborted.',
101
+ promise: pending,
102
+ signal,
103
+ });
104
+ };
105
+
106
+ private settle = () => {
107
+ this.loadConnectionIdPromise = undefined;
108
+ this.resolve = undefined;
109
+ this.reject = undefined;
110
+ };
111
+ }