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

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 (269) hide show
  1. package/dist/cjs/index.browser.js +2196 -3902
  2. package/dist/cjs/index.browser.js.map +3 -3
  3. package/dist/cjs/index.node.js +2197 -3902
  4. package/dist/cjs/index.node.js.map +3 -3
  5. package/dist/esm/index.mjs +2199 -3905
  6. package/dist/esm/index.mjs.map +4 -4
  7. package/dist/types/ChannelManager.d.ts +120 -233
  8. package/dist/types/CooldownTimer.d.ts +8 -23
  9. package/dist/types/EventHandlerPipeline.d.ts +17 -37
  10. package/dist/types/LiveLocationManager.d.ts +22 -50
  11. package/dist/types/api-client.d.ts +9 -14
  12. package/dist/types/channel.d.ts +253 -448
  13. package/dist/types/channel_state.d.ts +48 -95
  14. package/dist/types/client.d.ts +245 -370
  15. package/dist/types/client_state.d.ts +1 -3
  16. package/dist/types/configuration/ConfigController.d.ts +30 -124
  17. package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +31 -123
  18. package/dist/types/configuration/keys.d.ts +5 -19
  19. package/dist/types/configuration/shape.d.ts +12 -29
  20. package/dist/types/configuration/types.d.ts +59 -87
  21. package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +13 -35
  22. package/dist/types/configuration/utils/copyConfigPatch.d.ts +8 -0
  23. package/dist/types/configuration/utils/declarativeSlices.d.ts +5 -16
  24. package/dist/types/configuration/utils/deepFreezeConfig.d.ts +3 -17
  25. package/dist/types/configuration/utils/serverAuthority.d.ts +9 -29
  26. package/dist/types/connection/ConnectionIdManager.d.ts +18 -40
  27. package/dist/types/connection/ConnectionRecoveryManager.d.ts +29 -120
  28. package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +32 -103
  29. package/dist/types/connection/networkConnection/reporters.d.ts +9 -32
  30. package/dist/types/connection/networkConnection/types.d.ts +12 -27
  31. package/dist/types/connection/wsConnection/StableWSConnection.d.ts +37 -116
  32. package/dist/types/connection/wsConnection/WSConnection.d.ts +41 -104
  33. package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +8 -16
  34. package/dist/types/connection/wsConnection/config.d.ts +8 -28
  35. package/dist/types/connection/wsConnection/types.d.ts +17 -70
  36. package/dist/types/entityStore/EntityStore.d.ts +153 -113
  37. package/dist/types/entityStore/StoreBackedItemIndex.d.ts +13 -46
  38. package/dist/types/errors.d.ts +7 -19
  39. package/dist/types/gen/chat/ChannelApi.d.ts +2 -1
  40. package/dist/types/gen/chat/ChatApi.d.ts +28 -14
  41. package/dist/types/gen/models/index.d.ts +769 -86
  42. package/dist/types/gen/moderation/ModerationApi.d.ts +4 -4
  43. package/dist/types/index.d.ts +2 -4
  44. package/dist/types/languageNames.d.ts +9 -24
  45. package/dist/types/logger.d.ts +1 -3
  46. package/dist/types/messageComposer/LocationComposer.d.ts +1 -1
  47. package/dist/types/messageComposer/attachmentIdentity.d.ts +1 -6
  48. package/dist/types/messageComposer/attachmentManager.d.ts +10 -32
  49. package/dist/types/messageComposer/attachmentUtils.d.ts +3 -14
  50. package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
  51. package/dist/types/messageComposer/configuration/types.d.ts +29 -56
  52. package/dist/types/messageComposer/linkPreviewsManager.d.ts +6 -9
  53. package/dist/types/messageComposer/messageComposer.d.ts +30 -164
  54. package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +4 -14
  55. package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +2 -9
  56. package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +2 -4
  57. package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +7 -19
  58. package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +9 -0
  59. package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +11 -18
  60. package/dist/types/messageComposer/middleware/textComposer/textMiddlewareUtils.d.ts +9 -3
  61. package/dist/types/messageComposer/middleware/textComposer/types.d.ts +1 -6
  62. package/dist/types/messageComposer/pollComposer.d.ts +8 -4
  63. package/dist/types/messageComposer/textComposer.d.ts +3 -9
  64. package/dist/types/messageComposer/types.d.ts +5 -8
  65. package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +25 -79
  66. package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +15 -82
  67. package/dist/types/messageOperations/FailedSendCache.d.ts +4 -9
  68. package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +10 -20
  69. package/dist/types/messageOperations/MessageOperations.d.ts +20 -40
  70. package/dist/types/messageOperations/applyReactionLocally.d.ts +5 -22
  71. package/dist/types/messageOperations/createMessageOperations.d.ts +3 -5
  72. package/dist/types/messageOperations/reflectReactionEvent.d.ts +5 -13
  73. package/dist/types/messageOperations/sendOrdering.d.ts +4 -7
  74. package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +7 -15
  75. package/dist/types/messageOperations/types.d.ts +15 -30
  76. package/dist/types/middleware.d.ts +7 -5
  77. package/dist/types/moderation.d.ts +21 -14
  78. package/dist/types/notifications/NotificationManager.d.ts +8 -31
  79. package/dist/types/notifications/types.d.ts +19 -59
  80. package/dist/types/offline-support/offline_support_api.d.ts +145 -539
  81. package/dist/types/offline-support/offline_sync_manager.d.ts +18 -42
  82. package/dist/types/offline-support/queueableOperations.d.ts +24 -52
  83. package/dist/types/offline-support/types.d.ts +24 -187
  84. package/dist/types/pagination/ItemIndex.d.ts +4 -12
  85. package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +13 -0
  86. package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -4
  87. package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +2 -3
  88. package/dist/types/pagination/paginators/BasePaginator.d.ts +235 -622
  89. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +67 -125
  90. package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +133 -292
  91. package/dist/types/pagination/paginators/MessagePaginator.d.ts +69 -118
  92. package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +7 -26
  93. package/dist/types/pagination/paginators/ReminderPaginator.d.ts +2 -2
  94. package/dist/types/pagination/paginators/ThreadPaginator.d.ts +15 -23
  95. package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +2 -6
  96. package/dist/types/pagination/sortCompiler.d.ts +11 -22
  97. package/dist/types/pagination/utility.normalization.d.ts +5 -23
  98. package/dist/types/pagination/utility.search.d.ts +3 -8
  99. package/dist/types/poll.d.ts +14 -14
  100. package/dist/types/poll_manager.d.ts +11 -2
  101. package/dist/types/poll_optimistic_votes.d.ts +10 -14
  102. package/dist/types/reminders/Reminder.d.ts +4 -4
  103. package/dist/types/reminders/ReminderManager.d.ts +7 -20
  104. package/dist/types/search/BaseSearchSource.d.ts +7 -12
  105. package/dist/types/search/ChannelSearchSource.d.ts +7 -7
  106. package/dist/types/search/MessageSearchSource.d.ts +7 -9
  107. package/dist/types/search/SearchController.d.ts +17 -22
  108. package/dist/types/search/types.d.ts +6 -10
  109. package/dist/types/signing.d.ts +12 -3
  110. package/dist/types/thread.d.ts +23 -71
  111. package/dist/types/thread_manager.d.ts +45 -70
  112. package/dist/types/token_manager.d.ts +8 -13
  113. package/dist/types/types.d.ts +64 -125
  114. package/dist/types/types.utility.d.ts +3 -3
  115. package/dist/types/upload-utils.d.ts +5 -10
  116. package/dist/types/uploadManager.d.ts +17 -45
  117. package/dist/types/utils/FixedSizeQueueCache.d.ts +6 -11
  118. package/dist/types/utils/WithSubscriptions.d.ts +5 -15
  119. package/dist/types/utils/concurrency.d.ts +11 -19
  120. package/dist/types/utils/mergeWith/mergeWith.d.ts +8 -11
  121. package/dist/types/utils/mergeWith/mergeWithCore.d.ts +5 -13
  122. package/dist/types/utils/mergeWith/mergeWithDiff.d.ts +22 -0
  123. package/dist/types/utils/objectPath.d.ts +6 -41
  124. package/dist/types/utils/retryable.d.ts +8 -12
  125. package/dist/types/utils/throttling/throttle.d.ts +8 -23
  126. package/dist/types/utils/time.d.ts +24 -64
  127. package/dist/types/utils.d.ts +40 -86
  128. package/package.json +7 -2
  129. package/src/ChannelManager.ts +159 -300
  130. package/src/CooldownTimer.ts +11 -29
  131. package/src/EventHandlerPipeline.ts +21 -44
  132. package/src/LiveLocationManager.ts +35 -74
  133. package/src/api-client.ts +43 -61
  134. package/src/campaign.ts +1 -1
  135. package/src/channel.ts +396 -749
  136. package/src/channel_batch_updater.ts +1 -1
  137. package/src/channel_state.ts +50 -105
  138. package/src/client.ts +360 -588
  139. package/src/client_state.ts +1 -6
  140. package/src/configuration/ConfigController.ts +41 -157
  141. package/src/configuration/InstanceConfigurationRegistry.ts +42 -171
  142. package/src/configuration/index.ts +1 -1
  143. package/src/configuration/keys.ts +13 -32
  144. package/src/configuration/shape.ts +67 -70
  145. package/src/configuration/types.ts +60 -100
  146. package/src/configuration/utils/applyInstanceConfiguration.ts +21 -53
  147. package/src/configuration/utils/copyConfigPatch.ts +11 -32
  148. package/src/configuration/utils/declarativeSlices.ts +9 -39
  149. package/src/configuration/utils/deepFreezeConfig.ts +3 -17
  150. package/src/configuration/utils/index.ts +2 -4
  151. package/src/configuration/utils/serverAuthority.ts +20 -68
  152. package/src/connection/ConnectionIdManager.ts +20 -49
  153. package/src/connection/ConnectionRecoveryManager.ts +51 -178
  154. package/src/connection/networkConnection/NetworkConnectionObserver.ts +37 -114
  155. package/src/connection/networkConnection/reporters.ts +9 -36
  156. package/src/connection/networkConnection/types.ts +12 -27
  157. package/src/connection/wsConnection/StableWSConnection.ts +73 -193
  158. package/src/connection/wsConnection/WSConnection.ts +56 -131
  159. package/src/connection/wsConnection/WSConnectionFallback.ts +22 -31
  160. package/src/connection/wsConnection/config.ts +13 -48
  161. package/src/connection/wsConnection/types.ts +17 -70
  162. package/src/constants.ts +4 -4
  163. package/src/entityStore/EntityStore.ts +162 -167
  164. package/src/entityStore/StoreBackedItemIndex.ts +14 -47
  165. package/src/errors.ts +7 -19
  166. package/src/formatMessageMemo.ts +3 -9
  167. package/src/gen/chat/ChannelApi.ts +19 -0
  168. package/src/gen/chat/ChatApi.ts +87 -13
  169. package/src/gen/models/index.ts +793 -71
  170. package/src/gen/moderation/ModerationApi.ts +0 -4
  171. package/src/index.ts +10 -14
  172. package/src/languageNames.ts +9 -24
  173. package/src/logger.ts +1 -3
  174. package/src/messageComposer/LocationComposer.ts +7 -23
  175. package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
  176. package/src/messageComposer/attachmentIdentity.ts +2 -13
  177. package/src/messageComposer/attachmentManager.ts +17 -63
  178. package/src/messageComposer/attachmentUtils.ts +3 -17
  179. package/src/messageComposer/configuration/configuration.ts +5 -8
  180. package/src/messageComposer/configuration/types.ts +29 -56
  181. package/src/messageComposer/fileUtils.ts +1 -1
  182. package/src/messageComposer/linkPreviewsManager.ts +8 -20
  183. package/src/messageComposer/messageComposer.ts +54 -222
  184. package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +4 -16
  185. package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +1 -2
  186. package/src/messageComposer/middleware/messageComposer/attachments.ts +14 -40
  187. package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +3 -4
  188. package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
  189. package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +4 -11
  190. package/src/messageComposer/middleware/pollComposer/state.ts +2 -2
  191. package/src/messageComposer/middleware/pollComposer/types.ts +2 -4
  192. package/src/messageComposer/middleware/pollComposer/validation.ts +8 -26
  193. package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +1 -6
  194. package/src/messageComposer/middleware/textComposer/commandUtils.ts +1 -2
  195. package/src/messageComposer/middleware/textComposer/commands.ts +11 -16
  196. package/src/messageComposer/middleware/textComposer/mentions.ts +32 -70
  197. package/src/messageComposer/middleware/textComposer/textMiddlewareUtils.ts +10 -4
  198. package/src/messageComposer/middleware/textComposer/types.ts +1 -6
  199. package/src/messageComposer/pollComposer.ts +11 -8
  200. package/src/messageComposer/textComposer.ts +9 -59
  201. package/src/messageComposer/types.ts +9 -12
  202. package/src/messageDelivery/MessageDeliveryReporter.ts +60 -113
  203. package/src/messageDelivery/MessageReceiptsTracker.ts +21 -105
  204. package/src/messageOperations/FailedSendCache.ts +4 -9
  205. package/src/messageOperations/MessageOperationStatePolicy.ts +40 -67
  206. package/src/messageOperations/MessageOperations.ts +33 -62
  207. package/src/messageOperations/applyReactionLocally.ts +9 -28
  208. package/src/messageOperations/createMessageOperations.ts +17 -33
  209. package/src/messageOperations/reflectReactionEvent.ts +5 -13
  210. package/src/messageOperations/sendOrdering.ts +4 -7
  211. package/src/messageOperations/settlePendingAttachmentUploads.ts +10 -21
  212. package/src/messageOperations/types.ts +15 -30
  213. package/src/middleware.ts +7 -10
  214. package/src/moderation.ts +25 -21
  215. package/src/notifications/NotificationManager.ts +11 -35
  216. package/src/notifications/types.ts +19 -59
  217. package/src/offline-support/offline_support_api.ts +178 -608
  218. package/src/offline-support/offline_sync_manager.ts +25 -69
  219. package/src/offline-support/queueableOperations.ts +31 -84
  220. package/src/offline-support/types.ts +25 -188
  221. package/src/pagination/ItemIndex.ts +4 -12
  222. package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
  223. package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +13 -62
  224. package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
  225. package/src/pagination/cursorDerivation/linearPaginationFlags.ts +4 -6
  226. package/src/pagination/filterCompiler.ts +11 -25
  227. package/src/pagination/paginators/BasePaginator.ts +422 -976
  228. package/src/pagination/paginators/ChannelPaginator.ts +130 -190
  229. package/src/pagination/paginators/MessageIntervalPaginator.ts +226 -457
  230. package/src/pagination/paginators/MessagePaginator.ts +135 -175
  231. package/src/pagination/paginators/PinnedMessagePaginator.ts +13 -38
  232. package/src/pagination/paginators/ReminderPaginator.ts +12 -15
  233. package/src/pagination/paginators/ThreadPaginator.ts +16 -26
  234. package/src/pagination/paginators/UserGroupPaginator.ts +6 -17
  235. package/src/pagination/paginators/stateThrottling.ts +5 -10
  236. package/src/pagination/sortCompiler.ts +23 -50
  237. package/src/pagination/utility.normalization.ts +8 -30
  238. package/src/pagination/utility.search.ts +4 -11
  239. package/src/poll.ts +19 -19
  240. package/src/poll_manager.ts +16 -20
  241. package/src/poll_optimistic_votes.ts +17 -22
  242. package/src/reminders/Reminder.ts +5 -6
  243. package/src/reminders/ReminderManager.ts +9 -34
  244. package/src/reminders/ReminderTimer.ts +1 -2
  245. package/src/search/BaseSearchSource.ts +14 -29
  246. package/src/search/ChannelSearchSource.ts +8 -8
  247. package/src/search/MessageSearchSource.ts +19 -25
  248. package/src/search/SearchController.ts +18 -24
  249. package/src/search/types.ts +6 -10
  250. package/src/segment.ts +1 -1
  251. package/src/signing.ts +23 -3
  252. package/src/thread.ts +72 -173
  253. package/src/thread_manager.ts +59 -76
  254. package/src/token_manager.ts +11 -21
  255. package/src/types.ts +78 -126
  256. package/src/types.utility.ts +3 -3
  257. package/src/upload-utils.ts +5 -10
  258. package/src/uploadManager.ts +22 -54
  259. package/src/utils/FixedSizeQueueCache.ts +13 -21
  260. package/src/utils/WithSubscriptions.ts +5 -15
  261. package/src/utils/concurrency.ts +16 -55
  262. package/src/utils/mergeWith/mergeWith.ts +10 -13
  263. package/src/utils/mergeWith/mergeWithCore.ts +24 -81
  264. package/src/utils/mergeWith/mergeWithDiff.ts +15 -33
  265. package/src/utils/objectPath.ts +6 -41
  266. package/src/utils/retryable.ts +10 -14
  267. package/src/utils/throttling/throttle.ts +9 -25
  268. package/src/utils/time.ts +26 -66
  269. package/src/utils.ts +72 -128
