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