stream-chat 10.0.0-rc.9 → 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 +21650 -19790
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +21690 -19798
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +21755 -19895
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelManager.d.ts +216 -135
- package/dist/types/CooldownTimer.d.ts +13 -27
- package/dist/types/EventHandlerPipeline.d.ts +18 -38
- package/dist/types/LiveLocationManager.d.ts +24 -52
- package/dist/types/api-client.d.ts +17 -5
- package/dist/types/channel.d.ts +432 -470
- package/dist/types/channel_state.d.ts +68 -112
- package/dist/types/client.d.ts +321 -435
- 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 +2 -0
- 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 +2528 -690
- package/dist/types/gen/models/timestamp-guard.d.ts +22 -0
- package/dist/types/gen/moderation/ModerationApi.d.ts +33 -14
- package/dist/types/index.d.ts +10 -6
- 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 +7 -1
- 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 -128
- 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 +19 -18
- package/dist/types/messageComposer/middleware/textComposer/textMiddlewareUtils.d.ts +9 -3
- package/dist/types/messageComposer/middleware/textComposer/types.d.ts +1 -6
- package/dist/types/messageComposer/pollComposer.d.ts +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 +40 -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 -186
- 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 -334
- 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 +5 -23
- package/dist/types/pagination/utility.search.d.ts +3 -8
- package/dist/types/poll.d.ts +34 -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 +11 -11
- 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 +63 -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 -199
- 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 +33 -57
- package/dist/types/utils.d.ts +72 -91
- package/package.json +14 -40
- package/src/ChannelManager.ts +494 -303
- package/src/CooldownTimer.ts +28 -38
- package/src/EventHandlerPipeline.ts +22 -45
- package/src/LiveLocationManager.ts +37 -76
- package/src/api-client.ts +113 -50
- package/src/campaign.ts +1 -1
- package/src/channel.ts +1067 -1276
- package/src/channel_batch_updater.ts +1 -1
- package/src/channel_state.ts +73 -168
- package/src/client.ts +744 -974
- 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 -232
- 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 +6 -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 -1540
- package/src/gen/models/index.ts +2498 -3383
- package/src/gen/models/timestamp-guard.ts +27 -0
- package/src/gen/moderation/ModerationApi.ts +170 -367
- package/src/index.ts +22 -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 +19 -23
- 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 +223 -174
- 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/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 -125
- package/src/messageDelivery/MessageReceiptsTracker.ts +88 -101
- package/src/messageOperations/FailedSendCache.ts +85 -0
- package/src/messageOperations/MessageOperationStatePolicy.ts +121 -112
- package/src/messageOperations/MessageOperations.ts +297 -175
- package/src/{entityStore → messageOperations}/applyReactionLocally.ts +9 -28
- 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 +226 -669
- package/src/offline-support/offline_sync_manager.ts +51 -80
- package/src/offline-support/queueableOperations.ts +98 -73
- package/src/offline-support/types.ts +43 -186
- 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 +15 -63
- 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 +479 -217
- package/src/pagination/paginators/MessageIntervalPaginator.ts +1351 -772
- package/src/pagination/paginators/MessagePaginator.ts +513 -233
- 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 +16 -19
- 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 +8 -30
- package/src/pagination/utility.search.ts +4 -11
- package/src/poll.ts +177 -98
- package/src/poll_manager.ts +24 -22
- package/src/poll_optimistic_votes.ts +335 -0
- package/src/reminders/Reminder.ts +16 -12
- package/src/reminders/ReminderManager.ts +22 -55
- package/src/reminders/ReminderTimer.ts +1 -2
- 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 +418 -703
- package/src/thread_manager.ts +300 -234
- package/src/token_manager.ts +12 -22
- package/src/types.ts +102 -216
- 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 +40 -60
- package/src/utils.ts +181 -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 -32
- 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/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 -257
- package/src/messageOperations/persistence.ts +0 -40
- package/src/pagination/utility.queryChannel.ts +0 -84
- package/src/store.ts +0 -304
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core utility functions and types for mergeWith functionality.
|
|
3
|
-
* This file contains shared logic used by both mergeWith and mergeWithDiff functions.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
1
|
export type MergeWithCustomizer<T extends object> = (
|
|
7
2
|
objValue: unknown,
|
|
8
3
|
srcValue: unknown,
|
|
@@ -28,19 +23,15 @@ export interface DiffNode {
|
|
|
28
23
|
oldValue?: unknown;
|
|
29
24
|
}
|
|
30
25
|
|
|
26
|
+
/** True for objects of a class other than `Object`. Arrays and plain objects are not. */
|
|
31
27
|
export const isClassInstance = (value: unknown): boolean => {
|
|
32
28
|
if (!value || typeof value !== 'object') return false;
|
|
33
29
|
|
|
34
|
-
// Arrays are not class instances
|
|
35
30
|
if (Array.isArray(value)) return false;
|
|
36
31
|
|
|
37
|
-
// Get the prototype chain
|
|
38
32
|
const proto = Object.getPrototypeOf(value);
|
|
39
|
-
|
|
40
|
-
// If it's null or Object.prototype, it's a plain object
|
|
41
33
|
if (proto === null || proto === Object.prototype) return false;
|
|
42
34
|
|
|
43
|
-
// Check if it has a constructor that's not Object
|
|
44
35
|
return value.constructor && value.constructor !== Object;
|
|
45
36
|
};
|
|
46
37
|
|
|
@@ -55,18 +46,15 @@ function memoHasOrAdd(memo: PairMemo, a: object, b: object): boolean {
|
|
|
55
46
|
}
|
|
56
47
|
|
|
57
48
|
/**
|
|
58
|
-
* Deep
|
|
59
|
-
*
|
|
60
|
-
* - Dates/RegExps compared by value
|
|
61
|
-
* - "Class instances" are treated atomically (unequal unless ===)
|
|
62
|
-
* - NaN equals NaN; -0 equals 0 (same as ===)
|
|
49
|
+
* Deep equality that is cycle-safe and covers symbol keys. Dates and RegExps compare by value, Sets
|
|
50
|
+
* and Maps by content, other class instances only by `===`. `NaN` equals `NaN`, `-0` equals `0`.
|
|
63
51
|
*/
|
|
64
52
|
export const isEqual = (
|
|
65
53
|
value1: unknown,
|
|
66
54
|
value2: unknown,
|
|
67
55
|
pairMemo: PairMemo = new WeakMap(),
|
|
68
56
|
): boolean => {
|
|
69
|
-
if (value1 === value2) return true;
|
|
57
|
+
if (value1 === value2) return true;
|
|
70
58
|
if (value1 == null || value2 == null) return false;
|
|
71
59
|
|
|
72
60
|
const t1 = typeof value1;
|
|
@@ -74,21 +62,18 @@ export const isEqual = (
|
|
|
74
62
|
if (t1 !== t2) return false;
|
|
75
63
|
|
|
76
64
|
if (t1 !== 'object') {
|
|
77
|
-
// NaN handling
|
|
78
65
|
// eslint-disable-next-line no-self-compare
|
|
79
66
|
return value1 !== value1 && value2 !== value2 ? true : value1 === value2;
|
|
80
67
|
}
|
|
81
68
|
|
|
82
|
-
// Objects
|
|
83
69
|
const o1 = value1 as object;
|
|
84
70
|
const o2 = value2 as object;
|
|
85
71
|
|
|
86
|
-
// Fast path for tag mismatch
|
|
87
72
|
const tag1 = Object.prototype.toString.call(o1);
|
|
88
73
|
const tag2 = Object.prototype.toString.call(o2);
|
|
89
74
|
if (tag1 !== tag2) return false;
|
|
90
75
|
|
|
91
|
-
//
|
|
76
|
+
// Dates and RegExps are class instances: compare them before that test.
|
|
92
77
|
if (o1 instanceof Date && o2 instanceof Date) {
|
|
93
78
|
return (o1 as Date).getTime() === (o2 as Date).getTime();
|
|
94
79
|
}
|
|
@@ -98,11 +83,7 @@ export const isEqual = (
|
|
|
98
83
|
return r1.source === r2.source && r1.flags === r2.flags;
|
|
99
84
|
}
|
|
100
85
|
|
|
101
|
-
//
|
|
102
|
-
// Two sets are equal if they have the same size and
|
|
103
|
-
// every value in one has an equivalent value in the
|
|
104
|
-
// other (using deep equality).
|
|
105
|
-
// Cannot use the same item for multiple matches in another set.
|
|
86
|
+
// Sets are equal when every value matches a distinct deep-equal value in the other.
|
|
106
87
|
if (value1 instanceof Set && value2 instanceof Set) {
|
|
107
88
|
if (value1.size !== value2.size) return false;
|
|
108
89
|
if (memoHasOrAdd(pairMemo, value1, value2)) return true;
|
|
@@ -113,7 +94,7 @@ export const isEqual = (
|
|
|
113
94
|
let matched = false;
|
|
114
95
|
for (const v2 of unmatched) {
|
|
115
96
|
if (isEqual(v1, v2, pairMemo)) {
|
|
116
|
-
unmatched.delete(v2);
|
|
97
|
+
unmatched.delete(v2);
|
|
117
98
|
matched = true;
|
|
118
99
|
break;
|
|
119
100
|
}
|
|
@@ -124,13 +105,12 @@ export const isEqual = (
|
|
|
124
105
|
return unmatched.size === 0;
|
|
125
106
|
}
|
|
126
107
|
|
|
127
|
-
// Handle Map comparison
|
|
128
108
|
if (value1 instanceof Map && value2 instanceof Map) {
|
|
129
109
|
if (value1.size !== value2.size) return false;
|
|
130
110
|
|
|
131
111
|
if (memoHasOrAdd(pairMemo, value1, value2)) return true;
|
|
132
112
|
|
|
133
|
-
const unmatched = new Set(value2);
|
|
113
|
+
const unmatched = new Set(value2);
|
|
134
114
|
|
|
135
115
|
for (const [k1, v1] of value1) {
|
|
136
116
|
let matchedEntry: [unknown, unknown] | null = null;
|
|
@@ -143,20 +123,19 @@ export const isEqual = (
|
|
|
143
123
|
}
|
|
144
124
|
}
|
|
145
125
|
|
|
146
|
-
if (!matchedEntry) return false;
|
|
147
|
-
unmatched.delete(matchedEntry);
|
|
126
|
+
if (!matchedEntry) return false;
|
|
127
|
+
unmatched.delete(matchedEntry);
|
|
148
128
|
}
|
|
149
129
|
|
|
150
130
|
return unmatched.size === 0;
|
|
151
131
|
}
|
|
152
132
|
|
|
153
|
-
// Treat non-plain instances atomically (your current rule)
|
|
154
133
|
if (isClassInstance(o1) || isClassInstance(o2)) return false;
|
|
155
134
|
|
|
156
|
-
// Cycle guard
|
|
135
|
+
// Cycle guard: a pair already being compared counts as equal.
|
|
157
136
|
if (memoHasOrAdd(pairMemo, o1, o2)) return true;
|
|
158
137
|
|
|
159
|
-
//
|
|
138
|
+
// A hole differs from `undefined`.
|
|
160
139
|
if (Array.isArray(o1)) {
|
|
161
140
|
const a1 = value1 as unknown[],
|
|
162
141
|
a2 = value2 as unknown[];
|
|
@@ -167,7 +146,6 @@ export const isEqual = (
|
|
|
167
146
|
if (has1 !== has2) return false;
|
|
168
147
|
if (has1 && !isEqual(a1[i], a2[i], pairMemo)) return false;
|
|
169
148
|
}
|
|
170
|
-
// Compare enumerable non-index props as well (to align with objects)
|
|
171
149
|
const extraKeys1 = Reflect.ownKeys(o1)
|
|
172
150
|
.filter((k) => typeof k !== 'string' || isNaN(+k))
|
|
173
151
|
.filter((k) => Object.prototype.propertyIsEnumerable.call(o1, k));
|
|
@@ -183,7 +161,6 @@ export const isEqual = (
|
|
|
183
161
|
return true;
|
|
184
162
|
}
|
|
185
163
|
|
|
186
|
-
// Plain objects (string + symbol enumerable own keys)
|
|
187
164
|
const keys1 = Reflect.ownKeys(o1).filter((k) =>
|
|
188
165
|
Object.prototype.propertyIsEnumerable.call(o1, k),
|
|
189
166
|
);
|
|
@@ -192,7 +169,7 @@ export const isEqual = (
|
|
|
192
169
|
);
|
|
193
170
|
if (keys1.length !== keys2.length) return false;
|
|
194
171
|
|
|
195
|
-
//
|
|
172
|
+
// Same prototype, so `{}` differs from `Object.create(null)`.
|
|
196
173
|
if (Object.getPrototypeOf(o1) !== Object.getPrototypeOf(o2)) return false;
|
|
197
174
|
|
|
198
175
|
for (const k of keys1) {
|
|
@@ -203,42 +180,27 @@ export const isEqual = (
|
|
|
203
180
|
return true;
|
|
204
181
|
};
|
|
205
182
|
|
|
206
|
-
/**
|
|
207
|
-
* Generates a diff between original and modified objects.
|
|
208
|
-
* This is used after the merge operation to track what has changed.
|
|
209
|
-
*/
|
|
183
|
+
/** Diff of the keys added or updated in `modified`, or `null` when there are none. */
|
|
210
184
|
export function generateDiff(original: unknown, modified: unknown): DiffNode | null {
|
|
211
|
-
// Root diff node
|
|
212
185
|
const diffRoot: DiffNode = { children: {} };
|
|
213
186
|
|
|
214
|
-
// Compare the objects and build the diff tree
|
|
215
187
|
compareAndBuildDiff(original, modified, diffRoot);
|
|
216
188
|
|
|
217
|
-
// Clean up the diff tree (remove empty nodes)
|
|
218
189
|
return cleanupDiffTree(diffRoot);
|
|
219
190
|
}
|
|
220
191
|
|
|
221
|
-
/**
|
|
222
|
-
* Helper function to compare and build the diff tree
|
|
223
|
-
*/
|
|
224
192
|
function compareAndBuildDiff(
|
|
225
193
|
original: unknown,
|
|
226
194
|
modified: unknown,
|
|
227
195
|
parentDiffNode: DiffNode,
|
|
228
196
|
key?: string | symbol,
|
|
229
197
|
pairMemo: PairMemo = new WeakMap(),
|
|
230
|
-
/**
|
|
231
|
-
* Tracks individual objects that are being processed in the current traversal path
|
|
232
|
-
* - It's used to detect when we encounter the same object multiple times in a single traversal path
|
|
233
|
-
* - This helps identify self-referential or circular structures within a single object (e.g., when an object references itself)
|
|
234
|
-
* - When an object appears in `objectStack` again, we know it's a circular reference within the same object
|
|
235
|
-
*/
|
|
198
|
+
/** Objects on the current traversal path, to detect an object that references itself. */
|
|
236
199
|
objectStack = new Set<unknown>(),
|
|
237
200
|
): void {
|
|
238
|
-
// If values are equal, no diff to record
|
|
239
201
|
if (isEqual(original, modified)) return;
|
|
240
202
|
|
|
241
|
-
//
|
|
203
|
+
// A null/undefined original counts as an addition.
|
|
242
204
|
if (original === undefined || original === null) {
|
|
243
205
|
if (key !== undefined) {
|
|
244
206
|
parentDiffNode.children[String(key)] = {
|
|
@@ -250,7 +212,6 @@ function compareAndBuildDiff(
|
|
|
250
212
|
return;
|
|
251
213
|
}
|
|
252
214
|
|
|
253
|
-
// Check for circular references in objects
|
|
254
215
|
if (typeof original === 'object' && original !== null) {
|
|
255
216
|
if (objectStack.has(original)) {
|
|
256
217
|
if (key !== undefined) {
|
|
@@ -266,7 +227,6 @@ function compareAndBuildDiff(
|
|
|
266
227
|
objectStack.add(original);
|
|
267
228
|
}
|
|
268
229
|
|
|
269
|
-
// Check if we're dealing with non-objects or special object types that should be treated atomically
|
|
270
230
|
const shouldTreatAtomically =
|
|
271
231
|
typeof original !== 'object' ||
|
|
272
232
|
typeof modified !== 'object' ||
|
|
@@ -286,18 +246,15 @@ function compareAndBuildDiff(
|
|
|
286
246
|
};
|
|
287
247
|
}
|
|
288
248
|
|
|
289
|
-
// Remove from object stack if it was added
|
|
290
249
|
if (typeof original === 'object' && original !== null) {
|
|
291
250
|
objectStack.delete(original);
|
|
292
251
|
}
|
|
293
252
|
return;
|
|
294
253
|
}
|
|
295
254
|
|
|
296
|
-
// Handle objects
|
|
297
255
|
const originalObj = original as Record<string | symbol, unknown>;
|
|
298
256
|
const modifiedObj = modified as Record<string | symbol, unknown>;
|
|
299
257
|
|
|
300
|
-
// Create a diff node for this level if we're processing a property
|
|
301
258
|
const currentDiffNode =
|
|
302
259
|
key !== undefined
|
|
303
260
|
? {
|
|
@@ -312,7 +269,7 @@ function compareAndBuildDiff(
|
|
|
312
269
|
parentDiffNode.children[String(key)] = currentDiffNode;
|
|
313
270
|
}
|
|
314
271
|
|
|
315
|
-
// Pairwise cycle check
|
|
272
|
+
// Pairwise cycle check.
|
|
316
273
|
if (
|
|
317
274
|
typeof original === 'object' &&
|
|
318
275
|
original !== null &&
|
|
@@ -320,14 +277,11 @@ function compareAndBuildDiff(
|
|
|
320
277
|
modified !== null
|
|
321
278
|
) {
|
|
322
279
|
if (memoHasOrAdd(pairMemo, original as object, modified as object)) {
|
|
323
|
-
// already visited this exact pair in this diff traversal
|
|
324
|
-
// (prevents infinite recursion), so stop here
|
|
325
280
|
if (typeof original === 'object') objectStack.delete(original);
|
|
326
281
|
return;
|
|
327
282
|
}
|
|
328
283
|
}
|
|
329
284
|
|
|
330
|
-
// Process all keys from both objects
|
|
331
285
|
const allKeys = new Set([
|
|
332
286
|
...Object.keys(originalObj),
|
|
333
287
|
...Object.getOwnPropertySymbols(originalObj),
|
|
@@ -339,13 +293,11 @@ function compareAndBuildDiff(
|
|
|
339
293
|
const originalValue = originalObj[childKey];
|
|
340
294
|
const modifiedValue = modifiedObj[childKey];
|
|
341
295
|
|
|
342
|
-
//
|
|
296
|
+
// Deletions are not tracked.
|
|
343
297
|
if (!(childKey in modifiedObj)) {
|
|
344
|
-
// Currently we don't track deletions, but could be added here if needed
|
|
345
298
|
continue;
|
|
346
299
|
}
|
|
347
300
|
|
|
348
|
-
// Handle added properties (they exist in modified but not in original)
|
|
349
301
|
if (!(childKey in originalObj)) {
|
|
350
302
|
currentDiffNode.children[String(childKey)] = {
|
|
351
303
|
type: 'added',
|
|
@@ -355,7 +307,6 @@ function compareAndBuildDiff(
|
|
|
355
307
|
continue;
|
|
356
308
|
}
|
|
357
309
|
|
|
358
|
-
// Process properties that exist in both but may have changed
|
|
359
310
|
compareAndBuildDiff(
|
|
360
311
|
originalValue,
|
|
361
312
|
modifiedValue,
|
|
@@ -383,7 +334,6 @@ export function createMergeCore<T extends object>(options: { trackDiff?: boolean
|
|
|
383
334
|
}): { result: T; diff: DiffNode | null } {
|
|
384
335
|
const sources = Array.isArray(source) ? source : [source];
|
|
385
336
|
|
|
386
|
-
// Store the original target if we need to track diffs
|
|
387
337
|
const originalTarget = trackDiff ? structuredClone(target) : undefined;
|
|
388
338
|
|
|
389
339
|
function handleCustomizer(
|
|
@@ -422,21 +372,18 @@ export function createMergeCore<T extends object>(options: { trackDiff?: boolean
|
|
|
422
372
|
return srcValue;
|
|
423
373
|
}
|
|
424
374
|
if (targetValue && typeof targetValue === 'object') {
|
|
425
|
-
// Check if it's a class instance (not a plain object)
|
|
426
375
|
const isTargetClassInstance = isClassInstance(targetValue);
|
|
427
376
|
const isSourceClassInstance = isClassInstance(srcValue);
|
|
428
377
|
|
|
429
|
-
//
|
|
378
|
+
// A class instance on either side is not merged: the source one wins, else the target
|
|
379
|
+
// stays.
|
|
430
380
|
if (isTargetClassInstance || isSourceClassInstance) {
|
|
431
|
-
// If source is a class instance, use it
|
|
432
381
|
if (isSourceClassInstance) {
|
|
433
382
|
return srcValue as object;
|
|
434
383
|
}
|
|
435
|
-
// Otherwise preserve the target
|
|
436
384
|
return targetValue;
|
|
437
385
|
}
|
|
438
386
|
|
|
439
|
-
// For plain objects, use normal merging
|
|
440
387
|
return Array.isArray(targetValue) ? [...targetValue] : { ...targetValue };
|
|
441
388
|
}
|
|
442
389
|
return Array.isArray(srcValue) ? [] : {};
|
|
@@ -501,10 +448,8 @@ export function createMergeCore<T extends object>(options: { trackDiff?: boolean
|
|
|
501
448
|
pendingMerges: PendingMerge[],
|
|
502
449
|
): void {
|
|
503
450
|
if (stack.has(source)) {
|
|
504
|
-
//
|
|
505
|
-
//
|
|
506
|
-
|
|
507
|
-
// If we're tracking diffs, we need to mark this as a circular reference
|
|
451
|
+
// Circular reference in the source: skip the merge. With diff tracking the target is re-set
|
|
452
|
+
// on the parent.
|
|
508
453
|
if (trackDiff && sourceKey && parentTarget) {
|
|
509
454
|
Object.defineProperty(parentTarget, sourceKey, {
|
|
510
455
|
value: target,
|
|
@@ -526,7 +471,7 @@ export function createMergeCore<T extends object>(options: { trackDiff?: boolean
|
|
|
526
471
|
}
|
|
527
472
|
|
|
528
473
|
function baseMerge(object: T, source: object, stack = new Set<unknown>()): T {
|
|
529
|
-
//
|
|
474
|
+
// Prevents infinite recursion.
|
|
530
475
|
if (stack.has(object) || stack.has(source)) {
|
|
531
476
|
return { ...object };
|
|
532
477
|
}
|
|
@@ -553,7 +498,6 @@ export function createMergeCore<T extends object>(options: { trackDiff?: boolean
|
|
|
553
498
|
...target,
|
|
554
499
|
} as T);
|
|
555
500
|
|
|
556
|
-
// If diff tracking is enabled, generate the diff after the merge is complete
|
|
557
501
|
const diff =
|
|
558
502
|
trackDiff && originalTarget ? generateDiff(originalTarget, result) : null;
|
|
559
503
|
|
|
@@ -561,7 +505,7 @@ export function createMergeCore<T extends object>(options: { trackDiff?: boolean
|
|
|
561
505
|
};
|
|
562
506
|
}
|
|
563
507
|
|
|
564
|
-
|
|
508
|
+
/** Prunes nodes that have no type and no children. Returns `null` for an empty tree. */
|
|
565
509
|
export function cleanupDiffTree(diffNode: DiffNode): DiffNode | null {
|
|
566
510
|
const cleanChildren: Record<string | symbol, DiffNode> = {};
|
|
567
511
|
let hasChildren = false;
|
|
@@ -574,7 +518,6 @@ export function cleanupDiffTree(diffNode: DiffNode): DiffNode | null {
|
|
|
574
518
|
}
|
|
575
519
|
}
|
|
576
520
|
|
|
577
|
-
// If this node has a type (added/updated) or has children, keep it
|
|
578
521
|
if (diffNode.type || hasChildren) {
|
|
579
522
|
return {
|
|
580
523
|
...diffNode,
|
|
@@ -1,44 +1,28 @@
|
|
|
1
|
+
import { cleanupDiffTree, createMergeCore } from './mergeWithCore';
|
|
2
|
+
import type { DiffNode, MergeWithCustomizer } from './mergeWithCore';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
5
|
+
* Like `mergeWith`, and also returns a hierarchical diff of the keys that were added or
|
|
6
|
+
* updated.
|
|
4
7
|
*
|
|
5
|
-
* @
|
|
6
|
-
* @param
|
|
7
|
-
* @param source - A single source object or an array of objects to be merged into the object.
|
|
8
|
+
* @param target - The destination object. It is not mutated.
|
|
9
|
+
* @param source - A single source object or an array of objects to be merged into `target`.
|
|
8
10
|
* @param customizer - The function to customize assigned values.
|
|
9
|
-
* @returns
|
|
11
|
+
* @returns The merged result and a hierarchical diff object.
|
|
10
12
|
* @example
|
|
11
13
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* return objValue.concat(srcValue);
|
|
15
|
-
* }
|
|
16
|
-
* }
|
|
17
|
-
*
|
|
18
|
-
* var object = {
|
|
19
|
-
* 'fruits': ['apple'],
|
|
20
|
-
* 'vegetables': ['beet']
|
|
21
|
-
* };
|
|
22
|
-
*
|
|
23
|
-
* var other = {
|
|
24
|
-
* 'fruits': ['banana'],
|
|
25
|
-
* 'vegetables': ['carrot'],
|
|
26
|
-
* 'grains': ['wheat']
|
|
27
|
-
* };
|
|
28
|
-
*
|
|
29
|
-
* const { result, diff } = mergeWithDiff({ target: object, source: other, customizer });
|
|
30
|
-
* // result => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'], 'grains': ['wheat'] }
|
|
14
|
+
* const { result, diff } = mergeWithDiff({ a: 1, b: { c: 2 } }, { b: { c: 3 }, d: 4 });
|
|
15
|
+
* // result => { a: 1, b: { c: 3 }, d: 4 }
|
|
31
16
|
* // diff => {
|
|
32
17
|
* // children: {
|
|
33
|
-
* //
|
|
34
|
-
* //
|
|
35
|
-
* //
|
|
18
|
+
* // b: {
|
|
19
|
+
* // type: 'updated', value: { c: 3 }, oldValue: { c: 2 },
|
|
20
|
+
* // children: { c: { type: 'updated', value: 3, oldValue: 2, children: {} } }
|
|
21
|
+
* // },
|
|
22
|
+
* // d: { type: 'added', value: 4, children: {} }
|
|
36
23
|
* // }
|
|
37
24
|
* // }
|
|
38
25
|
*/
|
|
39
|
-
import { cleanupDiffTree, createMergeCore } from './mergeWithCore';
|
|
40
|
-
import type { DiffNode, MergeWithCustomizer } from './mergeWithCore';
|
|
41
|
-
|
|
42
26
|
export function mergeWithDiff<T extends object>(
|
|
43
27
|
target: T,
|
|
44
28
|
source: object | object[],
|
|
@@ -47,7 +31,5 @@ export function mergeWithDiff<T extends object>(
|
|
|
47
31
|
const mergeCore = createMergeCore<T>({ trackDiff: true });
|
|
48
32
|
const { result, diff } = mergeCore({ target, source, customizer });
|
|
49
33
|
|
|
50
|
-
// Clean up the diff tree to remove empty nodes
|
|
51
|
-
|
|
52
34
|
return { result, diff: cleanupDiffTree(diff ?? { children: {} }) || { children: {} } };
|
|
53
35
|
}
|
package/src/utils/objectPath.ts
CHANGED
|
@@ -1,52 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Dot-path access over
|
|
2
|
+
* Dot-path access over plain-object trees. `hasPath` tells an explicit `undefined` from an absent
|
|
3
|
+
* key, which `getPath` cannot.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
* patch may carry an explicit `undefined` — `{ messagePaginator: { initialCursor: undefined } }` — and a
|
|
6
|
-
* caller that has to tell that apart from an absent key needs {@link hasPath}, since both read back as
|
|
7
|
-
* `undefined`. That distinction is the whole reason the construction-only diagnostic in
|
|
8
|
-
* `InstanceConfigurationRegistry` can report a late registration at all.
|
|
9
|
-
*
|
|
10
|
-
* **Descends into plain objects only**, deliberately. A configuration tree holds class instances
|
|
11
|
-
* (`itemIndex`), functions and arrays as leaf *values*, and walking into their internals would be both
|
|
12
|
-
* meaningless and slow — `hasPath(config, 'messagePaginator.initialCursor')` must not start indexing an
|
|
13
|
-
* `ItemIndex`.
|
|
14
|
-
*
|
|
15
|
-
* **Three other dot-path walkers exist in this package and none is a drop-in replacement**, which is worth
|
|
16
|
-
* knowing before adding a fourth:
|
|
17
|
-
*
|
|
18
|
-
* - `get` in `src/utils.ts` (module-private, backs `uniqBy`) returns `undefined` for a missing path *and* for
|
|
19
|
-
* a present-but-undefined one, so it cannot express `hasPath`. It also descends on
|
|
20
|
-
* `typeof acc === 'object'`, which includes arrays and class instances.
|
|
21
|
-
* - `resolveDotPathValue` in `src/pagination/utility.normalization.ts` (backs the filter compiler)
|
|
22
|
-
* short-circuits on any falsy intermediate value, so `''.length` resolves to `undefined` rather than `0`.
|
|
23
|
-
* Its declared return type is `unknown[]` while it returns `unknown`.
|
|
24
|
-
* - `examples/vite`'s Configuration tab carries a segment-array variant identical in behaviour to this one.
|
|
25
|
-
*
|
|
26
|
-
* Consolidating those is a separate change: two of them are load-bearing for unrelated subsystems, and the
|
|
27
|
-
* filter compiler's falsy short-circuit is a behaviour difference rather than a refactor.
|
|
5
|
+
* Descends into plain objects only: arrays, class instances and functions are leaf values.
|
|
28
6
|
*
|
|
29
7
|
* @internal
|
|
30
8
|
*/
|
|
31
9
|
|
|
32
|
-
/**
|
|
33
|
-
* A record this module is willing to walk into: an object literal or `Object.create(null)`, and nothing
|
|
34
|
-
* else. Arrays, `Date`s, `RegExp`s and class instances are configuration *values*, not interiors.
|
|
35
|
-
*
|
|
36
|
-
* The prototype check is what makes that true. A `typeof value === 'object' && !Array.isArray(value)` test —
|
|
37
|
-
* which is what this and the three sibling walkers all used — happily descends into a class instance, so
|
|
38
|
-
* `hasPath(config, 'itemIndex.length')` answered `true` for a path that is not configuration at all.
|
|
39
|
-
*/
|
|
10
|
+
/** An object literal or `Object.create(null)`. Arrays, Dates and class instances are leaves. */
|
|
40
11
|
export const isWalkableRecord = (value: unknown): value is Record<string, unknown> => {
|
|
41
12
|
if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;
|
|
42
13
|
const prototype = Object.getPrototypeOf(value);
|
|
43
14
|
return prototype === Object.prototype || prototype === null;
|
|
44
15
|
};
|
|
45
16
|
|
|
46
|
-
/**
|
|
47
|
-
* Whether a dot-path is present. A key explicitly set to `undefined` counts as present — that is the point
|
|
48
|
-
* of having this alongside {@link getPath}.
|
|
49
|
-
*/
|
|
17
|
+
/** Whether a dot-path is present. A key set to `undefined` counts as present. */
|
|
50
18
|
export const hasPath = (source: Record<string, unknown>, path: string): boolean => {
|
|
51
19
|
const [head, ...rest] = path.split('.');
|
|
52
20
|
if (!(head in source)) return false;
|
|
@@ -55,10 +23,7 @@ export const hasPath = (source: Record<string, unknown>, path: string): boolean
|
|
|
55
23
|
return isWalkableRecord(next) ? hasPath(next, rest.join('.')) : false;
|
|
56
24
|
};
|
|
57
25
|
|
|
58
|
-
/**
|
|
59
|
-
* The value at a dot-path, or `undefined` when the path is absent. Pair with {@link hasPath} when the two
|
|
60
|
-
* cases have to be told apart.
|
|
61
|
-
*/
|
|
26
|
+
/** The value at a dot-path, or `undefined` when absent. Use {@link hasPath} to tell them apart. */
|
|
62
27
|
export const getPath = (source: Record<string, unknown>, path: string): unknown => {
|
|
63
28
|
const [head, ...rest] = path.split('.');
|
|
64
29
|
const next = source[head];
|
package/src/utils/retryable.ts
CHANGED
|
@@ -2,7 +2,6 @@ type FunctionToRetry<T = any> = (...functionArguments: any[]) => PromiseLike<T>;
|
|
|
2
2
|
|
|
3
3
|
enum RetryErrorType {
|
|
4
4
|
ABORT,
|
|
5
|
-
ATTEMPT_LIMIT_REACHED,
|
|
6
5
|
}
|
|
7
6
|
|
|
8
7
|
export class RetryError extends Error {
|
|
@@ -10,7 +9,6 @@ export class RetryError extends Error {
|
|
|
10
9
|
|
|
11
10
|
private static errorMap = {
|
|
12
11
|
[RetryErrorType.ABORT]: 'Value changed, retry handler aborted',
|
|
13
|
-
[RetryErrorType.ATTEMPT_LIMIT_REACHED]: 'Reached maximum amount of retry attempts',
|
|
14
12
|
} satisfies Record<RetryErrorType, string>;
|
|
15
13
|
|
|
16
14
|
constructor({ type }: { type: RetryErrorType }) {
|
|
@@ -49,17 +47,14 @@ export type RunWithRetryOptions<T extends FunctionToRetry> = {
|
|
|
49
47
|
};
|
|
50
48
|
|
|
51
49
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
50
|
+
* Wraps `f` so a failed call is retried. Throws the error when it is not retryable, else the last
|
|
51
|
+
* attempt's error once the retries run out. A falsy result counts as a failure and is retried.
|
|
54
52
|
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* - `delayBetweenRetries` - accepts either fixed numeric value or function which provides retry attempt as the argument, expects number as return value
|
|
61
|
-
*
|
|
62
|
-
* - `retryAttempts` - number of attempts to try out before rejecting the promise
|
|
53
|
+
* - `retryAttempts`: retries after the first attempt. Defaults to 3.
|
|
54
|
+
* - `isRetryable`: whether an error is worth retrying. Defaults to always.
|
|
55
|
+
* - `delayBetweenRetries`: ms, or a function of the 0-based retry number.
|
|
56
|
+
* - `didValueChange`: called with the call arguments before each attempt, `true` aborts with a
|
|
57
|
+
* `RetryError`.
|
|
63
58
|
*/
|
|
64
59
|
export const runWithRetry = <T extends FunctionToRetry>(
|
|
65
60
|
f: T,
|
|
@@ -73,10 +68,11 @@ export const runWithRetry = <T extends FunctionToRetry>(
|
|
|
73
68
|
async function retryable(...functionArguments: Parameters<T>) {
|
|
74
69
|
// starting with -1 as first attempt is not considered a retry
|
|
75
70
|
let retryAttempt = -1;
|
|
71
|
+
let error: unknown = null;
|
|
76
72
|
|
|
77
73
|
do {
|
|
78
74
|
let data: Awaited<ReturnType<T>> | null = null;
|
|
79
|
-
|
|
75
|
+
error = null;
|
|
80
76
|
|
|
81
77
|
if (await didValueChange?.(...functionArguments)) {
|
|
82
78
|
throw new RetryError({ type: RetryErrorType.ABORT });
|
|
@@ -113,5 +109,5 @@ export const runWithRetry = <T extends FunctionToRetry>(
|
|
|
113
109
|
}
|
|
114
110
|
} while (retryAttempt < retryAttempts);
|
|
115
111
|
|
|
116
|
-
throw
|
|
112
|
+
throw error;
|
|
117
113
|
};
|
|
@@ -1,40 +1,25 @@
|
|
|
1
1
|
export type ThrottledCallback = (...args: unknown[]) => unknown;
|
|
2
2
|
|
|
3
3
|
export type ThrottleOptions = {
|
|
4
|
-
/** Call on the leading edge
|
|
4
|
+
/** Call on the leading edge. Defaults to `true`. */
|
|
5
5
|
leading?: boolean;
|
|
6
|
-
/** Call once at the end of the window with the latest args
|
|
6
|
+
/** Call once at the end of the window with the latest args. Defaults to `false`. */
|
|
7
7
|
trailing?: boolean;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export type Throttled<T extends unknown[]> = {
|
|
11
|
-
/**
|
|
12
|
-
* The throttled function — call it as often as you like; it invokes `fn` at most once per window
|
|
13
|
-
* (leading and/or trailing per options).
|
|
14
|
-
*/
|
|
11
|
+
/** Invokes `fn` at most once per window (leading and/or trailing, per options). */
|
|
15
12
|
throttledFn: (...args: T) => void;
|
|
16
|
-
/**
|
|
13
|
+
/** Clears a pending trailing invocation without firing it. */
|
|
17
14
|
cancelTimer: () => void;
|
|
18
|
-
/**
|
|
19
|
-
* Fire a pending trailing invocation immediately (with the latest stored args), clearing the timer.
|
|
20
|
-
* No-op when nothing is pending. Use to bypass the throttle delay for updates that must land now.
|
|
21
|
-
*/
|
|
15
|
+
/** Fires a pending trailing invocation now with the latest args. No-op when none is pending. */
|
|
22
16
|
flush: () => void;
|
|
23
17
|
};
|
|
24
18
|
|
|
25
19
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* - `trailing`: remember the latest args/this and fire once when the window closes
|
|
30
|
-
*
|
|
31
|
-
* defaults: `{ leading: true, trailing: false }`
|
|
32
|
-
*
|
|
33
|
-
* Copied verbatim from the Feeds client (`packages/feeds-client/src/utils/throttling/throttle.ts`)
|
|
34
|
-
* and extended with a `flush()` method (the Feeds version only exposes `cancelTimer()`).
|
|
35
|
-
*
|
|
36
|
-
* notes:
|
|
37
|
-
* - make one throttled instance and reuse it; re-creating it resets internal state
|
|
20
|
+
* Runs `fn` at most once per `timeout` ms. `leading` fires when the window opens, `trailing` fires
|
|
21
|
+
* once at its end with the latest args and `this` (see {@link ThrottleOptions}). Create one
|
|
22
|
+
* instance and reuse it: recreating it resets the window. `timeout` defaults to 200.
|
|
38
23
|
*/
|
|
39
24
|
export const throttle = <T extends unknown[]>(
|
|
40
25
|
fn: (...args: T) => void,
|
|
@@ -110,8 +95,7 @@ export const throttle = <T extends unknown[]>(
|
|
|
110
95
|
clearTimeout(timer);
|
|
111
96
|
timer = null;
|
|
112
97
|
}
|
|
113
|
-
//
|
|
114
|
-
// the invocation this cancel was meant to drop.
|
|
98
|
+
// Also drops the stored args, so a later `flush()` cannot refire them.
|
|
115
99
|
storedArgs = null;
|
|
116
100
|
storedThis = null;
|
|
117
101
|
},
|