@@ -1,99 +1,46 @@
1
1
  import type { StableWSConnection } from '../../connection';
2
2
  export type WSConnectionState = {
3
- /**
4
- * Is this client's WebSocket up. After an `enableWSFallback` switch, whether its long-poll is up,
5
- * since the long-poll writes this store from then on.
6
- *
7
- * Deliberately the same field name as `client.networkConnection.state`'s — both answer the same
8
- * question about a different connection, which is why the two objects are named as parallels. The
9
- * types differ only where they must: this one is never `undefined`, because a socket always has a
10
- * state, so `!isHealthy` is safe here where the network's `isOnline` needs `=== false`.
11
- */
3
+ /** Whether the WebSocket, or the long-poll after an `enableWSFallback` switch, is up. */
12
4
  isHealthy: boolean;
13
5
  lastHealthyAt: Date | null;
14
6
  lastUnhealthyAt: Date | null;
15
7
  };
16
- /**
17
- * The WebSocket's settings: its timing knobs, what it is built from (`webSocketImpl`,
18
- * `urlParams`, `connection`), and {@link enableWSFallback}, the switch to long-polling when it
19
- * cannot connect.
20
- *
21
- * Declared, validated, and durable across reconnects. {@link offlineNotificationDisplayDelayMs} is
22
- * the odd one out: the only field here this package does not act on itself.
23
- *
24
- * The network-recovery retry is deliberately **not** configurable, and stays a constant in
25
- * `config.ts`: nothing could reach it, so exposing it would add surface rather than preserve it.
26
- *
27
- * The timings are all in **milliseconds**, and named with the unit, because a bare `pingInterval`
28
- * reads equally well as seconds.
29
- */
8
+ /** The WebSocket's settings. Timings are in milliseconds. */
30
9
  export type WSConnectionConfig = {
31
10
  /**
32
- * How long `connect()` waits for the server's `connection.ok` hello before giving up. The default
33
- * of 15s allows between two and three attempts of the underlying retry.
11
+ * How long `connect()` waits for the server's `connection.ok` before giving up. Defaults to 15s.
34
12
  */
35
13
  connectTimeoutMs: number;
36
14
  /**
37
- * Whether to enable the WebSocket fallback mechanism. Only enable this feature if you expect clients to be in environments where WebSocket connections might be blocked. Most integrators shouldn't need to turn on this flag.
38
- *
39
- * Falls back to HTTP long-polling when the WebSocket cannot connect, for networks that block
40
- * WebSockets. Defaults to `false`. The WebSocket connects within {@link connectTimeoutMs}, as
41
- * without the flag; lower it to switch sooner. The client dispatches
42
- * `connection.fallback_activated` with `mode: 'longpoll'` when it switches, and stays on long-poll
43
- * from then on.
15
+ * Falls back to HTTP long-polling, for networks that block WebSockets, when the WebSocket cannot
16
+ * connect within {@link connectTimeoutMs} (lower it to switch sooner) and the device is not known
17
+ * to be offline. Defaults to `false`; most integrators do not need it. The client dispatches
18
+ * `connection.fallback_activated` (`mode: 'longpoll'`) on the switch and stays on long-poll.
44
19
  */
45
20
  enableWSFallback: boolean;
46
21
  /**
47
- * How often a health-check ping goes out while the socket is up.
48
- *
49
- * **Can only be lowered.** 25s is both the default and the maximum, because a slower ping risks the
50
- * connection being closed for idleness. Shortening it makes a dead socket noticed sooner, since
51
- * {@link healthCheckGracePeriodMs} moves the connection check along with it. See
22
+ * How often a health-check ping goes out while the socket is up. Defaults to 25s, which is also the
23
+ * maximum (a slower ping risks an idle close), so it can only be lowered. See
52
24
  * {@link WS_CONNECTION_CONFIG_BOUNDS}.
53
25
  */
54
26
  pingIntervalMs: number;
55
27
  /**
56
- * Extra room on top of {@link pingIntervalMs} before the health-check loop declares the socket
57
- * dead — the time a ping has to make its round trip. The connection check fires at
58
- * `pingIntervalMs + healthCheckGracePeriodMs`, so changing the ping interval moves the connection check with it.
59
- *
60
- * A grace period rather than an absolute deadline, because a deadline can be set shorter than the
61
- * ping interval, which makes the socket declare itself dead on a healthy connection and do it again
62
- * after every reconnect. A grace period cannot express that.
28
+ * Extra time on top of {@link pingIntervalMs} before the health check declares the socket dead
29
+ * (the check fires after `pingIntervalMs + healthCheckGracePeriodMs` of silence). Defaults to 10s.
63
30
  */
64
31
  healthCheckGracePeriodMs: number;
65
32
  /**
66
- * How long a drop must last before a UI reports it. Defaults to 5s. Zero holds nothing back,
67
- * though a `setTimeout(…, 0)` still lands on the next task rather than synchronously.
68
- *
69
- * Most drops resolve in under a second, so a banner showing all of them makes a working application
70
- * look broken. **Nothing here waits on it** — it is configuration so the UI SDKs share one value.
71
- * `stream-chat-react`'s `<Chat>` reads it.
33
+ * How long a drop must last before a UI reports it. Defaults to 5s. Nothing in this package waits
34
+ * on it; it is configuration so the UI SDKs share one value.
72
35
  */
73
36
  offlineNotificationDisplayDelayMs: number;
74
- /**
75
- * The `WebSocket` constructor to open the socket with. Defaults to the global one.
76
- *
77
- * For hosts that have no usable global — a Node process, or a test wanting a fake socket.
78
- */
37
+ /** The `WebSocket` constructor to open the socket with. Defaults to the global one. */
79
38
  webSocketImpl: typeof WebSocket | undefined;
80
- /**
81
- * Extra query parameters to append to the WebSocket URL.
82
- */
39
+ /** Extra query parameters appended to the WebSocket URL. */
83
40
  urlParams: URLSearchParams | undefined;
84
41
  /**
85
- * A pre-built socket to use instead of constructing one, re-parented through
86
- * {@link StableWSConnection.setWSConnection} when {@link WSConnection.connect} first runs.
87
- *
88
- * An instance is safe to hold here: `copyConfigPatch` passes class instances by reference so
89
- * identity is preserved, only package defaults are deep-frozen, and the equality check guarding a
90
- * config write short-circuits on `===`.
91
- *
92
- * `client.config.reset()` restores this to `undefined`, as it does every field, so a later
93
- * `connect()` builds a real socket and opens a live WebSocket. A socket already open is unaffected —
94
- * only the next connect. The catch is that the failure lands at that connect rather than at the
95
- * reset, so a test that injected a fake socket to stay off the network breaks somewhere other than
96
- * where it went wrong.
42
+ * A pre-built socket to use instead of constructing one (honoured only when `client.node` is true).
43
+ * `client.config.reset()` clears it, so the next `connect()` opens a live WebSocket.
97
44
  */
98
45
  connection: StableWSConnection | undefined;
99
46
  };
