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

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 (298) hide show
  1. package/README.md +11 -8
  2. package/dist/cjs/index.browser.js +15397 -12090
  3. package/dist/cjs/index.browser.js.map +4 -4
  4. package/dist/cjs/index.node.js +15349 -11991
  5. package/dist/cjs/index.node.js.map +4 -4
  6. package/dist/esm/index.mjs +15164 -11880
  7. package/dist/esm/index.mjs.map +4 -4
  8. package/dist/types/ChannelManager.d.ts +246 -6
  9. package/dist/types/CooldownTimer.d.ts +22 -8
  10. package/dist/types/EventHandlerPipeline.d.ts +12 -16
  11. package/dist/types/LiveLocationManager.d.ts +69 -6
  12. package/dist/types/api-client.d.ts +22 -9
  13. package/dist/types/channel.d.ts +550 -300
  14. package/dist/types/channel_state.d.ts +167 -22
  15. package/dist/types/client.d.ts +325 -305
  16. package/dist/types/configuration/ConfigController.d.ts +172 -0
  17. package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +192 -0
  18. package/dist/types/configuration/index.d.ts +3 -0
  19. package/dist/types/configuration/keys.d.ts +31 -0
  20. package/dist/types/configuration/shape.d.ts +58 -0
  21. package/dist/types/configuration/types.d.ts +206 -50
  22. package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +59 -0
  23. package/dist/types/configuration/utils/copyConfigPatch.d.ts +1 -0
  24. package/dist/types/configuration/utils/declarativeSlices.d.ts +24 -0
  25. package/dist/types/configuration/utils/deepFreezeConfig.d.ts +22 -0
  26. package/dist/types/configuration/utils/index.d.ts +1 -0
  27. package/dist/types/configuration/utils/serverAuthority.d.ts +49 -0
  28. package/dist/types/connection/ConnectionIdManager.d.ts +67 -0
  29. package/dist/types/connection/ConnectionRecoveryManager.d.ts +164 -0
  30. package/dist/types/connection/index.d.ts +4 -0
  31. package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +153 -0
  32. package/dist/types/connection/networkConnection/index.d.ts +3 -0
  33. package/dist/types/connection/networkConnection/reporters.d.ts +43 -0
  34. package/dist/types/connection/networkConnection/types.d.ts +55 -0
  35. package/dist/types/connection/wsConnection/StableWSConnection.d.ts +204 -0
  36. package/dist/types/connection/wsConnection/WSConnection.d.ts +168 -0
  37. package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +55 -0
  38. package/dist/types/connection/wsConnection/config.d.ts +51 -0
  39. package/dist/types/connection/wsConnection/index.d.ts +4 -0
  40. package/dist/types/connection/wsConnection/types.d.ts +99 -0
  41. package/dist/types/constants.d.ts +3 -1
  42. package/dist/types/entityStore/EntityStore.d.ts +160 -40
  43. package/dist/types/entityStore/StoreBackedItemIndex.d.ts +48 -29
  44. package/dist/types/entityStore/index.d.ts +0 -1
  45. package/dist/types/errors.d.ts +24 -4
  46. package/dist/types/formatMessageMemo.d.ts +5 -0
  47. package/dist/types/gen/chat/ChannelApi.d.ts +51 -23
  48. package/dist/types/gen/chat/ChatApi.d.ts +215 -168
  49. package/dist/types/gen/models/index.d.ts +2164 -557
  50. package/dist/types/gen/models/timestamp-guard.d.ts +22 -0
  51. package/dist/types/gen/moderation/ModerationApi.d.ts +39 -32
  52. package/dist/types/gen-imports.d.ts +1 -0
  53. package/dist/types/index.d.ts +20 -7
  54. package/dist/types/languageNames.d.ts +97 -0
  55. package/dist/types/logger.d.ts +1 -1
  56. package/dist/types/messageComposer/CustomDataManager.d.ts +7 -1
  57. package/dist/types/messageComposer/LocationComposer.d.ts +10 -4
  58. package/dist/types/messageComposer/attachmentIdentity.d.ts +11 -0
  59. package/dist/types/messageComposer/attachmentManager.d.ts +48 -10
  60. package/dist/types/messageComposer/attachmentUtils.d.ts +34 -0
  61. package/dist/types/messageComposer/configuration/commands.configuration.d.ts +1 -3
  62. package/dist/types/messageComposer/configuration/configuration.d.ts +9 -1
  63. package/dist/types/messageComposer/configuration/index.d.ts +0 -1
  64. package/dist/types/messageComposer/configuration/types.d.ts +57 -1
  65. package/dist/types/messageComposer/index.d.ts +1 -0
  66. package/dist/types/messageComposer/linkPreviewsManager.d.ts +10 -4
  67. package/dist/types/messageComposer/messageComposer.d.ts +210 -14
  68. package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +20 -1
  69. package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +11 -0
  70. package/dist/types/messageComposer/middleware/messageComposer/types.d.ts +2 -2
  71. package/dist/types/messageComposer/middleware/pollComposer/index.d.ts +1 -0
  72. package/dist/types/messageComposer/middleware/pollComposer/state.d.ts +3 -2
  73. package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +9 -2
  74. package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +44 -0
  75. package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +2 -2
  76. package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +94 -229
  77. package/dist/types/messageComposer/pollComposer.d.ts +8 -3
  78. package/dist/types/messageComposer/textComposer.d.ts +9 -1
  79. package/dist/types/messageComposer/types.d.ts +7 -3
  80. package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +64 -8
  81. package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +48 -11
  82. package/dist/types/messageOperations/FailedSendCache.d.ts +34 -0
  83. package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +52 -6
  84. package/dist/types/messageOperations/MessageOperations.d.ts +94 -11
  85. package/dist/types/{entityStore → messageOperations}/applyReactionLocally.d.ts +8 -2
  86. package/dist/types/messageOperations/createMessageOperations.d.ts +11 -0
  87. package/dist/types/messageOperations/index.d.ts +7 -1
  88. package/dist/types/messageOperations/reflectReactionEvent.d.ts +24 -0
  89. package/dist/types/messageOperations/sendOrdering.d.ts +17 -0
  90. package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +28 -0
  91. package/dist/types/messageOperations/types.d.ts +66 -1
  92. package/dist/types/middleware.d.ts +8 -0
  93. package/dist/types/moderation.d.ts +18 -4
  94. package/dist/types/notifications/NotificationManager.d.ts +43 -2
  95. package/dist/types/notifications/types.d.ts +55 -42
  96. package/dist/types/offline-support/offline_support_api.d.ts +128 -12
  97. package/dist/types/offline-support/offline_sync_manager.d.ts +26 -5
  98. package/dist/types/offline-support/queueableOperations.d.ts +106 -0
  99. package/dist/types/offline-support/types.d.ts +77 -28
  100. package/dist/types/pagination/FilterBuilder.d.ts +1 -18
  101. package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -1
  102. package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +21 -3
  103. package/dist/types/pagination/filterCompiler.d.ts +5 -0
  104. package/dist/types/pagination/paginators/BasePaginator.d.ts +331 -7
  105. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +54 -11
  106. package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +283 -66
  107. package/dist/types/pagination/paginators/MessagePaginator.d.ts +10 -9
  108. package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +17 -1
  109. package/dist/types/pagination/paginators/ReminderPaginator.d.ts +8 -8
  110. package/dist/types/pagination/paginators/ThreadPaginator.d.ts +57 -0
  111. package/dist/types/pagination/paginators/index.d.ts +1 -0
  112. package/dist/types/pagination/utility.normalization.d.ts +29 -2
  113. package/dist/types/poll.d.ts +41 -14
  114. package/dist/types/poll_manager.d.ts +3 -2
  115. package/dist/types/poll_optimistic_votes.d.ts +61 -0
  116. package/dist/types/reminders/Reminder.d.ts +17 -7
  117. package/dist/types/reminders/ReminderManager.d.ts +34 -6
  118. package/dist/types/search/BaseSearchSource.d.ts +50 -25
  119. package/dist/types/search/ChannelMemberSearchSource.d.ts +11 -6
  120. package/dist/types/search/ChannelSearchSource.d.ts +27 -5
  121. package/dist/types/search/MessageSearchSource.d.ts +36 -6
  122. package/dist/types/search/SearchController.d.ts +44 -11
  123. package/dist/types/search/UserSearchSource.d.ts +11 -5
  124. package/dist/types/search/types.d.ts +14 -1
  125. package/dist/types/signing.d.ts +0 -157
  126. package/dist/types/thread.d.ts +118 -62
  127. package/dist/types/thread_manager.d.ts +124 -35
  128. package/dist/types/token_manager.d.ts +5 -8
  129. package/dist/types/types.d.ts +138 -562
  130. package/dist/types/types.utility.d.ts +8 -0
  131. package/dist/types/upload-utils.d.ts +20 -0
  132. package/dist/types/uploadManager.d.ts +50 -2
  133. package/dist/types/utils/FixedSizeQueueCache.d.ts +2 -0
  134. package/dist/types/utils/WithSubscriptions.d.ts +1 -1
  135. package/dist/types/utils/objectPath.d.ts +49 -0
  136. package/dist/types/utils/time.d.ts +85 -0
  137. package/dist/types/utils.d.ts +63 -40
  138. package/package.json +22 -33
  139. package/src/ChannelManager.ts +561 -109
  140. package/src/CooldownTimer.ts +55 -45
  141. package/src/EventHandlerPipeline.ts +13 -23
  142. package/src/LiveLocationManager.ts +191 -37
  143. package/src/api-client.ts +144 -53
  144. package/src/channel.ts +1573 -1050
  145. package/src/channel_state.ts +239 -129
  146. package/src/client.ts +843 -892
  147. package/src/client_state.ts +2 -2
  148. package/src/configuration/ConfigController.ts +298 -0
  149. package/src/configuration/InstanceConfigurationRegistry.ts +430 -0
  150. package/src/configuration/index.ts +7 -0
  151. package/src/configuration/keys.ts +86 -0
  152. package/src/configuration/shape.ts +776 -0
  153. package/src/configuration/types.ts +218 -60
  154. package/src/configuration/utils/applyInstanceConfiguration.ts +184 -0
  155. package/src/configuration/utils/copyConfigPatch.ts +61 -0
  156. package/src/configuration/utils/declarativeSlices.ts +81 -0
  157. package/src/configuration/utils/deepFreezeConfig.ts +33 -0
  158. package/src/configuration/utils/index.ts +5 -0
  159. package/src/configuration/utils/serverAuthority.ts +146 -0
  160. package/src/connection/ConnectionIdManager.ts +153 -0
  161. package/src/connection/ConnectionRecoveryManager.ts +371 -0
  162. package/src/connection/index.ts +4 -0
  163. package/src/connection/networkConnection/NetworkConnectionObserver.ts +281 -0
  164. package/src/connection/networkConnection/index.ts +3 -0
  165. package/src/connection/networkConnection/reporters.ts +85 -0
  166. package/src/connection/networkConnection/types.ts +60 -0
  167. package/src/{connection.ts → connection/wsConnection/StableWSConnection.ts} +242 -151
  168. package/src/connection/wsConnection/WSConnection.ts +345 -0
  169. package/src/connection/wsConnection/WSConnectionFallback.ts +259 -0
  170. package/src/connection/wsConnection/config.ts +108 -0
  171. package/src/connection/wsConnection/index.ts +4 -0
  172. package/src/connection/wsConnection/types.ts +101 -0
  173. package/src/constants.ts +5 -3
  174. package/src/entityStore/EntityStore.ts +350 -10
  175. package/src/entityStore/StoreBackedItemIndex.ts +66 -37
  176. package/src/entityStore/index.ts +0 -1
  177. package/src/errors.ts +40 -7
  178. package/src/formatMessageMemo.ts +23 -0
  179. package/src/gen/chat/ChannelApi.ts +230 -44
  180. package/src/gen/chat/ChatApi.ts +1047 -1745
  181. package/src/gen/models/index.ts +2378 -3721
  182. package/src/gen/models/timestamp-guard.ts +27 -0
  183. package/src/gen/moderation/ModerationApi.ts +218 -388
  184. package/src/gen-imports.ts +1 -0
  185. package/src/index.ts +82 -6
  186. package/src/languageNames.ts +103 -0
  187. package/src/logger.ts +1 -1
  188. package/src/messageComposer/CustomDataManager.ts +10 -1
  189. package/src/messageComposer/LocationComposer.ts +68 -20
  190. package/src/messageComposer/attachmentIdentity.ts +39 -0
  191. package/src/messageComposer/attachmentManager.ts +191 -68
  192. package/src/messageComposer/attachmentUtils.ts +58 -0
  193. package/src/messageComposer/configuration/commands.configuration.ts +1 -26
  194. package/src/messageComposer/configuration/configuration.ts +22 -3
  195. package/src/messageComposer/configuration/index.ts +0 -1
  196. package/src/messageComposer/configuration/types.ts +58 -1
  197. package/src/messageComposer/index.ts +1 -0
  198. package/src/messageComposer/linkPreviewsManager.ts +16 -10
  199. package/src/messageComposer/messageComposer.ts +487 -98
  200. package/src/messageComposer/middleware/attachmentManager/postUpload/AttachmentPostUploadMiddlewareExecutor.ts +1 -1
  201. package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +58 -33
  202. package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +7 -2
  203. package/src/messageComposer/middleware/attachmentManager/preUpload/blockedUploadNotification.ts +3 -2
  204. package/src/messageComposer/middleware/messageComposer/attachments.ts +98 -1
  205. package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +20 -10
  206. package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +7 -2
  207. package/src/messageComposer/middleware/messageComposer/types.ts +2 -7
  208. package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +11 -6
  209. package/src/messageComposer/middleware/pollComposer/index.ts +1 -0
  210. package/src/messageComposer/middleware/pollComposer/state.ts +43 -11
  211. package/src/messageComposer/middleware/pollComposer/types.ts +9 -2
  212. package/src/messageComposer/middleware/pollComposer/validation.ts +76 -0
  213. package/src/messageComposer/middleware/textComposer/commandUtils.ts +3 -2
  214. package/src/messageComposer/middleware/textComposer/commands.ts +1 -2
  215. package/src/messageComposer/middleware/textComposer/mentions.ts +91 -39
  216. package/src/messageComposer/pollComposer.ts +11 -3
  217. package/src/messageComposer/textComposer.ts +36 -4
  218. package/src/messageComposer/types.ts +19 -14
  219. package/src/messageDelivery/MessageDeliveryReporter.ts +154 -53
  220. package/src/messageDelivery/MessageReceiptsTracker.ts +136 -64
  221. package/src/messageOperations/FailedSendCache.ts +90 -0
  222. package/src/messageOperations/MessageOperationStatePolicy.ts +269 -27
  223. package/src/messageOperations/MessageOperations.ts +340 -136
  224. package/src/{entityStore → messageOperations}/applyReactionLocally.ts +10 -3
  225. package/src/messageOperations/createMessageOperations.ts +192 -0
  226. package/src/messageOperations/index.ts +7 -0
  227. package/src/messageOperations/reflectReactionEvent.ts +51 -0
  228. package/src/messageOperations/sendOrdering.ts +28 -0
  229. package/src/messageOperations/settlePendingAttachmentUploads.ts +110 -0
  230. package/src/messageOperations/types.ts +74 -0
  231. package/src/middleware.ts +11 -0
  232. package/src/moderation.ts +47 -24
  233. package/src/notifications/NotificationManager.ts +73 -3
  234. package/src/notifications/configuration.ts +10 -8
  235. package/src/notifications/types.ts +58 -42
  236. package/src/offline-support/offline_support_api.ts +380 -197
  237. package/src/offline-support/offline_sync_manager.ts +105 -32
  238. package/src/offline-support/queueableOperations.ts +270 -0
  239. package/src/offline-support/types.ts +85 -39
  240. package/src/pagination/FilterBuilder.ts +1 -22
  241. package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +11 -7
  242. package/src/pagination/cursorDerivation/linearPaginationFlags.ts +25 -7
  243. package/src/pagination/filterCompiler.ts +17 -0
  244. package/src/pagination/paginators/BasePaginator.ts +731 -81
  245. package/src/pagination/paginators/ChannelPaginator.ts +210 -102
  246. package/src/pagination/paginators/MessageIntervalPaginator.ts +703 -193
  247. package/src/pagination/paginators/MessagePaginator.ts +45 -36
  248. package/src/pagination/paginators/PinnedMessagePaginator.ts +74 -28
  249. package/src/pagination/paginators/ReminderPaginator.ts +15 -13
  250. package/src/pagination/paginators/ThreadPaginator.ts +181 -0
  251. package/src/pagination/paginators/UserGroupPaginator.ts +8 -1
  252. package/src/pagination/paginators/index.ts +1 -0
  253. package/src/pagination/utility.normalization.ts +37 -9
  254. package/src/poll.ts +189 -112
  255. package/src/poll_manager.ts +14 -8
  256. package/src/poll_optimistic_votes.ts +335 -0
  257. package/src/reminders/Reminder.ts +34 -16
  258. package/src/reminders/ReminderManager.ts +68 -41
  259. package/src/reminders/ReminderTimer.ts +7 -6
  260. package/src/search/BaseSearchSource.ts +133 -40
  261. package/src/search/ChannelMemberSearchSource.ts +27 -18
  262. package/src/search/ChannelSearchSource.ts +61 -7
  263. package/src/search/MessageSearchSource.ts +133 -28
  264. package/src/search/SearchController.ts +93 -16
  265. package/src/search/UserSearchSource.ts +27 -13
  266. package/src/search/types.ts +14 -1
  267. package/src/signing.ts +1 -315
  268. package/src/thread.ts +503 -511
  269. package/src/thread_manager.ts +339 -204
  270. package/src/token_manager.ts +12 -32
  271. package/src/types.ts +159 -780
  272. package/src/types.utility.ts +14 -0
  273. package/src/upload-utils.ts +53 -0
  274. package/src/uploadManager.ts +85 -7
  275. package/src/utils/FixedSizeQueueCache.ts +5 -0
  276. package/src/utils/WithSubscriptions.ts +1 -1
  277. package/src/utils/objectPath.ts +67 -0
  278. package/src/utils/time.ts +104 -0
  279. package/src/utils.ts +209 -157
  280. package/dist/types/base64.d.ts +0 -2
  281. package/dist/types/configuration/InstanceConfigurationService.d.ts +0 -26
  282. package/dist/types/connection.d.ts +0 -146
  283. package/dist/types/connection_fallback.d.ts +0 -42
  284. package/dist/types/gen/model-decoders/decoders.d.ts +0 -3
  285. package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +0 -6
  286. package/dist/types/insights.d.ts +0 -58
  287. package/dist/types/pagination/utility.queryChannel.d.ts +0 -26
  288. package/dist/types/permissions.d.ts +0 -55
  289. package/dist/types/store.d.ts +0 -125
  290. package/src/base64.ts +0 -78
  291. package/src/configuration/InstanceConfigurationService.ts +0 -73
  292. package/src/connection_fallback.ts +0 -215
  293. package/src/gen/model-decoders/decoders.ts +0 -2680
  294. package/src/gen/model-decoders/event-decoder-mapping.ts +0 -198
  295. package/src/insights.ts +0 -83
  296. package/src/pagination/utility.queryChannel.ts +0 -84
  297. package/src/permissions.ts +0 -102
  298. package/src/store.ts +0 -304
