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.
- package/dist/cjs/index.browser.js +2196 -3902
- package/dist/cjs/index.browser.js.map +3 -3
- package/dist/cjs/index.node.js +2197 -3902
- package/dist/cjs/index.node.js.map +3 -3
- package/dist/esm/index.mjs +2199 -3905
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelManager.d.ts +120 -233
- package/dist/types/CooldownTimer.d.ts +8 -23
- package/dist/types/EventHandlerPipeline.d.ts +17 -37
- package/dist/types/LiveLocationManager.d.ts +22 -50
- package/dist/types/api-client.d.ts +9 -14
- package/dist/types/channel.d.ts +253 -448
- package/dist/types/channel_state.d.ts +48 -95
- package/dist/types/client.d.ts +245 -370
- package/dist/types/client_state.d.ts +1 -3
- package/dist/types/configuration/ConfigController.d.ts +30 -124
- package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +31 -123
- package/dist/types/configuration/keys.d.ts +5 -19
- package/dist/types/configuration/shape.d.ts +12 -29
- package/dist/types/configuration/types.d.ts +59 -87
- package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +13 -35
- package/dist/types/configuration/utils/copyConfigPatch.d.ts +8 -0
- package/dist/types/configuration/utils/declarativeSlices.d.ts +5 -16
- package/dist/types/configuration/utils/deepFreezeConfig.d.ts +3 -17
- package/dist/types/configuration/utils/serverAuthority.d.ts +9 -29
- package/dist/types/connection/ConnectionIdManager.d.ts +18 -40
- package/dist/types/connection/ConnectionRecoveryManager.d.ts +29 -120
- package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +32 -103
- package/dist/types/connection/networkConnection/reporters.d.ts +9 -32
- package/dist/types/connection/networkConnection/types.d.ts +12 -27
- package/dist/types/connection/wsConnection/StableWSConnection.d.ts +37 -116
- package/dist/types/connection/wsConnection/WSConnection.d.ts +41 -104
- package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +8 -16
- package/dist/types/connection/wsConnection/config.d.ts +8 -28
- package/dist/types/connection/wsConnection/types.d.ts +17 -70
- package/dist/types/entityStore/EntityStore.d.ts +153 -113
- package/dist/types/entityStore/StoreBackedItemIndex.d.ts +13 -46
- package/dist/types/errors.d.ts +7 -19
- package/dist/types/gen/chat/ChannelApi.d.ts +2 -1
- package/dist/types/gen/chat/ChatApi.d.ts +28 -14
- package/dist/types/gen/models/index.d.ts +769 -86
- package/dist/types/gen/moderation/ModerationApi.d.ts +4 -4
- package/dist/types/index.d.ts +2 -4
- package/dist/types/languageNames.d.ts +9 -24
- package/dist/types/logger.d.ts +1 -3
- package/dist/types/messageComposer/LocationComposer.d.ts +1 -1
- package/dist/types/messageComposer/attachmentIdentity.d.ts +1 -6
- package/dist/types/messageComposer/attachmentManager.d.ts +10 -32
- package/dist/types/messageComposer/attachmentUtils.d.ts +3 -14
- package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
- package/dist/types/messageComposer/configuration/types.d.ts +29 -56
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +6 -9
- package/dist/types/messageComposer/messageComposer.d.ts +30 -164
- package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +4 -14
- package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +2 -9
- package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +2 -4
- package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +7 -19
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +9 -0
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +11 -18
- package/dist/types/messageComposer/middleware/textComposer/textMiddlewareUtils.d.ts +9 -3
- package/dist/types/messageComposer/middleware/textComposer/types.d.ts +1 -6
- package/dist/types/messageComposer/pollComposer.d.ts +8 -4
- package/dist/types/messageComposer/textComposer.d.ts +3 -9
- package/dist/types/messageComposer/types.d.ts +5 -8
- package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +25 -79
- package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +15 -82
- package/dist/types/messageOperations/FailedSendCache.d.ts +4 -9
- package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +10 -20
- package/dist/types/messageOperations/MessageOperations.d.ts +20 -40
- package/dist/types/messageOperations/applyReactionLocally.d.ts +5 -22
- package/dist/types/messageOperations/createMessageOperations.d.ts +3 -5
- package/dist/types/messageOperations/reflectReactionEvent.d.ts +5 -13
- package/dist/types/messageOperations/sendOrdering.d.ts +4 -7
- package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +7 -15
- package/dist/types/messageOperations/types.d.ts +15 -30
- package/dist/types/middleware.d.ts +7 -5
- package/dist/types/moderation.d.ts +21 -14
- package/dist/types/notifications/NotificationManager.d.ts +8 -31
- package/dist/types/notifications/types.d.ts +19 -59
- package/dist/types/offline-support/offline_support_api.d.ts +145 -539
- package/dist/types/offline-support/offline_sync_manager.d.ts +18 -42
- package/dist/types/offline-support/queueableOperations.d.ts +24 -52
- package/dist/types/offline-support/types.d.ts +24 -187
- package/dist/types/pagination/ItemIndex.d.ts +4 -12
- package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +13 -0
- package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -4
- package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +2 -3
- package/dist/types/pagination/paginators/BasePaginator.d.ts +235 -622
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +67 -125
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +133 -292
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +69 -118
- package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +7 -26
- package/dist/types/pagination/paginators/ReminderPaginator.d.ts +2 -2
- package/dist/types/pagination/paginators/ThreadPaginator.d.ts +15 -23
- package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +2 -6
- package/dist/types/pagination/sortCompiler.d.ts +11 -22
- package/dist/types/pagination/utility.normalization.d.ts +5 -23
- package/dist/types/pagination/utility.search.d.ts +3 -8
- package/dist/types/poll.d.ts +14 -14
- package/dist/types/poll_manager.d.ts +11 -2
- package/dist/types/poll_optimistic_votes.d.ts +10 -14
- package/dist/types/reminders/Reminder.d.ts +4 -4
- package/dist/types/reminders/ReminderManager.d.ts +7 -20
- package/dist/types/search/BaseSearchSource.d.ts +7 -12
- package/dist/types/search/ChannelSearchSource.d.ts +7 -7
- package/dist/types/search/MessageSearchSource.d.ts +7 -9
- package/dist/types/search/SearchController.d.ts +17 -22
- package/dist/types/search/types.d.ts +6 -10
- package/dist/types/signing.d.ts +12 -3
- package/dist/types/thread.d.ts +23 -71
- package/dist/types/thread_manager.d.ts +45 -70
- package/dist/types/token_manager.d.ts +8 -13
- package/dist/types/types.d.ts +64 -125
- package/dist/types/types.utility.d.ts +3 -3
- package/dist/types/upload-utils.d.ts +5 -10
- package/dist/types/uploadManager.d.ts +17 -45
- package/dist/types/utils/FixedSizeQueueCache.d.ts +6 -11
- package/dist/types/utils/WithSubscriptions.d.ts +5 -15
- package/dist/types/utils/concurrency.d.ts +11 -19
- package/dist/types/utils/mergeWith/mergeWith.d.ts +8 -11
- package/dist/types/utils/mergeWith/mergeWithCore.d.ts +5 -13
- package/dist/types/utils/mergeWith/mergeWithDiff.d.ts +22 -0
- package/dist/types/utils/objectPath.d.ts +6 -41
- package/dist/types/utils/retryable.d.ts +8 -12
- package/dist/types/utils/throttling/throttle.d.ts +8 -23
- package/dist/types/utils/time.d.ts +24 -64
- package/dist/types/utils.d.ts +40 -86
- package/package.json +7 -2
- package/src/ChannelManager.ts +159 -300
- package/src/CooldownTimer.ts +11 -29
- package/src/EventHandlerPipeline.ts +21 -44
- package/src/LiveLocationManager.ts +35 -74
- package/src/api-client.ts +43 -61
- package/src/campaign.ts +1 -1
- package/src/channel.ts +396 -749
- package/src/channel_batch_updater.ts +1 -1
- package/src/channel_state.ts +50 -105
- package/src/client.ts +360 -588
- package/src/client_state.ts +1 -6
- package/src/configuration/ConfigController.ts +41 -157
- package/src/configuration/InstanceConfigurationRegistry.ts +42 -171
- package/src/configuration/index.ts +1 -1
- package/src/configuration/keys.ts +13 -32
- package/src/configuration/shape.ts +67 -70
- package/src/configuration/types.ts +60 -100
- package/src/configuration/utils/applyInstanceConfiguration.ts +21 -53
- package/src/configuration/utils/copyConfigPatch.ts +11 -32
- package/src/configuration/utils/declarativeSlices.ts +9 -39
- package/src/configuration/utils/deepFreezeConfig.ts +3 -17
- package/src/configuration/utils/index.ts +2 -4
- package/src/configuration/utils/serverAuthority.ts +20 -68
- package/src/connection/ConnectionIdManager.ts +20 -49
- package/src/connection/ConnectionRecoveryManager.ts +51 -178
- package/src/connection/networkConnection/NetworkConnectionObserver.ts +37 -114
- package/src/connection/networkConnection/reporters.ts +9 -36
- package/src/connection/networkConnection/types.ts +12 -27
- package/src/connection/wsConnection/StableWSConnection.ts +73 -193
- package/src/connection/wsConnection/WSConnection.ts +56 -131
- package/src/connection/wsConnection/WSConnectionFallback.ts +22 -31
- package/src/connection/wsConnection/config.ts +13 -48
- package/src/connection/wsConnection/types.ts +17 -70
- package/src/constants.ts +4 -4
- package/src/entityStore/EntityStore.ts +162 -167
- package/src/entityStore/StoreBackedItemIndex.ts +14 -47
- package/src/errors.ts +7 -19
- package/src/formatMessageMemo.ts +3 -9
- package/src/gen/chat/ChannelApi.ts +19 -0
- package/src/gen/chat/ChatApi.ts +87 -13
- package/src/gen/models/index.ts +793 -71
- package/src/gen/moderation/ModerationApi.ts +0 -4
- package/src/index.ts +10 -14
- package/src/languageNames.ts +9 -24
- package/src/logger.ts +1 -3
- package/src/messageComposer/LocationComposer.ts +7 -23
- package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
- package/src/messageComposer/attachmentIdentity.ts +2 -13
- package/src/messageComposer/attachmentManager.ts +17 -63
- package/src/messageComposer/attachmentUtils.ts +3 -17
- package/src/messageComposer/configuration/configuration.ts +5 -8
- package/src/messageComposer/configuration/types.ts +29 -56
- package/src/messageComposer/fileUtils.ts +1 -1
- package/src/messageComposer/linkPreviewsManager.ts +8 -20
- package/src/messageComposer/messageComposer.ts +54 -222
- package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +4 -16
- package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +1 -2
- package/src/messageComposer/middleware/messageComposer/attachments.ts +14 -40
- package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +3 -4
- package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +4 -11
- package/src/messageComposer/middleware/pollComposer/state.ts +2 -2
- package/src/messageComposer/middleware/pollComposer/types.ts +2 -4
- package/src/messageComposer/middleware/pollComposer/validation.ts +8 -26
- package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +1 -6
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +1 -2
- package/src/messageComposer/middleware/textComposer/commands.ts +11 -16
- package/src/messageComposer/middleware/textComposer/mentions.ts +32 -70
- package/src/messageComposer/middleware/textComposer/textMiddlewareUtils.ts +10 -4
- package/src/messageComposer/middleware/textComposer/types.ts +1 -6
- package/src/messageComposer/pollComposer.ts +11 -8
- package/src/messageComposer/textComposer.ts +9 -59
- package/src/messageComposer/types.ts +9 -12
- package/src/messageDelivery/MessageDeliveryReporter.ts +60 -113
- package/src/messageDelivery/MessageReceiptsTracker.ts +21 -105
- package/src/messageOperations/FailedSendCache.ts +4 -9
- package/src/messageOperations/MessageOperationStatePolicy.ts +40 -67
- package/src/messageOperations/MessageOperations.ts +33 -62
- package/src/messageOperations/applyReactionLocally.ts +9 -28
- package/src/messageOperations/createMessageOperations.ts +17 -33
- package/src/messageOperations/reflectReactionEvent.ts +5 -13
- package/src/messageOperations/sendOrdering.ts +4 -7
- package/src/messageOperations/settlePendingAttachmentUploads.ts +10 -21
- package/src/messageOperations/types.ts +15 -30
- package/src/middleware.ts +7 -10
- package/src/moderation.ts +25 -21
- package/src/notifications/NotificationManager.ts +11 -35
- package/src/notifications/types.ts +19 -59
- package/src/offline-support/offline_support_api.ts +178 -608
- package/src/offline-support/offline_sync_manager.ts +25 -69
- package/src/offline-support/queueableOperations.ts +31 -84
- package/src/offline-support/types.ts +25 -188
- package/src/pagination/ItemIndex.ts +4 -12
- package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +13 -62
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
- package/src/pagination/cursorDerivation/linearPaginationFlags.ts +4 -6
- package/src/pagination/filterCompiler.ts +11 -25
- package/src/pagination/paginators/BasePaginator.ts +422 -976
- package/src/pagination/paginators/ChannelPaginator.ts +130 -190
- package/src/pagination/paginators/MessageIntervalPaginator.ts +226 -457
- package/src/pagination/paginators/MessagePaginator.ts +135 -175
- package/src/pagination/paginators/PinnedMessagePaginator.ts +13 -38
- package/src/pagination/paginators/ReminderPaginator.ts +12 -15
- package/src/pagination/paginators/ThreadPaginator.ts +16 -26
- package/src/pagination/paginators/UserGroupPaginator.ts +6 -17
- package/src/pagination/paginators/stateThrottling.ts +5 -10
- package/src/pagination/sortCompiler.ts +23 -50
- package/src/pagination/utility.normalization.ts +8 -30
- package/src/pagination/utility.search.ts +4 -11
- package/src/poll.ts +19 -19
- package/src/poll_manager.ts +16 -20
- package/src/poll_optimistic_votes.ts +17 -22
- package/src/reminders/Reminder.ts +5 -6
- package/src/reminders/ReminderManager.ts +9 -34
- package/src/reminders/ReminderTimer.ts +1 -2
- package/src/search/BaseSearchSource.ts +14 -29
- package/src/search/ChannelSearchSource.ts +8 -8
- package/src/search/MessageSearchSource.ts +19 -25
- package/src/search/SearchController.ts +18 -24
- package/src/search/types.ts +6 -10
- package/src/segment.ts +1 -1
- package/src/signing.ts +23 -3
- package/src/thread.ts +72 -173
- package/src/thread_manager.ts +59 -76
- package/src/token_manager.ts +11 -21
- package/src/types.ts +78 -126
- package/src/types.utility.ts +3 -3
- package/src/upload-utils.ts +5 -10
- package/src/uploadManager.ts +22 -54
- package/src/utils/FixedSizeQueueCache.ts +13 -21
- package/src/utils/WithSubscriptions.ts +5 -15
- package/src/utils/concurrency.ts +16 -55
- package/src/utils/mergeWith/mergeWith.ts +10 -13
- package/src/utils/mergeWith/mergeWithCore.ts +24 -81
- package/src/utils/mergeWith/mergeWithDiff.ts +15 -33
- package/src/utils/objectPath.ts +6 -41
- package/src/utils/retryable.ts +10 -14
- package/src/utils/throttling/throttle.ts +9 -25
- package/src/utils/time.ts +26 -66
- 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`
|
|
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
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
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
|
|
57
|
-
*
|
|
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.
|
|
67
|
-
*
|
|
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
|
|
86
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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
|
-
*
|
|
24
|
-
*
|
|
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
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
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
|
-
*
|
|
38
|
-
* {@link EntityStore.
|
|
39
|
-
*
|
|
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
|
|
52
|
-
*
|
|
53
|
-
*
|
|
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
|
|
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
|
|
70
|
-
*
|
|
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).
|
|
76
|
-
*
|
|
77
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
101
|
-
*
|
|
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
|
-
*
|
|
106
|
-
*
|
|
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
|
|
111
|
-
*
|
|
112
|
-
*
|
|
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
|
-
*
|
|
117
|
-
*
|
|
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
|
-
/**
|
|
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
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
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`,
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
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
|
-
*
|
|
138
|
-
*
|
|
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
|
|
143
|
-
* holders get {@link EntityStoreSubscriber.onIdChanged}, then holders of both
|
|
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
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
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
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
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
|
-
*
|
|
171
|
-
*
|
|
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
|
-
*
|
|
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},
|
|
179
|
-
*
|
|
180
|
-
*
|
|
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.
|
|
187
|
-
*
|
|
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
|
-
/**
|
|
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
|
|
197
|
-
* `onRelease`, unless
|
|
198
|
-
*
|
|
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
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
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
|
|
209
|
-
*
|
|
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
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
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
|
-
*
|
|
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
|
|
18
|
-
*
|
|
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).
|
|
25
|
-
*
|
|
26
|
-
*
|
|
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
|
-
*
|
|
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
|
|
59
|
-
*
|
|
60
|
-
*
|
|
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;
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -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 "
|
|
15
|
-
*
|
|
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
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
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
|
|
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;
|