@@ -1,83 +1,74 @@
1
1
  import type { Unsubscribe } from '@stream-io/state-store';
2
2
  /**
3
- * A batch of entity-store changes delivered to a subscriber in a single notification.
4
- *
5
- * `changedIds` are the ids the subscriber watches whose canonical object changed reference this
6
- * flush (an upsert, or a removal — a removal makes `store.get(id)` return `undefined`).
3
+ * The IDs a subscriber watches whose canonical object changed reference in this flush (an upsert or
4
+ * a removal; after a removal `store.get(id)` returns `undefined`).
7
5
  */
8
6
  export type EntityStoreChangeBatch = {
9
7
  changedIds: ReadonlySet<string>;
10
8
  };
11
9
  /**
12
- * Anything that observes entities held in an {@link EntityStore}, linked to them by id
13
- * ({@link EntityStore.link}).
14
- *
15
- * A subscriber watches a *set* of entity ids (a paginator watches all ids in its
16
- * intervals; a thread watches its single parent id). It is notified at most once
17
- * per store transaction with the subset of its watched ids that changed. While linked, it also
18
- * holds those entities; see {@link EntityStoreClaim} for holding without being notified.
10
+ * Observes entities in an {@link EntityStore}, linked to them by ID ({@link EntityStore.link}). It
11
+ * is notified at most once per store transaction with the subset of its watched IDs that changed,
12
+ * and while linked it holds those entities (see {@link EntityStoreClaim} to hold without being
13
+ * notified).
19
14
  */
