@aws-amplify/core 6.0.1-api-v6-models.9351bcf.0 → 6.0.1-api-v6-models.891fe0d.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/lib/BackgroundProcessManager/BackgroundManagerNotOpenError.js +4 -21
- package/lib/BackgroundProcessManager/BackgroundProcessManager.js +126 -245
- package/lib/Cache/StorageCache.js +32 -92
- package/lib/Cache/StorageCache.native.js +38 -140
- package/lib/Cache/StorageCacheCommon.js +271 -600
- package/lib/Cache/index.js +1 -1
- package/lib/Cache/utils/CacheList.js +42 -66
- package/lib/Cache/utils/cacheHelpers.js +6 -8
- package/lib/Cache/utils/errorHelpers.js +6 -7
- package/lib/Hub/index.js +34 -74
- package/lib/I18n/I18n.js +24 -39
- package/lib/I18n/errorHelpers.js +4 -5
- package/lib/I18n/index.js +24 -27
- package/lib/I18n/types.js +3 -4
- package/lib/Logger/ConsoleLogger.js +53 -129
- package/lib/Mutex/Mutex.js +15 -19
- package/lib/Platform/customUserAgent.js +13 -26
- package/lib/Platform/detectFramework.js +12 -13
- package/lib/Platform/detection/Angular.js +4 -5
- package/lib/Platform/detection/Expo.js +1 -1
- package/lib/Platform/detection/Next.js +1 -1
- package/lib/Platform/detection/Nuxt.js +1 -1
- package/lib/Platform/detection/React.js +5 -5
- package/lib/Platform/detection/Svelte.js +2 -2
- package/lib/Platform/detection/Vue.js +1 -1
- package/lib/Platform/detection/Web.js +1 -1
- package/lib/Platform/detection/helpers.js +7 -7
- package/lib/Platform/detection/index.js +13 -13
- package/lib/Platform/index.js +26 -55
- package/lib/Platform/types.d.ts +1 -1
- package/lib/Platform/types.js +1 -1
- package/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/Reachability/Reachability.js +20 -48
- package/lib/Reachability/Reachability.native.js +12 -16
- package/lib/ServiceWorker/ServiceWorker.js +80 -136
- package/lib/ServiceWorker/errorHelpers.js +6 -7
- package/lib/Signer/DateUtils.d.ts +9 -0
- package/lib/Signer/DateUtils.js +19 -28
- package/lib/Signer/Signer.d.ts +9 -0
- package/lib/Signer/Signer.js +58 -54
- package/lib/adapterCore/error/AmplifyServerContextError.js +9 -27
- package/lib/adapterCore/serverContext/serverContext.js +8 -8
- package/lib/adapterCore/serverContext/serverContextRegistry.js +6 -6
- package/lib/awsClients/cognitoIdentity/base.js +25 -73
- package/lib/awsClients/cognitoIdentity/getCredentialsForIdentity.js +24 -68
- package/lib/awsClients/cognitoIdentity/getId.js +19 -62
- package/lib/awsClients/pinpoint/base.js +12 -15
- package/lib/awsClients/pinpoint/errorHelpers.js +4 -5
- package/lib/awsClients/pinpoint/getInAppMessages.js +24 -68
- package/lib/awsClients/pinpoint/putEvents.js +26 -70
- package/lib/awsClients/pinpoint/updateEndpoint.js +28 -72
- package/lib/clients/endpoints/getDnsSuffix.js +7 -29
- package/lib/clients/handlers/authenticated.js +5 -5
- package/lib/clients/handlers/fetch.js +41 -98
- package/lib/clients/handlers/unauthenticated.js +4 -4
- package/lib/clients/internal/composeServiceApi.js +17 -67
- package/lib/clients/internal/composeTransferHandler.js +9 -11
- package/lib/clients/middleware/retry/defaultRetryDecider.js +18 -75
- package/lib/clients/middleware/retry/isClockSkewError.js +2 -4
- package/lib/clients/middleware/retry/jitteredBackoff.js +5 -5
- package/lib/clients/middleware/retry/middleware.js +61 -125
- package/lib/clients/middleware/signing/middleware.js +24 -86
- package/lib/clients/middleware/signing/signer/signatureV4/index.js +0 -1
- package/lib/clients/middleware/signing/signer/signatureV4/presignUrl.js +21 -56
- package/lib/clients/middleware/signing/signer/signatureV4/signRequest.js +14 -25
- package/lib/clients/middleware/signing/signer/signatureV4/utils/dataHashHelpers.js +7 -7
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getCanonicalHeaders.js +8 -30
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getCanonicalQueryString.js +11 -38
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getCanonicalRequest.js +13 -17
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getCanonicalUri.js +5 -8
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getCredentialScope.js +2 -2
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getFormattedDates.js +3 -3
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getHashedPayload.js +7 -11
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getSignature.js +9 -10
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getSignedHeaders.js +4 -6
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getSigningKey.js +8 -8
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getSigningValues.js +15 -16
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getStringToSign.js +2 -4
- package/lib/clients/middleware/signing/utils/extendedEncodeURIComponent.js +3 -5
- package/lib/clients/middleware/signing/utils/getSkewCorrectedDate.js +1 -3
- package/lib/clients/middleware/signing/utils/getUpdatedSystemClockOffset.js +2 -2
- package/lib/clients/middleware/signing/utils/isClockSkewed.js +4 -6
- package/lib/clients/middleware/userAgent/middleware.js +14 -63
- package/lib/clients/serde/json.js +30 -96
- package/lib/clients/serde/responseInfo.js +12 -18
- package/lib/clients/utils/memoization.js +3 -3
- package/lib/constants.js +1 -1
- package/lib/errors/AmplifyError.js +9 -28
- package/lib/errors/PlatformNotSupportedError.js +7 -24
- package/lib/errors/createAssertionFunction.js +12 -15
- package/lib/errors/errorHelpers.js +7 -8
- package/lib/index.d.ts +1 -1
- package/lib/libraryUtils.d.ts +4 -0
- package/lib/libraryUtils.js +13 -3
- package/lib/parseAWSExports.js +109 -100
- package/lib/providers/kinesis/types/kinesis.d.ts +1 -1
- package/lib/providers/kinesis-firehose/types/kinesis-firehose.d.ts +1 -1
- package/lib/providers/personalize/types/personalize.d.ts +1 -1
- package/lib/providers/pinpoint/apis/flushEvents.js +8 -8
- package/lib/providers/pinpoint/apis/record.js +58 -93
- package/lib/providers/pinpoint/apis/updateEndpoint.js +65 -112
- package/lib/providers/pinpoint/types/pinpoint.d.ts +3 -1
- package/lib/providers/pinpoint/utils/PinpointEventBuffer.js +105 -196
- package/lib/providers/pinpoint/utils/cacheEndpointId.js +12 -49
- package/lib/providers/pinpoint/utils/getCacheKey.js +2 -2
- package/lib/providers/pinpoint/utils/getEndpointId.js +7 -51
- package/lib/providers/pinpoint/utils/getEventBuffer.js +19 -21
- package/lib/providers/pinpoint/utils/isAppInForeground.js +1 -1
- package/lib/providers/pinpoint/utils/isAppInForeground.native.js +2 -2
- package/lib/providers/pinpoint/utils/resolveEndpointId.js +20 -71
- package/lib/singleton/Amplify.d.ts +4 -0
- package/lib/singleton/Amplify.js +21 -103
- package/lib/singleton/Analytics/types.d.ts +5 -1
- package/lib/singleton/Auth/index.js +48 -115
- package/lib/singleton/Auth/types.d.ts +2 -2
- package/lib/singleton/Auth/utils/errorHelpers.js +7 -8
- package/lib/singleton/Auth/utils/index.js +18 -19
- package/lib/singleton/Predictions/types.d.ts +49 -0
- package/lib/singleton/Predictions/types.js +4 -0
- package/lib/singleton/apis/clearCredentials.js +1 -1
- package/lib/singleton/apis/fetchAuthSession.js +3 -3
- package/lib/singleton/apis/internal/fetchAuthSession.js +1 -1
- package/lib/singleton/apis/server/fetchAuthSession.js +3 -3
- package/lib/singleton/types.d.ts +3 -1
- package/lib/storage/CookieStorage.js +29 -99
- package/lib/storage/CookieStorage.native.js +5 -22
- package/lib/storage/DefaultStorage.js +6 -23
- package/lib/storage/DefaultStorage.native.js +18 -64
- package/lib/storage/InMemoryStorage.js +17 -23
- package/lib/storage/KeyValueStorage.js +24 -80
- package/lib/storage/SessionStorage.js +6 -23
- package/lib/storage/index.js +4 -4
- package/lib/storage/utils.js +7 -11
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/WordArray.d.ts +7 -0
- package/lib/utils/WordArray.js +49 -0
- package/lib/utils/amplifyUrl/index.js +2 -2
- package/lib/utils/amplifyUrl/polyfill.native.js +1 -1
- package/lib/utils/amplifyUuid/index.d.ts +1 -1
- package/lib/utils/amplifyUuid/index.js +2 -2
- package/lib/utils/amplifyUuid/polyfill.native.js +1 -1
- package/lib/utils/convert/base64/base64Decoder.js +2 -2
- package/lib/utils/convert/base64/base64Encoder.js +5 -6
- package/lib/utils/convert/base64/bytesToString.js +1 -1
- package/lib/utils/cryptoSecureRandomInt.d.ts +1 -0
- package/lib/utils/cryptoSecureRandomInt.js +16 -0
- package/lib/utils/deepFreeze.js +6 -28
- package/lib/utils/generateRandomString.js +4 -4
- package/lib/utils/getClientInfo/getClientInfo.android.js +7 -7
- package/lib/utils/getClientInfo/getClientInfo.ios.js +12 -12
- package/lib/utils/getClientInfo/getClientInfo.js +16 -16
- package/lib/utils/globalHelpers/index.js +4 -4
- package/lib/utils/globalHelpers/index.native.js +6 -6
- package/lib/utils/isBrowser.js +1 -3
- package/lib/utils/isWebWorker.js +2 -2
- package/lib/utils/retry/NonRetryableError.js +5 -23
- package/lib/utils/retry/isNonRetryableError.js +2 -2
- package/lib/utils/retry/jitteredBackoff.js +6 -7
- package/lib/utils/retry/jitteredExponentialRetry.js +4 -7
- package/lib/utils/retry/retry.js +50 -140
- package/lib/utils/sessionListener/SessionListener.js +17 -19
- package/lib/utils/sessionListener/SessionListener.native.js +18 -22
- package/lib/utils/sessionListener/constants.d.ts +2 -0
- package/lib/utils/sessionListener/constants.js +8 -0
- package/lib/utils/sessionListener/index.d.ts +1 -0
- package/lib/utils/sessionListener/index.js +5 -2
- package/lib/utils/urlSafeDecode.js +2 -2
- package/lib/utils/urlSafeEncode.js +1 -1
- package/lib-esm/BackgroundProcessManager/BackgroundManagerNotOpenError.js +4 -22
- package/lib-esm/BackgroundProcessManager/BackgroundProcessManager.js +124 -244
- package/lib-esm/Cache/StorageCache.js +26 -87
- package/lib-esm/Cache/StorageCache.native.js +33 -136
- package/lib-esm/Cache/StorageCacheCommon.js +267 -597
- package/lib-esm/Cache/constants.js +2 -2
- package/lib-esm/Cache/index.js +1 -1
- package/lib-esm/Cache/utils/CacheList.js +41 -66
- package/lib-esm/Cache/utils/cacheHelpers.js +5 -7
- package/lib-esm/Cache/utils/errorHelpers.js +6 -7
- package/lib-esm/Hub/index.js +34 -75
- package/lib-esm/I18n/I18n.js +23 -39
- package/lib-esm/I18n/errorHelpers.js +4 -5
- package/lib-esm/I18n/index.js +21 -25
- package/lib-esm/I18n/types.js +3 -5
- package/lib-esm/Logger/ConsoleLogger.js +52 -128
- package/lib-esm/Mutex/Mutex.js +15 -20
- package/lib-esm/Platform/customUserAgent.js +13 -26
- package/lib-esm/Platform/detectFramework.js +11 -12
- package/lib-esm/Platform/detection/Angular.js +3 -4
- package/lib-esm/Platform/detection/React.js +4 -4
- package/lib-esm/Platform/detection/Svelte.js +1 -1
- package/lib-esm/Platform/detection/helpers.js +7 -7
- package/lib-esm/Platform/detection/index.js +3 -3
- package/lib-esm/Platform/index.js +23 -52
- package/lib-esm/Platform/types.d.ts +1 -1
- package/lib-esm/Platform/types.js +1 -1
- package/lib-esm/Platform/version.d.ts +1 -1
- package/lib-esm/Platform/version.js +1 -1
- package/lib-esm/Reachability/Reachability.js +18 -46
- package/lib-esm/Reachability/Reachability.native.js +10 -15
- package/lib-esm/ServiceWorker/ServiceWorker.js +74 -131
- package/lib-esm/ServiceWorker/errorHelpers.js +6 -7
- package/lib-esm/Signer/DateUtils.d.ts +9 -0
- package/lib-esm/Signer/DateUtils.js +20 -29
- package/lib-esm/Signer/Signer.d.ts +9 -0
- package/lib-esm/Signer/Signer.js +54 -51
- package/lib-esm/adapterCore/error/AmplifyServerContextError.js +8 -27
- package/lib-esm/adapterCore/serverContext/serverContext.js +6 -6
- package/lib-esm/adapterCore/serverContext/serverContextRegistry.js +7 -7
- package/lib-esm/awsClients/cognitoIdentity/base.js +21 -69
- package/lib-esm/awsClients/cognitoIdentity/getCredentialsForIdentity.js +22 -66
- package/lib-esm/awsClients/cognitoIdentity/getId.js +17 -60
- package/lib-esm/awsClients/pinpoint/base.js +8 -11
- package/lib-esm/awsClients/pinpoint/errorHelpers.js +4 -5
- package/lib-esm/awsClients/pinpoint/getInAppMessages.js +19 -63
- package/lib-esm/awsClients/pinpoint/putEvents.js +20 -64
- package/lib-esm/awsClients/pinpoint/updateEndpoint.js +23 -67
- package/lib-esm/clients/endpoints/getDnsSuffix.js +6 -28
- package/lib-esm/clients/endpoints/partitions.js +2 -2
- package/lib-esm/clients/handlers/authenticated.js +1 -1
- package/lib-esm/clients/handlers/fetch.js +40 -97
- package/lib-esm/clients/handlers/unauthenticated.js +1 -1
- package/lib-esm/clients/internal/composeServiceApi.js +17 -67
- package/lib-esm/clients/internal/composeTransferHandler.js +9 -11
- package/lib-esm/clients/middleware/retry/defaultRetryDecider.js +17 -74
- package/lib-esm/clients/middleware/retry/isClockSkewError.js +2 -4
- package/lib-esm/clients/middleware/retry/jitteredBackoff.js +4 -4
- package/lib-esm/clients/middleware/retry/middleware.js +61 -125
- package/lib-esm/clients/middleware/signing/middleware.js +21 -83
- package/lib-esm/clients/middleware/signing/signer/signatureV4/constants.js +17 -17
- package/lib-esm/clients/middleware/signing/signer/signatureV4/index.js +0 -1
- package/lib-esm/clients/middleware/signing/signer/signatureV4/presignUrl.js +17 -52
- package/lib-esm/clients/middleware/signing/signer/signatureV4/signRequest.js +10 -21
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/dataHashHelpers.js +5 -5
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalHeaders.js +8 -30
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalQueryString.js +11 -38
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalRequest.js +8 -12
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalUri.js +5 -8
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCredentialScope.js +1 -1
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getFormattedDates.js +3 -3
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getHashedPayload.js +5 -9
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getSignature.js +5 -6
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getSignedHeaders.js +4 -6
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getSigningKey.js +6 -6
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getSigningValues.js +13 -14
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getStringToSign.js +1 -3
- package/lib-esm/clients/middleware/signing/utils/extendedEncodeURIComponent.js +3 -5
- package/lib-esm/clients/middleware/signing/utils/getSkewCorrectedDate.js +1 -3
- package/lib-esm/clients/middleware/signing/utils/getUpdatedSystemClockOffset.js +1 -1
- package/lib-esm/clients/middleware/signing/utils/isClockSkewed.js +3 -5
- package/lib-esm/clients/middleware/userAgent/middleware.js +14 -63
- package/lib-esm/clients/serde/json.js +29 -95
- package/lib-esm/clients/serde/responseInfo.js +11 -17
- package/lib-esm/clients/utils/memoization.js +3 -3
- package/lib-esm/constants.js +5 -5
- package/lib-esm/errors/AmplifyError.js +9 -29
- package/lib-esm/errors/PlatformNotSupportedError.js +5 -23
- package/lib-esm/errors/createAssertionFunction.js +11 -14
- package/lib-esm/errors/errorHelpers.js +6 -7
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/libraryUtils.d.ts +4 -0
- package/lib-esm/libraryUtils.js +4 -0
- package/lib-esm/parseAWSExports.js +108 -99
- package/lib-esm/providers/kinesis/types/kinesis.d.ts +1 -1
- package/lib-esm/providers/kinesis-firehose/types/kinesis-firehose.d.ts +1 -1
- package/lib-esm/providers/personalize/types/personalize.d.ts +1 -1
- package/lib-esm/providers/pinpoint/apis/flushEvents.js +6 -6
- package/lib-esm/providers/pinpoint/apis/record.js +54 -89
- package/lib-esm/providers/pinpoint/apis/updateEndpoint.js +61 -108
- package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +3 -1
- package/lib-esm/providers/pinpoint/utils/PinpointEventBuffer.js +102 -194
- package/lib-esm/providers/pinpoint/utils/cacheEndpointId.js +10 -47
- package/lib-esm/providers/pinpoint/utils/constants.js +4 -4
- package/lib-esm/providers/pinpoint/utils/getCacheKey.js +2 -2
- package/lib-esm/providers/pinpoint/utils/getEndpointId.js +5 -49
- package/lib-esm/providers/pinpoint/utils/getEventBuffer.js +17 -19
- package/lib-esm/providers/pinpoint/utils/isAppInForeground.js +1 -1
- package/lib-esm/providers/pinpoint/utils/isAppInForeground.native.js +1 -1
- package/lib-esm/providers/pinpoint/utils/resolveEndpointId.js +16 -67
- package/lib-esm/singleton/Amplify.d.ts +4 -0
- package/lib-esm/singleton/Amplify.js +18 -101
- package/lib-esm/singleton/Analytics/types.d.ts +5 -1
- package/lib-esm/singleton/Auth/index.js +48 -116
- package/lib-esm/singleton/Auth/types.d.ts +2 -2
- package/lib-esm/singleton/Auth/utils/errorHelpers.js +7 -8
- package/lib-esm/singleton/Auth/utils/index.js +16 -17
- package/lib-esm/singleton/Predictions/types.d.ts +49 -0
- package/lib-esm/singleton/Predictions/types.js +3 -0
- package/lib-esm/singleton/apis/fetchAuthSession.js +1 -1
- package/lib-esm/singleton/apis/internal/fetchAuthSession.js +1 -1
- package/lib-esm/singleton/apis/server/fetchAuthSession.js +1 -1
- package/lib-esm/singleton/types.d.ts +3 -1
- package/lib-esm/storage/CookieStorage.js +28 -99
- package/lib-esm/storage/CookieStorage.native.js +4 -22
- package/lib-esm/storage/DefaultStorage.js +4 -22
- package/lib-esm/storage/DefaultStorage.native.js +17 -64
- package/lib-esm/storage/InMemoryStorage.js +17 -24
- package/lib-esm/storage/KeyValueStorage.js +23 -80
- package/lib-esm/storage/SessionStorage.js +4 -22
- package/lib-esm/storage/index.js +3 -3
- package/lib-esm/storage/utils.js +6 -10
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/utils/WordArray.d.ts +7 -0
- package/lib-esm/utils/WordArray.js +46 -0
- package/lib-esm/utils/amplifyUrl/index.js +2 -2
- package/lib-esm/utils/amplifyUuid/index.d.ts +1 -1
- package/lib-esm/utils/amplifyUuid/index.js +1 -1
- package/lib-esm/utils/convert/base64/base64Decoder.js +2 -2
- package/lib-esm/utils/convert/base64/base64Encoder.js +4 -5
- package/lib-esm/utils/convert/base64/bytesToString.js +1 -1
- package/lib-esm/utils/cryptoSecureRandomInt.d.ts +1 -0
- package/lib-esm/utils/cryptoSecureRandomInt.js +12 -0
- package/lib-esm/utils/deepFreeze.js +6 -28
- package/lib-esm/utils/generateRandomString.js +4 -4
- package/lib-esm/utils/getClientInfo/getClientInfo.android.js +5 -5
- package/lib-esm/utils/getClientInfo/getClientInfo.ios.js +10 -10
- package/lib-esm/utils/getClientInfo/getClientInfo.js +15 -15
- package/lib-esm/utils/globalHelpers/index.js +3 -3
- package/lib-esm/utils/globalHelpers/index.native.js +4 -4
- package/lib-esm/utils/isBrowser.js +1 -3
- package/lib-esm/utils/isWebWorker.js +2 -2
- package/lib-esm/utils/retry/NonRetryableError.js +5 -24
- package/lib-esm/utils/retry/constants.js +1 -1
- package/lib-esm/utils/retry/isNonRetryableError.js +2 -2
- package/lib-esm/utils/retry/jitteredBackoff.js +5 -6
- package/lib-esm/utils/retry/jitteredExponentialRetry.js +1 -4
- package/lib-esm/utils/retry/retry.js +48 -138
- package/lib-esm/utils/sessionListener/SessionListener.js +16 -19
- package/lib-esm/utils/sessionListener/SessionListener.native.js +17 -22
- package/lib-esm/utils/sessionListener/constants.d.ts +2 -0
- package/lib-esm/utils/sessionListener/constants.js +5 -0
- package/lib-esm/utils/sessionListener/index.d.ts +1 -0
- package/lib-esm/utils/sessionListener/index.js +2 -1
- package/lib-esm/utils/urlSafeDecode.js +2 -2
- package/lib-esm/utils/urlSafeEncode.js +1 -1
- package/package.json +11 -24
- package/src/Cache/types/index.ts +4 -4
- package/src/Platform/types.ts +1 -1
- package/src/Platform/version.ts +1 -1
- package/src/Signer/DateUtils.ts +10 -2
- package/src/Signer/Signer.ts +9 -2
- package/src/clients/middleware/signing/signer/signatureV4/index.ts +0 -1
- package/src/index.ts +1 -0
- package/src/libraryUtils.ts +7 -1
- package/src/parseAWSExports.ts +45 -6
- package/src/providers/kinesis/types/kinesis.ts +1 -1
- package/src/providers/kinesis-firehose/types/kinesis-firehose.ts +1 -1
- package/src/providers/personalize/types/personalize.ts +1 -1
- package/src/providers/pinpoint/apis/record.ts +22 -5
- package/src/providers/pinpoint/types/pinpoint.ts +3 -1
- package/src/singleton/Amplify.ts +9 -52
- package/src/singleton/Analytics/types.ts +9 -4
- package/src/singleton/Auth/types.ts +2 -2
- package/src/singleton/Predictions/types.ts +61 -0
- package/src/singleton/types.ts +3 -1
- package/src/utils/WordArray.ts +57 -0
- package/src/utils/amplifyUuid/index.ts +1 -1
- package/src/utils/cryptoSecureRandomInt.ts +14 -0
- package/src/utils/sessionListener/constants.ts +6 -0
- package/src/utils/sessionListener/index.ts +1 -0
|
@@ -1,52 +1,5 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
13
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
14
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
15
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
|
-
function step(op) {
|
|
17
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
18
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
19
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
20
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
21
|
-
switch (op[0]) {
|
|
22
|
-
case 0: case 1: t = op; break;
|
|
23
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
24
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
25
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
26
|
-
default:
|
|
27
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
28
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
29
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
30
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
31
|
-
if (t[2]) _.ops.pop();
|
|
32
|
-
_.trys.pop(); continue;
|
|
33
|
-
}
|
|
34
|
-
op = body.call(thisArg, _);
|
|
35
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
36
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
var __values = (this && this.__values) || function(o) {
|
|
40
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
41
|
-
if (m) return m.call(o);
|
|
42
|
-
if (o && typeof o.length === "number") return {
|
|
43
|
-
next: function () {
|
|
44
|
-
if (o && i >= o.length) o = void 0;
|
|
45
|
-
return { value: o && o[i++], done: !o };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
49
|
-
};
|
|
50
3
|
import { BackgroundManagerNotOpenError } from './BackgroundManagerNotOpenError';
|
|
51
4
|
import { BackgroundProcessManagerState } from './types';
|
|
52
5
|
/**
|
|
@@ -59,13 +12,13 @@ import { BackgroundProcessManagerState } from './types';
|
|
|
59
12
|
* As work completes on its own prior to close, the manager removes them
|
|
60
13
|
* from the registry to avoid holding references to completed jobs.
|
|
61
14
|
*/
|
|
62
|
-
|
|
15
|
+
export class BackgroundProcessManager {
|
|
63
16
|
/**
|
|
64
17
|
* Creates a new manager for promises, observables, and other types
|
|
65
18
|
* of work that may be running in the background. This manager provides
|
|
66
19
|
* a centralized mechanism to request termination and await completion.
|
|
67
20
|
*/
|
|
68
|
-
|
|
21
|
+
constructor() {
|
|
69
22
|
/**
|
|
70
23
|
* A string indicating whether the manager is accepting new work ("Open"),
|
|
71
24
|
* waiting for work to complete ("Closing"), or fully done with all
|
|
@@ -77,9 +30,9 @@ var BackgroundProcessManager = /** @class */ (function () {
|
|
|
77
30
|
*/
|
|
78
31
|
this.jobs = new Set();
|
|
79
32
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
33
|
+
add(jobOrDescription, optionalDescription) {
|
|
34
|
+
let job;
|
|
35
|
+
let description;
|
|
83
36
|
if (typeof jobOrDescription === 'string') {
|
|
84
37
|
job = undefined;
|
|
85
38
|
description = jobOrDescription;
|
|
@@ -88,7 +41,7 @@ var BackgroundProcessManager = /** @class */ (function () {
|
|
|
88
41
|
job = jobOrDescription;
|
|
89
42
|
description = optionalDescription;
|
|
90
43
|
}
|
|
91
|
-
|
|
44
|
+
const error = this.closedFailure(description);
|
|
92
45
|
if (error)
|
|
93
46
|
return error;
|
|
94
47
|
if (job === undefined) {
|
|
@@ -103,7 +56,7 @@ var BackgroundProcessManager = /** @class */ (function () {
|
|
|
103
56
|
else {
|
|
104
57
|
throw new Error('If `job` is provided, it must be an Observable, Function, or BackgroundProcessManager.');
|
|
105
58
|
}
|
|
106
|
-
}
|
|
59
|
+
}
|
|
107
60
|
/**
|
|
108
61
|
* Adds a **cleaner** function that doesn't immediately get executed.
|
|
109
62
|
* Instead, the caller gets a **terminate** function back. The *cleaner* is
|
|
@@ -114,51 +67,37 @@ var BackgroundProcessManager = /** @class */ (function () {
|
|
|
114
67
|
* @param description Optional description to help identify pending jobs.
|
|
115
68
|
* @returns A terminate function.
|
|
116
69
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
case 0: return [4 /*yield*/, clean()];
|
|
124
|
-
case 1:
|
|
125
|
-
_a.sent();
|
|
126
|
-
resolve();
|
|
127
|
-
return [2 /*return*/];
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}); };
|
|
70
|
+
addCleaner(clean, description) {
|
|
71
|
+
const { resolve, onTerminate } = this.addHook(description);
|
|
72
|
+
const proxy = async () => {
|
|
73
|
+
await clean();
|
|
74
|
+
resolve();
|
|
75
|
+
};
|
|
131
76
|
onTerminate.then(proxy);
|
|
132
77
|
return proxy;
|
|
133
|
-
}
|
|
134
|
-
|
|
78
|
+
}
|
|
79
|
+
addFunction(job, description) {
|
|
135
80
|
// the function we call when we want to try to terminate this job.
|
|
136
|
-
|
|
81
|
+
let terminate;
|
|
137
82
|
// the promise the job can opt into listening to for termination.
|
|
138
|
-
|
|
83
|
+
const onTerminate = new Promise(resolve => {
|
|
139
84
|
terminate = resolve;
|
|
140
85
|
});
|
|
141
86
|
// finally! start the job.
|
|
142
|
-
|
|
87
|
+
const jobResult = job(onTerminate);
|
|
143
88
|
// depending on what the job gives back, register the result
|
|
144
89
|
// so we can monitor for completion.
|
|
145
|
-
if (typeof
|
|
90
|
+
if (typeof jobResult?.then === 'function') {
|
|
146
91
|
this.registerPromise(jobResult, terminate, description);
|
|
147
92
|
}
|
|
148
93
|
// At the end of the day, or you know, method call, it doesn't matter
|
|
149
94
|
// what the return value is at all; we just pass it through to the
|
|
150
95
|
// caller.
|
|
151
96
|
return jobResult;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
switch (_a.label) {
|
|
157
|
-
case 0: return [4 /*yield*/, manager.close()];
|
|
158
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
159
|
-
}
|
|
160
|
-
}); }); }, description);
|
|
161
|
-
};
|
|
97
|
+
}
|
|
98
|
+
addManager(manager, description) {
|
|
99
|
+
this.addCleaner(async () => await manager.close(), description);
|
|
100
|
+
}
|
|
162
101
|
/**
|
|
163
102
|
* Creates and registers a fabricated job for processes that need to operate
|
|
164
103
|
* with callbacks/hooks. The returned `resolve` and `reject`
|
|
@@ -169,30 +108,30 @@ var BackgroundProcessManager = /** @class */ (function () {
|
|
|
169
108
|
* @param description Optional description to help identify pending jobs.
|
|
170
109
|
* @returns `{ resolve, reject, onTerminate }`
|
|
171
110
|
*/
|
|
172
|
-
|
|
111
|
+
addHook(description) {
|
|
173
112
|
// the resolve/reject functions we'll provide to the caller to signal
|
|
174
113
|
// the state of the job.
|
|
175
|
-
|
|
176
|
-
|
|
114
|
+
let resolve;
|
|
115
|
+
let reject;
|
|
177
116
|
// the underlying promise we'll use to manage it, pretty much like
|
|
178
117
|
// any other promise.
|
|
179
|
-
|
|
118
|
+
const promise = new Promise((res, rej) => {
|
|
180
119
|
resolve = res;
|
|
181
120
|
reject = rej;
|
|
182
121
|
});
|
|
183
122
|
// the function we call when we want to try to terminate this job.
|
|
184
|
-
|
|
123
|
+
let terminate;
|
|
185
124
|
// the promise the job can opt into listening to for termination.
|
|
186
|
-
|
|
125
|
+
const onTerminate = new Promise(resolveTerminate => {
|
|
187
126
|
terminate = resolveTerminate;
|
|
188
127
|
});
|
|
189
128
|
this.registerPromise(promise, terminate, description);
|
|
190
129
|
return {
|
|
191
|
-
resolve
|
|
192
|
-
reject
|
|
193
|
-
onTerminate
|
|
130
|
+
resolve,
|
|
131
|
+
reject,
|
|
132
|
+
onTerminate,
|
|
194
133
|
};
|
|
195
|
-
}
|
|
134
|
+
}
|
|
196
135
|
/**
|
|
197
136
|
* Adds a Promise based job to the list of jobs for monitoring and listens
|
|
198
137
|
* for either a success or failure, upon which the job is considered "done"
|
|
@@ -204,9 +143,8 @@ var BackgroundProcessManager = /** @class */ (function () {
|
|
|
204
143
|
* invoked to request the job stop.
|
|
205
144
|
* @param description Optional description to help identify pending jobs.
|
|
206
145
|
*/
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
var jobEntry = { promise: promise, terminate: terminate, description: description };
|
|
146
|
+
registerPromise(promise, terminate, description) {
|
|
147
|
+
const jobEntry = { promise, terminate, description };
|
|
210
148
|
this.jobs.add(jobEntry);
|
|
211
149
|
// in all of my testing, it is safe to multi-subscribe to a promise.
|
|
212
150
|
// so, rather than create another layer of promising, we're just going
|
|
@@ -219,97 +157,73 @@ var BackgroundProcessManager = /** @class */ (function () {
|
|
|
219
157
|
// `.finally` is invoked in a different order in the sequence, and this
|
|
220
158
|
// breaks assumptions throughout and causes failures.
|
|
221
159
|
promise
|
|
222
|
-
.then(
|
|
223
|
-
|
|
160
|
+
.then(() => {
|
|
161
|
+
this.jobs.delete(jobEntry);
|
|
224
162
|
})
|
|
225
|
-
.catch(
|
|
226
|
-
|
|
163
|
+
.catch(() => {
|
|
164
|
+
this.jobs.delete(jobEntry);
|
|
227
165
|
});
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
});
|
|
280
|
-
Object.defineProperty(BackgroundProcessManager.prototype, "isClosing", {
|
|
281
|
-
/**
|
|
282
|
-
* Whether the manager is rejecting new work, but still waiting for
|
|
283
|
-
* submitted work to complete.
|
|
284
|
-
*/
|
|
285
|
-
get: function () {
|
|
286
|
-
return this._state === BackgroundProcessManagerState.Closing;
|
|
287
|
-
},
|
|
288
|
-
enumerable: false,
|
|
289
|
-
configurable: true
|
|
290
|
-
});
|
|
291
|
-
Object.defineProperty(BackgroundProcessManager.prototype, "isClosed", {
|
|
292
|
-
/**
|
|
293
|
-
* Whether the manager is rejecting work and done waiting for submitted
|
|
294
|
-
* work to complete.
|
|
295
|
-
*/
|
|
296
|
-
get: function () {
|
|
297
|
-
return this._state === BackgroundProcessManagerState.Closed;
|
|
298
|
-
},
|
|
299
|
-
enumerable: false,
|
|
300
|
-
configurable: true
|
|
301
|
-
});
|
|
302
|
-
BackgroundProcessManager.prototype.closedFailure = function (description) {
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The number of jobs being waited on.
|
|
169
|
+
*
|
|
170
|
+
* We don't use this for anything. It's just informational for the caller,
|
|
171
|
+
* and can be used in logging and testing.
|
|
172
|
+
*
|
|
173
|
+
* @returns the number of jobs.
|
|
174
|
+
*/
|
|
175
|
+
get length() {
|
|
176
|
+
return this.jobs.size;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* The execution state of the manager. One of:
|
|
180
|
+
*
|
|
181
|
+
* 1. "Open" -> Accepting new jobs
|
|
182
|
+
* 1. "Closing" -> Not accepting new work. Waiting for jobs to complete.
|
|
183
|
+
* 1. "Closed" -> Not accepting new work. All submitted jobs are complete.
|
|
184
|
+
*/
|
|
185
|
+
get state() {
|
|
186
|
+
return this._state;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The registered `description` of all still-pending jobs.
|
|
190
|
+
*
|
|
191
|
+
* @returns descriptions as an array.
|
|
192
|
+
*/
|
|
193
|
+
get pending() {
|
|
194
|
+
return Array.from(this.jobs).map(job => job.description);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Whether the manager is accepting new jobs.
|
|
198
|
+
*/
|
|
199
|
+
get isOpen() {
|
|
200
|
+
return this._state === BackgroundProcessManagerState.Open;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Whether the manager is rejecting new work, but still waiting for
|
|
204
|
+
* submitted work to complete.
|
|
205
|
+
*/
|
|
206
|
+
get isClosing() {
|
|
207
|
+
return this._state === BackgroundProcessManagerState.Closing;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Whether the manager is rejecting work and done waiting for submitted
|
|
211
|
+
* work to complete.
|
|
212
|
+
*/
|
|
213
|
+
get isClosed() {
|
|
214
|
+
return this._state === BackgroundProcessManagerState.Closed;
|
|
215
|
+
}
|
|
216
|
+
closedFailure(description) {
|
|
303
217
|
if (!this.isOpen) {
|
|
304
218
|
return Promise.reject(new BackgroundManagerNotOpenError([
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
.map(
|
|
309
|
-
.join(',\n')
|
|
219
|
+
`The manager is ${this.state}.`,
|
|
220
|
+
`You tried to add "${description}".`,
|
|
221
|
+
`Pending jobs: [\n${this.pending
|
|
222
|
+
.map(t => ' ' + t)
|
|
223
|
+
.join(',\n')}\n]`,
|
|
310
224
|
].join('\n')));
|
|
311
225
|
}
|
|
312
|
-
}
|
|
226
|
+
}
|
|
313
227
|
/**
|
|
314
228
|
* Signals jobs to stop (for those that accept interruptions) and waits
|
|
315
229
|
* for confirmation that jobs have stopped.
|
|
@@ -327,49 +241,28 @@ var BackgroundProcessManager = /** @class */ (function () {
|
|
|
327
241
|
* manager is already closed, this will contain the results as of when the
|
|
328
242
|
* manager's `close()` was called in an `Open` state.
|
|
329
243
|
*/
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
case 0:
|
|
337
|
-
if (!this.isOpen) return [3 /*break*/, 2];
|
|
338
|
-
this._state = BackgroundProcessManagerState.Closing;
|
|
339
|
-
try {
|
|
340
|
-
for (_a = __values(Array.from(this.jobs)), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
341
|
-
job = _b.value;
|
|
342
|
-
try {
|
|
343
|
-
job.terminate();
|
|
344
|
-
}
|
|
345
|
-
catch (error) {
|
|
346
|
-
// Due to potential races with a job's natural completion, it's
|
|
347
|
-
// reasonable to expect the termination call to fail. Hence,
|
|
348
|
-
// not logging as an error.
|
|
349
|
-
console.warn("Failed to send termination signal to job. Error: ".concat(error.message), job);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
354
|
-
finally {
|
|
355
|
-
try {
|
|
356
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
357
|
-
}
|
|
358
|
-
finally { if (e_1) throw e_1.error; }
|
|
359
|
-
}
|
|
360
|
-
// Use `allSettled()` because we want to wait for all to finish. We do
|
|
361
|
-
// not want to stop waiting if there is a failure.
|
|
362
|
-
this._closingPromise = Promise.allSettled(Array.from(this.jobs).map(function (j) { return j.promise; }));
|
|
363
|
-
return [4 /*yield*/, this._closingPromise];
|
|
364
|
-
case 1:
|
|
365
|
-
_d.sent();
|
|
366
|
-
this._state = BackgroundProcessManagerState.Closed;
|
|
367
|
-
_d.label = 2;
|
|
368
|
-
case 2: return [2 /*return*/, this._closingPromise];
|
|
244
|
+
async close() {
|
|
245
|
+
if (this.isOpen) {
|
|
246
|
+
this._state = BackgroundProcessManagerState.Closing;
|
|
247
|
+
for (const job of Array.from(this.jobs)) {
|
|
248
|
+
try {
|
|
249
|
+
job.terminate();
|
|
369
250
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
251
|
+
catch (error) {
|
|
252
|
+
// Due to potential races with a job's natural completion, it's
|
|
253
|
+
// reasonable to expect the termination call to fail. Hence,
|
|
254
|
+
// not logging as an error.
|
|
255
|
+
console.warn(`Failed to send termination signal to job. Error: ${error.message}`, job);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// Use `allSettled()` because we want to wait for all to finish. We do
|
|
259
|
+
// not want to stop waiting if there is a failure.
|
|
260
|
+
this._closingPromise = Promise.allSettled(Array.from(this.jobs).map(j => j.promise));
|
|
261
|
+
await this._closingPromise;
|
|
262
|
+
this._state = BackgroundProcessManagerState.Closed;
|
|
263
|
+
}
|
|
264
|
+
return this._closingPromise;
|
|
265
|
+
}
|
|
373
266
|
/**
|
|
374
267
|
* Signals the manager to start accepting work (again) and returns once
|
|
375
268
|
* the manager is ready to do so.
|
|
@@ -381,23 +274,10 @@ var BackgroundProcessManager = /** @class */ (function () {
|
|
|
381
274
|
* If the state is `Closing`, this call waits for completion before it
|
|
382
275
|
* updates the state and returns.
|
|
383
276
|
*/
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
case 1:
|
|
392
|
-
_a.sent();
|
|
393
|
-
_a.label = 2;
|
|
394
|
-
case 2:
|
|
395
|
-
this._state = BackgroundProcessManagerState.Open;
|
|
396
|
-
return [2 /*return*/];
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
});
|
|
400
|
-
};
|
|
401
|
-
return BackgroundProcessManager;
|
|
402
|
-
}());
|
|
403
|
-
export { BackgroundProcessManager };
|
|
277
|
+
async open() {
|
|
278
|
+
if (this.isClosing) {
|
|
279
|
+
await this.close();
|
|
280
|
+
}
|
|
281
|
+
this._state = BackgroundProcessManagerState.Open;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
@@ -1,113 +1,52 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
var __extends = (this && this.__extends) || (function () {
|
|
4
|
-
var extendStatics = function (d, b) {
|
|
5
|
-
extendStatics = Object.setPrototypeOf ||
|
|
6
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
7
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
8
|
-
return extendStatics(d, b);
|
|
9
|
-
};
|
|
10
|
-
return function (d, b) {
|
|
11
|
-
if (typeof b !== "function" && b !== null)
|
|
12
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
13
|
-
extendStatics(d, b);
|
|
14
|
-
function __() { this.constructor = d; }
|
|
15
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
16
|
-
};
|
|
17
|
-
})();
|
|
18
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
19
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
20
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
21
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
22
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
23
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
24
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
28
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
29
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
30
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
31
|
-
function step(op) {
|
|
32
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
33
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
34
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
35
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
36
|
-
switch (op[0]) {
|
|
37
|
-
case 0: case 1: t = op; break;
|
|
38
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
39
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
40
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
41
|
-
default:
|
|
42
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
43
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
44
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
45
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
46
|
-
if (t[2]) _.ops.pop();
|
|
47
|
-
_.trys.pop(); continue;
|
|
48
|
-
}
|
|
49
|
-
op = body.call(thisArg, _);
|
|
50
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
51
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
3
|
import { ConsoleLogger as Logger } from '../Logger';
|
|
55
4
|
import { KeyValueStorage } from '../storage/KeyValueStorage';
|
|
56
5
|
import { getLocalStorageWithFallback } from '../storage/utils';
|
|
57
6
|
import { defaultConfig } from './constants';
|
|
58
7
|
import { StorageCacheCommon } from './StorageCacheCommon';
|
|
59
8
|
import { getCurrentSizeKey, getCurrentTime } from './utils';
|
|
60
|
-
|
|
9
|
+
const logger = new Logger('Cache');
|
|
61
10
|
/**
|
|
62
11
|
* Customized storage based on the SessionStorage or LocalStorage with LRU implemented
|
|
63
12
|
*/
|
|
64
|
-
|
|
65
|
-
__extends(StorageCache, _super);
|
|
13
|
+
export class StorageCache extends StorageCacheCommon {
|
|
66
14
|
/**
|
|
67
15
|
* initialize the cache
|
|
68
16
|
* @param config - the configuration of the cache
|
|
69
17
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
18
|
+
constructor(config) {
|
|
19
|
+
const storage = getLocalStorageWithFallback();
|
|
20
|
+
super({ config, keyValueStorage: new KeyValueStorage(storage) });
|
|
21
|
+
this.storage = storage;
|
|
22
|
+
this.getItem = this.getItem.bind(this);
|
|
23
|
+
this.setItem = this.setItem.bind(this);
|
|
24
|
+
this.removeItem = this.removeItem.bind(this);
|
|
25
|
+
}
|
|
26
|
+
async getAllCacheKeys(options) {
|
|
27
|
+
const { omitSizeKey } = options ?? {};
|
|
28
|
+
const keys = [];
|
|
29
|
+
for (let i = 0; i < this.storage.length; i++) {
|
|
30
|
+
const key = this.storage.key(i);
|
|
31
|
+
if (omitSizeKey && key === getCurrentSizeKey(this.config.keyPrefix)) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (key?.startsWith(this.config.keyPrefix)) {
|
|
35
|
+
keys.push(key.substring(this.config.keyPrefix.length));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return keys;
|
|
79
39
|
}
|
|
80
|
-
StorageCache.prototype.getAllCacheKeys = function (options) {
|
|
81
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
-
var omitSizeKey, keys, i, key;
|
|
83
|
-
return __generator(this, function (_a) {
|
|
84
|
-
omitSizeKey = (options !== null && options !== void 0 ? options : {}).omitSizeKey;
|
|
85
|
-
keys = [];
|
|
86
|
-
for (i = 0; i < this.storage.length; i++) {
|
|
87
|
-
key = this.storage.key(i);
|
|
88
|
-
if (omitSizeKey && key === getCurrentSizeKey(this.config.keyPrefix)) {
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
if (key === null || key === void 0 ? void 0 : key.startsWith(this.config.keyPrefix)) {
|
|
92
|
-
keys.push(key.substring(this.config.keyPrefix.length));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return [2 /*return*/, keys];
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
40
|
/**
|
|
100
41
|
* Return a new instance of cache with customized configuration.
|
|
101
42
|
* @param {Object} config - the customized configuration
|
|
102
43
|
* @return {Object} - the new instance of Cache
|
|
103
44
|
*/
|
|
104
|
-
|
|
45
|
+
createInstance(config) {
|
|
105
46
|
if (!config.keyPrefix || config.keyPrefix === defaultConfig.keyPrefix) {
|
|
106
47
|
logger.error('invalid keyPrefix, setting keyPrefix with timeStamp');
|
|
107
48
|
config.keyPrefix = getCurrentTime.toString();
|
|
108
49
|
}
|
|
109
50
|
return new StorageCache(config);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
}(StorageCacheCommon));
|
|
113
|
-
export { StorageCache };
|
|
51
|
+
}
|
|
52
|
+
}
|