@@ -1,81 +1,239 @@
1
1
  import type { StreamChat } from '../client';
2
+ import type {
3
+ LiveLocationManager,
4
+ LiveLocationManagerConfig,
5
+ } from '../LiveLocationManager';
6
+ import type {
7
+ SearchController,
8
+ SearchControllerConfig,
9
+ } from '../search/SearchController';
2
10
  import type { MessageComposer } from '../messageComposer';
3
- import type { Channel } from '../channel';
4
- import type { Thread } from '../thread';
5
- import type { StateStore } from '../store';
11
+ import type { MessageComposerConfig } from '../messageComposer/configuration/types';
12
+ import type { Channel, ChannelConfig } from '../channel';
13
+ import type { Thread, ThreadConfig } from '../thread';
14
+ import type { ReminderManagerConfig } from '../reminders/ReminderManager';
15
+ import type { NotificationManagerConfig } from '../notifications/types';
16
+ import type { MessageDeliveryReporterConfig } from '../messageDelivery/MessageDeliveryReporter';
17
+ import type { ThreadManagerConfig } from '../thread_manager';
18
+ import type {
19
+ ConnectionRecoveryManagerConfig,
20
+ NetworkConnectionObserverConfig,
21
+ WSConnectionConfig,
22
+ } from '../connection';
23
+ import type { MessageOperationsConfig } from '../messageOperations/MessageOperations';
24
+ import type { DeclarativePaginatorConfig as ImportedDeclarativePaginatorConfig } from '../pagination/paginators/BasePaginator';
25
+ import type { DeepPartial } from '../types.utility';
6
26
 