20
15
  export type EntityStoreSubscriber = {
21
16
  onEntitiesChanged: (batch: EntityStoreChangeBatch) => void;
22
17
  /**
23
- * Optional: emit any throttled/pending state notification immediately. Called by
24
- * {@link EntityStore.flushSubscribers} after an optimistic (local-user) write so the change
25
- * renders without throttle delay. A paginator implements this by flushing its throttled window
26
- * publish.
18
+ * Emits any throttled pending state immediately. Called by {@link EntityStore.flushSubscribers}
19
+ * after an optimistic (local-user) write.
27
20
  */
28
21
  flushState?: () => void;
29
22
  /**
30
- * Optional: called by {@link EntityStore.changeId} when this subscriber's link moves from `oldId`
31
- * to `newId`, before the change notification. A subscriber that keeps its own list of linked ids
32
- * implements it to rename the entry; otherwise its later `unlink(oldId)` would miss the moved link
33
- * and the entity would never be released.
23
+ * Called by {@link EntityStore.changeId} when this subscriber's link moves from `oldId` to
24
+ * `newId`, before the change notification. A subscriber keeping its own list of linked IDs renames
25
+ * the entry here, or its later `unlink(oldId)` misses the moved link.
34
26
  */
35
27
  onIdChanged?: (oldId: string, newId: string) => void;
36
28
  /**
37
- * Optional: called when the store removes an entity this subscriber holds, through
38
- * {@link EntityStore.remove} or {@link EntityStore.clear}, with the removed entity. Called after
39
- * its holders are dropped but while the entity can still be read, so a list can locate the item
40
- * and drop it on its side, and its unlink changes nothing. Not called when the last holder
41
- * unlinks: nobody holds the entity then.
29
+ * Called when the store removes an entity this subscriber holds ({@link EntityStore.remove},
30
+ * {@link EntityStore.clear}), after its holders are dropped but while the entity can still be
31
+ * read. Not called when the last holder unlinks.
42
32
  */
43
33
  onEntityRemoved?: (id: string, entity: unknown) => void;
44
- /**
45
- * Optional: what this subscriber is, for debugging tools that list who holds an entity. A
46
- * kebab-case identifier with no spaces, e.g. `channel-paginator`.
47
- */
34
+ /** What this subscriber is, for debugging tools: a kebab-case ID, e.g. `channel-paginator`. */
48
35
  name?: string;
49
36
  };
