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
package/dist/cjs/i18n.node.js
DELETED
|
@@ -1,1160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/i18n/index.ts
|
|
31
|
-
var i18n_exports = {};
|
|
32
|
-
__export(i18n_exports, {
|
|
33
|
-
A11Y_CALENDAR_FORMATS: () => A11Y_CALENDAR_FORMATS,
|
|
34
|
-
DEFAULT_LANGUAGE: () => DEFAULT_LANGUAGE,
|
|
35
|
-
LANGUAGE_NAMES: () => LANGUAGE_NAMES,
|
|
36
|
-
RELATIVE_TIME_CATALOG: () => RELATIVE_TIME_CATALOG,
|
|
37
|
-
Streami18n: () => Streami18n,
|
|
38
|
-
TranslationBuilder: () => TranslationBuilder,
|
|
39
|
-
TranslationStore: () => TranslationStore,
|
|
40
|
-
TranslationTopic: () => TranslationTopic,
|
|
41
|
-
addOrUpdateDayjsLocale: () => addOrUpdateDayjsLocale,
|
|
42
|
-
asDynamicKey: () => asDynamicKey,
|
|
43
|
-
createDefaultTranslatorFunction: () => createDefaultTranslatorFunction,
|
|
44
|
-
dayjsLocaleExists: () => dayjsLocaleExists,
|
|
45
|
-
defaultDateTimeParser: () => defaultDateTimeParser,
|
|
46
|
-
ensureDayjsPlugins: () => ensureDayjsPlugins,
|
|
47
|
-
getCalendarDateStringForA11y: () => getCalendarDateStringForA11y,
|
|
48
|
-
getDateString: () => getDateString,
|
|
49
|
-
getDateStringForA11y: () => getDateStringForA11y,
|
|
50
|
-
getDefaultDateTimeParserModule: () => getDefaultDateTimeParserModule,
|
|
51
|
-
guardMissingKeyHandler: () => guardMissingKeyHandler,
|
|
52
|
-
isDate: () => isDate,
|
|
53
|
-
isDayOrMoment: () => isDayOrMoment,
|
|
54
|
-
isDayjsLike: () => isDayjsLike,
|
|
55
|
-
isNumberOrString: () => isNumberOrString,
|
|
56
|
-
languageNameDefaults: () => languageNameDefaults,
|
|
57
|
-
predefinedFormatters: () => predefinedFormatters,
|
|
58
|
-
supportsTimezone: () => supportsTimezone
|
|
59
|
-
});
|
|
60
|
-
module.exports = __toCommonJS(i18n_exports);
|
|
61
|
-
|
|
62
|
-
// src/i18n/dayjs.ts
|
|
63
|
-
var import_dayjs = __toESM(require("dayjs"));
|
|
64
|
-
var import_calendar = __toESM(require("dayjs/plugin/calendar.js"));
|
|
65
|
-
var import_duration = __toESM(require("dayjs/plugin/duration.js"));
|
|
66
|
-
var import_localeData = __toESM(require("dayjs/plugin/localeData.js"));
|
|
67
|
-
var import_localizedFormat = __toESM(require("dayjs/plugin/localizedFormat.js"));
|
|
68
|
-
var import_relativeTime = __toESM(require("dayjs/plugin/relativeTime.js"));
|
|
69
|
-
var import_timezone = __toESM(require("dayjs/plugin/timezone.js"));
|
|
70
|
-
var import_updateLocale = __toESM(require("dayjs/plugin/updateLocale.js"));
|
|
71
|
-
var import_utc = __toESM(require("dayjs/plugin/utc.js"));
|
|
72
|
-
var ownDayjs = () => import_dayjs.default;
|
|
73
|
-
var EN_LOCALE_FALLBACK = {
|
|
74
|
-
/**
|
|
75
|
-
* `formats` and `relativeTime` are empty on purpose, and are not removable: `Dayjs.locale()` takes an
|
|
76
|
-
* `ILocale`, which declares both as required, so omitting them is a type error. Empty means "inherit
|
|
77
|
-
* dayjs's own defaults", which is the intent.
|
|
78
|
-
*/
|
|
79
|
-
formats: {},
|
|
80
|
-
relativeTime: {},
|
|
81
|
-
months: [
|
|
82
|
-
"January",
|
|
83
|
-
"February",
|
|
84
|
-
"March",
|
|
85
|
-
"April",
|
|
86
|
-
"May",
|
|
87
|
-
"June",
|
|
88
|
-
"July",
|
|
89
|
-
"August",
|
|
90
|
-
"September",
|
|
91
|
-
"October",
|
|
92
|
-
"November",
|
|
93
|
-
"December"
|
|
94
|
-
],
|
|
95
|
-
weekdays: [
|
|
96
|
-
"Sunday",
|
|
97
|
-
"Monday",
|
|
98
|
-
"Tuesday",
|
|
99
|
-
"Wednesday",
|
|
100
|
-
"Thursday",
|
|
101
|
-
"Friday",
|
|
102
|
-
"Saturday"
|
|
103
|
-
]
|
|
104
|
-
};
|
|
105
|
-
var REQUIRED_PLUGINS = [
|
|
106
|
-
import_updateLocale.default,
|
|
107
|
-
import_utc.default,
|
|
108
|
-
import_timezone.default,
|
|
109
|
-
import_localizedFormat.default,
|
|
110
|
-
import_calendar.default,
|
|
111
|
-
import_localeData.default,
|
|
112
|
-
import_relativeTime.default,
|
|
113
|
-
import_duration.default
|
|
114
|
-
];
|
|
115
|
-
var extendedModules = /* @__PURE__ */ new WeakSet();
|
|
116
|
-
var ensureDayjsPlugins = (module2 = import_dayjs.default) => {
|
|
117
|
-
if (extendedModules.has(module2)) return;
|
|
118
|
-
if (typeof module2.extend !== "function") return;
|
|
119
|
-
for (const plugin of REQUIRED_PLUGINS) module2.extend(plugin);
|
|
120
|
-
extendedModules.add(module2);
|
|
121
|
-
};
|
|
122
|
-
var defaultDateTimeParser = (input) => {
|
|
123
|
-
ensureDayjsPlugins();
|
|
124
|
-
return (0, import_dayjs.default)(input);
|
|
125
|
-
};
|
|
126
|
-
var getDefaultDateTimeParserModule = () => {
|
|
127
|
-
ensureDayjsPlugins();
|
|
128
|
-
return import_dayjs.default;
|
|
129
|
-
};
|
|
130
|
-
var addOrUpdateDayjsLocale = (language, config, module2 = ownDayjs()) => {
|
|
131
|
-
ensureDayjsPlugins(module2);
|
|
132
|
-
if (dayjsLocaleExists(language, module2)) {
|
|
133
|
-
module2.updateLocale?.(language, { ...config });
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
module2.locale?.({ name: language, ...EN_LOCALE_FALLBACK, ...config }, void 0, true);
|
|
137
|
-
};
|
|
138
|
-
var dayjsLocaleExists = (language, module2 = ownDayjs()) => Object.keys(module2.Ls ?? {}).includes(language);
|
|
139
|
-
var isDayjsLike = (parser) => typeof parser === "function" && typeof parser.extend === "function";
|
|
140
|
-
var supportsTimezone = (parser) => typeof parser === "function" && typeof parser.tz === "function";
|
|
141
|
-
var isDate = (value) => value instanceof Date;
|
|
142
|
-
var isNumberOrString = (value) => typeof value === "number" || typeof value === "string";
|
|
143
|
-
var isDayOrMoment = (value) => typeof value === "object" && value !== null && !(value instanceof Date) && typeof value.format === "function";
|
|
144
|
-
|
|
145
|
-
// src/i18n/translator.ts
|
|
146
|
-
var asDynamicKey = (key) => key;
|
|
147
|
-
var INTERPOLATION_PATTERN = /\{\{\s*([\w.]+)\s*\}\}/g;
|
|
148
|
-
var interpolate = (copy, values) => copy.replace(
|
|
149
|
-
INTERPOLATION_PATTERN,
|
|
150
|
-
(whole, name) => values[name] === void 0 ? whole : String(values[name])
|
|
151
|
-
);
|
|
152
|
-
var createDefaultTranslatorFunction = () => ((key, defaultValueOrOptions, maybeOptions) => {
|
|
153
|
-
if (typeof defaultValueOrOptions === "string") {
|
|
154
|
-
return maybeOptions ? interpolate(defaultValueOrOptions, maybeOptions) : defaultValueOrOptions;
|
|
155
|
-
}
|
|
156
|
-
const options = defaultValueOrOptions ?? maybeOptions;
|
|
157
|
-
if (!options) return key;
|
|
158
|
-
const resolved = (options.count === 1 ? options.defaultValue_one : options.defaultValue_other) ?? options.defaultValue;
|
|
159
|
-
return typeof resolved === "string" ? interpolate(resolved, options) : key;
|
|
160
|
-
});
|
|
161
|
-
var guardMissingKeyHandler = (handler) => (key, defaultValue) => typeof defaultValue === "string" ? defaultValue : handler(key, defaultValue);
|
|
162
|
-
|
|
163
|
-
// src/i18n/formatters.ts
|
|
164
|
-
var RELATIVE_TIME_CATALOG = {
|
|
165
|
-
"relativeTime.daysAgo_one": "{{ count }}d ago",
|
|
166
|
-
"relativeTime.daysAgo_other": "{{ count }}d ago",
|
|
167
|
-
"relativeTime.today": "Today",
|
|
168
|
-
"relativeTime.weeksAgo_one": "{{ count }}w ago",
|
|
169
|
-
"relativeTime.weeksAgo_other": "{{ count }}w ago",
|
|
170
|
-
"relativeTime.yesterday": "Yesterday"
|
|
171
|
-
};
|
|
172
|
-
var DEFAULT_RELATIVE_COMPACT_MAX_DAYS = 6;
|
|
173
|
-
var DEFAULT_RELATIVE_COMPACT_MAX_WEEKS = 3;
|
|
174
|
-
var isUnparseableDateString = (value) => Number.isNaN(Date.parse(value));
|
|
175
|
-
var asWeekRounding = (value) => value === "ceil" || value === true ? "ceil" : "floor";
|
|
176
|
-
var asNumber = (value, fallback) => {
|
|
177
|
-
const parsed = typeof value === "number" ? value : Number.parseInt(String(value ?? ""), 10);
|
|
178
|
-
return Number.isFinite(parsed) ? parsed : fallback;
|
|
179
|
-
};
|
|
180
|
-
var parseCalendarFormats = (value, logger) => {
|
|
181
|
-
if (!value) return void 0;
|
|
182
|
-
if (typeof value !== "string") return value;
|
|
183
|
-
try {
|
|
184
|
-
return JSON.parse(value);
|
|
185
|
-
} catch (error) {
|
|
186
|
-
logger(
|
|
187
|
-
`Streami18n: calendarFormats is not valid JSON, ignoring it: ${value} (${error instanceof Error ? error.message : String(error)})`
|
|
188
|
-
);
|
|
189
|
-
return void 0;
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
var relativeCompactDateString = ({
|
|
193
|
-
maxDays,
|
|
194
|
-
maxWeeks,
|
|
195
|
-
tDateTimeParser,
|
|
196
|
-
timestamp,
|
|
197
|
-
translate,
|
|
198
|
-
weekRounding
|
|
199
|
-
}) => {
|
|
200
|
-
const parsed = tDateTimeParser(timestamp);
|
|
201
|
-
if (!isDayOrMoment(parsed)) return null;
|
|
202
|
-
const now = tDateTimeParser(/* @__PURE__ */ new Date());
|
|
203
|
-
if (!isDayOrMoment(now)) return null;
|
|
204
|
-
const daysAgo = now.startOf("day").diff(parsed.startOf("day"), "day");
|
|
205
|
-
if (daysAgo < 0) return parsed.format("DD/MM/YY");
|
|
206
|
-
if (daysAgo === 0)
|
|
207
|
-
return translate("relativeTime.today", RELATIVE_TIME_CATALOG["relativeTime.today"]);
|
|
208
|
-
if (daysAgo === 1)
|
|
209
|
-
return translate(
|
|
210
|
-
"relativeTime.yesterday",
|
|
211
|
-
RELATIVE_TIME_CATALOG["relativeTime.yesterday"]
|
|
212
|
-
);
|
|
213
|
-
if (daysAgo <= maxDays) {
|
|
214
|
-
return translate("relativeTime.daysAgo", {
|
|
215
|
-
count: daysAgo,
|
|
216
|
-
defaultValue_one: RELATIVE_TIME_CATALOG["relativeTime.daysAgo_one"],
|
|
217
|
-
defaultValue_other: RELATIVE_TIME_CATALOG["relativeTime.daysAgo_other"]
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
const weeksAgo = weekRounding === "ceil" ? Math.ceil(daysAgo / 7) : Math.floor(daysAgo / 7);
|
|
221
|
-
const withinWindow = weekRounding === "ceil" ? daysAgo <= maxWeeks * 7 : weeksAgo <= maxWeeks;
|
|
222
|
-
if (maxWeeks > 0 && daysAgo >= 7 && withinWindow) {
|
|
223
|
-
return translate("relativeTime.weeksAgo", {
|
|
224
|
-
count: weeksAgo,
|
|
225
|
-
defaultValue_one: RELATIVE_TIME_CATALOG["relativeTime.weeksAgo_one"],
|
|
226
|
-
defaultValue_other: RELATIVE_TIME_CATALOG["relativeTime.weeksAgo_other"]
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
return parsed.format("DD/MM/YY");
|
|
230
|
-
};
|
|
231
|
-
var timestampFormatter = ({ logger, tDateTimeParser, translate }) => (value, _lng, options) => {
|
|
232
|
-
const {
|
|
233
|
-
calendar: calendar2,
|
|
234
|
-
calendarFormats,
|
|
235
|
-
format,
|
|
236
|
-
relativeCompact,
|
|
237
|
-
relativeCompactMaxDays,
|
|
238
|
-
relativeCompactMaxWeeks,
|
|
239
|
-
relativeCompactWeekRounding
|
|
240
|
-
} = options;
|
|
241
|
-
if (value === null || value === void 0) return "";
|
|
242
|
-
if (typeof value === "string" && isUnparseableDateString(value)) return "";
|
|
243
|
-
if (relativeCompact) {
|
|
244
|
-
const relative = relativeCompactDateString({
|
|
245
|
-
maxDays: asNumber(relativeCompactMaxDays, DEFAULT_RELATIVE_COMPACT_MAX_DAYS),
|
|
246
|
-
maxWeeks: asNumber(relativeCompactMaxWeeks, DEFAULT_RELATIVE_COMPACT_MAX_WEEKS),
|
|
247
|
-
tDateTimeParser,
|
|
248
|
-
timestamp: value,
|
|
249
|
-
translate,
|
|
250
|
-
weekRounding: asWeekRounding(relativeCompactWeekRounding)
|
|
251
|
-
});
|
|
252
|
-
if (relative !== null) return relative;
|
|
253
|
-
}
|
|
254
|
-
const parsed = tDateTimeParser(value);
|
|
255
|
-
if (isDayOrMoment(parsed)) {
|
|
256
|
-
if (calendar2 && typeof parsed.calendar === "function") {
|
|
257
|
-
return parsed.calendar(void 0, parseCalendarFormats(calendarFormats, logger));
|
|
258
|
-
}
|
|
259
|
-
return parsed.format(format);
|
|
260
|
-
}
|
|
261
|
-
if (isDate(parsed)) return parsed.toDateString();
|
|
262
|
-
if (isNumberOrString(parsed)) return String(parsed);
|
|
263
|
-
return "";
|
|
264
|
-
};
|
|
265
|
-
var durationFormatter = ({ dateTimeParser }) => (value, _lng, options) => {
|
|
266
|
-
const { format, withSuffix } = options;
|
|
267
|
-
if (typeof dateTimeParser.duration !== "function") return String(value);
|
|
268
|
-
const duration2 = dateTimeParser.duration(value);
|
|
269
|
-
if (format && typeof duration2.format === "function") return duration2.format(format);
|
|
270
|
-
return duration2.humanize(Boolean(withSuffix));
|
|
271
|
-
};
|
|
272
|
-
var fromNowFormatter = ({ tDateTimeParser }) => (value, _lng, options) => {
|
|
273
|
-
if (value === null || value === void 0) return "";
|
|
274
|
-
const parsed = tDateTimeParser(value);
|
|
275
|
-
if (!isDayOrMoment(parsed) || typeof parsed.fromNow !== "function") return "";
|
|
276
|
-
return parsed.fromNow(
|
|
277
|
-
Boolean(options.withoutSuffix)
|
|
278
|
-
);
|
|
279
|
-
};
|
|
280
|
-
var predefinedFormatters = {
|
|
281
|
-
durationFormatter,
|
|
282
|
-
fromNowFormatter,
|
|
283
|
-
timestampFormatter
|
|
284
|
-
};
|
|
285
|
-
var getDateString = ({
|
|
286
|
-
calendar: calendar2,
|
|
287
|
-
calendarFormats,
|
|
288
|
-
format,
|
|
289
|
-
formatDate,
|
|
290
|
-
messageCreatedAt,
|
|
291
|
-
relativeCompact,
|
|
292
|
-
relativeCompactMaxDays,
|
|
293
|
-
relativeCompactMaxWeeks,
|
|
294
|
-
relativeCompactWeekRounding,
|
|
295
|
-
t,
|
|
296
|
-
tDateTimeParser,
|
|
297
|
-
timestampTranslationKey
|
|
298
|
-
}) => {
|
|
299
|
-
if (!messageCreatedAt || typeof messageCreatedAt === "string" && isUnparseableDateString(messageCreatedAt)) {
|
|
300
|
-
return null;
|
|
301
|
-
}
|
|
302
|
-
if (formatDate) return formatDate(new Date(messageCreatedAt));
|
|
303
|
-
if (relativeCompact && t && tDateTimeParser) {
|
|
304
|
-
const relative = relativeCompactDateString({
|
|
305
|
-
maxDays: asNumber(relativeCompactMaxDays, DEFAULT_RELATIVE_COMPACT_MAX_DAYS),
|
|
306
|
-
maxWeeks: asNumber(relativeCompactMaxWeeks, DEFAULT_RELATIVE_COMPACT_MAX_WEEKS),
|
|
307
|
-
tDateTimeParser,
|
|
308
|
-
timestamp: messageCreatedAt,
|
|
309
|
-
translate: t,
|
|
310
|
-
weekRounding: asWeekRounding(relativeCompactWeekRounding)
|
|
311
|
-
});
|
|
312
|
-
if (relative) return relative;
|
|
313
|
-
}
|
|
314
|
-
if (t && timestampTranslationKey) {
|
|
315
|
-
const overrides = {};
|
|
316
|
-
const supplied = {
|
|
317
|
-
calendar: calendar2,
|
|
318
|
-
calendarFormats,
|
|
319
|
-
format,
|
|
320
|
-
relativeCompact,
|
|
321
|
-
relativeCompactMaxDays,
|
|
322
|
-
relativeCompactMaxWeeks,
|
|
323
|
-
relativeCompactWeekRounding
|
|
324
|
-
};
|
|
325
|
-
for (const [key, value] of Object.entries(supplied)) {
|
|
326
|
-
if (value !== void 0) overrides[key] = value;
|
|
327
|
-
}
|
|
328
|
-
const translated = t(asDynamicKey(timestampTranslationKey), {
|
|
329
|
-
...overrides,
|
|
330
|
-
// A `Date`, not the raw value. Integrators override a `timestamp.*` key with their own
|
|
331
|
-
// formatter, and those read `options.timestamp` expecting a Date — passing the string through
|
|
332
|
-
// breaks them with `timestamp.toISOString is not a function`.
|
|
333
|
-
timestamp: new Date(messageCreatedAt)
|
|
334
|
-
});
|
|
335
|
-
if (translated !== timestampTranslationKey) return translated;
|
|
336
|
-
}
|
|
337
|
-
if (!tDateTimeParser) return null;
|
|
338
|
-
const parsed = tDateTimeParser(messageCreatedAt);
|
|
339
|
-
if (isDayOrMoment(parsed)) {
|
|
340
|
-
if (calendar2 && typeof parsed.calendar === "function") {
|
|
341
|
-
return parsed.calendar(
|
|
342
|
-
void 0,
|
|
343
|
-
typeof calendarFormats === "string" ? void 0 : calendarFormats
|
|
344
|
-
);
|
|
345
|
-
}
|
|
346
|
-
return parsed.format(format);
|
|
347
|
-
}
|
|
348
|
-
if (isDate(parsed)) return parsed.toDateString();
|
|
349
|
-
if (isNumberOrString(parsed)) return parsed;
|
|
350
|
-
return null;
|
|
351
|
-
};
|
|
352
|
-
var getDateStringForA11y = ({
|
|
353
|
-
messageCreatedAt,
|
|
354
|
-
t,
|
|
355
|
-
tDateTimeParser,
|
|
356
|
-
timestampTranslationKey
|
|
357
|
-
}) => getDateString({
|
|
358
|
-
calendar: false,
|
|
359
|
-
format: "LLLL",
|
|
360
|
-
messageCreatedAt,
|
|
361
|
-
t,
|
|
362
|
-
tDateTimeParser,
|
|
363
|
-
timestampTranslationKey
|
|
364
|
-
});
|
|
365
|
-
var A11Y_CALENDAR_FORMATS = {
|
|
366
|
-
en: {
|
|
367
|
-
lastDay: "[Yesterday]",
|
|
368
|
-
lastWeek: "dddd",
|
|
369
|
-
nextDay: "[Tomorrow]",
|
|
370
|
-
nextWeek: "dddd [at] LT",
|
|
371
|
-
sameDay: "[Today]",
|
|
372
|
-
sameElse: "L"
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
var getCalendarDateStringForA11y = ({
|
|
376
|
-
calendarFormatOverrides,
|
|
377
|
-
calendarFormats = A11Y_CALENDAR_FORMATS,
|
|
378
|
-
messageCreatedAt,
|
|
379
|
-
tDateTimeParser,
|
|
380
|
-
userLanguage
|
|
381
|
-
}) => {
|
|
382
|
-
if (!messageCreatedAt || typeof messageCreatedAt === "string" && isUnparseableDateString(messageCreatedAt) || !tDateTimeParser) {
|
|
383
|
-
return void 0;
|
|
384
|
-
}
|
|
385
|
-
const parsed = tDateTimeParser(messageCreatedAt);
|
|
386
|
-
if (!isDayOrMoment(parsed) || !parsed.calendar) return void 0;
|
|
387
|
-
const localeFormats = userLanguage && calendarFormats[userLanguage] || calendarFormats.en;
|
|
388
|
-
return parsed.calendar(void 0, {
|
|
389
|
-
...localeFormats,
|
|
390
|
-
sameElse: "LL",
|
|
391
|
-
...calendarFormatOverrides
|
|
392
|
-
});
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
// src/i18n/languageNames.ts
|
|
396
|
-
var LANGUAGE_NAMES = {
|
|
397
|
-
af: "Afrikaans",
|
|
398
|
-
am: "Amharic",
|
|
399
|
-
ar: "Arabic",
|
|
400
|
-
az: "Azerbaijani",
|
|
401
|
-
bg: "Bulgarian",
|
|
402
|
-
bn: "Bengali",
|
|
403
|
-
bs: "Bosnian",
|
|
404
|
-
cs: "Czech",
|
|
405
|
-
da: "Danish",
|
|
406
|
-
de: "German",
|
|
407
|
-
el: "Greek",
|
|
408
|
-
en: "English",
|
|
409
|
-
es: "Spanish",
|
|
410
|
-
"es-MX": "Spanish (Mexico)",
|
|
411
|
-
et: "Estonian",
|
|
412
|
-
fa: "Persian",
|
|
413
|
-
"fa-AF": "Dari",
|
|
414
|
-
fi: "Finnish",
|
|
415
|
-
fr: "French",
|
|
416
|
-
"fr-CA": "French (Canada)",
|
|
417
|
-
ha: "Hausa",
|
|
418
|
-
he: "Hebrew",
|
|
419
|
-
hi: "Hindi",
|
|
420
|
-
hr: "Croatian",
|
|
421
|
-
ht: "Haitian Creole",
|
|
422
|
-
hu: "Hungarian",
|
|
423
|
-
id: "Indonesian",
|
|
424
|
-
it: "Italian",
|
|
425
|
-
ja: "Japanese",
|
|
426
|
-
ka: "Georgian",
|
|
427
|
-
ko: "Korean",
|
|
428
|
-
lt: "Lithuanian",
|
|
429
|
-
lv: "Latvian",
|
|
430
|
-
ms: "Malay",
|
|
431
|
-
nl: "Dutch",
|
|
432
|
-
no: "Norwegian",
|
|
433
|
-
pl: "Polish",
|
|
434
|
-
ps: "Pashto",
|
|
435
|
-
pt: "Portuguese",
|
|
436
|
-
ro: "Romanian",
|
|
437
|
-
ru: "Russian",
|
|
438
|
-
sk: "Slovak",
|
|
439
|
-
sl: "Slovenian",
|
|
440
|
-
so: "Somali",
|
|
441
|
-
sq: "Albanian",
|
|
442
|
-
sr: "Serbian",
|
|
443
|
-
sv: "Swedish",
|
|
444
|
-
sw: "Swahili",
|
|
445
|
-
ta: "Tamil",
|
|
446
|
-
th: "Thai",
|
|
447
|
-
tl: "Tagalog",
|
|
448
|
-
tr: "Turkish",
|
|
449
|
-
uk: "Ukrainian",
|
|
450
|
-
ur: "Urdu",
|
|
451
|
-
vi: "Vietnamese",
|
|
452
|
-
zh: "Chinese (Simplified)",
|
|
453
|
-
"zh-TW": "Chinese (Traditional)"
|
|
454
|
-
};
|
|
455
|
-
var languageNameDefaults = Object.fromEntries(
|
|
456
|
-
Object.entries(LANGUAGE_NAMES).map(([code, name]) => [`language.${code}`, name])
|
|
457
|
-
);
|
|
458
|
-
|
|
459
|
-
// src/i18n/Streami18n.ts
|
|
460
|
-
var import_i18next = __toESM(require("i18next"));
|
|
461
|
-
|
|
462
|
-
// src/store.ts
|
|
463
|
-
var isPatch = (value) => typeof value === "function";
|
|
464
|
-
var noop = () => {
|
|
465
|
-
};
|
|
466
|
-
var StateStore = class {
|
|
467
|
-
constructor(value) {
|
|
468
|
-
this.value = value;
|
|
469
|
-
this.handlers = /* @__PURE__ */ new Set();
|
|
470
|
-
this.preprocessors = /* @__PURE__ */ new Set();
|
|
471
|
-
this.partialNext = (partial) => this.next((current) => ({ ...current, ...partial }));
|
|
472
|
-
this.subscribeWithSelector = (selector, handler) => {
|
|
473
|
-
let previouslySelectedValues;
|
|
474
|
-
const wrappedHandler = (nextValue) => {
|
|
475
|
-
const newlySelectedValues = selector(nextValue);
|
|
476
|
-
let hasUpdatedValues = typeof previouslySelectedValues === "undefined";
|
|
477
|
-
for (const key in previouslySelectedValues) {
|
|
478
|
-
if (previouslySelectedValues[key] === newlySelectedValues[key]) continue;
|
|
479
|
-
hasUpdatedValues = true;
|
|
480
|
-
break;
|
|
481
|
-
}
|
|
482
|
-
if (!hasUpdatedValues) return;
|
|
483
|
-
const previouslySelectedValuesCopy = previouslySelectedValues;
|
|
484
|
-
previouslySelectedValues = newlySelectedValues;
|
|
485
|
-
handler(newlySelectedValues, previouslySelectedValuesCopy);
|
|
486
|
-
};
|
|
487
|
-
return this.subscribe(wrappedHandler);
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
/**
|
|
491
|
-
* Allows merging two stores only if their keys differ otherwise there's no way to ensure the data type stability.
|
|
492
|
-
*
|
|
493
|
-
* @experimental
|
|
494
|
-
* This method is experimental and may change in future versions.
|
|
495
|
-
*/
|
|
496
|
-
merge(stateStore) {
|
|
497
|
-
return new MergedStateStore({
|
|
498
|
-
original: this,
|
|
499
|
-
merged: stateStore
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
next(newValueOrPatch) {
|
|
503
|
-
const newValue = isPatch(newValueOrPatch) ? newValueOrPatch(this.value) : newValueOrPatch;
|
|
504
|
-
if (newValue === this.value) return;
|
|
505
|
-
this.preprocessors.forEach((preprocessor) => preprocessor(newValue, this.value));
|
|
506
|
-
const oldValue = this.value;
|
|
507
|
-
this.value = newValue;
|
|
508
|
-
this.handlers.forEach((handler) => handler(this.value, oldValue));
|
|
509
|
-
}
|
|
510
|
-
getLatestValue() {
|
|
511
|
-
return this.value;
|
|
512
|
-
}
|
|
513
|
-
subscribe(handler) {
|
|
514
|
-
handler(this.value, void 0);
|
|
515
|
-
this.handlers.add(handler);
|
|
516
|
-
return () => {
|
|
517
|
-
this.handlers.delete(handler);
|
|
518
|
-
};
|
|
519
|
-
}
|
|
520
|
-
/**
|
|
521
|
-
* Registers a preprocessor function that will be called before the state is updated.
|
|
522
|
-
*
|
|
523
|
-
* Preprocessors are invoked with the new and previous values whenever `next` or `partialNext` methods
|
|
524
|
-
* are called, allowing you to mutate or react to the new value before it is set. Preprocessors run in the
|
|
525
|
-
* order they were registered.
|
|
526
|
-
*
|
|
527
|
-
* @example
|
|
528
|
-
* ```ts
|
|
529
|
-
* const store = new StateStore<{ count: number; isMaxValue: bool; }>({ count: 0, isMaxValue: false });
|
|
530
|
-
*
|
|
531
|
-
* store.addPreprocessor((nextValue, prevValue) => {
|
|
532
|
-
* if (nextValue.count > 10) {
|
|
533
|
-
* nextValue.count = 10; // Clamp the value to a maximum of 10
|
|
534
|
-
* }
|
|
535
|
-
*
|
|
536
|
-
* if (nextValue.count === 10) {
|
|
537
|
-
* nextValue.isMaxValue = true; // Set isMaxValue to true if count is 10
|
|
538
|
-
* } else {
|
|
539
|
-
* nextValue.isMaxValue = false; // Reset isMaxValue otherwise
|
|
540
|
-
* }
|
|
541
|
-
* });
|
|
542
|
-
*
|
|
543
|
-
* store.partialNext({ count: 15 });
|
|
544
|
-
*
|
|
545
|
-
* store.getLatestValue(); // { count: 10, isMaxValue: true }
|
|
546
|
-
*
|
|
547
|
-
* store.partialNext({ count: 5 });
|
|
548
|
-
*
|
|
549
|
-
* store.getLatestValue(); // { count: 5, isMaxValue: false }
|
|
550
|
-
* ```
|
|
551
|
-
*
|
|
552
|
-
* @param preprocessor - The function to be called with the next and previous values before the state is updated.
|
|
553
|
-
* @returns A `RemovePreprocessor` function that removes the preprocessor when called.
|
|
554
|
-
*/
|
|
555
|
-
addPreprocessor(preprocessor) {
|
|
556
|
-
this.preprocessors.add(preprocessor);
|
|
557
|
-
return () => {
|
|
558
|
-
this.preprocessors.delete(preprocessor);
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
};
|
|
562
|
-
var MergedStateStore = class _MergedStateStore extends StateStore {
|
|
563
|
-
constructor({ original, merged }) {
|
|
564
|
-
const originalValue = original.getLatestValue();
|
|
565
|
-
const mergedValue = merged.getLatestValue();
|
|
566
|
-
super({
|
|
567
|
-
...originalValue,
|
|
568
|
-
...mergedValue
|
|
569
|
-
});
|
|
570
|
-
// override original methods and "disable" them
|
|
571
|
-
this.next = () => {
|
|
572
|
-
console.warn(
|
|
573
|
-
`${_MergedStateStore.name}.next is disabled, call original.next or merged.next instead`
|
|
574
|
-
);
|
|
575
|
-
};
|
|
576
|
-
this.partialNext = () => {
|
|
577
|
-
console.warn(
|
|
578
|
-
`${_MergedStateStore.name}.partialNext is disabled, call original.partialNext or merged.partialNext instead`
|
|
579
|
-
);
|
|
580
|
-
};
|
|
581
|
-
this.cachedOriginalValue = originalValue;
|
|
582
|
-
this.cachedMergedValue = mergedValue;
|
|
583
|
-
this.original = original;
|
|
584
|
-
this.merged = merged;
|
|
585
|
-
}
|
|
586
|
-
/**
|
|
587
|
-
* Subscribes to changes in the merged state store.
|
|
588
|
-
*
|
|
589
|
-
* This method extends the base subscribe functionality to handle the merged nature of this store:
|
|
590
|
-
* 1. The first subscriber triggers registration of helper subscribers that listen to both source stores
|
|
591
|
-
* 2. Changes from either source store are propagated to this merged store
|
|
592
|
-
* 3. Source store values are cached to prevent unnecessary updates
|
|
593
|
-
*
|
|
594
|
-
* When the first subscriber is added, the method sets up listeners on both original and merged stores.
|
|
595
|
-
* These listeners update the combined store value whenever either source store changes.
|
|
596
|
-
* All subscriptions (helpers and the actual handler) are tracked so they can be properly cleaned up.
|
|
597
|
-
*
|
|
598
|
-
* @param handler - The callback function that will be executed when the state changes
|
|
599
|
-
* @returns An unsubscribe function that, when called, removes the subscription and any helper subscriptions
|
|
600
|
-
*/
|
|
601
|
-
subscribe(handler) {
|
|
602
|
-
const unsubscribeFunctions = [];
|
|
603
|
-
if (!this.handlers.size) {
|
|
604
|
-
const base = (nextValue) => {
|
|
605
|
-
super.next((currentValue) => ({
|
|
606
|
-
...currentValue,
|
|
607
|
-
...nextValue
|
|
608
|
-
}));
|
|
609
|
-
};
|
|
610
|
-
unsubscribeFunctions.push(
|
|
611
|
-
this.original.subscribe((nextValue) => {
|
|
612
|
-
if (nextValue === this.cachedOriginalValue) return;
|
|
613
|
-
this.cachedOriginalValue = nextValue;
|
|
614
|
-
base(nextValue);
|
|
615
|
-
}),
|
|
616
|
-
this.merged.subscribe((nextValue) => {
|
|
617
|
-
if (nextValue === this.cachedMergedValue) return;
|
|
618
|
-
this.cachedMergedValue = nextValue;
|
|
619
|
-
base(nextValue);
|
|
620
|
-
})
|
|
621
|
-
);
|
|
622
|
-
}
|
|
623
|
-
unsubscribeFunctions.push(super.subscribe(handler));
|
|
624
|
-
return () => {
|
|
625
|
-
unsubscribeFunctions.forEach((unsubscribe) => unsubscribe());
|
|
626
|
-
};
|
|
627
|
-
}
|
|
628
|
-
/**
|
|
629
|
-
* Retrieves the latest combined state from both original and merged stores.
|
|
630
|
-
*
|
|
631
|
-
* This method extends the base getLatestValue functionality to ensure the merged store
|
|
632
|
-
* remains in sync with its source stores even when there are no active subscribers.
|
|
633
|
-
*
|
|
634
|
-
* When there are no handlers registered, the method:
|
|
635
|
-
* 1. Fetches the latest values from both source stores
|
|
636
|
-
* 2. Compares them with the cached values to detect changes
|
|
637
|
-
* 3. If changes are detected, updates the internal value and caches
|
|
638
|
-
* the new source values to maintain consistency
|
|
639
|
-
*
|
|
640
|
-
* This approach ensures that calling getLatestValue() always returns the most
|
|
641
|
-
* up-to-date combined state, even if the merged store hasn't been actively
|
|
642
|
-
* receiving updates through subscriptions.
|
|
643
|
-
*
|
|
644
|
-
* @returns The latest combined state from both original and merged stores
|
|
645
|
-
*/
|
|
646
|
-
getLatestValue() {
|
|
647
|
-
if (!this.handlers.size) {
|
|
648
|
-
const originalValue = this.original.getLatestValue();
|
|
649
|
-
const mergedValue = this.merged.getLatestValue();
|
|
650
|
-
if (originalValue !== this.cachedOriginalValue || mergedValue !== this.cachedMergedValue) {
|
|
651
|
-
this.value = {
|
|
652
|
-
...originalValue,
|
|
653
|
-
...mergedValue
|
|
654
|
-
};
|
|
655
|
-
this.cachedMergedValue = mergedValue;
|
|
656
|
-
this.cachedOriginalValue = originalValue;
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
return super.getLatestValue();
|
|
660
|
-
}
|
|
661
|
-
addPreprocessor() {
|
|
662
|
-
console.warn(
|
|
663
|
-
`${_MergedStateStore.name}.addPreprocessor is disabled, call original.addPreprocessor or merged.addPreprocessor instead`
|
|
664
|
-
);
|
|
665
|
-
return noop;
|
|
666
|
-
}
|
|
667
|
-
};
|
|
668
|
-
|
|
669
|
-
// src/i18n/TranslationBuilder.ts
|
|
670
|
-
var TranslationTopic = class {
|
|
671
|
-
constructor(options) {
|
|
672
|
-
this.options = options;
|
|
673
|
-
this.translators = /* @__PURE__ */ new Map();
|
|
674
|
-
this.setTranslator = (name, translator) => {
|
|
675
|
-
this.translators.set(name, translator);
|
|
676
|
-
};
|
|
677
|
-
this.removeTranslator = (name) => {
|
|
678
|
-
this.translators.delete(name);
|
|
679
|
-
};
|
|
680
|
-
this.i18next = options.i18next;
|
|
681
|
-
if (options.translators) {
|
|
682
|
-
Object.entries(options.translators).forEach(([name, translator]) => {
|
|
683
|
-
this.setTranslator(name, translator);
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
};
|
|
688
|
-
var forwardTranslation = ({ value }) => value;
|
|
689
|
-
var TranslationBuilder = class {
|
|
690
|
-
constructor(i18next2) {
|
|
691
|
-
this.i18next = i18next2;
|
|
692
|
-
this.topics = /* @__PURE__ */ new Map();
|
|
693
|
-
/**
|
|
694
|
-
* Translators registered before their topic exists.
|
|
695
|
-
*
|
|
696
|
-
* Topics are only created during `Streami18n.init()`, but an integrator registers translators against
|
|
697
|
-
* the constructed instance — so registrations that arrive first are buffered and flushed when the
|
|
698
|
-
* topic appears, rather than silently dropped.
|
|
699
|
-
*/
|
|
700
|
-
this.translatorRegistrationsBuffer = {};
|
|
701
|
-
this.registerTopic = (name, Topic) => {
|
|
702
|
-
let topic = this.topics.get(name);
|
|
703
|
-
if (!topic) {
|
|
704
|
-
topic = new Topic({ i18next: this.i18next });
|
|
705
|
-
this.topics.set(name, topic);
|
|
706
|
-
this.i18next.use({
|
|
707
|
-
name,
|
|
708
|
-
process: (value, key, options) => {
|
|
709
|
-
const registered = this.topics.get(name);
|
|
710
|
-
if (!registered) return value;
|
|
711
|
-
return registered.translate(value, key, options);
|
|
712
|
-
},
|
|
713
|
-
type: "postProcessor"
|
|
714
|
-
});
|
|
715
|
-
}
|
|
716
|
-
const buffered = this.translatorRegistrationsBuffer[name];
|
|
717
|
-
if (buffered) {
|
|
718
|
-
Object.entries(buffered).forEach(([translatorName, translator]) => {
|
|
719
|
-
topic.setTranslator(translatorName, translator);
|
|
720
|
-
});
|
|
721
|
-
delete this.translatorRegistrationsBuffer[name];
|
|
722
|
-
}
|
|
723
|
-
return topic;
|
|
724
|
-
};
|
|
725
|
-
this.disableTopic = (topicName) => {
|
|
726
|
-
const topic = this.topics.get(topicName);
|
|
727
|
-
if (!topic) return;
|
|
728
|
-
this.i18next.use({
|
|
729
|
-
name: topicName,
|
|
730
|
-
process: forwardTranslation,
|
|
731
|
-
type: "postProcessor"
|
|
732
|
-
});
|
|
733
|
-
this.topics.delete(topicName);
|
|
734
|
-
};
|
|
735
|
-
this.getTopic = (topicName) => this.topics.get(topicName);
|
|
736
|
-
}
|
|
737
|
-
registerTranslators(topicName, translators) {
|
|
738
|
-
var _a;
|
|
739
|
-
const topic = this.getTopic(topicName);
|
|
740
|
-
if (!topic) {
|
|
741
|
-
(_a = this.translatorRegistrationsBuffer)[topicName] ?? (_a[topicName] = {});
|
|
742
|
-
Object.entries(translators).forEach(([translatorName, translator]) => {
|
|
743
|
-
this.translatorRegistrationsBuffer[topicName][translatorName] = translator;
|
|
744
|
-
});
|
|
745
|
-
return;
|
|
746
|
-
}
|
|
747
|
-
Object.entries(translators).forEach(([name, translator]) => {
|
|
748
|
-
topic.setTranslator(name, translator);
|
|
749
|
-
});
|
|
750
|
-
}
|
|
751
|
-
removeTranslators(topicName, translators) {
|
|
752
|
-
if (this.translatorRegistrationsBuffer[topicName]) {
|
|
753
|
-
translators.forEach((translatorName) => {
|
|
754
|
-
delete this.translatorRegistrationsBuffer[topicName][translatorName];
|
|
755
|
-
});
|
|
756
|
-
}
|
|
757
|
-
const topic = this.getTopic(topicName);
|
|
758
|
-
if (!topic) return;
|
|
759
|
-
translators.forEach((name) => {
|
|
760
|
-
topic.removeTranslator(name);
|
|
761
|
-
});
|
|
762
|
-
}
|
|
763
|
-
};
|
|
764
|
-
|
|
765
|
-
// src/i18n/TranslationStore.ts
|
|
766
|
-
var DEFAULT_LANGUAGE = "en";
|
|
767
|
-
var TranslationStore = class {
|
|
768
|
-
constructor(runtimeDefaults = {}) {
|
|
769
|
-
this.dictionaries = /* @__PURE__ */ new Map();
|
|
770
|
-
this.registered = /* @__PURE__ */ new Set([DEFAULT_LANGUAGE]);
|
|
771
|
-
this.runtimeDefaults = runtimeDefaults;
|
|
772
|
-
}
|
|
773
|
-
/**
|
|
774
|
-
* Languages an integrator actually supplied a dictionary for.
|
|
775
|
-
*
|
|
776
|
-
* Deliberately narrower than {@link TranslationStore.languages}, which also counts every language
|
|
777
|
-
* created just to carry the bundled defaults. Without the distinction there would be no way to warn
|
|
778
|
-
* that the active language has no translations — every language would look registered.
|
|
779
|
-
*/
|
|
780
|
-
get registeredLanguages() {
|
|
781
|
-
return this.registered;
|
|
782
|
-
}
|
|
783
|
-
/** Every language with a dictionary, including those carrying only the bundled defaults. */
|
|
784
|
-
get languages() {
|
|
785
|
-
return [...this.dictionaries.keys()];
|
|
786
|
-
}
|
|
787
|
-
/** `language -> dictionary`, for a caller that has to hand them all over at once. */
|
|
788
|
-
entries() {
|
|
789
|
-
return [...this.dictionaries];
|
|
790
|
-
}
|
|
791
|
-
isRegistered(language) {
|
|
792
|
-
return this.registered.has(language);
|
|
793
|
-
}
|
|
794
|
-
/**
|
|
795
|
-
* Guarantees `language` has a dictionary, and returns it.
|
|
796
|
-
*
|
|
797
|
-
* Called for a language nobody registered, so that it still formats dates and renders the SDK's copy
|
|
798
|
-
* in English rather than raw dotted keys.
|
|
799
|
-
*/
|
|
800
|
-
ensure(language) {
|
|
801
|
-
return this.merge(language);
|
|
802
|
-
}
|
|
803
|
-
/**
|
|
804
|
-
* Layers a dictionary over what `language` already has, and marks it registered.
|
|
805
|
-
*
|
|
806
|
-
* **Merged, not replaced.** Repeated calls for one language accumulate, and — the reason this class
|
|
807
|
-
* exists — the bundled defaults survive a partial dictionary. A bundled key has no inline
|
|
808
|
-
* `defaultValue` at its call site and `fallbackLng` is false, so a language that loses them renders
|
|
809
|
-
* raw dotted keys and unformatted ISO timestamps. That is guarantee G1 of the i18n suite.
|
|
810
|
-
*/
|
|
811
|
-
register(language, dictionary) {
|
|
812
|
-
const merged = this.merge(language, dictionary);
|
|
813
|
-
this.registered.add(language);
|
|
814
|
-
return merged;
|
|
815
|
-
}
|
|
816
|
-
/**
|
|
817
|
-
* Bundled defaults first, then whatever the language already had, then the incoming dictionary — so
|
|
818
|
-
* an integrator can override a bundled key, and a later registration wins over an earlier one.
|
|
819
|
-
*/
|
|
820
|
-
merge(language, dictionary) {
|
|
821
|
-
const merged = {
|
|
822
|
-
...this.runtimeDefaults,
|
|
823
|
-
...this.dictionaries.get(language),
|
|
824
|
-
...dictionary
|
|
825
|
-
};
|
|
826
|
-
this.dictionaries.set(language, merged);
|
|
827
|
-
return merged;
|
|
828
|
-
}
|
|
829
|
-
};
|
|
830
|
-
|
|
831
|
-
// src/i18n/Streami18n.ts
|
|
832
|
-
var DEFAULT_NAMESPACE = "translation";
|
|
833
|
-
var Streami18n = class {
|
|
834
|
-
constructor(options = {}) {
|
|
835
|
-
this.i18nInstance = import_i18next.default.createInstance();
|
|
836
|
-
/** Applied when the language becomes active, not on registration: `Dayjs.locale()` is global. */
|
|
837
|
-
this.dayjsLocales = {};
|
|
838
|
-
/** Set by {@link overrideTFunction}, so `init()` does not clobber a swapped-in implementation. */
|
|
839
|
-
this.tOverridden = false;
|
|
840
|
-
/**
|
|
841
|
-
* Re-run on every language change, not just at `init()`: factories destructure the language out of
|
|
842
|
-
* their context, so one built once keeps formatting in the initial language forever. `formatter.add`
|
|
843
|
-
* replaces by name, which is what makes re-registering sufficient.
|
|
844
|
-
*/
|
|
845
|
-
this.registerFormatters = () => {
|
|
846
|
-
const context = this.createFormatterContext();
|
|
847
|
-
Object.entries(this.formatters).forEach(([name, factory]) => {
|
|
848
|
-
if (!factory) return;
|
|
849
|
-
const formatter = factory(context);
|
|
850
|
-
this.i18nInstance.services.formatter?.add(
|
|
851
|
-
name,
|
|
852
|
-
formatter
|
|
853
|
-
);
|
|
854
|
-
});
|
|
855
|
-
};
|
|
856
|
-
/**
|
|
857
|
-
* Accessors rather than snapshots, for a formatter that holds the context and reads per call; one
|
|
858
|
-
* that destructures is covered by {@link registerFormatters} re-running instead.
|
|
859
|
-
*
|
|
860
|
-
* The nested arrows are load-bearing: a getter in an object literal binds `this` to the literal.
|
|
861
|
-
*/
|
|
862
|
-
this.createFormatterContext = () => {
|
|
863
|
-
const readLanguage = () => this.currentLanguage;
|
|
864
|
-
const readDateTimeParser = () => this.tDateTimeParser;
|
|
865
|
-
return {
|
|
866
|
-
get currentLanguage() {
|
|
867
|
-
return readLanguage();
|
|
868
|
-
},
|
|
869
|
-
dateTimeParser: this.DateTimeParser,
|
|
870
|
-
logger: this.logger,
|
|
871
|
-
get tDateTimeParser() {
|
|
872
|
-
return readDateTimeParser();
|
|
873
|
-
},
|
|
874
|
-
timezone: this.timezone,
|
|
875
|
-
translate: this.translate
|
|
876
|
-
};
|
|
877
|
-
};
|
|
878
|
-
/** The store's flat dictionaries in i18next's nested `resources` shape. */
|
|
879
|
-
this.i18nextResources = () => Object.fromEntries(
|
|
880
|
-
this.translations.entries().map(([language, dictionary]) => [language, { [DEFAULT_NAMESPACE]: dictionary }])
|
|
881
|
-
);
|
|
882
|
-
/** The only route for a language added after `init()`. */
|
|
883
|
-
this.ensureLanguage = (language) => {
|
|
884
|
-
this.addResources(language, this.translations.ensure(language));
|
|
885
|
-
};
|
|
886
|
-
this.addResources = (language, dictionary) => {
|
|
887
|
-
if (!this.initialized) return;
|
|
888
|
-
this.i18nInstance.addResources(language, DEFAULT_NAMESPACE, dictionary);
|
|
889
|
-
};
|
|
890
|
-
/**
|
|
891
|
-
* Warns rather than falling back to `en`: the language renders English copy from the inline defaults
|
|
892
|
-
* while keeping its own date formats, and resetting it would discard the integrator's choice.
|
|
893
|
-
*/
|
|
894
|
-
this.validateCurrentLanguage = () => {
|
|
895
|
-
const language = this.currentLanguageValue;
|
|
896
|
-
if (this.translations.isRegistered(language)) return;
|
|
897
|
-
this.logger(
|
|
898
|
-
`Streami18n: no translation dictionary is registered for '${language}', so the SDK's copy renders in English. Call registerTranslation('${language}', {...}) to translate it. Registered: ${[...this.translations.registeredLanguages].join(", ")}`
|
|
899
|
-
);
|
|
900
|
-
};
|
|
901
|
-
/**
|
|
902
|
-
* Checked against the module that actually formats the dates.
|
|
903
|
-
*
|
|
904
|
-
* A supplied dayjs copy has its own locale registry, so consulting ours would answer for the wrong
|
|
905
|
-
* one. True for a non-dayjs parser, whose registry we cannot inspect.
|
|
906
|
-
*/
|
|
907
|
-
this.localeExists = (language) => {
|
|
908
|
-
if (!isDayjsLike(this.DateTimeParser)) return true;
|
|
909
|
-
return dayjsLocaleExists(language, this.DateTimeParser);
|
|
910
|
-
};
|
|
911
|
-
/**
|
|
912
|
-
* For formatters, which resolve keys handed to them at runtime -- including their own
|
|
913
|
-
* `relativeTime.*` copy, which no catalog declares.
|
|
914
|
-
*/
|
|
915
|
-
this.translate = (key, defaultValueOrOptions, options) => this.t(
|
|
916
|
-
asDynamicKey(key),
|
|
917
|
-
defaultValueOrOptions,
|
|
918
|
-
options
|
|
919
|
-
);
|
|
920
|
-
/**
|
|
921
|
-
* Hermes ships a partial ICU: `Intl.PluralRules` silently falls back to root rules (`other` only) for
|
|
922
|
-
* locales it lacks, so a dictionary's `_few` / `_many` never render and nothing errors.
|
|
923
|
-
*
|
|
924
|
-
* Called from `init()` because i18next caches a resolver per language there — the last moment
|
|
925
|
-
* `intl-pluralrules` could still have been loaded in time.
|
|
926
|
-
*/
|
|
927
|
-
this.assertPluralRulesCoverage = (language) => {
|
|
928
|
-
try {
|
|
929
|
-
const resolved = new Intl.PluralRules(language).resolvedOptions().locale;
|
|
930
|
-
if (resolved.split("-")[0] === language.split("-")[0]) return;
|
|
931
|
-
this.logger(
|
|
932
|
-
`Streami18n: Intl.PluralRules has no data for '${language}' (it resolved to '${resolved}'), so every count selects the '_other' form. On React Native, import 'intl-pluralrules' before anything else in your entry file.`
|
|
933
|
-
);
|
|
934
|
-
} catch {
|
|
935
|
-
this.logger(
|
|
936
|
-
`Streami18n: Intl.PluralRules is unavailable, so plural selection will not work. On React Native, import 'intl-pluralrules' before anything else in your entry file.`
|
|
937
|
-
);
|
|
938
|
-
}
|
|
939
|
-
};
|
|
940
|
-
this.logger = options.logger ?? ((message) => console.warn(message));
|
|
941
|
-
this.translations = new TranslationStore(options.runtimeDefaults);
|
|
942
|
-
this.disableDateTimeTranslations = options.disableDateTimeTranslations ?? false;
|
|
943
|
-
this.timezone = options.timezone;
|
|
944
|
-
this.formatters = { ...predefinedFormatters, ...options.formatters };
|
|
945
|
-
this.translationBuilder = new TranslationBuilder(this.i18nInstance);
|
|
946
|
-
this.translationBuilderTopics = options.translationBuilderTopics ?? {};
|
|
947
|
-
const language = options.language ?? DEFAULT_LANGUAGE;
|
|
948
|
-
if (options.DateTimeParser) {
|
|
949
|
-
this.DateTimeParser = options.DateTimeParser;
|
|
950
|
-
if (isDayjsLike(this.DateTimeParser)) ensureDayjsPlugins(this.DateTimeParser);
|
|
951
|
-
} else {
|
|
952
|
-
this.DateTimeParser = getDefaultDateTimeParserModule();
|
|
953
|
-
}
|
|
954
|
-
const tDateTimeParser = (timestamp) => {
|
|
955
|
-
const locale = this.disableDateTimeTranslations || !this.localeExists(this.currentLanguageValue) ? DEFAULT_LANGUAGE : this.currentLanguageValue;
|
|
956
|
-
const parsed = this.DateTimeParser(timestamp);
|
|
957
|
-
const withZone = this.timezone && supportsTimezone(this.DateTimeParser) ? parsed.tz(this.timezone) : parsed;
|
|
958
|
-
return withZone.locale(
|
|
959
|
-
locale
|
|
960
|
-
);
|
|
961
|
-
};
|
|
962
|
-
this.state = new StateStore({
|
|
963
|
-
initialized: false,
|
|
964
|
-
language,
|
|
965
|
-
t: createDefaultTranslatorFunction(),
|
|
966
|
-
tDateTimeParser
|
|
967
|
-
});
|
|
968
|
-
this.translations.ensure(DEFAULT_LANGUAGE);
|
|
969
|
-
this.translations.ensure(language);
|
|
970
|
-
if (options.translationsForLanguage) {
|
|
971
|
-
this.translations.register(
|
|
972
|
-
language,
|
|
973
|
-
options.translationsForLanguage
|
|
974
|
-
);
|
|
975
|
-
}
|
|
976
|
-
const missingKeyHandler = options.parseMissingKeyHandler ?? options.i18nextConfigOverrides?.parseMissingKeyHandler;
|
|
977
|
-
this.i18nextConfig = {
|
|
978
|
-
debug: options.debug ?? false,
|
|
979
|
-
fallbackLng: false,
|
|
980
|
-
interpolation: { escapeValue: false, formatSeparator: "|" },
|
|
981
|
-
// Must stay false: keys are flat strings containing dots, and some copy contains `...`.
|
|
982
|
-
keySeparator: false,
|
|
983
|
-
lng: language,
|
|
984
|
-
nsSeparator: false,
|
|
985
|
-
// i18next only runs post-processors it was told about at init time.
|
|
986
|
-
...Object.keys(this.translationBuilderTopics).length > 0 ? { postProcess: Object.keys(this.translationBuilderTopics) } : {},
|
|
987
|
-
...options.i18nextConfigOverrides,
|
|
988
|
-
// Guarded even when integrator-supplied: an unguarded handler silently blanks every prose key.
|
|
989
|
-
parseMissingKeyHandler: missingKeyHandler ? guardMissingKeyHandler(missingKeyHandler) : (key, defaultValue) => {
|
|
990
|
-
if (typeof defaultValue === "string") return defaultValue;
|
|
991
|
-
this.logger(`Streami18n: missing translation for key: ${key}`);
|
|
992
|
-
return key;
|
|
993
|
-
}
|
|
994
|
-
};
|
|
995
|
-
if (options.dayjsLocaleConfigForLanguage) {
|
|
996
|
-
this.addOrUpdateLocale(language, options.dayjsLocaleConfigForLanguage);
|
|
997
|
-
} else if (!this.localeExists(language)) {
|
|
998
|
-
this.logger(
|
|
999
|
-
`Streami18n: no dayjs locale is registered for '${language}', so dates render with the English locale. Import it with "import 'dayjs/locale/${language}';" in your app, or pass a config via registerTranslation('${language}', translation, dayjsLocaleConfig).`
|
|
1000
|
-
);
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
get t() {
|
|
1004
|
-
return this.state.getLatestValue().t;
|
|
1005
|
-
}
|
|
1006
|
-
get tDateTimeParser() {
|
|
1007
|
-
return this.state.getLatestValue().tDateTimeParser;
|
|
1008
|
-
}
|
|
1009
|
-
get currentLanguage() {
|
|
1010
|
-
return this.state.getLatestValue().language;
|
|
1011
|
-
}
|
|
1012
|
-
get initialized() {
|
|
1013
|
-
return this.state.getLatestValue().initialized;
|
|
1014
|
-
}
|
|
1015
|
-
/** Read inside the constructor, before `state` getters are safe to rely on externally. */
|
|
1016
|
-
get currentLanguageValue() {
|
|
1017
|
-
return this.state?.getLatestValue().language ?? DEFAULT_LANGUAGE;
|
|
1018
|
-
}
|
|
1019
|
-
/**
|
|
1020
|
-
* Initializes i18next. Memoized, so concurrent callers share one initialization.
|
|
1021
|
-
*
|
|
1022
|
-
* **Rejects on failure**, so handle it. The instance stays usable either way: `initialized` stays
|
|
1023
|
-
* false, keeping {@link Streami18n.registerTranslation} and {@link Streami18n.setLanguage} off a
|
|
1024
|
-
* dead i18next instance, and `t` keeps returning each call site's inline English.
|
|
1025
|
-
*/
|
|
1026
|
-
init() {
|
|
1027
|
-
if (this.initPromise) return this.initPromise;
|
|
1028
|
-
const pending = this.runInit();
|
|
1029
|
-
this.initPromise = pending;
|
|
1030
|
-
pending.catch(() => {
|
|
1031
|
-
if (this.initPromise === pending) this.initPromise = void 0;
|
|
1032
|
-
});
|
|
1033
|
-
return pending;
|
|
1034
|
-
}
|
|
1035
|
-
async runInit() {
|
|
1036
|
-
this.validateCurrentLanguage();
|
|
1037
|
-
this.assertPluralRulesCoverage(this.currentLanguage);
|
|
1038
|
-
const dayjsLocale = this.dayjsLocales[this.currentLanguage];
|
|
1039
|
-
if (dayjsLocale) this.addOrUpdateLocale(this.currentLanguage, dayjsLocale);
|
|
1040
|
-
const t = await this.i18nInstance.init({
|
|
1041
|
-
...this.i18nextConfig,
|
|
1042
|
-
lng: this.currentLanguage,
|
|
1043
|
-
resources: this.i18nextResources()
|
|
1044
|
-
});
|
|
1045
|
-
this.registerFormatters();
|
|
1046
|
-
Object.entries(this.translationBuilderTopics).forEach(([topic, Topic]) => {
|
|
1047
|
-
this.translationBuilder.registerTopic(topic, Topic);
|
|
1048
|
-
});
|
|
1049
|
-
this.state.partialNext({
|
|
1050
|
-
initialized: true,
|
|
1051
|
-
...this.tOverridden ? {} : { t }
|
|
1052
|
-
});
|
|
1053
|
-
return this.state.getLatestValue();
|
|
1054
|
-
}
|
|
1055
|
-
registerTranslation(language, translation, dayjsLocaleConfig) {
|
|
1056
|
-
if (!translation) {
|
|
1057
|
-
this.logger(
|
|
1058
|
-
"Streami18n: registerTranslation called without a translation dictionary"
|
|
1059
|
-
);
|
|
1060
|
-
return;
|
|
1061
|
-
}
|
|
1062
|
-
const merged = this.translations.register(
|
|
1063
|
-
language,
|
|
1064
|
-
translation
|
|
1065
|
-
);
|
|
1066
|
-
if (dayjsLocaleConfig) {
|
|
1067
|
-
this.dayjsLocales[language] = { ...dayjsLocaleConfig };
|
|
1068
|
-
} else if (!this.localeExists(language)) {
|
|
1069
|
-
this.logger(
|
|
1070
|
-
`Streami18n: no dayjs locale is registered for '${language}'. Import it with "import 'dayjs/locale/${language}';" in your app, or pass a config as the third argument to registerTranslation.`
|
|
1071
|
-
);
|
|
1072
|
-
}
|
|
1073
|
-
this.addResources(language, merged);
|
|
1074
|
-
}
|
|
1075
|
-
/**
|
|
1076
|
-
* Returns nothing: the new `t` is published to {@link Streami18n.state}. Handing one back would offer
|
|
1077
|
-
* a value that goes stale on the next language change.
|
|
1078
|
-
*/
|
|
1079
|
-
async setLanguage(language) {
|
|
1080
|
-
const previousLanguage = this.state.getLatestValue().language;
|
|
1081
|
-
this.state.partialNext({ language });
|
|
1082
|
-
this.ensureLanguage(language);
|
|
1083
|
-
if (!this.initialized) return;
|
|
1084
|
-
this.validateCurrentLanguage();
|
|
1085
|
-
this.assertPluralRulesCoverage(language);
|
|
1086
|
-
try {
|
|
1087
|
-
const t = await this.i18nInstance.changeLanguage(language);
|
|
1088
|
-
const dayjsLocale = this.dayjsLocales[language];
|
|
1089
|
-
if (dayjsLocale) this.addOrUpdateLocale(language, dayjsLocale);
|
|
1090
|
-
this.registerFormatters();
|
|
1091
|
-
if (!this.tOverridden) {
|
|
1092
|
-
this.state.partialNext({ t });
|
|
1093
|
-
}
|
|
1094
|
-
} catch (error) {
|
|
1095
|
-
this.state.partialNext({ language: previousLanguage });
|
|
1096
|
-
this.logger(`Streami18n: failed to set language: ${describeError(error)}`);
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
/**
|
|
1100
|
-
* Swaps in a different translation implementation, for an app that already has an i18n layer. Safe
|
|
1101
|
-
* before `init()`, which will not overwrite it.
|
|
1102
|
-
*/
|
|
1103
|
-
overrideTFunction(t) {
|
|
1104
|
-
this.tOverridden = true;
|
|
1105
|
-
this.state.partialNext({ t });
|
|
1106
|
-
}
|
|
1107
|
-
/**
|
|
1108
|
-
* Languages an integrator supplied a dictionary for. Read-only because adding to it would claim a
|
|
1109
|
-
* language is registered with no dictionary behind it; use `registerTranslation`.
|
|
1110
|
-
*/
|
|
1111
|
-
get registeredLanguages() {
|
|
1112
|
-
return this.translations.registeredLanguages;
|
|
1113
|
-
}
|
|
1114
|
-
/**
|
|
1115
|
-
* Registers a locale on the module that formats the dates, not on ours.
|
|
1116
|
-
*
|
|
1117
|
-
* Only dayjs has a registry we can write to. For a Moment the config cannot be applied at all, so it
|
|
1118
|
-
* is reported -- previously it was written to core's own dayjs, where nothing would ever read it.
|
|
1119
|
-
*/
|
|
1120
|
-
addOrUpdateLocale(language, config) {
|
|
1121
|
-
if (!isDayjsLike(this.DateTimeParser)) {
|
|
1122
|
-
this.logger(
|
|
1123
|
-
`Streami18n: a dayjs locale config was supplied for '${language}', but DateTimeParser is not dayjs, so it cannot be applied. Configure the locale on your own date library instead.`
|
|
1124
|
-
);
|
|
1125
|
-
return;
|
|
1126
|
-
}
|
|
1127
|
-
addOrUpdateDayjsLocale(language, config, this.DateTimeParser);
|
|
1128
|
-
}
|
|
1129
|
-
};
|
|
1130
|
-
var describeError = (error) => error instanceof Error ? error.message : String(error);
|
|
1131
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1132
|
-
0 && (module.exports = {
|
|
1133
|
-
A11Y_CALENDAR_FORMATS,
|
|
1134
|
-
DEFAULT_LANGUAGE,
|
|
1135
|
-
LANGUAGE_NAMES,
|
|
1136
|
-
RELATIVE_TIME_CATALOG,
|
|
1137
|
-
Streami18n,
|
|
1138
|
-
TranslationBuilder,
|
|
1139
|
-
TranslationStore,
|
|
1140
|
-
TranslationTopic,
|
|
1141
|
-
addOrUpdateDayjsLocale,
|
|
1142
|
-
asDynamicKey,
|
|
1143
|
-
createDefaultTranslatorFunction,
|
|
1144
|
-
dayjsLocaleExists,
|
|
1145
|
-
defaultDateTimeParser,
|
|
1146
|
-
ensureDayjsPlugins,
|
|
1147
|
-
getCalendarDateStringForA11y,
|
|
1148
|
-
getDateString,
|
|
1149
|
-
getDateStringForA11y,
|
|
1150
|
-
getDefaultDateTimeParserModule,
|
|
1151
|
-
guardMissingKeyHandler,
|
|
1152
|
-
isDate,
|
|
1153
|
-
isDayOrMoment,
|
|
1154
|
-
isDayjsLike,
|
|
1155
|
-
isNumberOrString,
|
|
1156
|
-
languageNameDefaults,
|
|
1157
|
-
predefinedFormatters,
|
|
1158
|
-
supportsTimezone
|
|
1159
|
-
});
|
|
1160
|
-
//# sourceMappingURL=i18n.node.js.map
|