7
- export type MessageComposerTearDownFunction = () => void;
27
+ // ---------------------------------------------------------------------------
28
+ // Keys
29
+ // ---------------------------------------------------------------------------
8
30
 
9
- export type MessageComposerSetupFunction = ({
10
- composer,
11
- }: {
12
- composer: MessageComposer;
13
- }) => void | MessageComposerTearDownFunction;
14
-
15
- export type MessageComposerSetupState = {
16
- /**
17
- * Each `MessageComposer` runs this function each time its signature changes or
18
- * whenever you run `MessageComposer.registerSubscriptions`. Function returned
19
- * from `applyModifications` will be used as a cleanup function - it will be stored
20
- * and ran before new modification is applied. Cleaning up only the
21
- * modified parts is the general way to go but if your setup gets a bit
22
- * complicated, feel free to restore the whole composer with `MessageComposer.restore`.
23
- */
24
- setupFunction: MessageComposerSetupFunction | null;
31
+ /**
32
+ * Maps a configuration key to the argument its setup function receives.
33
+ *
34
+ * A closed set, and deliberately not an `interface`: a type alias cannot be reached by module
35
+ * augmentation, so the key space cannot be extended from outside this package. Configuration for a class
36
+ * this package does not own belongs to whoever owns that class — a registry of its own, not a key in this
37
+ * one, which the SDK could neither type nor apply.
38
+ */
39
+ export type InstanceSetupFunctionArgs = {
40
+ channel: { channel: Channel };
41
+ client: { client: StreamChat };
42
+ liveLocationManager: { liveLocationManager: LiveLocationManager };
43
+ messageComposer: { composer: MessageComposer };
44
+ searchController: { searchController: SearchController };
45
+ thread: { thread: Thread };
25
46
  };
26
47
 
27
- export type StreamChatTearDownFunction = () => void;
48
+ /**
49
+ * The keys that take a **setup function** — every one names a class the setup function receives an
50
+ * instance of.
51
+ *
52
+ * Closed, and not extensible: an undeclared string is a compile error, and {@link
53
+ * InstanceSetupFunctionArgs} is a type alias rather than an interface, so a key cannot be added by module
54
+ * augmentation either. This key space describes what *this package* configures.
55
+ *
56
+ * A strict subset of {@link InstanceConfigKey}: `messagePaginator` and `messageOperations` take
57
+ * configuration but have no setup function, because they are not built one-per-key — a channel and every
58
+ * one of its threads each own one.
59
+ */
60
+ export type InstanceSetupKey = keyof InstanceSetupFunctionArgs;
61
+
62
+ // ---------------------------------------------------------------------------
63
+ // Tier 2 — setup functions
64
+ // ---------------------------------------------------------------------------
28
65
 
29
- export type StreamChatSetupFunction = ({
30
- client,
31
- }: {
32
- client: StreamChat;
33
- }) => void | StreamChatTearDownFunction;
66
+ export type InstanceSetupFunctionArgsOf<K extends InstanceSetupKey> =
67
+ InstanceSetupFunctionArgs[K];
34
68
 
35
- export type StreamChatSetupState = {
36
- setupFunction: StreamChatSetupFunction | null;
69
+ export type InstanceSetupTearDownFunction = () => void;
70
+
71
+ /**
72
+ * Runs against every instance of its class — those that already exist when it is registered, and
73
+ * every one created afterwards. Return a function that undoes whatever you changed: it is invoked
74
+ * before the setup function is re-applied, and when the instance is disposed of.
75
+ */
76
+ export type InstanceSetupFunction<K extends InstanceSetupKey = InstanceSetupKey> = (
77
+ args: InstanceSetupFunctionArgsOf<K>,
78
+ ) => void | InstanceSetupTearDownFunction;
79
+
80
+ export type InstanceSetupState<K extends InstanceSetupKey = InstanceSetupKey> = {
81
+ setupFunction: InstanceSetupFunction<K> | null;
37
82
  };
38
83
 
39
- export type ChannelTearDownFunction = () => void;
84
+ // ---------------------------------------------------------------------------
85
+ // Tier 1 — declarative configuration
86
+ // ---------------------------------------------------------------------------
87
+
88
+ /** Whether `jumpToTheFirstUnreadMessage` prefers the paginator's snapshot or the channel read state. */
89
+ export type UnreadReferencePolicy = 'snapshot' | 'read-state-only';
40
90
 
41
- export type ChannelSetupFunction = ({
42
- channel,
43
- }: {
44
- channel: Channel;
45
- }) => void | ChannelTearDownFunction;
91
+ /**
92
+ * Paginator fields settable through the declarative tree. Single source of truth lives with the
93
+ * paginator itself (`DeclarativePaginatorConfig` in `BasePaginator`), so the tree and the paginator's
94
+ * own `initializeConfig` can never accept different sets of fields.
95
+ *
96
+ * Deliberately excluded there:
97
+ * - `itemIndex` / `createItemIndex` — an index instance and a factory, not configuration. Deep-merging
98
+ * a class instance is unsound, and swapping an index would drop already-loaded items.
99
+ * - `doRequest`, `itemOrderComparator`, `deriveCursor` — installed per paginator subclass
100
+ * (`PinnedMessagePaginator` supplies all three). Replace them through a setup function, where the
101
+ * existing value is visible and restorable.
102
+ *
103
+ * `initialCursor` and `initialOffset` are included but read only during construction — see
104
+ * {@link CONSTRUCTION_ONLY_CONFIG_PATHS}.
105
+ */
106
+ export type { DeclarativePaginatorConfig } from '../pagination/paginators/BasePaginator';
46
107
 
47
- export type ChannelSetupState = {
48
- setupFunction: ChannelSetupFunction | null;
108
+ /** Adds the message-list-only unread reference policy, which is a constructor argument. */
109
+ export type DeclarativeMessagePaginatorConfig = ImportedDeclarativePaginatorConfig & {
110
+ unreadReferencePolicy?: UnreadReferencePolicy;
49
111
  };
50
112
 
51
- export type ThreadTearDownFunction = () => void;
113
+ export type ChannelDeclarativeConfig = {
114
+ /** Overrides the shared top-level `messageOperations` key for channels only. */
115
+ messageOperations?: Partial<MessageOperationsConfig>;
116
+ messagePaginator?: DeclarativeMessagePaginatorConfig;
117
+ pinnedMessagesPaginator?: ImportedDeclarativePaginatorConfig;
118
+ requestHandlers?: ChannelConfig['requestHandlers'];
119
+ /** Typing indicators, ANDed with the channel type's `typing_events`. */
120
+ typingEvents?: Partial<ChannelConfig['typingEvents']>;
121
+ /** Read receipts, ANDed with the channel type's `read_events`. */
122
+ readEvents?: Partial<ChannelConfig['readEvents']>;
123
+ /** Threaded replies, ANDed with the channel type's `replies`. */
124
+ replies?: Partial<ChannelConfig['replies']>;
125
+ /** Message reminders, ANDed with the channel type's `user_message_reminders`. */
126
+ userMessageReminders?: Partial<ChannelConfig['userMessageReminders']>;
127
+ /** Delivery receipts, ANDed with the channel type's `delivery_events`. */
128
+ deliveryEvents?: Partial<ChannelConfig['deliveryEvents']>;
129
+ // `commands` is deliberately absent: the server owns the list outright, so there is nothing to set.
130
+ };
52
131
 
53
- export type ThreadSetupFunction = ({
54
- thread,
55
- }: {
56
- thread: Thread;
57
- }) => void | ThreadTearDownFunction;
132
+ export type ThreadDeclarativeConfig = {
133
+ /** Overrides the shared top-level `messageOperations` key for thread replies only. */
134
+ messageOperations?: Partial<MessageOperationsConfig>;
135
+ messagePaginator?: DeclarativeMessagePaginatorConfig;
136
+ requestHandlers?: ThreadConfig['requestHandlers'];
137
+ };
58
138
 
59
- export type ThreadSetupState = {
60
- setupFunction: ThreadSetupFunction | null;
139
+ export type ClientDeclarativeConfig = {
140
+ /**
141
+ * Nested rather than top-level keys: each of these managers has exactly one parent — the client — so
142
+ * there is nothing to say once and reuse, which is what a top-level key buys (**DEC-25**).
143
+ */
144
+ connectionRecovery?: Partial<ConnectionRecoveryManagerConfig>;
145
+ messageDelivery?: Partial<MessageDeliveryReporterConfig>;
146
+ /**
147
+ * Connection status — specifically, the platform listener that reports the device's network. There
148
+ * is no default outside the browser, so this is how React Native and other hosts supply one.
149
+ * `Partial`, not `DeepPartial`: the only field holds a function, which `DeepPartial` would descend
150
+ * into.
151
+ */
152
+ networkConnection?: Partial<NetworkConnectionObserverConfig>;
153
+ threads?: Partial<ThreadManagerConfig>;
154
+ /**
155
+ * The WebSocket's timing: connect timeout, ping interval, and the health-check grace period on top of it.
156
+ * These three, and only these, because each was a public mutable field before it was configuration.
157
+ * `Partial`, not `DeepPartial`: every field is a flat number.
158
+ */
159
+ wsConnection?: Partial<WSConnectionConfig>;
160
+ notifications?: DeepPartial<NotificationManagerConfig>;
161
+ /**
162
+ * `Partial`, not `DeepPartial`: `scheduledOffsetsMs` is a `number[]`, and `DeepPartial` would widen
163
+ * its elements to `number | undefined`, which `ReminderManager.updateConfig` rightly rejects.
164
+ */
165
+ reminders?: Partial<ReminderManagerConfig>;
61
166
  };
62
167
 
63
- export type SetInstanceConfigurationServiceStates = {
64
- Channel: StateStore<ChannelSetupState>;
65
- MessageComposer: StateStore<MessageComposerSetupState>;
66
- StreamChat: StateStore<StreamChatSetupState>;
67
- Thread: StateStore<ThreadSetupState>;
168
+ /**
169
+ * Maps a configuration key to its declarative configuration subtree. Augmentable alongside
170
+ * {@link InstanceSetupFunctionArgs}, so a custom key gets declarative configuration on the same terms
171
+ * as a built-in one.
172
+ *
173
+ * **When something gets its own key rather than being nested under a parent** — the rule that decides
174
+ * the shape of this interface:
175
+ *
176
+ * - **One parent type ⇒ nest it.** `channel.pinnedMessagesPaginator`, `channel.cooldownTimer`, the
177
+ * composer's own sub-managers. There is only one place it can be reached from.
178
+ * - **Several parent types, and the configuration means the same thing under each ⇒ own key.**
179
+ * `MessageComposer` hangs off a `Channel`, a `Thread`, *and* a message (the React SDK builds
180
+ * message-scoped composers for editing). `drafts.enabled` means the same in all three, so nesting it
181
+ * under `channel` would silently miss two thirds of the composers.
182
+ * - **Several parent types, but the configuration is inherently parent-specific ⇒ nest it anyway.**
183
+ * No built-in falls here today. It is kept as a case because it is the one that decides against a shared
184
+ * key, and the next entity to arrive may need it.
185
+ * - **Several parent types, mixed ⇒ both.** A shared top-level key for what means the same thing, plus
186
+ * per-parent paths that override it field by field (see {@link mergeDeclarativeMessageOperationsConfig}).
187
+ * Both shared keys are here: `MessagePaginator` backs the channel message list *and* thread replies
188
+ * (`stateThrottleMs` / `retryCount` have no reason to differ, `pageSize` legitimately does), and
189
+ * `MessageOperations` backs channel *and* thread sends. `messageOperations` was briefly nested under
190
+ * `channel` on the reasoning that a channel send and a thread reply are different operations — which made
191
+ * `thread.messageOperations` unconfigurable entirely (**DV-15**). Counting parents is the check.
192
+ */
193
+ export type InstanceConfigTree = {
194
+ channel: ChannelDeclarativeConfig;
195
+ client: ClientDeclarativeConfig;
196
+ /**
197
+ * Constructed by whoever needs it — the React SDK's `useLiveLocationSharingManager`, or an app
198
+ * directly — never by this package. It reaches its configuration the way a `MessageComposer` does, by
199
+ * registering itself against this key, so its owner does not have to thread a slice through.
200
+ */
201
+ liveLocationManager: Partial<LiveLocationManagerConfig>;
202
+ messageComposer: DeepPartial<MessageComposerConfig>;
203
+ /**
204
+ * Applies to **every** `MessageOperations` — the channel's and every thread's, since messages are sent
205
+ * from both. `channel.messageOperations` and `thread.messageOperations` override it per parent.
206
+ */
207
+ messageOperations: Partial<MessageOperationsConfig>;
208
+ /**
209
+ * Applies to **every** `MessagePaginator` — the channel message list and thread replies alike.
210
+ * `channel.messagePaginator` and `thread.messagePaginator` override it per parent.
211
+ *
212
+ * `channel.pinnedMessagesPaginator` is deliberately **not** included: it has a single parent, so by
213
+ * the rule above it stays nested. It is also a different class (`PinnedMessagePaginator`, with its own
214
+ * ordering and endpoint) rather than a `MessagePaginator`.
215
+ */
216
+ messagePaginator: DeclarativeMessagePaginatorConfig;
217
+ /**
218
+ * Same story as {@link InstanceConfigTree.liveLocationManager}, with one caveat: a `SearchController`
219
+ * only reaches this key when it was constructed with a `client` — it is the one configurable class the
220
+ * SDK does not hand a client to. See `SearchControllerOptions.client`.
221
+ */
222
+ searchController: Partial<SearchControllerConfig>;
223
+ thread: ThreadDeclarativeConfig;
68
224
  };
69
225
 
70
- export type SetupFnOf<T> =
71
- T extends StateStore<infer S>
72
- ? S extends { setupFunction?: infer F }
73
- ? F
74
- : never
75
- : never;
76
-
77
- export type SetInstanceConfigurationFunctions = {
78
- [K in keyof SetInstanceConfigurationServiceStates]?: SetupFnOf<
79
- SetInstanceConfigurationServiceStates[K]
80
- >;
226
+ /**
227
+ * Every key that takes **declarative configuration** — {@link InstanceSetupKey} plus the two that are
228
+ * configuration-only.
229
+ *
230
+ * Closed for the same reason, and {@link InstanceConfigTree} is likewise a type alias, so this set is
231
+ * fixed by the package.
232
+ */
233
+ export type InstanceConfigKey = keyof InstanceConfigTree;
234
+
235
+ export type InstanceConfigOf<K extends InstanceConfigKey> = InstanceConfigTree[K];
236
+
237
+ export type InstanceConfigState<K extends InstanceConfigKey = InstanceConfigKey> = {
238
+ config: DeepPartial<InstanceConfigOf<K>> | null;
81
239
  };
@@ -0,0 +1,184 @@
1
+ import { chatLoggerSystem } from '../../logger';
2
+ import type {
3
+ ConfiguredInstance,
4
+ InstanceConfigurationRegistry,
5
+ } from '../InstanceConfigurationRegistry';
6
+ import type {
7
+ InstanceConfigKey,
8
+ InstanceConfigOf,
9
+ InstanceSetupFunctionArgsOf,
10
+ InstanceSetupKey,
11
+ InstanceSetupTearDownFunction,
12
+ } from '../types';
13
+ import type { DeepPartial } from '../../types.utility';
14
+ import type { Unsubscribe } from '@stream-io/state-store';
15
+
16
+ const logger = chatLoggerSystem.getLogger('instance-configuration');
17
+
18
+ /** @internal */
19
+ export type ApplyInstanceConfigurationParams<K extends InstanceSetupKey> = {
20
+ /** The instance's argument for its setup function — `{ channel }`, `{ composer }`, and so on. */
21
+ args: InstanceSetupFunctionArgsOf<K>;
22
+ /** The client's configuration registry, i.e. `client.config`. */
23
+ config: InstanceConfigurationRegistry;
24
+ key: K;
25
+ /**
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.
35
+ */
36
+ alsoWatch?: readonly InstanceConfigKey[];
37
+ /**
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.
44
+ */
45
+ applyConfig?: (config?: DeepPartial<InstanceConfigOf<K>>) => void;
46
+ /**
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.
50
+ */
51
+ reinitializeConfig?: () => void;
52
+ };
53
+
54
+ /**
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.channelManager.ensure()` 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.
70
+ *
71
+ * @internal
72
+ */
73
+ export const applyInstanceConfiguration = <K extends InstanceSetupKey>({
74
+ alsoWatch,
75
+ applyConfig,
76
+ args,
77
+ config: service,
78
+ key,
79
+ reinitializeConfig,
80
+ }: ApplyInstanceConfigurationParams<K>): Unsubscribe => {
81
+ const scopedLogger = logger.withExtraTags(key);
82
+ let tearDown: InstanceSetupTearDownFunction | null = null;
83
+
84
+ const runTearDown = () => {
85
+ if (!tearDown) return;
86
+ const pending = tearDown;
87
+ // Cleared before invoking, so a throwing teardown is never retried.
88
+ tearDown = null;
89
+ try {
90
+ pending();
91
+ } catch (error) {
92
+ scopedLogger.error('Setup function teardown threw', error);
93
+ }
94
+ };
95
+
96
+ const apply = () => {
97
+ runTearDown();
98
+
99
+ if (applyConfig) {
100
+ const declarative = service.getConfigState(key).getLatestValue().config;
101
+ try {
102
+ applyConfig(declarative ?? undefined);
103
+ } catch (error) {
104
+ scopedLogger.error('Applying declarative configuration threw', error);
105
+ }
106
+ }
107
+
108
+ const setupFunction = service.getSetupState(key).getLatestValue().setupFunction;
109
+ if (setupFunction) {
110
+ try {
111
+ tearDown = setupFunction(args) ?? null;
112
+ } catch (error) {
113
+ scopedLogger.error('Setup function threw', error);
114
+ }
115
+ }
116
+ };
117
+
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.
121
+ const instanceHandle: ConfiguredInstance = { reinitializeConfig };
122
+
123
+ const unregisterInstance = service.registerInstance(key, instanceHandle);
124
+
125
+ // `StateStore.subscribe` fires immediately, and we subscribe to two stores — so suppress while
126
+ // wiring and apply exactly once afterwards.
127
+ let suppress = true;
128
+
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.
134
+ const coveredByResetsOwnPass = () => !!reinitializeConfig && service.isResetting;
135
+
136
+ const onConfigChange = () => {
137
+ if (suppress || coveredByResetsOwnPass()) return;
138
+ apply();
139
+ };
140
+
141
+ const onSetupChange = () => {
142
+ 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.
145
+ if (coveredByResetsOwnPass()) {
146
+ runTearDown();
147
+ return;
148
+ }
149
+ apply();
150
+ };
151
+
152
+ const unsubscribeConfig = service
153
+ .getConfigState(key)
154
+ .subscribeWithSelector(({ config }) => ({ config }), onConfigChange);
155
+ const unsubscribeSetup = service
156
+ .getSetupState(key)
157
+ .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.
161
+ const unsubscribeExtra = (alsoWatch ?? []).map((watchedKey) =>
162
+ service
163
+ .getConfigState(watchedKey)
164
+ .subscribeWithSelector(({ config }) => ({ config }), onConfigChange),
165
+ );
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.
169
+ const unregisterExtra = (alsoWatch ?? []).map((watchedKey) =>
170
+ service.registerInstance(watchedKey, instanceHandle),
171
+ );
172
+ suppress = false;
173
+
174
+ apply();
175
+
176
+ return () => {
177
+ unsubscribeConfig();
178
+ unsubscribeSetup();
179
+ unsubscribeExtra.forEach((unsubscribe) => unsubscribe());
180
+ unregisterExtra.forEach((unregister) => unregister());
181
+ unregisterInstance();
182
+ runTearDown();
183
+ };
184
+ };
@@ -0,0 +1,61 @@
1
+ import { isWalkableRecord } from '../../utils/objectPath';
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
+ */
31
+ const copyInto = <T>(value: T, copies: WeakMap<object, unknown>): T => {
32
+ if (Array.isArray(value)) {
33
+ if (copies.has(value)) return copies.get(value) as T;
34
+
35
+ 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.
38
+ copies.set(value, copy);
39
+ for (const entry of value) copy.push(copyInto(entry, copies));
40
+ return copy as unknown as T;
41
+ }
42
+
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.
45
+ if (typeof value === 'object' && value !== null) {
46
+ if (!isWalkableRecord(value)) return value;
47
+ if (copies.has(value)) return copies.get(value) as T;
48
+
49
+ const copy: Record<string | symbol, unknown> = {};
50
+ copies.set(value, copy);
51
+ for (const key of Reflect.ownKeys(value)) {
52
+ if (!Object.prototype.propertyIsEnumerable.call(value, key)) continue;
53
+ copy[key] = copyInto((value as Record<string | symbol, unknown>)[key], copies);
54
+ }
55
+ return copy as T;
56
+ }
57
+
58
+ return value;
59
+ };
60
+
61
+ export const copyConfigPatch = <T>(value: T): T => copyInto(value, new WeakMap());
@@ -0,0 +1,81 @@
1
+ import type { DeclarativePaginatorConfig } from '../../pagination/paginators/BasePaginator';
2
+ import type { MessageOperationsConfig } from '../../messageOperations/MessageOperations';
3
+ import type { DeclarativeMessagePaginatorConfig } from '../types';
4
+
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.
29
+ */
30
+ const mergeDeclarativeSlice = <TConfig extends object>(
31
+ general?: TConfig,
32
+ specific?: TConfig,
33
+ ): TConfig | undefined => {
34
+ if (!general) return specific;
35
+ if (!specific) return general;
36
+
37
+ const merged: TConfig = { ...general };
38
+ for (const [key, value] of Object.entries(specific)) {
39
+ if (typeof value === 'undefined') continue;
40
+ (merged as Record<string, unknown>)[key] = value;
41
+ }
42
+ return merged;
43
+ };
44
+
45
+ /** Layers `channel.messageOperations` / `thread.messageOperations` over the shared `messageOperations` key. */
46
+ export const mergeDeclarativeMessageOperationsConfig = (
47
+ general?: Partial<MessageOperationsConfig>,
48
+ specific?: Partial<MessageOperationsConfig>,
49
+ ): Partial<MessageOperationsConfig> | undefined =>
50
+ mergeDeclarativeSlice(general, specific);
51
+
52
+ /** Layers `channel.messagePaginator` / `thread.messagePaginator` over the shared `messagePaginator` key. */
53
+ export const mergeDeclarativePaginatorConfig = (
54
+ general?: DeclarativeMessagePaginatorConfig,
55
+ specific?: DeclarativeMessagePaginatorConfig,
56
+ ): DeclarativeMessagePaginatorConfig | undefined =>
57
+ mergeDeclarativeSlice(general, specific);
58
+
59
+ /**
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.
74
+ */
75
+ export const toDeclarativePaginatorConfig = (
76
+ slice?: DeclarativeMessagePaginatorConfig,
77
+ ): DeclarativePaginatorConfig | undefined => {
78
+ if (!slice) return undefined;
79
+ const { unreadReferencePolicy: _constructionOnly, ...paginatorConfig } = slice;
80
+ return paginatorConfig;
81
+ };
@@ -0,0 +1,33 @@
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.
19
+ *
20
+ * @internal
21
+ */
22
+ export const deepFreezeConfig = <T>(value: T): Readonly<T> => {
23
+ if (value === null || typeof value !== 'object' || Object.isFrozen(value)) {
24
+ return value as Readonly<T>;
25
+ }
26
+
27
+ Object.freeze(value);
28
+ for (const nested of Object.values(value as Record<string, unknown>)) {
29
+ deepFreezeConfig(nested);
30
+ }
31
+
32
+ return value as Readonly<T>;
33
+ };