50
37
  /**
51
- * A standing claim on entities in an {@link EntityStore}, added once with
52
- * {@link EntityStore.addClaim}. Unlike a subscriber it isn't linked per id and gets no
53
- * notifications: the store asks {@link EntityStoreClaim.heldBy} whenever it needs to know what is
54
- * held, so the claim never reports a change.
38
+ * A standing claim on entities, added with {@link EntityStore.addClaim}. Unlike a subscriber it is
39
+ * not linked per ID and never notified: the store asks {@link EntityStoreClaim.heldBy} whenever it
40
+ * needs to know what is held.
55
41
  */
56
42
  export type EntityStoreClaim<T> = {
57
- /** The entities held by this claim right now. Matched by identity against the stored ones. */
43
+ /** The entities held by this claim right now, matched by identity against the stored ones. */
58
44
  heldBy: () => Iterable<T>;
59
- /**
60
- * Optional: what makes the claim, for debugging tools that list who holds an entity. A kebab-case
61
- * identifier with no spaces, e.g. `message-composer-cache`.
62
- */
45
+ /** What makes the claim, for debugging tools: a kebab-case ID, e.g. `message-composer-cache`. */
63
46
  name?: string;
64
47
  };
65
48
  export type EntityStoreOptions<T> = {
66
- /** Extracts the canonical id an entity is stored and addressed under. */
67
49
  getEntityId: (entity: T) => string;
68
50
  /**
69
- * Called with an entity after its entry is removed because its last holder unlinked, or because
70
- * {@link EntityStore.clear} ran. A store of class instances uses it to tear the instance down
71
- * (unsubscribe listeners, stop timers). Optional.
51
+ * Called with an entity removed because its last holder unlinked or {@link EntityStore.clear} ran.
52
+ * A store of class instances uses it to tear them down (listeners, timers).
72
53
  */
73
54
  onRelease?: (entity: T) => void;
74
55
  /**
75
- * Whether an entry is removed when its last holder unlinks (the default). A store that decides
76
- * on its own when to remove entries sets it to `false`; holders then only receive notifications,
77
- * and entries leave through {@link EntityStore.remove} or {@link EntityStore.clear}.
56
+ * Whether an entry is removed when its last holder unlinks (the default). Set `false` when the
57
+ * store decides itself: entries then leave through {@link EntityStore.remove} or
58
+ * {@link EntityStore.clear}, and holders only receive notifications.
78
59
  */
79
60
  releaseOnLastUnlink?: boolean;
80
61
  };
