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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
BasePaginatorConfig,
|
|
3
|
-
|
|
3
|
+
DoRequestResponse,
|
|
4
4
|
PaginatorOptions,
|
|
5
5
|
} from './BasePaginator';
|
|
6
6
|
import {
|
|
@@ -33,25 +33,18 @@ export type PinnedMessagePaginatorOptions = {
|
|
|
33
33
|
const PINNED_AT_SORT: SortParamRequest[] = [{ field: 'pinned_at', direction: 1 }];
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* The channel's pinned messages, ordered by `pinned_at` ascending (oldest-pinned first). Extends
|
|
37
|
+
* {@link MessageIntervalPaginator} rather than {@link MessagePaginator}: pinned messages are a subset
|
|
38
|
+
* of the channel and take no part in read/unread or delivery-receipt tracking.
|
|
37
39
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* the channel and thread message timelines). By extending the base rather than {@link MessagePaginator}
|
|
41
|
-
* it simply never gets the unread surface.
|
|
42
|
-
*
|
|
43
|
-
* Differences from the main list:
|
|
44
|
-
* - fetches from the `/pinned_messages` endpoint (`channel.getPinnedMessages`) rather than
|
|
45
|
-
* `channel.query({ messages })`;
|
|
46
|
-
* - includes only pinned, non-shadowed messages (`shouldIncludeMessageInInterval`), and filters on
|
|
47
|
-
* `{ cid, pinned: true }` so `ingestItem` auto-adds on pin and auto-removes on unpin;
|
|
48
|
-
* - orders by `pinned_at` ascending (oldest-pinned first), matching the legacy
|
|
49
|
-
* `channel.state.pinnedMessages` order.
|
|
50
|
-
*
|
|
51
|
-
* Navigation (`jumpToMessage` / `jumpToTheLatestMessage`) is inherited and meaningful — the endpoint
|
|
52
|
-
* supports `id_around` — but no unread-coupled navigation exists.
|
|
40
|
+
* Fetches through `channel.getPinnedMessages`, includes only pinned, non-shadowed messages and
|
|
41
|
+
* matches `{ cid, pinned: true }`, so `ingestItem` adds on pin and removes on unpin.
|
|
53
42
|
*/
|
|
54
43
|
export class PinnedMessagePaginator extends MessageIntervalPaginator {
|
|
44
|
+
protected get holderName() {
|
|
45
|
+
return 'pinned-message-paginator';
|
|
46
|
+
}
|
|
47
|
+
|
|
55
48
|
constructor({
|
|
56
49
|
channel,
|
|
57
50
|
id,
|
|
@@ -61,9 +54,7 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
|
|
|
61
54
|
super({
|
|
62
55
|
channel,
|
|
63
56
|
id: id ?? `pinned-message-paginator-${generateUUIDv4()}`,
|
|
64
|
-
//
|
|
65
|
-
// pinned message shares the single canonical copy with the main list / thread and reflects
|
|
66
|
-
// reactions & edits applied elsewhere. A caller may still inject a custom `itemIndex`.
|
|
57
|
+
// Omitted: the inherited store-backed index shares one copy of each message with the main list.
|
|
67
58
|
itemIndex,
|
|
68
59
|
paginatorOptions,
|
|
69
60
|
});
|
|
@@ -71,11 +62,7 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
|
|
|
71
62
|
this.installPinnedMessageBehaviour();
|
|
72
63
|
}
|
|
73
64
|
|
|
74
|
-
/**
|
|
75
|
-
* Memoized for the reason {@link MessageIntervalPaginator}'s overlay is: the base derivation folds
|
|
76
|
-
* this in and skips the publish when nothing moved, which needs stable references. Both close over
|
|
77
|
-
* `this` and over a fixed `pinned_at` sort, so there is nothing to rebuild.
|
|
78
|
-
*/
|
|
65
|
+
/** Memoized: stable references let the base derivation skip a publish when nothing moved. */
|
|
79
66
|
private pinnedBehaviour?: Partial<BasePaginatorConfig<LocalMessage, MessageQueryShape>>;
|
|
80
67
|
|
|
81
68
|
private buildPinnedBehaviour(): Partial<
|
|
@@ -89,12 +76,11 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
|
|
|
89
76
|
tiebreaker: this.pinnedTiebreaker,
|
|
90
77
|
}),
|
|
91
78
|
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
// them by direction.
|
|
79
|
+
// The base passes the resolved shape (including `id_around` jumps) as `options`. Both
|
|
80
|
+
// cursors are returned and the base `extractQueryPage` gates them by direction.
|
|
95
81
|
doRequest: async (
|
|
96
82
|
options: MessageQueryShape,
|
|
97
|
-
): Promise<
|
|
83
|
+
): Promise<DoRequestResponse<LocalMessage>> => {
|
|
98
84
|
const { messages } = await this.channel.getPinnedMessages({
|
|
99
85
|
...(options as PinnedMessagePaginationOptions),
|
|
100
86
|
sort: PINNED_AT_SORT,
|
|
@@ -113,11 +99,7 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
|
|
|
113
99
|
return leftId < rightId ? -1 : leftId > rightId ? 1 : 0;
|
|
114
100
|
};
|
|
115
101
|
|
|
116
|
-
/**
|
|
117
|
-
* The ordering and request behaviour that makes this a *pinned*-message paginator, contributed to the
|
|
118
|
-
* base derivation so a re-derivation cannot drop it and does not need a second write to restore it.
|
|
119
|
-
* Spread over the interval overlay, so this class's `pinned_at` comparator wins.
|
|
120
|
-
*/
|
|
102
|
+
/** Adds the pinned ordering and request behaviour to the derivation, over the interval overlay. */
|
|
121
103
|
protected override getBehaviourOverrides(): Partial<
|
|
122
104
|
BasePaginatorConfig<LocalMessage, MessageQueryShape>
|
|
123
105
|
> {
|
|
@@ -125,12 +107,9 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
|
|
|
125
107
|
}
|
|
126
108
|
|
|
127
109
|
private installPinnedMessageBehaviour(): void {
|
|
128
|
-
//
|
|
129
|
-
// the
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
// A plain field rather than config, so a re-derivation never touches it — which is why only the
|
|
133
|
-
// constructor sets it.
|
|
110
|
+
// Ascending `pinned_at` keeps the head edge (most recently pinned) at the end of an interval,
|
|
111
|
+
// like the base's `created_at` ascending. A plain field rather than config, so a re-derivation
|
|
112
|
+
// never touches it and only the constructor sets it.
|
|
134
113
|
this.sortComparator = makeComparator<LocalMessage>({
|
|
135
114
|
sort: PINNED_AT_SORT,
|
|
136
115
|
resolvePathValue: resolveDotPathValue,
|
|
@@ -139,6 +118,19 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
|
|
|
139
118
|
this.updateConfig(this.buildPinnedBehaviour());
|
|
140
119
|
}
|
|
141
120
|
|
|
121
|
+
/**
|
|
122
|
+
* The newest page (no cursor, not around a message) holds the most recently pinned messages, so
|
|
123
|
+
* it reaches the head: its interval becomes the only newest interval, and an older interval that
|
|
124
|
+
* was the newest one can load newer pins (see `makeOnlyHead`). A newest page comes from this
|
|
125
|
+
* paginator's own query or with a channel response.
|
|
126
|
+
*/
|
|
127
|
+
protected override pageReachesHead(
|
|
128
|
+
_page: LocalMessage[],
|
|
129
|
+
queryShape: MessageQueryShape | undefined,
|
|
130
|
+
): boolean | undefined {
|
|
131
|
+
return this.isHeadPageQueryShape(queryShape) ? true : undefined;
|
|
132
|
+
}
|
|
133
|
+
|
|
142
134
|
buildMatchFilters = (): PinnedMessagePaginatorFilter => ({
|
|
143
135
|
cid: this.channel.cid,
|
|
144
136
|
pinned: true,
|
|
@@ -15,12 +15,10 @@ import { StoreBackedItemIndex } from '../../entityStore/StoreBackedItemIndex';
|
|
|
15
15
|
import { makeComparator } from '../sortCompiler';
|
|
16
16
|
import { resolveDotPathValue } from '../utility.normalization';
|
|
17
17
|
|
|
18
|
-
// Reminders are keyed by the message they belong to
|
|
18
|
+
// Reminders are keyed by the message they belong to.
|
|
19
19
|
const getReminderId = (reminder: ReminderResponseData) => reminder.message_id;
|
|
20
20
|
|
|
21
|
-
//
|
|
22
|
-
// (ReminderManager stores reminders in a message_id-keyed Map), but interval storage needs a total
|
|
23
|
-
// order, so default to a deterministic one.
|
|
21
|
+
// Interval storage needs a total order, so default to a deterministic one when no sort is set.
|
|
24
22
|
const DEFAULT_SORT: SortParamRequest[] = [{ direction: 1, field: 'created_at' }];
|
|
25
23
|
|
|
26
24
|
export class ReminderPaginator extends BasePaginator<
|
|
@@ -58,6 +56,7 @@ export class ReminderPaginator extends BasePaginator<
|
|
|
58
56
|
initialCursor: ZERO_PAGE_CURSOR,
|
|
59
57
|
itemIndex: new StoreBackedItemIndex<ReminderResponseData>({
|
|
60
58
|
getEntityId: getReminderId,
|
|
59
|
+
holderName: 'reminder-paginator',
|
|
61
60
|
}),
|
|
62
61
|
...options,
|
|
63
62
|
});
|
|
@@ -69,8 +68,7 @@ export class ReminderPaginator extends BasePaginator<
|
|
|
69
68
|
return getReminderId(item);
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
//
|
|
73
|
-
// changes, which also resets the accumulated pages), with a message_id tiebreaker.
|
|
71
|
+
// Total order for interval storage: the requested sort, with a message_id tiebreaker.
|
|
74
72
|
private buildSortComparator() {
|
|
75
73
|
return makeComparator<ReminderResponseData>({
|
|
76
74
|
sort: this._sort ?? DEFAULT_SORT,
|
|
@@ -80,28 +78,35 @@ export class ReminderPaginator extends BasePaginator<
|
|
|
80
78
|
});
|
|
81
79
|
}
|
|
82
80
|
|
|
83
|
-
protected getNextQueryShape({
|
|
84
|
-
direction,
|
|
85
|
-
}: Required<
|
|
86
|
-
Pick<PaginationQueryParams<QueryRemindersRequest>, 'direction'>
|
|
87
|
-
>): QueryRemindersRequest {
|
|
88
|
-
const cursor = this.cursor?.[direction];
|
|
81
|
+
protected getNextQueryShape(): QueryRemindersRequest {
|
|
89
82
|
return {
|
|
90
83
|
filter: this.filters,
|
|
91
84
|
sort: this.sort,
|
|
92
85
|
limit: this.pageSize,
|
|
93
|
-
[direction]: cursor,
|
|
94
86
|
};
|
|
95
87
|
}
|
|
96
88
|
|
|
97
|
-
|
|
89
|
+
protected override fetchQueryResponse = async ({
|
|
90
|
+
direction,
|
|
98
91
|
queryShape,
|
|
99
92
|
}: PaginationQueryParams<QueryRemindersRequest>): Promise<
|
|
100
93
|
PaginationQueryReturnValue<ReminderResponseData>
|
|
101
94
|
> => {
|
|
102
|
-
const
|
|
95
|
+
const cursor = direction ? (this.cursor?.[direction] ?? undefined) : undefined;
|
|
96
|
+
const request: QueryRemindersRequest = {
|
|
97
|
+
...(queryShape ?? this.getNextQueryShape()),
|
|
98
|
+
// The request names its cursors after the response's `next` / `prev`, not after the direction.
|
|
99
|
+
...(cursor ? { [direction === 'tailward' ? 'next' : 'prev']: cursor } : {}),
|
|
100
|
+
};
|
|
101
|
+
const { reminders: items, next, prev } = await this.client.queryReminders(request);
|
|
103
102
|
return { items, headward: prev, tailward: next };
|
|
104
103
|
};
|
|
105
104
|
|
|
106
|
-
|
|
105
|
+
/** The extracting step of the query pipeline: the response is the page. */
|
|
106
|
+
protected override extractQueryPage(
|
|
107
|
+
response: PaginationQueryReturnValue<ReminderResponseData>,
|
|
108
|
+
_params: PaginationQueryParams<QueryRemindersRequest>,
|
|
109
|
+
) {
|
|
110
|
+
return response;
|
|
111
|
+
}
|
|
107
112
|
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { BasePaginator, ZERO_PAGE_CURSOR } from './BasePaginator';
|
|
2
|
+
import type {
|
|
3
|
+
PaginationQueryParams,
|
|
4
|
+
PaginationQueryReturnValue,
|
|
5
|
+
PaginationQueryShapeChangeIdentifier,
|
|
6
|
+
PaginatorOptions,
|
|
7
|
+
PaginatorState,
|
|
8
|
+
} from './BasePaginator';
|
|
9
|
+
import type { StreamChat } from '../../client';
|
|
10
|
+
import { EntityStore } from '../../entityStore/EntityStore';
|
|
11
|
+
import { StoreBackedItemIndex } from '../../entityStore/StoreBackedItemIndex';
|
|
12
|
+
import type { Thread } from '../../thread';
|
|
13
|
+
import type { QueryThreadsRequest } from '../../types';
|
|
14
|
+
import { isEqual } from '../../utils/mergeWith/mergeWithCore';
|
|
15
|
+
|
|
16
|
+
export const DEFAULT_THREAD_PAGE_SIZE = 25;
|
|
17
|
+
|
|
18
|
+
/** Default query options for every page of the thread list. */
|
|
19
|
+
export const DEFAULT_THREAD_QUERY: QueryThreadsRequest = {
|
|
20
|
+
participant_limit: 10,
|
|
21
|
+
reply_limit: 10,
|
|
22
|
+
watch: true,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** What identifies the query, as opposed to which page of it is requested. */
|
|
26
|
+
const getQueryIdentity = (queryShape: QueryThreadsRequest | undefined) => {
|
|
27
|
+
if (!queryShape) return queryShape;
|
|
28
|
+
const { limit: _, next: __, prev: ___, ...identity } = queryShape;
|
|
29
|
+
return identity;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const hasPaginationQueryShapeChanged: PaginationQueryShapeChangeIdentifier<
|
|
33
|
+
QueryThreadsRequest
|
|
34
|
+
> = (prevQueryShape, nextQueryShape) =>
|
|
35
|
+
!isEqual(getQueryIdentity(prevQueryShape), getQueryIdentity(nextQueryShape));
|
|
36
|
+
|
|
37
|
+
export type ThreadPaginatorOptions = {
|
|
38
|
+
client: StreamChat;
|
|
39
|
+
/** Store holding the list's threads (`client.threads`' thread store). Omitted: a private one. */
|
|
40
|
+
store?: EntityStore<Thread>;
|
|
41
|
+
paginatorOptions?: PaginatorOptions<Thread, QueryThreadsRequest>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The thread list, in the order `queryThreads` returns it. There is no client-side sort: the server
|
|
46
|
+
* order (unread first, then latest reply) depends on state a `Thread` mutates in place, so a
|
|
47
|
+
* comparator would corrupt interval storage. Pages append in server order and
|
|
48
|
+
* {@link ThreadPaginator.reload} replaces the list.
|
|
49
|
+
*/
|
|
50
|
+
export class ThreadPaginator extends BasePaginator<Thread, QueryThreadsRequest> {
|
|
51
|
+
private readonly client: StreamChat;
|
|
52
|
+
private readonly store: EntityStore<Thread>;
|
|
53
|
+
|
|
54
|
+
constructor({
|
|
55
|
+
client,
|
|
56
|
+
store = new EntityStore<Thread>({ getEntityId: (thread) => thread.id }),
|
|
57
|
+
paginatorOptions,
|
|
58
|
+
}: ThreadPaginatorOptions) {
|
|
59
|
+
super({
|
|
60
|
+
hasPaginationQueryShapeChanged,
|
|
61
|
+
initialCursor: ZERO_PAGE_CURSOR,
|
|
62
|
+
itemIndex: new StoreBackedItemIndex<Thread>({
|
|
63
|
+
getEntityId: (thread) => thread.id,
|
|
64
|
+
holderName: 'thread-paginator',
|
|
65
|
+
store,
|
|
66
|
+
}),
|
|
67
|
+
pageSize: DEFAULT_THREAD_PAGE_SIZE,
|
|
68
|
+
...paginatorOptions,
|
|
69
|
+
});
|
|
70
|
+
this.client = client;
|
|
71
|
+
this.store = store;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** No next page until a load has landed, so `toTail()` is a no-op before the first reload. */
|
|
75
|
+
get initialState(): PaginatorState<Thread> {
|
|
76
|
+
return {
|
|
77
|
+
...super.initialState,
|
|
78
|
+
hasMoreTail: false,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
getItemId(thread: Thread): string {
|
|
83
|
+
return thread.id;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
protected getNextQueryShape({
|
|
87
|
+
direction,
|
|
88
|
+
}: Required<
|
|
89
|
+
Pick<PaginationQueryParams<QueryThreadsRequest>, 'direction'>
|
|
90
|
+
>): QueryThreadsRequest {
|
|
91
|
+
const cursor = this.cursor?.[direction] ?? undefined;
|
|
92
|
+
return {
|
|
93
|
+
...DEFAULT_THREAD_QUERY,
|
|
94
|
+
limit: this.pageSize,
|
|
95
|
+
...(cursor ? { [direction === 'tailward' ? 'next' : 'prev']: cursor } : {}),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected override fetchQueryResponse = async ({
|
|
100
|
+
queryShape,
|
|
101
|
+
}: PaginationQueryParams<QueryThreadsRequest>): Promise<
|
|
102
|
+
PaginationQueryReturnValue<Thread>
|
|
103
|
+
> => {
|
|
104
|
+
const { threads, next } = await this.client.queryThreadsAndHydrate(queryShape);
|
|
105
|
+
return {
|
|
106
|
+
items: threads.map((thread) => this.store.get(thread.id) ?? thread),
|
|
107
|
+
tailward: next,
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/** The extracting step of the query pipeline: the response is the page. */
|
|
112
|
+
protected override extractQueryPage(
|
|
113
|
+
response: PaginationQueryReturnValue<Thread>,
|
|
114
|
+
_params: PaginationQueryParams<QueryThreadsRequest>,
|
|
115
|
+
) {
|
|
116
|
+
return response;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Re-queries the first page and replaces the list in server order; also the first load. The
|
|
121
|
+
* current threads stay until the response lands. A failed query leaves them and records
|
|
122
|
+
* `lastQueryError`; a success clears it. Only the first load publishes `isLoading` (with items it
|
|
123
|
+
* would mean the next page).
|
|
124
|
+
*/
|
|
125
|
+
reload = async ({ limit = this.pageSize }: { limit?: number } = {}) => {
|
|
126
|
+
const isFirstLoad = !this.hasResults;
|
|
127
|
+
if (isFirstLoad) this.state.partialNext({ isLoading: true });
|
|
128
|
+
let replaced = false;
|
|
129
|
+
try {
|
|
130
|
+
const fetchParams = {
|
|
131
|
+
queryShape: { ...DEFAULT_THREAD_QUERY, limit },
|
|
132
|
+
retryCount: this.config.retryCount,
|
|
133
|
+
};
|
|
134
|
+
const response = await this.fetchQueryResponseWithRetries(fetchParams);
|
|
135
|
+
if (!response) return;
|
|
136
|
+
// The query pipeline's steps (see `executeQuery`) with a placing step of its own, below. A
|
|
137
|
+
// thread list's response is its page, so nothing else is left to apply.
|
|
138
|
+
const results = this.extractQueryPage(response, fetchParams);
|
|
139
|
+
|
|
140
|
+
// Replace rather than merge (the order is server-driven): IDs absent from the response go.
|
|
141
|
+
const nextIds = new Set(results.items.map((thread) => thread.id));
|
|
142
|
+
this.setIntervals([]);
|
|
143
|
+
this.setActiveInterval(undefined);
|
|
144
|
+
for (const [id] of this._itemIndex.entries()) {
|
|
145
|
+
if (!nextIds.has(id)) this._itemIndex.remove(id);
|
|
146
|
+
}
|
|
147
|
+
this.setItems({
|
|
148
|
+
cursor: { headward: undefined, tailward: results.tailward },
|
|
149
|
+
isFirstPage: true,
|
|
150
|
+
isLastPage: !results.tailward,
|
|
151
|
+
valueOrFactory: results.items,
|
|
152
|
+
});
|
|
153
|
+
replaced = true;
|
|
154
|
+
} finally {
|
|
155
|
+
const clearError = replaced && this.lastQueryError;
|
|
156
|
+
if (isFirstLoad || clearError) {
|
|
157
|
+
this.state.partialNext({
|
|
158
|
+
...(isFirstLoad ? { isLoading: false } : {}),
|
|
159
|
+
...(clearError ? { lastQueryError: undefined } : {}),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/** Also clears the item index (the base reset keeps it), before the base publishes. */
|
|
166
|
+
resetState() {
|
|
167
|
+
this._itemIndex.clear();
|
|
168
|
+
super.resetState();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
} from './BasePaginator';
|
|
8
8
|
import type { ListUserGroupsOptions, UserGroupResponse } from '../../types';
|
|
9
9
|
import type { StreamChat } from '../../client';
|
|
10
|
+
import { nsToRfc3339 } from '../../utils/time';
|
|
10
11
|
import { StoreBackedItemIndex } from '../../entityStore/StoreBackedItemIndex';
|
|
11
12
|
|
|
12
13
|
type UserGroupListCursor = {
|
|
@@ -29,12 +30,8 @@ const decodeCursor = <TCursor extends object>(cursor: string | null | undefined)
|
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
|
-
* Paginates
|
|
33
|
-
*
|
|
34
|
-
* This entity only supports forward (tailward) cursor pagination via
|
|
35
|
-
* `created_at_gt` and `id_gt`. Backward (headward) pagination is not available
|
|
36
|
-
* because the API does not expose a backward cursor, so the headward cursor is
|
|
37
|
-
* initialized as exhausted (`null`).
|
|
33
|
+
* Paginates `/usergroups` forward (tailward) only, via `created_at_gt` and `id_gt`. The API has no
|
|
34
|
+
* backward cursor, so the headward cursor starts exhausted (`null`).
|
|
38
35
|
*/
|
|
39
36
|
export class UserGroupPaginator extends BasePaginator<
|
|
40
37
|
UserGroupResponse,
|
|
@@ -51,13 +48,12 @@ export class UserGroupPaginator extends BasePaginator<
|
|
|
51
48
|
initialCursor: { ...ZERO_PAGE_CURSOR, headward: null },
|
|
52
49
|
itemIndex: new StoreBackedItemIndex<UserGroupResponse>({
|
|
53
50
|
getEntityId: (group) => group.id,
|
|
51
|
+
holderName: 'user-group-paginator',
|
|
54
52
|
}),
|
|
55
53
|
...options,
|
|
56
54
|
});
|
|
57
55
|
this.client = client;
|
|
58
|
-
//
|
|
59
|
-
// the forward cursor (`created_at_gt`, `id_gt`), i.e. ascending `created_at` then `id` — mirror
|
|
60
|
-
// that here so the visible order matches the server's.
|
|
56
|
+
// Total order for interval storage, mirroring the server's ascending (`created_at`, `id`).
|
|
61
57
|
this.sortComparator = (a, b) => {
|
|
62
58
|
if (a.created_at !== b.created_at) return a.created_at < b.created_at ? -1 : 1;
|
|
63
59
|
return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
@@ -87,14 +83,15 @@ export class UserGroupPaginator extends BasePaginator<
|
|
|
87
83
|
if (!lastItem) return undefined;
|
|
88
84
|
|
|
89
85
|
return JSON.stringify({
|
|
90
|
-
|
|
86
|
+
// `nsToRfc3339` keeps the nanoseconds: a `Date` would floor the boundary timestamp and the
|
|
87
|
+
// strict `created_at_gt` could return that same item on the next page.
|
|
88
|
+
created_at_gt: nsToRfc3339(lastItem.created_at),
|
|
91
89
|
id_gt: lastItem.id,
|
|
92
90
|
} satisfies UserGroupListCursor);
|
|
93
91
|
};
|
|
94
92
|
|
|
95
|
-
// The
|
|
96
|
-
//
|
|
97
|
-
// forward cursor is NOT part of the shape — it is applied per request in `query`.
|
|
93
|
+
// The cursor stays out of the shape (a shape change resets the list): `fetchQueryResponse`
|
|
94
|
+
// applies it.
|
|
98
95
|
protected getNextQueryShape(): ListUserGroupsOptions {
|
|
99
96
|
return {
|
|
100
97
|
limit: this.pageSize,
|
|
@@ -102,7 +99,7 @@ export class UserGroupPaginator extends BasePaginator<
|
|
|
102
99
|
};
|
|
103
100
|
}
|
|
104
101
|
|
|
105
|
-
|
|
102
|
+
protected override fetchQueryResponse = async ({
|
|
106
103
|
direction,
|
|
107
104
|
queryShape,
|
|
108
105
|
}: PaginationQueryParams<ListUserGroupsOptions>): Promise<
|
|
@@ -123,5 +120,11 @@ export class UserGroupPaginator extends BasePaginator<
|
|
|
123
120
|
return { items, tailward: this.buildNextCursor(items) };
|
|
124
121
|
};
|
|
125
122
|
|
|
126
|
-
|
|
123
|
+
/** The extracting step of the query pipeline: the response is the page. */
|
|
124
|
+
protected override extractQueryPage(
|
|
125
|
+
response: PaginationQueryReturnValue<UserGroupResponse>,
|
|
126
|
+
_params: PaginationQueryParams<ListUserGroupsOptions>,
|
|
127
|
+
) {
|
|
128
|
+
return response;
|
|
129
|
+
}
|
|
127
130
|
}
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Global switch for the message-list `state` publish throttle (see `BasePaginator.scheduleWindowPublish`).
|
|
3
|
-
*
|
|
4
|
-
* Auto-disabled under test runners (Vitest / Jest) so the existing unit suites keep their synchronous,
|
|
5
|
-
* un-throttled behavior with zero per-test changes: with throttling off, every live mutation publishes
|
|
6
|
-
* to `state` immediately, exactly as before this feature. A dedicated throttle test flips it on
|
|
7
|
-
* (around fake timers) via {@link setStateThrottlingEnabled} and restores it afterwards.
|
|
8
|
-
*
|
|
9
|
-
* Production (an app bundle) defaults ON.
|
|
10
|
-
*/
|
|
11
1
|
const isTestRunner = (): boolean => {
|
|
12
2
|
try {
|
|
13
3
|
return (
|
|
@@ -22,6 +12,11 @@ const isTestRunner = (): boolean => {
|
|
|
22
12
|
}
|
|
23
13
|
};
|
|
24
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Global switch for the `state` publish throttle (see `BasePaginator.scheduleActiveIntervalPublish`). On by
|
|
17
|
+
* default, off under test runners (Vitest / Jest) so every mutation publishes synchronously. Tests
|
|
18
|
+
* of the throttle itself turn it on with {@link setStateThrottlingEnabled}.
|
|
19
|
+
*/
|
|
25
20
|
let enabled = !isTestRunner();
|
|
26
21
|
|
|
27
22
|
export const isStateThrottlingEnabled = (): boolean => enabled;
|
|
@@ -12,15 +12,10 @@ export type ItemLocation = {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* - a getter `getItemAt(index)` that returns the item (or undefined)
|
|
20
|
-
*
|
|
21
|
-
* It returns:
|
|
22
|
-
* - current: actual index of the item in the array
|
|
23
|
-
* - expected: lower-bound position where the item belongs according to compare function
|
|
15
|
+
* Binary search over an abstract sorted array. Returns the needle's `currentIndex` (`-1` if absent)
|
|
16
|
+
* and the `insertionIndex` where `compare` places it (after items that compare equal). With
|
|
17
|
+
* `plateauScan`, a needle not at the insertion index is looked for by identity, scanning outward
|
|
18
|
+
* from it.
|
|
24
19
|
*/
|
|
25
20
|
export function binarySearch<T>({
|
|
26
21
|
needle,
|
|
@@ -30,43 +25,32 @@ export function binarySearch<T>({
|
|
|
30
25
|
compare,
|
|
31
26
|
plateauScan,
|
|
32
27
|
}: {
|
|
33
|
-
/** Target item in the searched array */
|
|
34
28
|
needle: T;
|
|
35
29
|
length: number;
|
|
36
|
-
/**
|
|
37
|
-
* Therefore, we do not access the array directly but allow to determine, how the item is constructed.
|
|
38
|
-
*/
|
|
30
|
+
/** Reads the item at an index (the array may hold IDs resolved through an index). */
|
|
39
31
|
getItemAt: (index: number) => T | undefined;
|
|
40
|
-
/**
|
|
32
|
+
/** Identity, not equality under the sort order. */
|
|
41
33
|
itemIdentityEquals: (item1: T, item2: T) => boolean;
|
|
42
|
-
/** Used to determine equality from the sort order point of view. */
|
|
43
34
|
compare: Comparator<T>;
|
|
44
35
|
plateauScan?: boolean;
|
|
45
36
|
}): ItemLocation {
|
|
46
|
-
// empty array
|
|
47
37
|
if (length === 0) return { currentIndex: -1, insertionIndex: 0 };
|
|
48
38
|
|
|
49
|
-
// --- 1) Binary search to find lower bound (insertionIndex) ---
|
|
50
39
|
let lo = 0;
|
|
51
40
|
let hi = length;
|
|
52
41
|
|
|
53
42
|
while (lo < hi) {
|
|
54
|
-
const mid = (lo + hi) >> 1;
|
|
43
|
+
const mid = (lo + hi) >> 1;
|
|
55
44
|
const midItem = getItemAt(mid);
|
|
56
45
|
if (!midItem) {
|
|
57
|
-
//
|
|
58
|
-
// Bail out with "not found".
|
|
46
|
+
// An ID without a backing item: report not found.
|
|
59
47
|
return { currentIndex: -1, insertionIndex: -1 };
|
|
60
48
|
}
|
|
61
49
|
|
|
62
50
|
if (itemIdentityEquals(midItem, needle) && mid > 0) {
|
|
63
|
-
// The
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
// `Channel` mutated in place before the paginator is told) already carry the new value.
|
|
67
|
-
// Walking right on that 0 reports "insert just after where you are" — read downstream as
|
|
68
|
-
// "already in place" — so the item never moves. The left neighbour is the reliable signal;
|
|
69
|
-
// otherwise fall through, keeping the established end-of-plateau result.
|
|
51
|
+
// The needle's own slot compares 0 and says nothing about where it belongs, and its value may
|
|
52
|
+
// have just changed in place (items held by reference): use the left neighbour, or it never
|
|
53
|
+
// moves.
|
|
70
54
|
const leftItem = getItemAt(mid - 1);
|
|
71
55
|
if (leftItem && compare(leftItem, needle) > 0) {
|
|
72
56
|
hi = mid;
|
|
@@ -75,17 +59,14 @@ export function binarySearch<T>({
|
|
|
75
59
|
}
|
|
76
60
|
|
|
77
61
|
if (compare(midItem, needle) <= 0) {
|
|
78
|
-
// midItem < needle ⇒ go right
|
|
79
62
|
lo = mid + 1;
|
|
80
63
|
} else {
|
|
81
|
-
// midItem ≥ needle ⇒ go left
|
|
82
64
|
hi = mid;
|
|
83
65
|
}
|
|
84
66
|
}
|
|
85
67
|
|
|
86
68
|
const insertionIndex = lo;
|
|
87
69
|
|
|
88
|
-
// item is located where it is expected to be according to the sort
|
|
89
70
|
const itemAtExpectedIndex = getItemAt(insertionIndex);
|
|
90
71
|
if (itemAtExpectedIndex && itemIdentityEquals(itemAtExpectedIndex, needle)) {
|
|
91
72
|
return { currentIndex: insertionIndex, insertionIndex };
|
|
@@ -95,8 +76,6 @@ export function binarySearch<T>({
|
|
|
95
76
|
return { currentIndex: -1, insertionIndex };
|
|
96
77
|
}
|
|
97
78
|
|
|
98
|
-
// --- 2) Plateau scan around insertionIndex ---
|
|
99
|
-
|
|
100
79
|
const checkSide = (atIndex: number) => {
|
|
101
80
|
const result = { exhausted: false, found: false };
|
|
102
81
|
const item = getItemAt(atIndex);
|
|
@@ -105,9 +84,8 @@ export function binarySearch<T>({
|
|
|
105
84
|
return result;
|
|
106
85
|
};
|
|
107
86
|
|
|
108
|
-
// Alternating left/right scan
|
|
109
87
|
let iLeft = insertionIndex - 1;
|
|
110
|
-
let iRight = insertionIndex + 1; //
|
|
88
|
+
let iRight = insertionIndex + 1; // insertionIndex itself is already checked
|
|
111
89
|
let leftDone = iLeft < 0;
|
|
112
90
|
let rightDone = iRight >= length;
|
|
113
91
|
|
|
@@ -125,22 +103,19 @@ export function binarySearch<T>({
|
|
|
125
103
|
}
|
|
126
104
|
}
|
|
127
105
|
|
|
128
|
-
// Not found in plateau; insertion index is still the correct lower bound.
|
|
129
106
|
return { currentIndex: -1, insertionIndex };
|
|
130
107
|
}
|
|
131
108
|
|
|
132
109
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* Zero (0) → leave a and b unchanged relative to each other
|
|
136
|
-
* (but they can still move relative to others — sort in JS is not guaranteed stable in older engines, though modern V8/Node/Chrome/Firefox make it stable)
|
|
137
|
-
*
|
|
138
|
-
* Positive number (> 0) → a comes after b
|
|
110
|
+
* Builds a comparator from a sort spec: terms apply in order, then `tiebreaker`.
|
|
111
|
+
* `null`/`undefined` values sort last whatever the direction.
|
|
139
112
|
*
|
|
140
113
|
* @param params - Comparator configuration.
|
|
141
114
|
* @param params.sort - The sort specification defining fields and directions.
|
|
142
115
|
* @param params.resolvePathValue - Resolver used to read a field value from an item.
|
|
143
|
-
* @param params.tiebreaker - Comparator applied when all sort terms are equal.
|
|
116
|
+
* @param params.tiebreaker - Comparator applied when all sort terms are equal. Defaults to
|
|
117
|
+
* comparing `cid`.
|
|
118
|
+
* @returns The comparator.
|
|
144
119
|
*/
|
|
145
120
|
export function makeComparator<T>({
|
|
146
121
|
sort,
|
|
@@ -165,17 +140,15 @@ export function makeComparator<T>({
|
|
|
165
140
|
comparison = compare(normalized.a, normalized.b);
|
|
166
141
|
break;
|
|
167
142
|
default: {
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
// `{ last_message_at: -1 }`) negates "null last" into "null first" and floats value-less
|
|
171
|
-
// items (e.g. channels with no last message) to the head of the list.
|
|
143
|
+
// Return before the direction flip below, which would turn "null last" into "null first"
|
|
144
|
+
// on a descending sort.
|
|
172
145
|
if (leftValue == null && rightValue == null) {
|
|
173
|
-
comparison = 0;
|
|
146
|
+
comparison = 0;
|
|
174
147
|
break;
|
|
175
148
|
}
|
|
176
|
-
if (leftValue == null) return 1;
|
|
177
|
-
if (rightValue == null) return -1;
|
|
178
|
-
// Both non-null but not normalizable:
|
|
149
|
+
if (leftValue == null) return 1;
|
|
150
|
+
if (rightValue == null) return -1;
|
|
151
|
+
// Both non-null but not normalizable: compare as strings (respects direction).
|
|
179
152
|
const stringLeftValue = String(leftValue),
|
|
180
153
|
stringRightValue = String(rightValue);
|
|
181
154
|
comparison =
|