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,25 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Holds the configuration an integrator registers for classes the SDK constructs
|
|
3
|
-
* `
|
|
2
|
+
* Holds the configuration an integrator registers for classes the SDK constructs (`Channel`, `Thread`,
|
|
3
|
+
* `MessageComposer`, the client's managers). Reached as `client.config`, one per client. Not to be
|
|
4
|
+
* confused with `client.channelServerConfigs` (server-provided channel configs).
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
+
* Two ways in: `set(tree)` / `setConfig(key, subtree)` register values, and `setSetupFunction(key, fn)`
|
|
7
|
+
* is the escape hatch for behaviour a value cannot express. Declarative configuration applies first, so
|
|
8
|
+
* a setup function wins for the same field.
|
|
6
9
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* - `set(tree)` / `setConfig(key, subtree)` — declarative values (page sizes, throttles, feature
|
|
10
|
-
* flags). The primary surface.
|
|
11
|
-
* - `setSetupFunction(key, fn)` — an imperative escape hatch for behaviour that cannot be expressed as
|
|
12
|
-
* a value (middleware, comparators, custom request logic).
|
|
13
|
-
*
|
|
14
|
-
* Declarative configuration is applied before the setup function, so a setup function always wins for
|
|
15
|
-
* the same field.
|
|
16
|
-
*
|
|
17
|
-
* The key space is **fixed** by this package: `InstanceConfigTree` and `InstanceSetupFunctionArgs` are type
|
|
18
|
-
* aliases, so a key can be neither misspelled into existence nor added by module augmentation. Stores are
|
|
19
|
-
* still created lazily, because for any key the setter and the subscriber can arrive in either order.
|
|
20
|
-
*
|
|
21
|
-
* One service per client, not a singleton: a process-global registry would leak configuration between
|
|
22
|
-
* clients, which breaks tests and apps that connect as more than one user.
|
|
10
|
+
* The key space is closed by the types. Stores are created lazily, since a setter and a subscriber for
|
|
11
|
+
* a key can arrive in either order.
|
|
23
12
|
*/
|
|
24
13
|
|
|
25
14
|
import { StateStore } from '@stream-io/state-store';
|
|
@@ -43,92 +32,41 @@ import type { DeepPartial } from '../types.utility';
|
|
|
43
32
|
const logger = chatLoggerSystem.getLogger('instance-configuration');
|
|
44
33
|
|
|
45
34
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* live instance at all.
|
|
35
|
+
* A live instance registered by `applyInstanceConfiguration`, so `reset` can reach it and the registry
|
|
36
|
+
* can tell whether a key has any live instance.
|
|
49
37
|
*
|
|
50
38
|
* @internal
|
|
51
39
|
*/
|
|
52
|
-
/**
|
|
53
|
-
* A handle to one live instance that derives configuration from a key.
|
|
54
|
-
*
|
|
55
|
-
* Deliberately just the re-derivation hook rather than the instance itself: the registry never reads an
|
|
56
|
-
* instance's configuration, it only needs a way to tell the instance to rebuild.
|
|
57
|
-
*/
|
|
58
40
|
export type ConfiguredInstance = {
|
|
59
|
-
/** The instance's
|
|
41
|
+
/** The instance's `initializeConfig`, bound. Invoked by `reset` after both slots are cleared. */
|
|
60
42
|
reinitializeConfig?: () => void;
|
|
61
43
|
};
|
|
62
44
|
|
|
63
|
-
//
|
|
64
|
-
//
|
|
45
|
+
// Keyed by plain string, so value types cannot be tied to the key here. Callers narrow through
|
|
46
|
+
// `getSetupState` / `getConfigState`.
|
|
65
47
|
type AnySetupStore = StateStore<InstanceSetupState<InstanceSetupKey>>;
|
|
66
48
|
type AnyConfigStore = StateStore<InstanceConfigState<InstanceConfigKey>>;
|
|
67
49
|
|
|
68
50
|
export class InstanceConfigurationRegistry {
|
|
69
51
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* registered for `'channel'`, `'messageComposer'` and so on, each wrapped in a store so that registering
|
|
73
|
-
* a setup function is observable.
|
|
74
|
-
*
|
|
75
|
-
* A setup function receives the instance and may do anything, including the things plain data cannot
|
|
76
|
-
* express — branch on the instance, install middleware, swap another function in. Declarative
|
|
77
|
-
* configuration ({@link configStates}) is the other way, and carries values only.
|
|
78
|
-
*
|
|
79
|
-
* A store rather than a bare function because timing is not guaranteed in either direction. Instances
|
|
80
|
-
* subscribe to the store for the relevant key, so a setup function registered after those instances were
|
|
81
|
-
* built still reaches every one of them, and an instance built afterwards picks up the setup function
|
|
82
|
-
* already sitting in the store.
|
|
83
|
-
*
|
|
84
|
-
* Entries appear on first access through {@link getSetupState}, never up front — the key space is open,
|
|
85
|
-
* so the full set of keys is not knowable here.
|
|
52
|
+
* Setup function per key, each in a store so that instances built before or after a registration both
|
|
53
|
+
* see it. Applied after declarative configuration, so it wins for the same field.
|
|
86
54
|
*/
|
|
87
55
|
private setupStates = new Map<string, AnySetupStore>();
|
|
88
56
|
|
|
89
57
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* configuration key: the subtree registered through {@link InstanceConfigurationRegistry.set} or
|
|
93
|
-
* {@link InstanceConfigurationRegistry.setConfig}, `null` until a caller registers something.
|
|
94
|
-
*
|
|
95
|
-
* Plain data, no code — the ordinary way to configure, and the reason a configuration tree can be
|
|
96
|
-
* written as JSON. Anything needing code goes through a setup function ({@link setupStates}).
|
|
97
|
-
*
|
|
98
|
-
* These stores hold **registered intent only** — the values an integrator asked for. The value an
|
|
99
|
-
* instance ended up with lives on the instance itself, as `configState`, after defaults, construction
|
|
100
|
-
* arguments, the setup function and the server's restrictions have all been applied. Reading a
|
|
101
|
-
* declarative store answers "what was asked for", never "what is in effect".
|
|
102
|
-
*
|
|
103
|
-
* Entries appear on first access through {@link getConfigState}, matching `setupStates`.
|
|
58
|
+
* Registered declarative values per key (`null` until set). Registered intent only: the value in
|
|
59
|
+
* effect is the instance's own `configState`.
|
|
104
60
|
*/
|
|
105
61
|
private configStates = new Map<string, AnyConfigStore>();
|
|
106
62
|
|
|
107
63
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* adds an entry when an instance is constructed, and the callback returned by
|
|
111
|
-
* {@link registerInstance} removes the entry when that instance is disposed of. Liveness is the whole
|
|
112
|
-
* point of the map: a disposed instance must neither be re-derived nor counted.
|
|
113
|
-
*
|
|
114
|
-
* A single instance appears under several keys, because registration also covers every key named in
|
|
115
|
-
* `alsoWatch` — a `Channel` is registered under `'channel'`, `'messagePaginator'` and
|
|
116
|
-
* `'messageOperations'`. {@link reset} de-duplicates across keys so that one reset re-derives each
|
|
117
|
-
* instance once rather than once per key.
|
|
118
|
-
*
|
|
119
|
-
* Two features read the map. {@link reset} walks the registered instances and makes each one re-derive,
|
|
120
|
-
* once both configuration slots are cleared. {@link hasLiveInstances} answers the narrower question
|
|
121
|
-
* "have instances already been built for this key?", which is what separates a construction-only path
|
|
122
|
-
* registered too late — worth a warning, because already-built instances will never see the value — from
|
|
123
|
-
* the same path registered before construction, where the value applies normally.
|
|
64
|
+
* Live instances per key. One instance sits under several keys when it passes `alsoWatch`, and `reset`
|
|
65
|
+
* de-duplicates across them.
|
|
124
66
|
*/
|
|
125
67
|
private liveInstances = new Map<string, Set<ConfiguredInstance>>();
|
|
126
68
|
|
|
127
|
-
/**
|
|
128
|
-
* The setup-function store for a key, created on first access. Lazy creation is a correctness
|
|
129
|
-
* requirement rather than an optimization: for a key the SDK does not define, neither the setter nor
|
|
130
|
-
* the subscriber can be assumed to come first.
|
|
131
|
-
*/
|
|
69
|
+
/** The setup-function store for a key, created on first access. */
|
|
132
70
|
getSetupState<K extends InstanceSetupKey>(key: K): StateStore<InstanceSetupState<K>> {
|
|
133
71
|
let store = this.setupStates.get(key);
|
|
134
72
|
if (!store) {
|
|
@@ -152,10 +90,6 @@ export class InstanceConfigurationRegistry {
|
|
|
152
90
|
return store as unknown as StateStore<InstanceConfigState<K>>;
|
|
153
91
|
}
|
|
154
92
|
|
|
155
|
-
// -------------------------------------------------------------------------
|
|
156
|
-
// Tier 2 — setup functions
|
|
157
|
-
// -------------------------------------------------------------------------
|
|
158
|
-
|
|
159
93
|
/**
|
|
160
94
|
* Registers the setup function for a key, replacing any previous one (whose teardown runs first) and
|
|
161
95
|
* applying it to every live instance. Pass `null` to clear.
|
|
@@ -172,18 +106,12 @@ export class InstanceConfigurationRegistry {
|
|
|
172
106
|
return this.getSetupState(key).getLatestValue().setupFunction;
|
|
173
107
|
}
|
|
174
108
|
|
|
175
|
-
// -------------------------------------------------------------------------
|
|
176
|
-
// Tier 1 — declarative configuration
|
|
177
|
-
// -------------------------------------------------------------------------
|
|
178
|
-
|
|
179
109
|
/**
|
|
180
110
|
* Registers declarative configuration for several keys at once. Deep-merges into whatever is already
|
|
181
111
|
* registered, so a later call only affects the paths it names.
|
|
182
112
|
*/
|
|
183
113
|
set(tree: DeepPartial<InstanceConfigTree>): void {
|
|
184
114
|
for (const [key, subtree] of Object.entries(tree)) {
|
|
185
|
-
// Skip absent entries but keep going — one empty or unrecognized entry must never discard the
|
|
186
|
-
// rest of the tree.
|
|
187
115
|
if (subtree === undefined || subtree === null) continue;
|
|
188
116
|
this.setConfig(
|
|
189
117
|
key as InstanceConfigKey,
|
|
@@ -204,11 +132,8 @@ export class InstanceConfigurationRegistry {
|
|
|
204
132
|
const current = store.getLatestValue().config;
|
|
205
133
|
const next = mergeWith(
|
|
206
134
|
{ ...((current ?? {}) as Record<string, unknown>) },
|
|
207
|
-
// Copied
|
|
208
|
-
//
|
|
209
|
-
// objects, and a later `patch.text.maxLengthOnSend = 5` changed resolved configuration behind every
|
|
210
|
-
// live instance's back, with no notification. Functions and class instances pass through by reference,
|
|
211
|
-
// which is what a caller hands over rather than a structure to merge into.
|
|
135
|
+
// Copied because `mergeWith` reuses source subtrees verbatim, which would alias the caller's
|
|
136
|
+
// objects. Functions and class instances pass through by reference.
|
|
212
137
|
copyConfigPatch(config) as unknown as object,
|
|
213
138
|
) as DeepPartial<InstanceConfigOf<K>>;
|
|
214
139
|
|
|
@@ -222,22 +147,12 @@ export class InstanceConfigurationRegistry {
|
|
|
222
147
|
}
|
|
223
148
|
|
|
224
149
|
/**
|
|
225
|
-
* Everything currently registered, as one tree.
|
|
226
|
-
*
|
|
227
|
-
* Built for the case `getConfig(key)` cannot serve: enumerating what has been configured without
|
|
228
|
-
* knowing the keys up front — a settings UI, a diagnostic dump, or a test asserting that every
|
|
229
|
-
* configurable thing has a place in the tree.
|
|
230
|
-
*
|
|
231
|
-
* Includes custom keys alongside the built-in ones, since both are equally real. Keys with nothing
|
|
232
|
-
* registered are omitted rather than emitted as `{}`, so an empty result means "nothing configured"
|
|
233
|
-
* instead of "five empty subtrees". This is *registered intent*, not resolved values — for those, read
|
|
234
|
-
* the instance's `config`.
|
|
150
|
+
* Everything currently registered, as one tree. Keys with nothing registered are omitted. This is
|
|
151
|
+
* registered intent, not resolved values: for those, read the instance's `config`.
|
|
235
152
|
*/
|
|
236
153
|
getTree(): DeepPartial<InstanceConfigTree> {
|
|
237
154
|
const tree: Record<string, unknown> = {};
|
|
238
155
|
|
|
239
|
-
// The store map is keyed by a plain string — every entry was created through a typed setter, so the
|
|
240
|
-
// cast recovers what the type system already guaranteed at the call site.
|
|
241
156
|
for (const key of this.configStates.keys() as Iterable<InstanceConfigKey>) {
|
|
242
157
|
const config = this.getConfigState(key).getLatestValue().config;
|
|
243
158
|
if (config && Object.keys(config).length > 0) tree[key] = config;
|
|
@@ -246,23 +161,12 @@ export class InstanceConfigurationRegistry {
|
|
|
246
161
|
return tree as DeepPartial<InstanceConfigTree>;
|
|
247
162
|
}
|
|
248
163
|
|
|
249
|
-
// -------------------------------------------------------------------------
|
|
250
|
-
// Reset
|
|
251
|
-
// -------------------------------------------------------------------------
|
|
252
|
-
|
|
253
164
|
/**
|
|
254
|
-
* Returns the
|
|
255
|
-
*
|
|
256
|
-
* instance re-derive its configuration from current inputs.
|
|
257
|
-
*
|
|
258
|
-
* Re-derivation, rather than restoring a saved copy, is what makes this recover a known state even
|
|
259
|
-
* when a setup function's teardown was incomplete; teardowns are integrator-written. It also
|
|
260
|
-
* re-installs constructor-set behaviour (a `PinnedMessagePaginator`'s `doRequest` and comparators)
|
|
261
|
-
* that no snapshot of configuration values could have restored.
|
|
165
|
+
* Returns the key (or every touched key) to its baseline: clears declarative configuration and the
|
|
166
|
+
* setup function (running its teardown), then has every live instance re-derive its configuration.
|
|
262
167
|
*
|
|
263
|
-
*
|
|
264
|
-
* middleware, added subscriptions.
|
|
265
|
-
* baseline, not that the object returns to factory state.
|
|
168
|
+
* Does not undo what a setup function changed outside the configuration surface (inserted
|
|
169
|
+
* middleware, added subscriptions).
|
|
266
170
|
*/
|
|
267
171
|
reset(key?: InstanceConfigKey): void {
|
|
268
172
|
const keys =
|
|
@@ -280,25 +184,16 @@ export class InstanceConfigurationRegistry {
|
|
|
280
184
|
this.getConfigState(currentKey as InstanceConfigKey).partialNext({
|
|
281
185
|
config: null,
|
|
282
186
|
});
|
|
283
|
-
//
|
|
284
|
-
//
|
|
285
|
-
// undo the re-derivation.
|
|
286
|
-
//
|
|
287
|
-
// Read rather than created: a configuration-only key such as `messagePaginator` has no setup
|
|
288
|
-
// function, and anything subscribed to one already has a store in this map.
|
|
187
|
+
// Teardown runs through the subscription in `applyInstanceConfiguration`, before re-derivation.
|
|
188
|
+
// Read, not created: a configuration-only key such as `messagePaginator` has no setup function.
|
|
289
189
|
this.setupStates.get(currentKey)?.partialNext({ setupFunction: null });
|
|
290
190
|
}
|
|
291
191
|
} finally {
|
|
292
192
|
this.resetting = false;
|
|
293
193
|
}
|
|
294
194
|
|
|
295
|
-
// Every slot is cleared before anything re-derives, and each instance
|
|
296
|
-
// registered under several keys
|
|
297
|
-
// `messageOperations`.
|
|
298
|
-
//
|
|
299
|
-
// Both halves of that need {@link isResetting}. Without it the loop above re-derives an instance as
|
|
300
|
-
// each key is cleared, so it derives against a *half-cleared* tree — the opposite of "every slot is
|
|
301
|
-
// cleared first" — and once per populated key rather than once in total.
|
|
195
|
+
// Every slot is cleared before anything re-derives, and each instance re-derives once even when it
|
|
196
|
+
// is registered under several keys. `isResetting` keeps the clearing loop from re-deriving early.
|
|
302
197
|
const instancesToReinitialize = new Set<ConfiguredInstance>();
|
|
303
198
|
for (const currentKey of keys) {
|
|
304
199
|
for (const instance of this.liveInstances.get(currentKey) ?? []) {
|
|
@@ -318,13 +213,8 @@ export class InstanceConfigurationRegistry {
|
|
|
318
213
|
private resetting = false;
|
|
319
214
|
|
|
320
215
|
/**
|
|
321
|
-
* Whether {@link reset} is
|
|
322
|
-
*
|
|
323
|
-
* `applyInstanceConfiguration` reads it to skip the per-key notifications the clearing loop emits: an
|
|
324
|
-
* instance that supplied a `reinitializeConfig` is guaranteed exactly one re-derivation in reset's final
|
|
325
|
-
* phase, so reacting to each individual clear would only re-derive it repeatedly, and against a tree
|
|
326
|
-
* that is not finished being cleared. Teardown is *not* skipped — it lives in the helper's closure and
|
|
327
|
-
* has no other route.
|
|
216
|
+
* Whether {@link reset} is clearing slots. `applyInstanceConfiguration` uses it to skip the per-key
|
|
217
|
+
* notifications for instances that reset re-derives itself.
|
|
328
218
|
*
|
|
329
219
|
* @internal
|
|
330
220
|
*/
|
|
@@ -332,10 +222,6 @@ export class InstanceConfigurationRegistry {
|
|
|
332
222
|
return this.resetting;
|
|
333
223
|
}
|
|
334
224
|
|
|
335
|
-
// -------------------------------------------------------------------------
|
|
336
|
-
// Consumer registry
|
|
337
|
-
// -------------------------------------------------------------------------
|
|
338
|
-
|
|
339
225
|
/**
|
|
340
226
|
* Called by `applyInstanceConfiguration`. Returns the deregistration function.
|
|
341
227
|
*
|
|
@@ -362,17 +248,10 @@ export class InstanceConfigurationRegistry {
|
|
|
362
248
|
return (this.liveInstances.get(key)?.size ?? 0) > 0;
|
|
363
249
|
}
|
|
364
250
|
|
|
365
|
-
// -------------------------------------------------------------------------
|
|
366
|
-
// Diagnostics
|
|
367
|
-
// -------------------------------------------------------------------------
|
|
368
|
-
|
|
369
251
|
/**
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
* Warns rather than throwing, because a throw here would turn a no-op registration into a crash for a
|
|
374
|
-
* caller the types already warned. The live-instance check keeps it quiet for a key whose owner has not
|
|
375
|
-
* been constructed yet, which is the normal ordering.
|
|
252
|
+
* Warns, rather than throws, when a key this package does not define (a JavaScript caller or a
|
|
253
|
+
* cast) is registered while no live instance uses it. Quiet once an instance has subscribed under
|
|
254
|
+
* the key.
|
|
376
255
|
*/
|
|
377
256
|
private warnIfKeyLooksUnknown(key: InstanceConfigKey): void {
|
|
378
257
|
if ((INSTANCE_CONFIG_TREE_KEYS as readonly string[]).includes(key)) return;
|
|
@@ -387,21 +266,14 @@ export class InstanceConfigurationRegistry {
|
|
|
387
266
|
}
|
|
388
267
|
|
|
389
268
|
/**
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
* diagnostics it fires only when configuration genuinely did not apply.
|
|
393
|
-
*
|
|
394
|
-
* Only paths whose value actually **moves** warn. Re-registering a value identical to the one already
|
|
395
|
-
* stored changes nothing, so there is nothing that failed to apply and nothing to report — and without
|
|
396
|
-
* this, a settings UI that applies on every keystroke, or any `set()` on a render path, produced one
|
|
397
|
-
* warning per call about a value that had not changed. Measured before the guard: 100 identical
|
|
398
|
-
* `setConfig` calls, 100 warnings.
|
|
269
|
+
* Warns when paths read once during construction are registered after instances exist, since those
|
|
270
|
+
* instances will not see them. Only paths whose registered value changes warn.
|
|
399
271
|
*/
|
|
400
272
|
private warnAboutLateConstructionOnlyPaths(
|
|
401
273
|
key: InstanceConfigKey,
|
|
402
274
|
config: DeepPartial<InstanceConfigOf<InstanceSetupKey>>,
|
|
403
275
|
): void {
|
|
404
|
-
if (!this.hasLiveInstances(key)) return; // nothing constructed yet
|
|
276
|
+
if (!this.hasLiveInstances(key)) return; // nothing constructed yet: these will apply
|
|
405
277
|
|
|
406
278
|
const paths = CONSTRUCTION_ONLY_CONFIG_PATHS[key];
|
|
407
279
|
if (!paths || !isWalkableRecord(config)) return;
|
|
@@ -411,9 +283,8 @@ export class InstanceConfigurationRegistry {
|
|
|
411
283
|
|
|
412
284
|
const late = paths.filter((path) => {
|
|
413
285
|
if (!hasPath(config, path)) return false;
|
|
414
|
-
// Compared against what is registered
|
|
415
|
-
//
|
|
416
|
-
// (a setup function or the server may have moved it).
|
|
286
|
+
// Compared against what is registered, not what the instance resolved to (which a setup function
|
|
287
|
+
// or the server may have moved).
|
|
417
288
|
if (!registered || !hasPath(registered, path)) return true;
|
|
418
289
|
return !isEqual(getPath(registered, path), getPath(config, path));
|
|
419
290
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './shape';
|
|
2
2
|
export * from './types';
|
|
3
3
|
export * from './utils';
|
|
4
|
-
//
|
|
4
|
+
// Reached as `client.config`, never constructed by integrators: export the type only.
|
|
5
5
|
export type {
|
|
6
6
|
ConfiguredInstance,
|
|
7
7
|
InstanceConfigurationRegistry,
|
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
import type { InstanceConfigTree, InstanceSetupFunctionArgs } from './types';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
6
|
-
* runtime behaviour.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The keys this package wires itself, i.e. the ones that take a setup function. Used to scope
|
|
11
|
-
* diagnostics only; the key space is closed by the types, so there is nothing here to reject.
|
|
12
|
-
*
|
|
13
|
-
* Exported for the settings UI in `examples/vite`, which enumerates the tree. Diagnostics rather than
|
|
14
|
-
* API: the contents track whatever this package happens to wire, so they can change in a minor.
|
|
4
|
+
* The keys that take a setup function. Exported for settings UIs that enumerate the tree; the contents
|
|
5
|
+
* track what this package wires, so they can change in a minor.
|
|
15
6
|
*
|
|
16
7
|
* @internal
|
|
17
8
|
*/
|
|
@@ -25,14 +16,9 @@ export const BUILT_IN_INSTANCE_KEYS: readonly (keyof InstanceSetupFunctionArgs)[
|
|
|
25
16
|
];
|
|
26
17
|
|
|
27
18
|
/**
|
|
28
|
-
* Every key of the declarative configuration
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* omits `messagePaginator`, which is configuration-only. Typed as an exhaustive `Record` rather than a
|
|
32
|
-
* bare array so adding a key to {@link InstanceConfigTree} fails the build until it is listed here, which
|
|
33
|
-
* is what keeps the two from drifting.
|
|
34
|
-
*
|
|
35
|
-
* The exported array is diagnostics, not API — a new key is a minor, and this list grows with it.
|
|
19
|
+
* Every key of the declarative tree, including configuration-only ones such as `messagePaginator`
|
|
20
|
+
* (unlike {@link BUILT_IN_INSTANCE_KEYS}). An exhaustive `Record`, so adding a key to
|
|
21
|
+
* {@link InstanceConfigTree} fails the build until it is listed here.
|
|
36
22
|
*
|
|
37
23
|
* @internal
|
|
38
24
|
*/
|
|
@@ -52,25 +38,20 @@ export const INSTANCE_CONFIG_TREE_KEYS = Object.keys(
|
|
|
52
38
|
).sort() as readonly (keyof InstanceConfigTree)[];
|
|
53
39
|
|
|
54
40
|
/**
|
|
55
|
-
* Dot-paths, per key,
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* `stateThrottleMs` and `debounceMs` are read once too but are **not** listed, because a late change to
|
|
60
|
-
* either is re-applied by the config controller's change hook.
|
|
61
|
-
*
|
|
62
|
-
* Exported for the settings UI, which flags these paths. Diagnostics rather than API: the set tracks
|
|
63
|
-
* which fields happen to be read once, so it can change in a minor.
|
|
41
|
+
* Dot-paths, per key, read once during construction. Registered after an instance exists they cannot
|
|
42
|
+
* take effect, so the registry warns. `stateThrottleMs` and `debounceMs` are not listed: a late change
|
|
43
|
+
* is re-applied by the config controller's change hook. Exported for settings UIs that flag these paths.
|
|
64
44
|
*
|
|
65
45
|
* @internal
|
|
66
46
|
*/
|
|
67
47
|
export const CONSTRUCTION_ONLY_CONFIG_PATHS: Readonly<Record<string, readonly string[]>> =
|
|
68
48
|
{
|
|
69
|
-
// The shared key needs its own entry: paths
|
|
70
|
-
//
|
|
71
|
-
// `messagePaginator` was silent while the identical field under `channel`/`thread` warned — the same
|
|
72
|
-
// read-once field, warned through one route and not the other.
|
|
49
|
+
// The shared key needs its own entry: paths are relative to the key's subtree, and the warning is
|
|
50
|
+
// looked up by top-level key.
|
|
73
51
|
messagePaginator: ['initialCursor', 'initialOffset', 'unreadReferencePolicy'],
|
|
52
|
+
// Consumed while the client is constructed (axios instance, base URL, notification manager).
|
|
53
|
+
// `browser` and `persistUserOnConnectionFailure` are read when needed, so they are not listed.
|
|
54
|
+
client: ['axiosRequestConfig', 'baseURL', 'notificationManager'],
|
|
74
55
|
channel: [
|
|
75
56
|
'messagePaginator.initialCursor',
|
|
76
57
|
'messagePaginator.initialOffset',
|