62
+ /**
63
+ * A normalized store of entities addressed by ID: one canonical `T` per ID (`upsert` replaces the
64
+ * reference; `getOrCreate` hydrates the stored one in place), shared by any number of subscribers
65
+ * linked to individual IDs.
66
+ * A write notifies exactly the subscribers holding that ID, with the changed IDs only (they pull
67
+ * content via `get`). Links are also the refcount: by default an entity is dropped when its last
68
+ * holder unlinks. {@link EntityStore.transaction} coalesces notifications into one flush.
69
+ *
70
+ * @template T The domain entity type held by the store.
71
+ */
81
72
  export declare class EntityStore<T> {
82
73
  private byId;
83
74
  private subscribers;
@@ -87,67 +78,108 @@ export declare class EntityStore<T> {
87
78
  private readonly releaseOnLastUnlink;
88
79
  private transactionDepth;
89
80
  private pendingChanged;
90
- /** Ids whose {@link EntityStore.flushSubscribers} was requested while a transaction was open. */
81
+ /** IDs whose {@link EntityStore.flushSubscribers} was requested while a transaction was open. */
91
82
  private pendingFlushIds?;
92
83
  constructor({ getEntityId, onRelease, releaseOnLastUnlink, }: EntityStoreOptions<T>);
84
+ /**
85
+ * Reads the canonical copy stored under an ID.
86
+ *
87
+ * @param id - The ID to read. `undefined` reads nothing.
88
+ * @returns The stored entity, or `undefined` when none is stored under `id`.
89
+ */
93
90
  get(id: string | undefined): T | undefined;
91
+ /**
92
+ * Checks whether an entity is stored under an ID.
93
+ *
94
+ * @param id - The ID to look up.
95
+ * @returns Whether an entity is stored under `id`.
96
+ */
94
97
  has(id: string): boolean;
95
- /** Whether `subscriber` is one of the holders of `id`. */
98
+ /**
99
+ * Checks whether a subscriber is linked to an ID.
100
+ *
101
+ * @param id - The ID to look up.
102
+ * @param subscriber - The subscriber to look for.
103
+ * @returns Whether `subscriber` is linked to `id`.
104
+ */
96
105
  isHeldBy(id: string, subscriber: EntityStoreSubscriber): boolean;
97
- /** Whether a subscriber linked to `id`, or a claim listing its entity, holds it. */
106
+ /**
107
+ * Checks whether anything holds the entity stored under an ID.
108
+ *
109
+ * @param id - The ID to look up.
110
+ * @returns Whether a subscriber linked to `id`, or a claim listing its entity, holds it.
111
+ */
98
112
  isHeld(id: string): boolean;
99
113
  /**
100
- * The names of what holds `id`: the subscribers linked to it and the claims listing its entity;
101
- * unnamed ones are left out. For debugging tools.
114
+ * Lists what holds the entity stored under an ID, for debugging.
115
+ *
116
+ * @param id - The ID to look up.
117
+ * @returns The names of the named subscribers linked to `id` and of the named claims listing its
118
+ * entity.
102
119
  */
103
120
  holderNames(id: string): string[];
104
121
  /**
105
- * Every stored entity that neither a linked subscriber nor a claim holds, with the id it is stored
106
- * under. Each claim is asked once for the whole list.
122
+ * Lists the stored entities nothing holds. Each claim is asked once for the whole list.
123
+ *
124
+ * @returns Every stored entity that neither a linked subscriber nor a claim holds, with the ID it
125
+ * is stored under.
107
126
  */
108
127
  unheldEntries(): [string, T][];
109
128
  /**
110
- * Adds `claim`, which holds the entities its {@link EntityStoreClaim.heldBy} lists, until the
111
- * returned function removes it. Entities are matched by identity, so one stored under an id other
112
- * than its own (a temporary id) is still found.
129
+ * Adds a claim. Entities are matched by identity, so one stored under an ID other than its own (a
130
+ * temporary ID) is still found.
131
+ *
132
+ * @param claim - The claim to add.
133
+ * @returns A function that removes the claim.
113
134
  */
114
135
  addClaim(claim: EntityStoreClaim<T>): () => void;
136
+ /** Maps each claimed entity to the claims listing it, each once (a claim may repeat an entity). */
137
+ private claimsByEntity;
115
138
  /**
116
- * Each entity the claims list, with the claims listing it, each once: a claim may list an entity
117
- * several times, e.g. the threads claim lists a channel once per thread.
139
+ * Lists the stored entities.
140
+ *
141
+ * @returns Every stored entity.
118
142
  */
119
- private claimsByEntity;
120
- /** Every entity currently in the store. */
121
143
  values(): T[];
122
- /** Every stored entity with the id it is stored under, which can differ from its own id. */
144
+ /**
145
+ * Lists the stored entities with their keys.
146
+ *
147
+ * @returns Every stored entity with the ID it is stored under, which can differ from its own ID.
148
+ */
123
149
  entries(): [string, T][];
124
150
  /**
125
- * Replaces the canonical copy of `entity` and notifies every subscriber watching its id —
126
- * except `subscriber`, the one that performed the write, which is expected to re-render itself
127
- * (the paginator that performed the write already emits its own window inline, so it must not be
128
- * notified a second time through the subscription).
151
+ * Replaces the canonical copy of `entity` and notifies the subscribers watching its ID.
152
+ *
153
+ * @param entity - The new canonical copy, stored under its own ID.
154
+ * @param subscriber - The writer, which updates itself and is not notified.
129
155
  */
130
156
  upsert(entity: T, subscriber?: EntityStoreSubscriber): void;
131
157
  /**
132
- * Returns the entity stored under `id`, passing it to `hydrate` first, or stores and returns the
133
- * result of `create` when `id` is not stored. A stored entity is never replaced, which is what a
134
- * store of class instances needs: every caller asking for `id` gets the same instance, and fresh
135
- * data is applied to it through `hydrate`.
158
+ * Returns the entity stored under `id`, or stores a new one. A stored entity is never replaced, so
159
+ * every caller gets the same instance and fresh data goes in through `hydrate`. Storing a new
160
+ * entity notifies the subscribers already linked to `id`; hydrating does not, since the reference
161
+ * is unchanged.
136
162
  *
137
- * Storing a new entity notifies the subscribers already linked to `id`. Hydrating does not — the
138
- * stored reference is unchanged, and the entity publishes its own state changes.
163
+ * @param id - The ID to read or store under.
164
+ * @param create - Builds the entity when none is stored under `id`.
165
+ * @param hydrate - Receives an already stored entity, to update it in place.
166
+ * @returns The stored entity, or the new one from `create()`.
139
167
  */
140
168
  getOrCreate(id: string, create: () => T, hydrate?: (stored: T) => void): T;
141
169
  /**
142
- * Moves an entity and its holders from `oldId` to `newId`, for ids assigned after storing. Moved
143
- * holders get {@link EntityStoreSubscriber.onIdChanged}, then holders of both ids are notified.
144
- * Returns `false` without changes when `oldId` is not stored or the ids are equal.
170
+ * Moves an entity and its holders from `oldId` to `newId`, for IDs assigned after storing. Moved
171
+ * holders get {@link EntityStoreSubscriber.onIdChanged}, then holders of both IDs are notified.
145
172
  *
146
- * When `newId` holds another entity, nothing changes unless `replace` is set (merging is the
147
- * caller's decision). With `replace`, the moved entity takes that entity's place: the holders of
148
- * `newId` stay linked and now hold the moved one, and the replaced entity is passed to
149
- * `onRelease`. Its holders are not told it was removed, so a list can swap the item in place.
173
+ * When `newId` holds another entity, nothing changes unless `replace` is set. With `replace`, the
174
+ * moved entity takes its place: the holders of `newId` stay linked and hold the moved one, and
175
+ * the replaced entity goes to `onRelease`. Its holders are not told it was removed, so a list can
176
+ * swap the item in place.
150
177
  *
178
+ * @param oldId - The ID the entity is stored under.
179
+ * @param newId - The ID to move it to.
180
+ * @param options.replace - Take the place of an entity already stored under `newId`.
181
+ * @returns Whether the entry moved: `false`, with nothing changed, when `oldId` is not stored, the
182
+ * IDs are equal, or `newId` is taken and `replace` is not set.
151
183
  * @example
152
184
  * // A channel created from members has no id until the server creates it, so it is stored under a
153
185
  * // temporary cid built from its member ids.
@@ -159,72 +191,80 @@ export declare class EntityStore<T> {
159
191
  replace?: boolean;
160
192
  }): boolean;
161
193
  /**
162
- * Stores `entity` in place of another entity stored under the same id. The holders of that id stay
163
- * linked and now hold `entity`; they are notified of a change, not told of a removal, so a list
164
- * can swap the item in place. The replaced entity is passed to `onRelease`. Storing an entity
165
- * under an id nothing holds yet stores it, as {@link EntityStore.upsert} does.
194
+ * Stores `entity` in place of another stored under the same ID. The holders of that ID stay linked
195
+ * and hold `entity`; they are notified of a change, not a removal, so a list can swap the item
196
+ * in place. The replaced entity goes to `onRelease`. With nothing under the ID it stores like
197
+ * {@link EntityStore.upsert}.
198
+ *
199
+ * @param entity - The entity to store under its own ID.
166
200
  */
167
201
  replace(entity: T): void;
168
202
  /**
169
- * Removes the entry stored under `id` whatever holds it, drops its holders and calls `onRelease`
170
- * with the entity. Each holder gets {@link EntityStoreSubscriber.onEntityRemoved}, and is notified
171
- * that `id` changed (it now resolves to `undefined`). Removing an ID that isn't stored does nothing.
203
+ * Removes the entry stored under `id` whatever holds it, drops its holders and calls `onRelease`.
204
+ * Each holder gets {@link EntityStoreSubscriber.onEntityRemoved} and a change notification for
205
+ * `id`. Does nothing when `id` is not stored. A throwing holder or `onRelease` does not stop the
206
+ * removal: the first error is rethrown at the end.
172
207
  *
173
- * A holder or `onRelease` that throws doesn't stop the removal: every holder is told, the entry is
174
- * deleted and released, and then the first error is rethrown.
208
+ * @param id - The ID to remove.
175
209
  */
176
210
  remove(id: string): void;
177
211
  /**
178
- * Like {@link EntityStore.remove}, except the entity is not passed to `onRelease`: it left this
179
- * entry but is still in use elsewhere, so whoever detaches it decides when it is released.
180
- * Detaching an ID that isn't stored does nothing.
212
+ * Like {@link EntityStore.remove}, but the entity is not passed to `onRelease`: it is still in use
213
+ * elsewhere, so whoever detaches it decides when it is released.
214
+ *
215
+ * @param id - The ID to remove.
181
216
  */
182
217
  detach(id: string): void;
183
218
  private dropEntry;
184
219
  /**
185
220
  * Removes every entry and holder. Each holder gets {@link EntityStoreSubscriber.onEntityRemoved}
186
- * for every entity it held, then `onRelease` is called for each removed entity. Calling it on an
187
- * empty store does nothing.
188
- *
189
- * A holder or `onRelease` that throws doesn't stop the clear: every holder is told, the store is
190
- * emptied and every entity released, and then the first error is rethrown.
221
+ * for every entity it held, then `onRelease` is called for each removed entity. A throwing holder
222
+ * or `onRelease` does not stop the clear: the first error is rethrown at the end.
191
223
  */
192
224
  clear(): void;
193
- /** Registers `subscriber` for `id` (notification target + refcount). */
225
+ /**
226
+ * Registers a subscriber as a holder of an ID (notification target and refcount).
227
+ *
228
+ * @param id - The ID to hold.
229
+ * @param subscriber - The holder.
230
+ */
194
231
  link(id: string, subscriber: EntityStoreSubscriber): void;
195
232
  /**
196
- * Drops `subscriber` from `id`; GCs the canonical copy when none remain and passes it to
197
- * `onRelease`, unless the store keeps unheld entries (`releaseOnLastUnlink: false`). Unlinking a
198
- * subscriber that is not linked does nothing.
233
+ * Drops `subscriber` from `id`. When none remain, the canonical copy is dropped and passed to
234
+ * `onRelease`, unless `releaseOnLastUnlink` is `false`. Does nothing if it is not linked.
235
+ *
236
+ * @param id - The ID to release.
237
+ * @param subscriber - The holder to drop.
199
238
  */
200
239
  unlink(id: string, subscriber: EntityStoreSubscriber): void;
201
240
  /**
202
- * Sugar for atomic / ad-hoc consumers that watch a single id (e.g. a thread watching its parent
203
- * message). Fires `handler` immediately with the current value (mirroring
204
- * {@link StateStore.subscribe}) and on every subsequent change.
241
+ * Watches a single ID. Fires `handler` immediately with the current value (like
242
+ * {@link StateStore.subscribe}) and on every change.
243
+ *
244
+ * @param id - The ID to watch.
245
+ * @param handler - Called with the entity stored under `id`, or `undefined`.
246
+ * @returns A function that stops watching.
205
247
  */
206
248
  subscribe(id: string, handler: (entity: T | undefined) => void): Unsubscribe;
207
249
  /**
208
- * Runs `fn`, coalescing all notifications produced by writes inside it into a single flush on
209
- * exit. Re-entrant: nested transactions flush only when the outermost exits.
250
+ * Runs `fn`, coalescing the notifications of writes inside it into a single flush on exit. Nested
251
+ * transactions flush only when the outermost exits.
252
+ *
253
+ * @param fn - The writes to batch.
254
+ * @returns What `fn` returns.
210
255
  */
211
256
  transaction<R>(fn: () => R): R;
212
257
  /**
213
- * Immediately flushes any throttled/pending state publish on the subscribers of `id` (via
214
- * {@link EntityStoreSubscriber.flushState}). Called after an optimistic (local-user) write to
215
- * `id` so it renders without the throttle delay. Only that id's own subscribers are flushed — the
216
- * write touched no other id — and flushing a subscriber with nothing pending is a no-op.
258
+ * Immediately flushes any throttled state publish ({@link EntityStoreSubscriber.flushState}) on
259
+ * the subscribers of `id`, so an optimistic (local-user) write renders without the throttle delay.
260
+ * Inside a transaction it is deferred to the outermost exit, since inline it would be a no-op
261
+ * (nobody has been notified yet).
217
262
  *
218
- * Inside a transaction it is deferred to the outermost exit — inline there it would be a no-op,
219
- * since `markDirty` has not notified anyone yet. Getting this wrong costs the siblings (pinned
220
- * list, open thread) up to 500ms on an optimistic write, while the writer updates inline.
263
+ * @param id - The ID whose subscribers flush.
221
264
  */
222
265
  flushSubscribers(id: string): void;
223
266
  private flushSubscribersNow;
224
- /**
225
- * Records `id` as changed for every subscriber watching it, except `subscriber` — the one that
226
- * wrote it and is responsible for updating itself (see {@link EntityStore.upsert}).
227
- */
267
+ /** Records `id` as changed for every subscriber watching it, except the writer `subscriber`. */
228
268
  private markDirty;
229
269
  private autoFlush;
230
270
  private flush;
@@ -2,52 +2,24 @@ import type { ItemIndexApi } from '../pagination/ItemIndex';
2
2
  import { EntityStore, type EntityStoreSubscriber } from './EntityStore';
3
3
  export type StoreBackedItemIndexOptions<T> = {
4
4
  getEntityId: (item: T) => string;
5
- /**
6
- * The list that owns this index; the index's holder passes the store's notifications, id renames
7
- * and removals on to it. Paginators pass themselves, so updates from other lists and removals from
8
- * the store reach them.
9
- */
5
+ /** The list that owns this index; the store's notifications, ID renames and removals reach it. */
10
6
  owner?: EntityStoreSubscriber;
11
- /**
12
- * The name the index's holder goes by in the store, for debugging tools; no spaces, e.g.
13
- * `channel-paginator`.
14
- */
7
+ /** The holder's name in the store, for debugging tools: no spaces, e.g. `channel-paginator`. */
15
8
  holderName?: string;
16
9
  /**
17
- * The store the items live in, shared with other lists (the message store, the channel store).
18
- * Optional: without it the index makes a private store and behaves like a plain per-list map, as
19
- * single-home collections and paginators built without a client (in tests) do.
10
+ * The store the items live in, shared with other lists. Without it the index makes a private
11
+ * store and behaves like a plain per-list map (e.g. paginators built without a client).
20
12
  */
21
13
  store?: EntityStore<T>;
22
14
  };
23
15
  /**
24
- * The item index of one list (a paginator). The list's items live in an {@link EntityStore}, which
25
- * can be shared with other lists; the index itself only records which ids belong to this list
26
- * (`memberIds`) and stands for the list in the store with one `holder` object.
27
- *
28
- * Example: the "Inbox" and "Work" channel lists both show channel C.
29
- *
30
- * 1. Inbox adds C (`setOne`): its index adds C's id to `memberIds`, links Inbox's holder for C in
31
- * the store, and saves C there. Work does the same with its own holder, so the store keeps one C
32
- * with the holders {Inbox, Work}.
33
- * 2. Inbox reads (`get`, `has`, `values`, `entries`): the index checks its own `memberIds` first,
34
- * then takes the item from the store. A list only ever sees its own items, which is what lets
35
- * `threadPaginator.getItem(id)` tell a thread's reply from a channel message.
36
- * 3. Inbox drops C (`remove`, `clear`): its index forgets the id and unlinks Inbox's holder. C stays
37
- * while Work holds it; once the last holder unlinks, the store drops C (and calls its
38
- * `onRelease`). The store tells holders apart by object, so every index has its own.
39
- *
40
- * The store also talks back through the holder:
41
- *
42
- * - "an item you hold changed": passed on to the owner, so a list re-renders when another list
43
- * updates a shared item (a reaction written by the channel list reaches the open thread). The list
44
- * that made the change is skipped; it updates itself.
45
- * - "an id you hold was renamed" ({@link EntityStore.changeId}): applied to `memberIds`, so a later
46
- * remove unlinks the renamed entry rather than missing it.
47
- * - "an item you hold was removed" ({@link EntityStore.remove}, {@link EntityStore.clear}): the id
48
- * leaves `memberIds`, and the owner gets the removed item so it can drop it from its windows.
16
+ * The item index of one list (a paginator). Items live in an {@link EntityStore}, which can be
17
+ * shared with other lists; the index only records which IDs belong to this list (`memberIds`) and
18
+ * stands for the list in the store with one `holder`. Reads see only this list's items, even when a
19
+ * shared store holds other lists' items.
49
20
  *
50
- * Without a shared store, the index makes a private one and behaves like a plain per-list map.
21
+ * Store callbacks reach the owner through the holder: changes to held items (except the owner's own
22
+ * writes), removals (with the removed item), and ID renames, which are also applied to `memberIds`.
51
23
  *
52
24
  * @template T The item type held by the index and its store.
53
25
  */
@@ -55,14 +27,9 @@ export declare class StoreBackedItemIndex<T> implements ItemIndexApi<T> {
55
27
  private memberIds;
56
28
  private readonly store;
57
29
  /**
58
- * This index's identity in the store. Linking it for an id keeps that entity stored while the
59
- * index lists it; unlinking it on remove or clear lets the store drop the entity once no other
60
- * holder remains. The store tells holders apart by object reference, so every index gets its own,
61
- * even two indexes with the same owner or with none.
62
- *
63
- * It also receives what the store sends this index: change notifications and removals, passed on
64
- * to the owner, and id renames ({@link EntityStore.changeId}), applied to `memberIds` so a later
65
- * remove unlinks the renamed entry.
30
+ * This index's identity in the store: linked per ID while the index lists it, and unlinked on
31
+ * remove or clear. The store tells holders apart by object, so every index has its own, even with
32
+ * the same owner or none.
66
33
  */
67
34
  private readonly holder;
68
35
  private readonly getEntityId;
@@ -11,34 +11,22 @@ export type APIError = Error & {
11
11
  };
12
12
  export declare function isAPIError(error: Error): error is APIError;
13
13
  /**
14
- * Whether the server answered "this does not exist" — a definitive, expected answer rather than a
15
- * failure. Distinct from a network error: the request succeeded, the resource simply is not there.
16
- * Use it to avoid surfacing an error state for something a caller can legitimately ask about before
17
- * it exists (a thread on a parent that has no replies yet, say).
18
- *
19
- * Resolved through {@link APIErrorCodes} rather than comparing the numeric code, so the table stays
20
- * the single place the mapping lives.
14
+ * Whether the server answered "does not exist": an expected answer for a resource a caller may ask
15
+ * about before it exists, not a failure.
21
16
  */
22
17
  export declare function isDoesNotExistError(error: Error): boolean;
23
18
  export declare function isErrorRetryable(error: APIError): boolean;
24
19
  export declare function isConnectionIDError(error: APIError): boolean;
25
20
  /**
26
- * Whether an error is EPHEMERAL — a transient failure worth queueing/retrying rather than a
27
- * definitive rejection. True when the server never responded (connection/network/offline error - no
28
- * `response`, i.e an axios network error or an `OfflineError`) and when the server responded with a
29
- * retryable code (see {@link APIErrorCodes}); false when the server responded with a
30
- * non-retryable code (InputError 4, DoesNotExist 16, NotAllowed 17, …) and when the caller
31
- * cancelled the request.
32
- *
33
- * Cancellation is deliberately NOT ephemeral even though an aborted request carries no `response`.
34
- * A caller who aborts via `StreamRequestOptions.signal` wants the operation dropped, so treating it
35
- * as transient would do the opposite of what was asked: the task would be queued and replayed on
36
- * reconnect, and any optimistic local update would be kept rather than rolled back.
21
+ * Whether an error is transient and worth queueing or retrying: the server never responded (no
22
+ * `response`, e.g. an axios network error or an `OfflineError`) or responded with a retryable code
23
+ * (see {@link APIErrorCodes}). A request cancelled by the caller is not ephemeral: it is dropped,
24
+ * not queued for replay.
37
25
  */
38
26
  export declare function isEphemeral(error: Error): boolean;
39
27
  export declare function isWSFailure(err: APIError): boolean;
40
28
  export declare function isErrorResponse(res: AxiosResponse<unknown>): res is AxiosResponse<Gen_APIError>;
41
29
  /** Turns whatever a request threw into a plain error object, so it can be stored on a message. */
42
30
  export declare const parseError: (error: unknown) => StreamAPIError;
43
- /** Whether the server rejected a send because a message with that id already exists. */
31
+ /** Whether the server rejected a send because a message with that ID already exists. */
44
32
  export declare const isAlreadyExistsError: (error: unknown, parsed: StreamAPIError) => boolean;