@aws-amplify/core 6.0.1-preview-testing.034e780.0 → 6.0.1-server-generate-client.1e317a1.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/internals/aws-clients/pinpoint/package.json +4 -4
- package/lib/BackgroundProcessManager/BackgroundManagerNotOpenError.d.ts +3 -0
- package/lib/BackgroundProcessManager/BackgroundManagerNotOpenError.js +28 -0
- package/lib/{Util → BackgroundProcessManager}/BackgroundProcessManager.d.ts +1 -23
- package/lib/{Util → BackgroundProcessManager}/BackgroundProcessManager.js +13 -56
- package/lib/BackgroundProcessManager/index.d.ts +1 -0
- package/lib/BackgroundProcessManager/index.js +7 -0
- package/lib/BackgroundProcessManager/types.d.ts +41 -0
- package/lib/BackgroundProcessManager/types.js +23 -0
- package/lib/Cache/StorageCache.d.ts +14 -31
- package/lib/Cache/StorageCache.js +97 -102
- package/lib/Cache/StorageCache.native.d.ts +19 -0
- package/lib/Cache/StorageCache.native.js +164 -0
- package/lib/Cache/{AsyncStorageCache.d.ts → StorageCacheCommon.d.ts} +124 -99
- package/lib/Cache/{AsyncStorageCache.js → StorageCacheCommon.js} +494 -441
- package/lib/Cache/constants.d.ts +6 -0
- package/lib/Cache/constants.js +17 -0
- package/lib/Cache/index.d.ts +2 -0
- package/lib/Cache/index.js +7 -0
- package/lib/Cache/types/cache.d.ts +38 -0
- package/lib/Cache/types/index.d.ts +1 -1
- package/lib/Cache/types/index.js +1 -1
- package/lib/Cache/{Utils → utils}/CacheList.d.ts +1 -1
- package/lib/Cache/{Utils → utils}/CacheList.js +7 -19
- package/lib/Cache/utils/cacheHelpers.d.ts +14 -0
- package/lib/Cache/utils/cacheHelpers.js +51 -0
- package/lib/Cache/utils/errorHelpers.d.ts +7 -0
- package/lib/Cache/utils/errorHelpers.js +25 -0
- package/lib/Cache/utils/index.d.ts +2 -0
- package/lib/Cache/utils/index.js +12 -0
- package/lib/Hub/index.d.ts +7 -0
- package/lib/Hub/index.js +12 -5
- package/lib/Hub/types/AuthTypes.d.ts +19 -0
- package/lib/I18n/I18n.d.ts +3 -19
- package/lib/I18n/I18n.js +1 -21
- package/lib/I18n/errorHelpers.d.ts +5 -0
- package/lib/I18n/errorHelpers.js +17 -0
- package/lib/I18n/index.d.ts +3 -15
- package/lib/I18n/index.js +5 -30
- package/lib/I18n/types.d.ts +1 -4
- package/lib/I18n/types.js +5 -8
- package/lib/Logger/ConsoleLogger.js +2 -2
- package/{lib-esm/Util → lib/Mutex}/Mutex.d.ts +2 -15
- package/lib/{Util → Mutex}/Mutex.js +2 -1
- package/lib/Mutex/index.d.ts +1 -0
- package/lib/Mutex/index.js +7 -0
- package/lib/Mutex/types.d.ts +13 -0
- package/lib/Platform/customUserAgent.d.ts +16 -0
- package/lib/Platform/customUserAgent.js +70 -0
- package/lib/Platform/index.js +10 -1
- package/lib/Platform/types.d.ts +75 -8
- package/lib/Platform/types.js +40 -39
- package/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/Reachability/Reachability.d.ts +7 -0
- package/lib/{Util → Reachability}/Reachability.js +24 -23
- package/lib/Reachability/Reachability.native.d.ts +6 -0
- package/lib/{Util → Reachability}/Reachability.native.js +8 -10
- package/lib/Reachability/index.d.ts +1 -0
- package/lib/Reachability/index.js +7 -0
- package/lib/Reachability/types.d.ts +3 -0
- package/lib/Reachability/types.js +4 -0
- package/lib/ServiceWorker/ServiceWorker.js +84 -54
- package/lib/ServiceWorker/errorHelpers.d.ts +7 -0
- package/lib/ServiceWorker/errorHelpers.js +25 -0
- package/lib/ServiceWorker/index.d.ts +0 -12
- package/lib/ServiceWorker/index.js +0 -12
- package/lib/{Signer.js → Signer/Signer.js} +6 -5
- package/lib/Signer/index.d.ts +1 -0
- package/lib/Signer/index.js +7 -0
- package/lib/adapterCore/error/AmplifyServerContextError.d.ts +1 -1
- package/lib/adapterCore/error/AmplifyServerContextError.js +2 -2
- package/lib/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/base.js +2 -1
- package/lib/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/getCredentialsForIdentity.d.ts +2 -1
- package/lib/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/getId.d.ts +2 -1
- package/lib/awsClients/cognitoIdentity/types.js +4 -0
- package/lib/{AwsClients/Pinpoint → awsClients/pinpoint}/base.js +2 -1
- package/lib/awsClients/pinpoint/errorHelpers.d.ts +5 -0
- package/lib/awsClients/pinpoint/errorHelpers.js +17 -0
- package/{lib-esm/AwsClients/Pinpoint → lib/awsClients/pinpoint}/getInAppMessages.d.ts +4 -3
- package/lib/{AwsClients/Pinpoint → awsClients/pinpoint}/getInAppMessages.js +2 -1
- package/{lib-esm/AwsClients/Pinpoint → lib/awsClients/pinpoint}/putEvents.d.ts +4 -3
- package/lib/{AwsClients/Pinpoint → awsClients/pinpoint}/putEvents.js +4 -7
- package/lib/{AwsClients/Pinpoint → awsClients/pinpoint}/updateEndpoint.d.ts +4 -3
- package/lib/{AwsClients/Pinpoint → awsClients/pinpoint}/updateEndpoint.js +2 -1
- package/lib/clients/handlers/fetch.js +2 -1
- package/lib/clients/middleware/retry/jitteredBackoff.js +2 -2
- package/lib/clients/middleware/signing/signer/signatureV4/presignUrl.js +2 -1
- package/lib/clients/types/http.d.ts +17 -1
- package/lib/constants.d.ts +4 -0
- package/lib/constants.js +18 -0
- package/lib/{Util/Errors.d.ts → errors/AmplifyError.d.ts} +2 -9
- package/lib/{Util/Errors.js → errors/AmplifyError.js} +1 -18
- package/lib/errors/PlatformNotSupportedError.d.ts +4 -0
- package/lib/errors/PlatformNotSupportedError.js +33 -0
- package/lib/errors/createAssertionFunction.d.ts +3 -0
- package/lib/errors/createAssertionFunction.js +22 -0
- package/lib/errors/errorHelpers.d.ts +2 -0
- package/lib/errors/errorHelpers.js +20 -0
- package/lib/errors/index.d.ts +4 -0
- package/lib/errors/index.js +13 -0
- package/lib/index.d.ts +7 -7
- package/lib/index.js +17 -16
- package/lib/libraryUtils.d.ts +19 -16
- package/lib/libraryUtils.js +57 -69
- package/lib/parseAWSExports.js +144 -13
- package/lib/providers/kinesis/types/index.d.ts +1 -0
- package/lib/providers/kinesis/types/index.js +19 -0
- package/lib/providers/kinesis/types/kinesis.d.ts +9 -0
- package/lib/providers/kinesis/types/kinesis.js +4 -0
- package/lib/providers/kinesis-firehose/types/index.d.ts +1 -0
- package/lib/providers/kinesis-firehose/types/index.js +4 -0
- package/lib/providers/kinesis-firehose/types/kinesis-firehose.d.ts +9 -0
- package/lib/providers/kinesis-firehose/types/kinesis-firehose.js +4 -0
- package/lib/providers/personalize/types/index.d.ts +1 -0
- package/lib/providers/personalize/types/index.js +4 -0
- package/lib/providers/personalize/types/personalize.d.ts +8 -0
- package/lib/providers/personalize/types/personalize.js +4 -0
- package/lib/providers/pinpoint/apis/flushEvents.d.ts +2 -0
- package/lib/providers/pinpoint/apis/flushEvents.js +21 -0
- package/lib/providers/pinpoint/apis/index.d.ts +1 -0
- package/lib/providers/pinpoint/apis/index.js +3 -1
- package/lib/providers/pinpoint/apis/record.d.ts +1 -1
- package/lib/providers/pinpoint/apis/record.js +8 -24
- package/lib/providers/pinpoint/apis/updateEndpoint.d.ts +1 -1
- package/lib/providers/pinpoint/apis/updateEndpoint.js +15 -13
- package/lib/providers/pinpoint/index.d.ts +2 -1
- package/lib/providers/pinpoint/index.js +5 -0
- package/lib/providers/pinpoint/types/errors.d.ts +9 -0
- package/lib/providers/pinpoint/types/errors.js +15 -0
- package/lib/providers/pinpoint/types/index.d.ts +1 -0
- package/lib/providers/pinpoint/types/index.js +3 -0
- package/lib/providers/pinpoint/types/pinpoint.d.ts +5 -4
- package/lib/providers/pinpoint/utils/PinpointEventBuffer.d.ts +1 -0
- package/lib/providers/pinpoint/utils/PinpointEventBuffer.js +12 -7
- package/lib/providers/pinpoint/utils/index.d.ts +1 -0
- package/lib/providers/pinpoint/utils/index.js +3 -1
- package/lib/providers/pinpoint/utils/isAppInForeground.d.ts +1 -0
- package/lib/{RNComponents → providers/pinpoint/utils}/isAppInForeground.js +1 -4
- package/lib/providers/pinpoint/utils/isAppInForeground.native.d.ts +1 -0
- package/lib/providers/pinpoint/utils/isAppInForeground.native.js +9 -0
- package/lib/providers/pinpoint/utils/resolveEndpointId.d.ts +8 -0
- package/lib/{StorageHelper/inMemoryStorage.js → providers/pinpoint/utils/resolveEndpointId.js} +44 -41
- package/lib/singleton/API/types.d.ts +165 -0
- package/lib/singleton/API/types.js +12 -0
- package/lib/singleton/Amplify.d.ts +2 -2
- package/lib/singleton/Amplify.js +6 -5
- package/lib/singleton/Analytics/types.d.ts +4 -1
- package/lib/singleton/Auth/types.d.ts +29 -2
- package/lib/singleton/Auth/utils/errorHelpers.d.ts +8 -0
- package/lib/singleton/Auth/utils/errorHelpers.js +33 -0
- package/lib/singleton/Auth/utils/index.d.ts +1 -1
- package/lib/singleton/Auth/utils/index.js +21 -36
- package/lib/singleton/Cache/types.d.ts +18 -0
- package/lib/singleton/Cache/types.js +4 -0
- package/lib/singleton/Geo/types.d.ts +17 -0
- package/lib/singleton/Geo/types.js +4 -0
- package/lib/singleton/Interactions/types.d.ts +21 -0
- package/lib/singleton/Interactions/types.js +4 -0
- package/lib/singleton/Notifications/InAppMessaging/types.d.ts +2 -0
- package/lib/singleton/Notifications/InAppMessaging/types.js +4 -0
- package/lib/singleton/Notifications/PushNotification/types.d.ts +2 -0
- package/lib/singleton/Notifications/PushNotification/types.js +4 -0
- package/lib/singleton/Notifications/types.d.ts +6 -0
- package/lib/singleton/Notifications/types.js +4 -0
- package/lib/singleton/types.d.ts +10 -1
- package/{lib-esm/StorageHelper/cookieStorage.d.ts → lib/storage/CookieStorage.d.ts} +4 -3
- package/lib/{StorageHelper/cookieStorage.js → storage/CookieStorage.js} +38 -83
- package/lib/storage/CookieStorage.native.d.ts +7 -0
- package/lib/storage/CookieStorage.native.js +32 -0
- package/lib/storage/DefaultStorage.d.ts +7 -0
- package/lib/storage/DefaultStorage.js +33 -0
- package/{lib-esm/StorageHelper/localStorage.d.ts → lib/storage/DefaultStorage.native.d.ts} +6 -5
- package/lib/{StorageHelper/localStorage.js → storage/DefaultStorage.native.js} +25 -43
- package/lib/storage/InMemoryStorage.d.ts +12 -0
- package/lib/storage/InMemoryStorage.js +41 -0
- package/lib/{StorageHelper/sessionStorage.d.ts → storage/KeyValueStorage.d.ts} +5 -4
- package/{lib-esm/StorageHelper/sessionStorage.js → lib/storage/KeyValueStorage.js} +20 -19
- package/lib/storage/SessionStorage.d.ts +7 -0
- package/lib/storage/SessionStorage.js +33 -0
- package/lib/storage/index.d.ts +7 -0
- package/lib/storage/index.js +14 -0
- package/lib/storage/utils.d.ts +10 -0
- package/lib/storage/utils.js +26 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/core.d.ts +4 -1
- package/lib/types/errors.d.ts +9 -3
- package/lib/types/errors.js +7 -0
- package/lib/types/storage.d.ts +3 -0
- package/lib/utils/amplifyUrl/index.d.ts +13 -0
- package/lib/utils/amplifyUrl/index.js +10 -0
- package/lib/utils/amplifyUrl/polyfill.d.ts +0 -0
- package/lib/utils/amplifyUrl/polyfill.js +4 -0
- package/lib/utils/amplifyUrl/polyfill.native.d.ts +1 -0
- package/lib/utils/amplifyUrl/polyfill.native.js +6 -0
- package/lib/utils/amplifyUuid/index.d.ts +3 -0
- package/lib/utils/amplifyUuid/index.js +9 -0
- package/lib/utils/amplifyUuid/polyfill.d.ts +0 -0
- package/lib/utils/amplifyUuid/polyfill.js +4 -0
- package/lib/utils/amplifyUuid/polyfill.native.d.ts +1 -0
- package/lib/utils/amplifyUuid/polyfill.native.js +6 -0
- package/lib/utils/convert/base64/base64Decoder.d.ts +2 -0
- package/lib/utils/convert/base64/base64Decoder.js +11 -0
- package/lib/utils/convert/base64/base64Encoder.d.ts +2 -0
- package/lib/utils/convert/base64/base64Encoder.js +18 -0
- package/lib/utils/convert/base64/bytesToString.d.ts +1 -0
- package/lib/utils/convert/base64/bytesToString.js +9 -0
- package/lib/utils/convert/index.d.ts +2 -0
- package/lib/utils/convert/index.js +9 -0
- package/lib/utils/convert/types.d.ts +9 -0
- package/lib/utils/convert/types.js +4 -0
- package/lib/utils/deepFreeze.d.ts +1 -0
- package/lib/utils/deepFreeze.js +38 -0
- package/lib/utils/generateRandomString.d.ts +1 -0
- package/lib/utils/generateRandomString.js +14 -0
- package/lib/{ClientDevice/android.d.ts → utils/getClientInfo/getClientInfo.android.d.ts} +1 -1
- package/lib/{ClientDevice/android.js → utils/getClientInfo/getClientInfo.android.js} +4 -4
- package/{lib-esm/ClientDevice/browser.d.ts → lib/utils/getClientInfo/getClientInfo.d.ts} +1 -9
- package/lib/{ClientDevice/ios.d.ts → utils/getClientInfo/getClientInfo.ios.d.ts} +1 -1
- package/lib/{ClientDevice/ios.js → utils/getClientInfo/getClientInfo.ios.js} +4 -4
- package/lib/{ClientDevice/browser.js → utils/getClientInfo/getClientInfo.js} +6 -18
- package/lib/utils/getClientInfo/index.d.ts +1 -0
- package/lib/utils/getClientInfo/index.js +7 -0
- package/lib/utils/globalHelpers/index.d.ts +3 -0
- package/lib/utils/globalHelpers/index.js +50 -0
- package/lib/utils/globalHelpers/index.native.d.ts +3 -0
- package/lib/utils/globalHelpers/index.native.js +28 -0
- package/lib/utils/index.d.ts +8 -0
- package/lib/utils/index.js +25 -0
- package/lib/utils/isBrowser.d.ts +1 -0
- package/lib/utils/isBrowser.js +9 -0
- package/lib/utils/isWebWorker.d.ts +1 -0
- package/lib/utils/isWebWorker.js +14 -0
- package/lib/utils/retry/NonRetryableError.d.ts +4 -0
- package/lib/utils/retry/NonRetryableError.js +30 -0
- package/lib/utils/retry/constants.d.ts +1 -0
- package/lib/utils/retry/constants.js +6 -0
- package/lib/utils/retry/index.d.ts +5 -0
- package/lib/utils/retry/index.js +15 -0
- package/lib/utils/retry/isNonRetryableError.d.ts +2 -0
- package/lib/utils/retry/isNonRetryableError.js +10 -0
- package/lib/utils/retry/jitteredBackoff.d.ts +6 -0
- package/lib/utils/retry/jitteredBackoff.js +20 -0
- package/lib/utils/retry/jitteredExponentialRetry.d.ts +5 -0
- package/lib/utils/retry/jitteredExponentialRetry.js +17 -0
- package/lib/utils/retry/retry.d.ts +6 -0
- package/lib/{Util/Retry.js → utils/retry/retry.js} +6 -57
- package/lib/utils/sessionListener/SessionListener.d.ts +10 -0
- package/lib/utils/sessionListener/SessionListener.js +55 -0
- package/lib/utils/sessionListener/SessionListener.native.d.ts +10 -0
- package/lib/utils/sessionListener/SessionListener.native.js +54 -0
- package/lib/utils/sessionListener/index.d.ts +2 -0
- package/lib/utils/sessionListener/index.js +7 -0
- package/lib/utils/sessionListener/types.d.ts +6 -0
- package/lib/utils/sessionListener/types.js +4 -0
- package/lib/utils/urlSafeDecode.d.ts +1 -0
- package/lib/{Util/StringUtils.js → utils/urlSafeDecode.js} +2 -9
- package/lib/utils/urlSafeEncode.d.ts +1 -0
- package/lib/utils/urlSafeEncode.js +12 -0
- package/lib-esm/BackgroundProcessManager/BackgroundManagerNotOpenError.d.ts +3 -0
- package/lib-esm/BackgroundProcessManager/BackgroundManagerNotOpenError.js +25 -0
- package/lib-esm/{Util → BackgroundProcessManager}/BackgroundProcessManager.d.ts +1 -23
- package/lib-esm/{Util → BackgroundProcessManager}/BackgroundProcessManager.js +4 -47
- package/lib-esm/BackgroundProcessManager/index.d.ts +1 -0
- package/lib-esm/BackgroundProcessManager/index.js +3 -0
- package/lib-esm/BackgroundProcessManager/types.d.ts +41 -0
- package/lib-esm/BackgroundProcessManager/types.js +20 -0
- package/lib-esm/Cache/StorageCache.d.ts +14 -31
- package/lib-esm/Cache/StorageCache.js +97 -102
- package/lib-esm/Cache/StorageCache.native.d.ts +19 -0
- package/lib-esm/Cache/StorageCache.native.js +161 -0
- package/lib-esm/Cache/{AsyncStorageCache.d.ts → StorageCacheCommon.d.ts} +124 -99
- package/lib-esm/Cache/{AsyncStorageCache.js → StorageCacheCommon.js} +494 -437
- package/lib-esm/Cache/constants.d.ts +6 -0
- package/lib-esm/Cache/constants.js +14 -0
- package/lib-esm/Cache/index.d.ts +2 -0
- package/lib-esm/Cache/index.js +4 -0
- package/lib-esm/Cache/types/cache.d.ts +38 -0
- package/lib-esm/Cache/types/index.d.ts +1 -1
- package/lib-esm/Cache/types/index.js +1 -1
- package/lib-esm/Cache/{Utils → utils}/CacheList.d.ts +1 -1
- package/lib-esm/Cache/{Utils → utils}/CacheList.js +6 -19
- package/lib-esm/Cache/utils/cacheHelpers.d.ts +14 -0
- package/lib-esm/Cache/utils/cacheHelpers.js +44 -0
- package/lib-esm/Cache/utils/errorHelpers.d.ts +7 -0
- package/lib-esm/Cache/utils/errorHelpers.js +22 -0
- package/lib-esm/Cache/utils/index.d.ts +2 -0
- package/lib-esm/Cache/utils/index.js +4 -0
- package/lib-esm/Hub/index.d.ts +7 -0
- package/lib-esm/Hub/index.js +9 -2
- package/lib-esm/Hub/types/AuthTypes.d.ts +19 -0
- package/lib-esm/I18n/I18n.d.ts +3 -19
- package/lib-esm/I18n/I18n.js +1 -21
- package/lib-esm/I18n/errorHelpers.d.ts +5 -0
- package/lib-esm/I18n/errorHelpers.js +14 -0
- package/lib-esm/I18n/index.d.ts +3 -15
- package/lib-esm/I18n/index.js +5 -30
- package/lib-esm/I18n/types.d.ts +1 -4
- package/lib-esm/I18n/types.js +4 -7
- package/lib-esm/Logger/ConsoleLogger.js +1 -1
- package/{lib/Util → lib-esm/Mutex}/Mutex.d.ts +2 -15
- package/lib-esm/{Util → Mutex}/Mutex.js +1 -1
- package/lib-esm/Mutex/index.d.ts +1 -0
- package/lib-esm/Mutex/index.js +3 -0
- package/lib-esm/Mutex/types.d.ts +13 -0
- package/lib-esm/Platform/customUserAgent.d.ts +16 -0
- package/lib-esm/Platform/customUserAgent.js +65 -0
- package/lib-esm/Platform/index.js +10 -1
- package/lib-esm/Platform/types.d.ts +75 -8
- package/lib-esm/Platform/types.js +40 -39
- package/lib-esm/Platform/version.d.ts +1 -1
- package/lib-esm/Platform/version.js +1 -1
- package/lib-esm/Reachability/Reachability.d.ts +7 -0
- package/lib-esm/{Util → Reachability}/Reachability.js +22 -19
- package/lib-esm/Reachability/Reachability.native.d.ts +6 -0
- package/lib-esm/{Util → Reachability}/Reachability.native.js +6 -6
- package/lib-esm/Reachability/index.d.ts +1 -0
- package/lib-esm/Reachability/index.js +3 -0
- package/lib-esm/Reachability/types.d.ts +3 -0
- package/lib-esm/Reachability/types.js +3 -0
- package/lib-esm/ServiceWorker/ServiceWorker.js +78 -48
- package/lib-esm/ServiceWorker/errorHelpers.d.ts +7 -0
- package/lib-esm/ServiceWorker/errorHelpers.js +22 -0
- package/lib-esm/ServiceWorker/index.d.ts +0 -12
- package/lib-esm/ServiceWorker/index.js +0 -12
- package/lib-esm/{Signer.js → Signer/Signer.js} +5 -4
- package/lib-esm/Signer/index.d.ts +1 -0
- package/lib-esm/Signer/index.js +3 -0
- package/lib-esm/adapterCore/error/AmplifyServerContextError.d.ts +1 -1
- package/lib-esm/adapterCore/error/AmplifyServerContextError.js +1 -1
- package/lib-esm/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/base.js +2 -1
- package/lib-esm/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/getCredentialsForIdentity.d.ts +2 -1
- package/lib-esm/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/getId.d.ts +2 -1
- package/lib-esm/awsClients/cognitoIdentity/types.js +3 -0
- package/lib-esm/{AwsClients/Pinpoint → awsClients/pinpoint}/base.js +2 -1
- package/lib-esm/awsClients/pinpoint/errorHelpers.d.ts +5 -0
- package/lib-esm/awsClients/pinpoint/errorHelpers.js +14 -0
- package/{lib/AwsClients/Pinpoint → lib-esm/awsClients/pinpoint}/getInAppMessages.d.ts +4 -3
- package/lib-esm/{AwsClients/Pinpoint → awsClients/pinpoint}/getInAppMessages.js +2 -1
- package/{lib/AwsClients/Pinpoint → lib-esm/awsClients/pinpoint}/putEvents.d.ts +4 -3
- package/lib-esm/{AwsClients/Pinpoint → awsClients/pinpoint}/putEvents.js +4 -7
- package/lib-esm/{AwsClients/Pinpoint → awsClients/pinpoint}/updateEndpoint.d.ts +4 -3
- package/lib-esm/{AwsClients/Pinpoint → awsClients/pinpoint}/updateEndpoint.js +2 -1
- package/lib-esm/clients/handlers/fetch.js +2 -1
- package/lib-esm/clients/middleware/retry/jitteredBackoff.js +1 -1
- package/lib-esm/clients/middleware/signing/signer/signatureV4/presignUrl.js +2 -1
- package/lib-esm/clients/types/http.d.ts +17 -1
- package/lib-esm/constants.d.ts +4 -0
- package/lib-esm/{Util/Constants.js → constants.js} +0 -11
- package/lib-esm/{Util/Errors.d.ts → errors/AmplifyError.d.ts} +2 -9
- package/lib-esm/{Util/Errors.js → errors/AmplifyError.js} +0 -15
- package/lib-esm/errors/PlatformNotSupportedError.d.ts +4 -0
- package/lib-esm/errors/PlatformNotSupportedError.js +30 -0
- package/lib-esm/errors/createAssertionFunction.d.ts +3 -0
- package/lib-esm/errors/createAssertionFunction.js +18 -0
- package/lib-esm/errors/errorHelpers.d.ts +2 -0
- package/lib-esm/errors/errorHelpers.js +17 -0
- package/lib-esm/errors/index.d.ts +4 -0
- package/lib-esm/errors/index.js +6 -0
- package/lib-esm/index.d.ts +7 -7
- package/lib-esm/index.js +7 -6
- package/lib-esm/libraryUtils.d.ts +19 -16
- package/lib-esm/libraryUtils.js +20 -18
- package/lib-esm/parseAWSExports.js +144 -13
- package/lib-esm/providers/kinesis/types/index.d.ts +1 -0
- package/lib-esm/providers/kinesis/types/index.js +3 -0
- package/lib-esm/providers/kinesis/types/kinesis.d.ts +9 -0
- package/lib-esm/providers/kinesis/types/kinesis.js +3 -0
- package/lib-esm/providers/kinesis-firehose/types/index.d.ts +1 -0
- package/lib-esm/providers/kinesis-firehose/types/index.js +3 -0
- package/lib-esm/providers/kinesis-firehose/types/kinesis-firehose.d.ts +9 -0
- package/lib-esm/providers/kinesis-firehose/types/kinesis-firehose.js +3 -0
- package/lib-esm/providers/personalize/types/index.d.ts +1 -0
- package/lib-esm/providers/personalize/types/index.js +3 -0
- package/lib-esm/providers/personalize/types/personalize.d.ts +8 -0
- package/lib-esm/providers/personalize/types/personalize.js +3 -0
- package/lib-esm/providers/pinpoint/apis/flushEvents.d.ts +2 -0
- package/lib-esm/providers/pinpoint/apis/flushEvents.js +17 -0
- package/lib-esm/providers/pinpoint/apis/index.d.ts +1 -0
- package/lib-esm/providers/pinpoint/apis/index.js +1 -0
- package/lib-esm/providers/pinpoint/apis/record.d.ts +1 -1
- package/lib-esm/providers/pinpoint/apis/record.js +9 -25
- package/lib-esm/providers/pinpoint/apis/updateEndpoint.d.ts +1 -1
- package/lib-esm/providers/pinpoint/apis/updateEndpoint.js +14 -12
- package/lib-esm/providers/pinpoint/index.d.ts +2 -1
- package/lib-esm/providers/pinpoint/index.js +2 -0
- package/lib-esm/providers/pinpoint/types/errors.d.ts +9 -0
- package/lib-esm/providers/pinpoint/types/errors.js +12 -0
- package/lib-esm/providers/pinpoint/types/index.d.ts +1 -0
- package/lib-esm/providers/pinpoint/types/index.js +1 -0
- package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +5 -4
- package/lib-esm/providers/pinpoint/utils/PinpointEventBuffer.d.ts +1 -0
- package/lib-esm/providers/pinpoint/utils/PinpointEventBuffer.js +11 -6
- package/lib-esm/providers/pinpoint/utils/index.d.ts +1 -0
- package/lib-esm/providers/pinpoint/utils/index.js +1 -0
- package/lib-esm/providers/pinpoint/utils/isAppInForeground.js +3 -0
- package/lib-esm/providers/pinpoint/utils/isAppInForeground.native.js +5 -0
- package/lib-esm/providers/pinpoint/utils/resolveEndpointId.d.ts +8 -0
- package/lib-esm/providers/pinpoint/utils/resolveEndpointId.js +81 -0
- package/lib-esm/singleton/API/types.d.ts +165 -0
- package/lib-esm/singleton/API/types.js +9 -0
- package/lib-esm/singleton/Amplify.d.ts +2 -2
- package/lib-esm/singleton/Amplify.js +6 -5
- package/lib-esm/singleton/Analytics/types.d.ts +4 -1
- package/lib-esm/singleton/Auth/types.d.ts +29 -2
- package/lib-esm/singleton/Auth/utils/errorHelpers.d.ts +8 -0
- package/lib-esm/singleton/Auth/utils/errorHelpers.js +30 -0
- package/lib-esm/singleton/Auth/utils/index.d.ts +1 -1
- package/lib-esm/singleton/Auth/utils/index.js +19 -34
- package/lib-esm/singleton/Cache/types.d.ts +18 -0
- package/lib-esm/singleton/Cache/types.js +3 -0
- package/lib-esm/singleton/Geo/types.d.ts +17 -0
- package/lib-esm/singleton/Geo/types.js +3 -0
- package/lib-esm/singleton/Interactions/types.d.ts +21 -0
- package/lib-esm/singleton/Interactions/types.js +3 -0
- package/lib-esm/singleton/Notifications/InAppMessaging/types.d.ts +2 -0
- package/lib-esm/singleton/Notifications/InAppMessaging/types.js +3 -0
- package/lib-esm/singleton/Notifications/PushNotification/types.d.ts +2 -0
- package/lib-esm/singleton/Notifications/PushNotification/types.js +3 -0
- package/lib-esm/singleton/Notifications/types.d.ts +6 -0
- package/lib-esm/singleton/Notifications/types.js +3 -0
- package/lib-esm/singleton/types.d.ts +10 -1
- package/{lib/StorageHelper/cookieStorage.d.ts → lib-esm/storage/CookieStorage.d.ts} +4 -3
- package/lib-esm/{StorageHelper/cookieStorage.js → storage/CookieStorage.js} +36 -61
- package/lib-esm/storage/CookieStorage.native.d.ts +7 -0
- package/lib-esm/storage/CookieStorage.native.js +29 -0
- package/lib-esm/storage/DefaultStorage.d.ts +7 -0
- package/lib-esm/storage/DefaultStorage.js +30 -0
- package/{lib/StorageHelper/localStorage.d.ts → lib-esm/storage/DefaultStorage.native.d.ts} +6 -5
- package/{lib/StorageHelper/sessionStorage.js → lib-esm/storage/DefaultStorage.native.js} +24 -45
- package/lib-esm/storage/InMemoryStorage.d.ts +12 -0
- package/lib-esm/storage/InMemoryStorage.js +38 -0
- package/lib-esm/{StorageHelper/sessionStorage.d.ts → storage/KeyValueStorage.d.ts} +5 -4
- package/lib-esm/{StorageHelper/localStorage.js → storage/KeyValueStorage.js} +17 -19
- package/lib-esm/storage/SessionStorage.d.ts +7 -0
- package/lib-esm/storage/SessionStorage.js +30 -0
- package/lib-esm/storage/index.d.ts +7 -0
- package/lib-esm/storage/index.js +10 -0
- package/lib-esm/storage/utils.d.ts +10 -0
- package/lib-esm/storage/utils.js +21 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/core.d.ts +4 -1
- package/lib-esm/types/errors.d.ts +9 -3
- package/lib-esm/types/errors.js +6 -1
- package/lib-esm/types/storage.d.ts +3 -0
- package/lib-esm/utils/amplifyUrl/index.d.ts +13 -0
- package/lib-esm/utils/amplifyUrl/index.js +6 -0
- package/lib-esm/utils/amplifyUrl/polyfill.d.ts +0 -0
- package/lib-esm/utils/amplifyUrl/polyfill.js +4 -0
- package/lib-esm/utils/amplifyUrl/polyfill.native.d.ts +1 -0
- package/lib-esm/utils/amplifyUrl/polyfill.native.js +4 -0
- package/lib-esm/utils/amplifyUuid/index.d.ts +3 -0
- package/lib-esm/utils/amplifyUuid/index.js +6 -0
- package/lib-esm/utils/amplifyUuid/polyfill.d.ts +0 -0
- package/lib-esm/utils/amplifyUuid/polyfill.js +4 -0
- package/lib-esm/utils/amplifyUuid/polyfill.native.d.ts +1 -0
- package/lib-esm/utils/amplifyUuid/polyfill.native.js +4 -0
- package/lib-esm/utils/convert/base64/base64Decoder.d.ts +2 -0
- package/lib-esm/utils/convert/base64/base64Decoder.js +8 -0
- package/lib-esm/utils/convert/base64/base64Encoder.d.ts +2 -0
- package/lib-esm/utils/convert/base64/base64Encoder.js +15 -0
- package/lib-esm/utils/convert/base64/bytesToString.d.ts +1 -0
- package/lib-esm/utils/convert/base64/bytesToString.js +5 -0
- package/lib-esm/utils/convert/index.d.ts +2 -0
- package/lib-esm/utils/convert/index.js +4 -0
- package/lib-esm/utils/convert/types.d.ts +9 -0
- package/lib-esm/utils/convert/types.js +3 -0
- package/lib-esm/utils/deepFreeze.d.ts +1 -0
- package/lib-esm/utils/deepFreeze.js +34 -0
- package/lib-esm/utils/generateRandomString.d.ts +1 -0
- package/lib-esm/utils/generateRandomString.js +10 -0
- package/lib-esm/{ClientDevice/android.d.ts → utils/getClientInfo/getClientInfo.android.d.ts} +1 -1
- package/lib-esm/{ClientDevice/android.js → utils/getClientInfo/getClientInfo.android.js} +2 -2
- package/{lib/ClientDevice/browser.d.ts → lib-esm/utils/getClientInfo/getClientInfo.d.ts} +1 -9
- package/lib-esm/{ClientDevice/ios.d.ts → utils/getClientInfo/getClientInfo.ios.d.ts} +1 -1
- package/lib-esm/{ClientDevice/ios.js → utils/getClientInfo/getClientInfo.ios.js} +2 -2
- package/lib-esm/{ClientDevice/browser.js → utils/getClientInfo/getClientInfo.js} +4 -14
- package/lib-esm/utils/getClientInfo/index.d.ts +1 -0
- package/lib-esm/utils/getClientInfo/index.js +3 -0
- package/lib-esm/utils/globalHelpers/index.d.ts +3 -0
- package/lib-esm/utils/globalHelpers/index.js +44 -0
- package/lib-esm/utils/globalHelpers/index.native.d.ts +3 -0
- package/lib-esm/utils/globalHelpers/index.native.js +22 -0
- package/lib-esm/utils/index.d.ts +8 -0
- package/lib-esm/utils/index.js +10 -0
- package/lib-esm/utils/isBrowser.d.ts +1 -0
- package/lib-esm/utils/isBrowser.js +5 -0
- package/lib-esm/utils/isWebWorker.d.ts +1 -0
- package/lib-esm/utils/isWebWorker.js +10 -0
- package/lib-esm/utils/retry/NonRetryableError.d.ts +4 -0
- package/lib-esm/utils/retry/NonRetryableError.js +27 -0
- package/lib-esm/utils/retry/constants.d.ts +1 -0
- package/lib-esm/utils/retry/constants.js +3 -0
- package/lib-esm/utils/retry/index.d.ts +5 -0
- package/lib-esm/utils/retry/index.js +7 -0
- package/lib-esm/utils/retry/isNonRetryableError.d.ts +2 -0
- package/lib-esm/utils/retry/isNonRetryableError.js +6 -0
- package/lib-esm/utils/retry/jitteredBackoff.d.ts +6 -0
- package/lib-esm/utils/retry/jitteredBackoff.js +16 -0
- package/lib-esm/utils/retry/jitteredExponentialRetry.d.ts +5 -0
- package/lib-esm/utils/retry/jitteredExponentialRetry.js +13 -0
- package/lib-esm/utils/retry/retry.d.ts +6 -0
- package/lib-esm/{Util/Retry.js → utils/retry/retry.js} +4 -52
- package/lib-esm/utils/sessionListener/SessionListener.d.ts +10 -0
- package/lib-esm/utils/sessionListener/SessionListener.js +52 -0
- package/lib-esm/utils/sessionListener/SessionListener.native.d.ts +10 -0
- package/lib-esm/utils/sessionListener/SessionListener.native.js +51 -0
- package/lib-esm/utils/sessionListener/index.d.ts +2 -0
- package/lib-esm/utils/sessionListener/index.js +4 -0
- package/lib-esm/utils/sessionListener/types.d.ts +6 -0
- package/lib-esm/utils/sessionListener/types.js +3 -0
- package/lib-esm/{Util/StringUtils.d.ts → utils/urlSafeDecode.d.ts} +0 -1
- package/lib-esm/{Util/StringUtils.js → utils/urlSafeDecode.js} +0 -6
- package/{lib/Util/StringUtils.d.ts → lib-esm/utils/urlSafeEncode.d.ts} +0 -1
- package/lib-esm/utils/urlSafeEncode.js +8 -0
- package/package.json +12 -26
- package/src/BackgroundProcessManager/BackgroundManagerNotOpenError.ts +8 -0
- package/src/{Util → BackgroundProcessManager}/BackgroundProcessManager.ts +4 -58
- package/src/BackgroundProcessManager/index.ts +4 -0
- package/src/BackgroundProcessManager/types.ts +49 -0
- package/src/Cache/StorageCache.native.ts +65 -0
- package/src/Cache/StorageCache.ts +61 -158
- package/src/Cache/StorageCacheCommon.ts +577 -0
- package/src/Cache/constants.ts +18 -0
- package/src/Cache/index.ts +6 -0
- package/src/Cache/types/cache.ts +51 -0
- package/src/Cache/types/index.ts +4 -4
- package/src/Cache/{Utils → utils}/CacheList.ts +185 -198
- package/src/Cache/utils/cacheHelpers.ts +52 -0
- package/src/Cache/utils/errorHelpers.ts +26 -0
- package/src/Cache/{Utils → utils}/index.ts +4 -5
- package/src/Hub/index.ts +11 -2
- package/src/Hub/types/AuthTypes.ts +12 -1
- package/src/I18n/I18n.ts +4 -25
- package/src/I18n/errorHelpers.ts +18 -0
- package/src/I18n/index.ts +9 -33
- package/src/I18n/types.ts +1 -4
- package/src/Logger/ConsoleLogger.ts +1 -1
- package/src/{Util → Mutex}/Mutex.ts +2 -20
- package/src/Mutex/index.ts +4 -0
- package/src/Mutex/types.ts +20 -0
- package/src/Platform/customUserAgent.ts +75 -0
- package/src/Platform/index.ts +14 -1
- package/src/Platform/types.ts +84 -39
- package/src/Platform/version.ts +1 -1
- package/src/{Util → Reachability}/Reachability.native.ts +7 -12
- package/src/Reachability/Reachability.ts +55 -0
- package/src/Reachability/index.ts +4 -0
- package/src/Reachability/types.ts +6 -0
- package/src/ServiceWorker/ServiceWorker.ts +39 -48
- package/src/ServiceWorker/errorHelpers.ts +26 -0
- package/src/ServiceWorker/index.ts +0 -12
- package/src/{Util → Signer}/DateUtils.ts +1 -1
- package/src/{Signer.ts → Signer/Signer.ts} +5 -4
- package/src/Signer/index.ts +4 -0
- package/src/adapterCore/error/AmplifyServerContextError.ts +1 -1
- package/src/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/base.ts +4 -1
- package/src/{AwsClients/Pinpoint → awsClients/pinpoint}/base.ts +2 -1
- package/src/awsClients/pinpoint/errorHelpers.ts +19 -0
- package/src/{AwsClients/Pinpoint → awsClients/pinpoint}/getInAppMessages.ts +2 -1
- package/src/{AwsClients/Pinpoint → awsClients/pinpoint}/putEvents.ts +4 -7
- package/src/{AwsClients/Pinpoint → awsClients/pinpoint}/updateEndpoint.ts +2 -1
- package/src/clients/handlers/fetch.ts +5 -1
- package/src/clients/middleware/retry/jitteredBackoff.ts +1 -1
- package/src/clients/middleware/signing/signer/signatureV4/presignUrl.ts +2 -1
- package/src/clients/types/http.ts +19 -1
- package/src/{Util/Constants.ts → constants.ts} +0 -11
- package/src/{Util/Errors.ts → errors/AmplifyError.ts} +2 -18
- package/src/errors/PlatformNotSupportedError.ts +14 -0
- package/src/errors/createAssertionFunction.ts +23 -0
- package/src/errors/errorHelpers.ts +20 -0
- package/src/errors/index.ts +7 -0
- package/src/index.ts +15 -11
- package/src/libraryUtils.ts +57 -57
- package/src/parseAWSExports.ts +179 -14
- package/src/providers/kinesis/types/index.ts +4 -0
- package/src/providers/kinesis/types/kinesis.ts +12 -0
- package/src/providers/kinesis-firehose/types/index.ts +4 -0
- package/src/providers/kinesis-firehose/types/kinesis-firehose.ts +12 -0
- package/src/providers/personalize/types/index.ts +4 -0
- package/src/providers/personalize/types/personalize.ts +11 -0
- package/src/providers/pinpoint/apis/flushEvents.ts +31 -0
- package/src/providers/pinpoint/apis/index.ts +1 -0
- package/src/providers/pinpoint/apis/record.ts +14 -28
- package/src/providers/pinpoint/apis/updateEndpoint.ts +26 -10
- package/src/providers/pinpoint/index.ts +6 -1
- package/src/providers/pinpoint/types/errors.ts +12 -0
- package/src/providers/pinpoint/types/index.ts +1 -0
- package/src/providers/pinpoint/types/pinpoint.ts +5 -3
- package/src/providers/pinpoint/utils/PinpointEventBuffer.ts +21 -13
- package/src/providers/pinpoint/utils/index.ts +1 -0
- package/src/providers/pinpoint/utils/isAppInForeground.native.ts +7 -0
- package/src/providers/pinpoint/utils/isAppInForeground.ts +4 -0
- package/src/providers/pinpoint/utils/resolveEndpointId.ts +46 -0
- package/src/singleton/API/types.ts +203 -0
- package/src/singleton/Amplify.ts +10 -8
- package/src/singleton/Analytics/types.ts +7 -1
- package/src/singleton/Auth/types.ts +51 -2
- package/src/singleton/Auth/utils/errorHelpers.ts +37 -0
- package/src/singleton/Auth/utils/index.ts +35 -38
- package/src/singleton/Cache/types.ts +27 -0
- package/src/singleton/Geo/types.ts +20 -0
- package/src/singleton/Interactions/types.ts +29 -0
- package/src/singleton/Notifications/InAppMessaging/types.ts +6 -0
- package/src/singleton/Notifications/PushNotification/types.ts +6 -0
- package/src/singleton/Notifications/types.ts +10 -0
- package/src/singleton/types.ts +12 -6
- package/src/storage/CookieStorage.native.ts +13 -0
- package/src/storage/CookieStorage.ts +68 -0
- package/src/storage/DefaultStorage.native.ts +58 -0
- package/src/storage/DefaultStorage.ts +14 -0
- package/src/storage/InMemoryStorage.ts +36 -0
- package/src/{StorageHelper/sessionStorage.ts → storage/KeyValueStorage.ts} +15 -18
- package/src/storage/SessionStorage.ts +14 -0
- package/src/storage/index.ts +13 -0
- package/src/storage/utils.ts +22 -0
- package/src/types/core.ts +4 -1
- package/src/types/errors.ts +15 -3
- package/src/types/storage.ts +4 -0
- package/src/utils/amplifyUrl/index.ts +9 -0
- package/src/utils/amplifyUrl/polyfill.native.ts +6 -0
- package/src/utils/amplifyUrl/polyfill.ts +4 -0
- package/src/utils/amplifyUuid/index.ts +9 -0
- package/src/utils/amplifyUuid/polyfill.native.ts +6 -0
- package/src/utils/amplifyUuid/polyfill.ts +4 -0
- package/src/utils/convert/base64/base64Decoder.ts +11 -0
- package/src/utils/convert/base64/base64Encoder.ts +18 -0
- package/src/utils/convert/base64/bytesToString.ts +6 -0
- package/src/utils/convert/index.ts +5 -0
- package/src/utils/convert/types.ts +17 -0
- package/src/utils/deepFreeze.ts +16 -0
- package/src/utils/generateRandomString.ts +16 -0
- package/src/{ClientDevice/android.ts → utils/getClientInfo/getClientInfo.android.ts} +2 -2
- package/src/{ClientDevice/ios.ts → utils/getClientInfo/getClientInfo.ios.ts} +3 -3
- package/src/{ClientDevice/browser.ts → utils/getClientInfo/getClientInfo.ts} +4 -16
- package/src/utils/getClientInfo/index.ts +4 -0
- package/src/utils/globalHelpers/index.native.ts +30 -0
- package/src/utils/globalHelpers/index.ts +54 -0
- package/src/utils/index.ts +17 -0
- package/src/utils/isBrowser.ts +5 -0
- package/src/utils/isWebWorker.ts +13 -0
- package/src/utils/retry/NonRetryableError.ts +9 -0
- package/src/utils/retry/constants.ts +4 -0
- package/src/utils/retry/index.ts +8 -0
- package/src/utils/retry/isNonRetryableError.ts +9 -0
- package/src/utils/retry/jitteredBackoff.ts +21 -0
- package/src/utils/retry/jitteredExponentialRetry.ts +18 -0
- package/src/{Util/Retry.ts → utils/retry/retry.ts} +4 -44
- package/src/utils/sessionListener/SessionListener.native.ts +70 -0
- package/src/utils/sessionListener/SessionListener.ts +74 -0
- package/src/utils/sessionListener/index.ts +6 -0
- package/src/utils/sessionListener/types.ts +11 -0
- package/src/{Util/StringUtils.ts → utils/urlSafeDecode.ts} +0 -6
- package/src/utils/urlSafeEncode.ts +9 -0
- package/lib/Amplify.d.ts +0 -29
- package/lib/Amplify.js +0 -118
- package/lib/Cache/BrowserStorageCache.d.ts +0 -166
- package/lib/Cache/BrowserStorageCache.js +0 -469
- package/lib/Cache/InMemoryCache.d.ts +0 -129
- package/lib/Cache/InMemoryCache.js +0 -349
- package/lib/Cache/Utils/CacheUtils.d.ts +0 -25
- package/lib/Cache/Utils/CacheUtils.js +0 -88
- package/lib/Cache/Utils/index.d.ts +0 -2
- package/lib/Cache/Utils/index.js +0 -16
- package/lib/Cache/reactnative.d.ts +0 -3
- package/lib/Cache/reactnative.js +0 -8
- package/lib/Cache/types/Cache.d.ts +0 -55
- package/lib/ClientDevice/index.d.ts +0 -23
- package/lib/ClientDevice/index.js +0 -18
- package/lib/ClientDevice/reactnative.d.ts +0 -7
- package/lib/ClientDevice/reactnative.js +0 -24
- package/lib/RNComponents/index.d.ts +0 -6
- package/lib/RNComponents/index.js +0 -16
- package/lib/RNComponents/reactnative.d.ts +0 -3
- package/lib/RNComponents/reactnative.js +0 -14
- package/lib/StorageHelper/inMemoryStorage.d.ts +0 -10
- package/lib/StorageHelper/index.d.ts +0 -45
- package/lib/StorageHelper/index.js +0 -83
- package/lib/StorageHelper/reactnative.d.ts +0 -83
- package/lib/StorageHelper/reactnative.js +0 -250
- package/lib/Util/Constants.d.ts +0 -12
- package/lib/Util/Constants.js +0 -29
- package/lib/Util/JS.d.ts +0 -29
- package/lib/Util/JS.js +0 -214
- package/lib/Util/Reachability.d.ts +0 -13
- package/lib/Util/Reachability.native.d.ts +0 -12
- package/lib/Util/Retry.d.ts +0 -21
- package/lib/Util/errors/AssertError.d.ts +0 -2
- package/lib/Util/errors/AssertError.js +0 -11
- package/lib/Util/index.d.ts +0 -7
- package/lib/Util/index.js +0 -31
- package/lib/clients/middleware/signing/signer/signatureV4/index.native.d.ts +0 -5
- package/lib/clients/middleware/signing/signer/signatureV4/index.native.js +0 -15
- package/lib-esm/Amplify.d.ts +0 -29
- package/lib-esm/Amplify.js +0 -115
- package/lib-esm/Cache/BrowserStorageCache.d.ts +0 -166
- package/lib-esm/Cache/BrowserStorageCache.js +0 -466
- package/lib-esm/Cache/InMemoryCache.d.ts +0 -129
- package/lib-esm/Cache/InMemoryCache.js +0 -346
- package/lib-esm/Cache/Utils/CacheUtils.d.ts +0 -25
- package/lib-esm/Cache/Utils/CacheUtils.js +0 -81
- package/lib-esm/Cache/Utils/index.d.ts +0 -2
- package/lib-esm/Cache/Utils/index.js +0 -4
- package/lib-esm/Cache/reactnative.d.ts +0 -3
- package/lib-esm/Cache/reactnative.js +0 -6
- package/lib-esm/Cache/types/Cache.d.ts +0 -55
- package/lib-esm/ClientDevice/index.d.ts +0 -23
- package/lib-esm/ClientDevice/index.js +0 -15
- package/lib-esm/ClientDevice/reactnative.d.ts +0 -7
- package/lib-esm/ClientDevice/reactnative.js +0 -21
- package/lib-esm/RNComponents/index.d.ts +0 -6
- package/lib-esm/RNComponents/index.js +0 -13
- package/lib-esm/RNComponents/isAppInForeground.js +0 -6
- package/lib-esm/RNComponents/reactnative.d.ts +0 -3
- package/lib-esm/RNComponents/reactnative.js +0 -6
- package/lib-esm/StorageHelper/inMemoryStorage.d.ts +0 -10
- package/lib-esm/StorageHelper/inMemoryStorage.js +0 -79
- package/lib-esm/StorageHelper/index.d.ts +0 -45
- package/lib-esm/StorageHelper/index.js +0 -76
- package/lib-esm/StorageHelper/reactnative.d.ts +0 -83
- package/lib-esm/StorageHelper/reactnative.js +0 -244
- package/lib-esm/Util/Constants.d.ts +0 -12
- package/lib-esm/Util/JS.d.ts +0 -29
- package/lib-esm/Util/JS.js +0 -199
- package/lib-esm/Util/Reachability.d.ts +0 -13
- package/lib-esm/Util/Reachability.native.d.ts +0 -12
- package/lib-esm/Util/Retry.d.ts +0 -21
- package/lib-esm/Util/errors/AssertError.d.ts +0 -2
- package/lib-esm/Util/errors/AssertError.js +0 -7
- package/lib-esm/Util/index.d.ts +0 -7
- package/lib-esm/Util/index.js +0 -9
- package/lib-esm/clients/middleware/signing/signer/signatureV4/index.native.d.ts +0 -5
- package/lib-esm/clients/middleware/signing/signer/signatureV4/index.native.js +0 -8
- package/polyfills/URL/index.ts +0 -14
- package/polyfills/URL/tsconfig.json +0 -10
- package/polyfills/URL/webpack.config.js +0 -43
- package/src/Amplify.ts +0 -106
- package/src/Cache/AsyncStorageCache.ts +0 -500
- package/src/Cache/BrowserStorageCache.ts +0 -517
- package/src/Cache/CHANGELOG.md +0 -1239
- package/src/Cache/InMemoryCache.ts +0 -354
- package/src/Cache/Utils/CacheUtils.ts +0 -92
- package/src/Cache/reactnative.ts +0 -9
- package/src/Cache/types/Cache.ts +0 -75
- package/src/ClientDevice/index.ts +0 -14
- package/src/ClientDevice/reactnative.ts +0 -18
- package/src/RNComponents/index.ts +0 -16
- package/src/RNComponents/isAppInForeground.ts +0 -8
- package/src/RNComponents/reactnative.ts +0 -6
- package/src/StorageHelper/cookieStorage.ts +0 -99
- package/src/StorageHelper/inMemoryStorage.ts +0 -32
- package/src/StorageHelper/index.ts +0 -78
- package/src/StorageHelper/localStorage.ts +0 -60
- package/src/StorageHelper/reactnative.ts +0 -182
- package/src/Util/JS.ts +0 -255
- package/src/Util/Reachability.ts +0 -58
- package/src/Util/errors/AssertError.ts +0 -11
- package/src/Util/index.ts +0 -23
- package/src/clients/middleware/signing/signer/signatureV4/index.native.ts +0 -10
- /package/lib/{AwsClients/CognitoIdentity/types.js → Cache/types/cache.js} +0 -0
- /package/lib/{Cache/types/Cache.js → Mutex/types.js} +0 -0
- /package/lib/{Util → Signer}/DateUtils.d.ts +0 -0
- /package/lib/{Util → Signer}/DateUtils.js +0 -0
- /package/lib/{Signer.d.ts → Signer/Signer.d.ts} +0 -0
- /package/lib/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/base.d.ts +0 -0
- /package/lib/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/getCredentialsForIdentity.js +0 -0
- /package/lib/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/getId.js +0 -0
- /package/lib/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/index.d.ts +0 -0
- /package/lib/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/index.js +0 -0
- /package/lib/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/types.d.ts +0 -0
- /package/lib/{AwsClients/Pinpoint → awsClients/pinpoint}/base.d.ts +0 -0
- /package/lib/{AwsClients/Pinpoint → awsClients/pinpoint}/index.d.ts +0 -0
- /package/lib/{AwsClients/Pinpoint → awsClients/pinpoint}/index.js +0 -0
- /package/lib/{AwsClients/Pinpoint → awsClients/pinpoint}/types.d.ts +0 -0
- /package/lib/{AwsClients/Pinpoint → awsClients/pinpoint}/types.js +0 -0
- /package/lib-esm/{AwsClients/CognitoIdentity/types.js → Cache/types/cache.js} +0 -0
- /package/lib-esm/{Cache/types/Cache.js → Mutex/types.js} +0 -0
- /package/lib-esm/{Util → Signer}/DateUtils.d.ts +0 -0
- /package/lib-esm/{Util → Signer}/DateUtils.js +0 -0
- /package/lib-esm/{Signer.d.ts → Signer/Signer.d.ts} +0 -0
- /package/lib-esm/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/base.d.ts +0 -0
- /package/lib-esm/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/getCredentialsForIdentity.js +0 -0
- /package/lib-esm/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/getId.js +0 -0
- /package/lib-esm/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/index.d.ts +0 -0
- /package/lib-esm/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/index.js +0 -0
- /package/lib-esm/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/types.d.ts +0 -0
- /package/lib-esm/{AwsClients/Pinpoint → awsClients/pinpoint}/base.d.ts +0 -0
- /package/lib-esm/{AwsClients/Pinpoint → awsClients/pinpoint}/index.d.ts +0 -0
- /package/lib-esm/{AwsClients/Pinpoint → awsClients/pinpoint}/index.js +0 -0
- /package/lib-esm/{AwsClients/Pinpoint → awsClients/pinpoint}/types.d.ts +0 -0
- /package/lib-esm/{AwsClients/Pinpoint → awsClients/pinpoint}/types.js +0 -0
- /package/lib-esm/{RNComponents → providers/pinpoint/utils}/isAppInForeground.d.ts +0 -0
- /package/{lib/RNComponents/isAppInForeground.d.ts → lib-esm/providers/pinpoint/utils/isAppInForeground.native.d.ts} +0 -0
- /package/src/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/getCredentialsForIdentity.ts +0 -0
- /package/src/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/getId.ts +0 -0
- /package/src/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/index.ts +0 -0
- /package/src/{AwsClients/CognitoIdentity → awsClients/cognitoIdentity}/types.ts +0 -0
- /package/src/{AwsClients/Pinpoint → awsClients/pinpoint}/index.ts +0 -0
- /package/src/{AwsClients/Pinpoint → awsClients/pinpoint}/types.ts +0 -0
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 __());
|
|
3
|
+
var __assign = (this && this.__assign) || function () {
|
|
4
|
+
__assign = Object.assign || function(t) {
|
|
5
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
+
s = arguments[i];
|
|
7
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
8
|
+
t[p] = s[p];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
16
11
|
};
|
|
17
|
-
|
|
12
|
+
return __assign.apply(this, arguments);
|
|
13
|
+
};
|
|
18
14
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
19
15
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
20
16
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -51,117 +47,323 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
51
47
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
52
48
|
}
|
|
53
49
|
};
|
|
54
|
-
|
|
50
|
+
var __values = (this && this.__values) || function(o) {
|
|
51
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
52
|
+
if (m) return m.call(o);
|
|
53
|
+
if (o && typeof o.length === "number") return {
|
|
54
|
+
next: function () {
|
|
55
|
+
if (o && i >= o.length) o = void 0;
|
|
56
|
+
return { value: o && o[i++], done: !o };
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
60
|
+
};
|
|
55
61
|
import { ConsoleLogger as Logger } from '../Logger';
|
|
56
|
-
import {
|
|
57
|
-
import {
|
|
58
|
-
import {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
* Customized cache which based on the AsyncStorage with LRU implemented
|
|
62
|
+
import { currentSizeKey, defaultConfig } from './constants';
|
|
63
|
+
import { getCurrentSizeKey, getCurrentTime, getByteLength } from './utils';
|
|
64
|
+
import { assert, CacheErrorCode } from './utils/errorHelpers';
|
|
65
|
+
var logger = new Logger('StorageCache');
|
|
66
|
+
/**
|
|
67
|
+
* Initialization of the cache
|
|
68
|
+
*
|
|
64
69
|
*/
|
|
65
|
-
var
|
|
66
|
-
__extends(AsyncStorageCache, _super);
|
|
70
|
+
var StorageCacheCommon = /** @class */ (function () {
|
|
67
71
|
/**
|
|
68
|
-
*
|
|
72
|
+
* Initialize the cache
|
|
69
73
|
*
|
|
70
|
-
* @param
|
|
74
|
+
* @param config - Custom configuration for this instance.
|
|
71
75
|
*/
|
|
72
|
-
function
|
|
73
|
-
var
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
logger.debug('Using AsyncStorageCache');
|
|
78
|
-
return _this;
|
|
76
|
+
function StorageCacheCommon(_a) {
|
|
77
|
+
var config = _a.config, keyValueStorage = _a.keyValueStorage;
|
|
78
|
+
this.config = __assign(__assign({}, defaultConfig), config);
|
|
79
|
+
this.keyValueStorage = keyValueStorage;
|
|
80
|
+
this.sanitizeConfig();
|
|
79
81
|
}
|
|
82
|
+
StorageCacheCommon.prototype.getModuleName = function () {
|
|
83
|
+
return 'Cache';
|
|
84
|
+
};
|
|
80
85
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* @param
|
|
86
|
+
* Set custom configuration for the cache instance.
|
|
87
|
+
*
|
|
88
|
+
* @param config - customized configuration (without keyPrefix, which can't be changed)
|
|
89
|
+
*
|
|
90
|
+
* @return - the current configuration
|
|
84
91
|
*/
|
|
85
|
-
|
|
92
|
+
StorageCacheCommon.prototype.configure = function (config) {
|
|
93
|
+
if (config) {
|
|
94
|
+
if (config.keyPrefix) {
|
|
95
|
+
logger.warn('keyPrefix can not be re-configured on an existing Cache instance.');
|
|
96
|
+
}
|
|
97
|
+
this.config = __assign(__assign({}, this.config), config);
|
|
98
|
+
}
|
|
99
|
+
this.sanitizeConfig();
|
|
100
|
+
return this.config;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* return the current size of the cache
|
|
104
|
+
* @return {Promise}
|
|
105
|
+
*/
|
|
106
|
+
StorageCacheCommon.prototype.getCurrentCacheSize = function () {
|
|
86
107
|
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
-
var
|
|
108
|
+
var size;
|
|
88
109
|
return __generator(this, function (_a) {
|
|
89
110
|
switch (_a.label) {
|
|
90
|
-
case 0: return [4 /*yield*/, this.
|
|
111
|
+
case 0: return [4 /*yield*/, this.getStorage().getItem(getCurrentSizeKey(this.config.keyPrefix))];
|
|
91
112
|
case 1:
|
|
92
|
-
|
|
93
|
-
return [
|
|
113
|
+
size = _a.sent();
|
|
114
|
+
if (!!size) return [3 /*break*/, 3];
|
|
115
|
+
return [4 /*yield*/, this.getStorage().setItem(getCurrentSizeKey(this.config.keyPrefix), '0')];
|
|
94
116
|
case 2:
|
|
95
117
|
_a.sent();
|
|
96
|
-
|
|
118
|
+
size = '0';
|
|
119
|
+
_a.label = 3;
|
|
120
|
+
case 3: return [2 /*return*/, Number(size)];
|
|
97
121
|
}
|
|
98
122
|
});
|
|
99
123
|
});
|
|
100
124
|
};
|
|
101
125
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
126
|
+
* Set item into cache. You can put number, string, boolean or object.
|
|
127
|
+
* The cache will first check whether has the same key.
|
|
128
|
+
* If it has, it will delete the old item and then put the new item in
|
|
129
|
+
* The cache will pop out items if it is full
|
|
130
|
+
* You can specify the cache item options. The cache will abort and output a warning:
|
|
131
|
+
* If the key is invalid
|
|
132
|
+
* If the size of the item exceeds itemMaxSize.
|
|
133
|
+
* If the value is undefined
|
|
134
|
+
* If incorrect cache item configuration
|
|
135
|
+
* If error happened with browser storage
|
|
136
|
+
*
|
|
137
|
+
* @param {String} key - the key of the item
|
|
138
|
+
* @param {Object} value - the value of the item
|
|
139
|
+
* @param {Object} [options] - optional, the specified meta-data
|
|
140
|
+
*
|
|
141
|
+
* @return {Promise}
|
|
105
142
|
*/
|
|
106
|
-
|
|
143
|
+
StorageCacheCommon.prototype.setItem = function (key, value, options) {
|
|
107
144
|
return __awaiter(this, void 0, void 0, function () {
|
|
108
|
-
var
|
|
145
|
+
var cacheItemOptions, prefixedKey, item, val, validKeys, sizeToPop, e_1;
|
|
109
146
|
return __generator(this, function (_a) {
|
|
110
147
|
switch (_a.label) {
|
|
111
|
-
case 0:
|
|
148
|
+
case 0:
|
|
149
|
+
logger.debug("Set item: key is ".concat(key, ", value is ").concat(value, " with options: ").concat(options));
|
|
150
|
+
if (!key || key === currentSizeKey) {
|
|
151
|
+
logger.warn("Invalid key: should not be empty or reserved key: '".concat(currentSizeKey, "'"));
|
|
152
|
+
return [2 /*return*/];
|
|
153
|
+
}
|
|
154
|
+
if (typeof value === 'undefined') {
|
|
155
|
+
logger.warn("The value of item should not be undefined!");
|
|
156
|
+
return [2 /*return*/];
|
|
157
|
+
}
|
|
158
|
+
cacheItemOptions = {
|
|
159
|
+
priority: (options === null || options === void 0 ? void 0 : options.priority) !== undefined
|
|
160
|
+
? options.priority
|
|
161
|
+
: this.config.defaultPriority,
|
|
162
|
+
expires: (options === null || options === void 0 ? void 0 : options.expires) !== undefined
|
|
163
|
+
? options.expires
|
|
164
|
+
: this.config.defaultTTL + getCurrentTime(),
|
|
165
|
+
};
|
|
166
|
+
if (cacheItemOptions.priority < 1 || cacheItemOptions.priority > 5) {
|
|
167
|
+
logger.warn("Invalid parameter: priority due to out or range. It should be within 1 and 5.");
|
|
168
|
+
return [2 /*return*/];
|
|
169
|
+
}
|
|
170
|
+
prefixedKey = "".concat(this.config.keyPrefix).concat(key);
|
|
171
|
+
item = this.fillCacheItem(prefixedKey, value, cacheItemOptions);
|
|
172
|
+
// check whether this item is too big;
|
|
173
|
+
if (item.byteSize > this.config.itemMaxSize) {
|
|
174
|
+
logger.warn("Item with key: ".concat(key, " you are trying to put into is too big!"));
|
|
175
|
+
return [2 /*return*/];
|
|
176
|
+
}
|
|
177
|
+
_a.label = 1;
|
|
112
178
|
case 1:
|
|
113
|
-
|
|
114
|
-
return [4 /*yield*/,
|
|
179
|
+
_a.trys.push([1, 11, , 12]);
|
|
180
|
+
return [4 /*yield*/, this.getStorage().getItem(prefixedKey)];
|
|
115
181
|
case 2:
|
|
182
|
+
val = _a.sent();
|
|
183
|
+
if (!val) return [3 /*break*/, 4];
|
|
184
|
+
return [4 /*yield*/, this.removeCacheItem(prefixedKey, JSON.parse(val).byteSize)];
|
|
185
|
+
case 3:
|
|
116
186
|
_a.sent();
|
|
117
|
-
|
|
187
|
+
_a.label = 4;
|
|
188
|
+
case 4: return [4 /*yield*/, this.isCacheFull(item.byteSize)];
|
|
189
|
+
case 5:
|
|
190
|
+
if (!_a.sent()) return [3 /*break*/, 10];
|
|
191
|
+
return [4 /*yield*/, this.clearInvalidAndGetRemainingKeys()];
|
|
192
|
+
case 6:
|
|
193
|
+
validKeys = _a.sent();
|
|
194
|
+
return [4 /*yield*/, this.isCacheFull(item.byteSize)];
|
|
195
|
+
case 7:
|
|
196
|
+
if (!_a.sent()) return [3 /*break*/, 10];
|
|
197
|
+
return [4 /*yield*/, this.sizeToPop(item.byteSize)];
|
|
198
|
+
case 8:
|
|
199
|
+
sizeToPop = _a.sent();
|
|
200
|
+
return [4 /*yield*/, this.popOutItems(validKeys, sizeToPop)];
|
|
201
|
+
case 9:
|
|
202
|
+
_a.sent();
|
|
203
|
+
_a.label = 10;
|
|
204
|
+
case 10:
|
|
205
|
+
// put item in the cache
|
|
206
|
+
return [2 /*return*/, this.setCacheItem(prefixedKey, item)];
|
|
207
|
+
case 11:
|
|
208
|
+
e_1 = _a.sent();
|
|
209
|
+
logger.warn("setItem failed! ".concat(e_1));
|
|
210
|
+
return [3 /*break*/, 12];
|
|
211
|
+
case 12: return [2 /*return*/];
|
|
118
212
|
}
|
|
119
213
|
});
|
|
120
214
|
});
|
|
121
215
|
};
|
|
122
216
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
217
|
+
* Get item from cache. It will return null if item doesn’t exist or it has been expired.
|
|
218
|
+
* If you specified callback function in the options,
|
|
219
|
+
* then the function will be executed if no such item in the cache
|
|
220
|
+
* and finally put the return value into cache.
|
|
221
|
+
* Please make sure the callback function will return the value you want to put into the cache.
|
|
222
|
+
* The cache will abort output a warning:
|
|
223
|
+
* If the key is invalid
|
|
224
|
+
* If error happened with AsyncStorage
|
|
127
225
|
*
|
|
128
|
-
* @
|
|
226
|
+
* @param {String} key - the key of the item
|
|
227
|
+
* @param {Object} [options] - the options of callback function
|
|
228
|
+
*
|
|
229
|
+
* @return {Promise} - return a promise resolves to be the value of the item
|
|
129
230
|
*/
|
|
130
|
-
|
|
231
|
+
StorageCacheCommon.prototype.getItem = function (key, options) {
|
|
131
232
|
return __awaiter(this, void 0, void 0, function () {
|
|
233
|
+
var cached, prefixedKey, item, val, e_2;
|
|
132
234
|
return __generator(this, function (_a) {
|
|
133
235
|
switch (_a.label) {
|
|
134
236
|
case 0:
|
|
135
|
-
item.
|
|
136
|
-
|
|
237
|
+
logger.debug("Get item: key is ".concat(key, " with options ").concat(options));
|
|
238
|
+
if (!key || key === currentSizeKey) {
|
|
239
|
+
logger.warn("Invalid key: should not be empty or reserved key: '".concat(currentSizeKey, "'"));
|
|
240
|
+
return [2 /*return*/, null];
|
|
241
|
+
}
|
|
242
|
+
prefixedKey = "".concat(this.config.keyPrefix).concat(key);
|
|
243
|
+
_a.label = 1;
|
|
137
244
|
case 1:
|
|
245
|
+
_a.trys.push([1, 11, , 12]);
|
|
246
|
+
return [4 /*yield*/, this.getStorage().getItem(prefixedKey)];
|
|
247
|
+
case 2:
|
|
248
|
+
cached = _a.sent();
|
|
249
|
+
if (!(cached != null)) return [3 /*break*/, 7];
|
|
250
|
+
return [4 /*yield*/, this.isExpired(prefixedKey)];
|
|
251
|
+
case 3:
|
|
252
|
+
if (!_a.sent()) return [3 /*break*/, 5];
|
|
253
|
+
// if expired, remove that item and return null
|
|
254
|
+
return [4 /*yield*/, this.removeCacheItem(prefixedKey, JSON.parse(cached).byteSize)];
|
|
255
|
+
case 4:
|
|
256
|
+
// if expired, remove that item and return null
|
|
138
257
|
_a.sent();
|
|
139
|
-
return [
|
|
258
|
+
return [3 /*break*/, 7];
|
|
259
|
+
case 5: return [4 /*yield*/, this.updateVisitedTime(JSON.parse(cached), prefixedKey)];
|
|
260
|
+
case 6:
|
|
261
|
+
item = _a.sent();
|
|
262
|
+
return [2 /*return*/, item.data];
|
|
263
|
+
case 7:
|
|
264
|
+
if (!(options === null || options === void 0 ? void 0 : options.callback)) return [3 /*break*/, 10];
|
|
265
|
+
val = options.callback();
|
|
266
|
+
if (!(val !== null)) return [3 /*break*/, 9];
|
|
267
|
+
return [4 /*yield*/, this.setItem(key, val, options)];
|
|
268
|
+
case 8:
|
|
269
|
+
_a.sent();
|
|
270
|
+
_a.label = 9;
|
|
271
|
+
case 9: return [2 /*return*/, val];
|
|
272
|
+
case 10: return [2 /*return*/, null];
|
|
273
|
+
case 11:
|
|
274
|
+
e_2 = _a.sent();
|
|
275
|
+
logger.warn("getItem failed! ".concat(e_2));
|
|
276
|
+
return [2 /*return*/, null];
|
|
277
|
+
case 12: return [2 /*return*/];
|
|
140
278
|
}
|
|
141
279
|
});
|
|
142
280
|
});
|
|
143
281
|
};
|
|
144
282
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
283
|
+
* remove item from the cache
|
|
284
|
+
* The cache will abort output a warning:
|
|
285
|
+
* If error happened with AsyncStorage
|
|
286
|
+
* @param {String} key - the key of the item
|
|
287
|
+
* @return {Promise}
|
|
288
|
+
*/
|
|
289
|
+
StorageCacheCommon.prototype.removeItem = function (key) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
291
|
+
var prefixedKey, val, e_3;
|
|
292
|
+
return __generator(this, function (_a) {
|
|
293
|
+
switch (_a.label) {
|
|
294
|
+
case 0:
|
|
295
|
+
logger.debug("Remove item: key is ".concat(key));
|
|
296
|
+
if (!key || key === currentSizeKey) {
|
|
297
|
+
logger.warn("Invalid key: should not be empty or reserved key: '".concat(currentSizeKey, "'"));
|
|
298
|
+
return [2 /*return*/];
|
|
299
|
+
}
|
|
300
|
+
prefixedKey = "".concat(this.config.keyPrefix).concat(key);
|
|
301
|
+
_a.label = 1;
|
|
302
|
+
case 1:
|
|
303
|
+
_a.trys.push([1, 5, , 6]);
|
|
304
|
+
return [4 /*yield*/, this.getStorage().getItem(prefixedKey)];
|
|
305
|
+
case 2:
|
|
306
|
+
val = _a.sent();
|
|
307
|
+
if (!val) return [3 /*break*/, 4];
|
|
308
|
+
return [4 /*yield*/, this.removeCacheItem(prefixedKey, JSON.parse(val).byteSize)];
|
|
309
|
+
case 3:
|
|
310
|
+
_a.sent();
|
|
311
|
+
_a.label = 4;
|
|
312
|
+
case 4: return [3 /*break*/, 6];
|
|
313
|
+
case 5:
|
|
314
|
+
e_3 = _a.sent();
|
|
315
|
+
logger.warn("removeItem failed! ".concat(e_3));
|
|
316
|
+
return [3 /*break*/, 6];
|
|
317
|
+
case 6: return [2 /*return*/];
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* Return all the keys owned by this cache.
|
|
324
|
+
* Will return an empty array if error occurred.
|
|
325
|
+
*
|
|
326
|
+
* @return {Promise}
|
|
327
|
+
*/
|
|
328
|
+
StorageCacheCommon.prototype.getAllKeys = function () {
|
|
329
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
330
|
+
var e_4;
|
|
331
|
+
return __generator(this, function (_a) {
|
|
332
|
+
switch (_a.label) {
|
|
333
|
+
case 0:
|
|
334
|
+
_a.trys.push([0, 2, , 3]);
|
|
335
|
+
return [4 /*yield*/, this.getAllCacheKeys()];
|
|
336
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
337
|
+
case 2:
|
|
338
|
+
e_4 = _a.sent();
|
|
339
|
+
logger.warn("getAllkeys failed! ".concat(e_4));
|
|
340
|
+
return [2 /*return*/, []];
|
|
341
|
+
case 3: return [2 /*return*/];
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
};
|
|
346
|
+
StorageCacheCommon.prototype.getStorage = function () {
|
|
347
|
+
return this.keyValueStorage;
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* check whether item is expired
|
|
351
|
+
*
|
|
147
352
|
* @param key - the key of the item
|
|
148
353
|
*
|
|
149
354
|
* @return true if the item is expired.
|
|
150
355
|
*/
|
|
151
|
-
|
|
356
|
+
StorageCacheCommon.prototype.isExpired = function (key) {
|
|
152
357
|
return __awaiter(this, void 0, void 0, function () {
|
|
153
358
|
var text, item;
|
|
154
359
|
return __generator(this, function (_a) {
|
|
155
360
|
switch (_a.label) {
|
|
156
|
-
case 0: return [4 /*yield*/,
|
|
361
|
+
case 0: return [4 /*yield*/, this.getStorage().getItem(key)];
|
|
157
362
|
case 1:
|
|
158
363
|
text = _a.sent();
|
|
159
|
-
|
|
160
|
-
name: STORAGE_CACHE_EXCEPTION,
|
|
161
|
-
message: "Item not found in the storage by the key: ".concat(key, "."),
|
|
162
|
-
});
|
|
364
|
+
assert(text !== null, CacheErrorCode.NoCacheItem, "Key: ".concat(key));
|
|
163
365
|
item = JSON.parse(text);
|
|
164
|
-
if (
|
|
366
|
+
if (getCurrentTime() >= item.expires) {
|
|
165
367
|
return [2 /*return*/, true];
|
|
166
368
|
}
|
|
167
369
|
return [2 /*return*/, false];
|
|
@@ -171,39 +373,36 @@ var AsyncStorageCache = /** @class */ (function (_super) {
|
|
|
171
373
|
};
|
|
172
374
|
/**
|
|
173
375
|
* delete item from cache
|
|
174
|
-
*
|
|
376
|
+
*
|
|
175
377
|
* @param prefixedKey - the key of the item
|
|
176
378
|
* @param size - optional, the byte size of the item
|
|
177
379
|
*/
|
|
178
|
-
|
|
380
|
+
StorageCacheCommon.prototype.removeCacheItem = function (prefixedKey, size) {
|
|
179
381
|
return __awaiter(this, void 0, void 0, function () {
|
|
180
|
-
var
|
|
382
|
+
var item, itemSize, removeItemError_1;
|
|
181
383
|
return __generator(this, function (_a) {
|
|
182
384
|
switch (_a.label) {
|
|
183
|
-
case 0: return [4 /*yield*/,
|
|
385
|
+
case 0: return [4 /*yield*/, this.getStorage().getItem(prefixedKey)];
|
|
184
386
|
case 1:
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
message: "Item not found in the storage by the key: ".concat(prefixedKey, "."),
|
|
189
|
-
});
|
|
190
|
-
itemSize = size !== null && size !== void 0 ? size : JSON.parse(config).byteSize;
|
|
387
|
+
item = _a.sent();
|
|
388
|
+
assert(item !== null, CacheErrorCode.NoCacheItem, "Key: ".concat(prefixedKey));
|
|
389
|
+
itemSize = size !== null && size !== void 0 ? size : JSON.parse(item).byteSize;
|
|
191
390
|
// first try to update the current size of the cache
|
|
192
|
-
return [4 /*yield*/, this.
|
|
391
|
+
return [4 /*yield*/, this.decreaseCurrentSizeInBytes(itemSize)];
|
|
193
392
|
case 2:
|
|
194
393
|
// first try to update the current size of the cache
|
|
195
394
|
_a.sent();
|
|
196
395
|
_a.label = 3;
|
|
197
396
|
case 3:
|
|
198
397
|
_a.trys.push([3, 5, , 7]);
|
|
199
|
-
return [4 /*yield*/,
|
|
398
|
+
return [4 /*yield*/, this.getStorage().removeItem(prefixedKey)];
|
|
200
399
|
case 4:
|
|
201
400
|
_a.sent();
|
|
202
401
|
return [3 /*break*/, 7];
|
|
203
402
|
case 5:
|
|
204
403
|
removeItemError_1 = _a.sent();
|
|
205
404
|
// if some error happened, we need to rollback the current size
|
|
206
|
-
return [4 /*yield*/, this.
|
|
405
|
+
return [4 /*yield*/, this.increaseCurrentSizeInBytes(itemSize)];
|
|
207
406
|
case 6:
|
|
208
407
|
// if some error happened, we need to rollback the current size
|
|
209
408
|
_a.sent();
|
|
@@ -214,35 +413,145 @@ var AsyncStorageCache = /** @class */ (function (_super) {
|
|
|
214
413
|
});
|
|
215
414
|
});
|
|
216
415
|
};
|
|
416
|
+
/**
|
|
417
|
+
* produce a JSON object with meta-data and data value
|
|
418
|
+
* @param value - the value of the item
|
|
419
|
+
* @param options - optional, the specified meta-data
|
|
420
|
+
*
|
|
421
|
+
* @return - the item which has the meta-data and the value
|
|
422
|
+
*/
|
|
423
|
+
StorageCacheCommon.prototype.fillCacheItem = function (key, value, options) {
|
|
424
|
+
var _a, _b;
|
|
425
|
+
var item = {
|
|
426
|
+
key: key,
|
|
427
|
+
data: value,
|
|
428
|
+
timestamp: getCurrentTime(),
|
|
429
|
+
visitedTime: getCurrentTime(),
|
|
430
|
+
priority: (_a = options.priority) !== null && _a !== void 0 ? _a : 0,
|
|
431
|
+
expires: (_b = options.expires) !== null && _b !== void 0 ? _b : 0,
|
|
432
|
+
type: typeof value,
|
|
433
|
+
byteSize: 0,
|
|
434
|
+
};
|
|
435
|
+
// calculate byte size
|
|
436
|
+
item.byteSize = getByteLength(JSON.stringify(item));
|
|
437
|
+
// re-calculate using cache item with updated byteSize property
|
|
438
|
+
item.byteSize = getByteLength(JSON.stringify(item));
|
|
439
|
+
return item;
|
|
440
|
+
};
|
|
441
|
+
StorageCacheCommon.prototype.sanitizeConfig = function () {
|
|
442
|
+
if (this.config.itemMaxSize > this.config.capacityInBytes) {
|
|
443
|
+
logger.error('Invalid parameter: itemMaxSize. It should be smaller than capacityInBytes. Setting back to default.');
|
|
444
|
+
this.config.itemMaxSize = defaultConfig.itemMaxSize;
|
|
445
|
+
}
|
|
446
|
+
if (this.config.defaultPriority > 5 || this.config.defaultPriority < 1) {
|
|
447
|
+
logger.error('Invalid parameter: defaultPriority. It should be between 1 and 5. Setting back to default.');
|
|
448
|
+
this.config.defaultPriority = defaultConfig.defaultPriority;
|
|
449
|
+
}
|
|
450
|
+
if (Number(this.config.warningThreshold) > 1 ||
|
|
451
|
+
Number(this.config.warningThreshold) < 0) {
|
|
452
|
+
logger.error('Invalid parameter: warningThreshold. It should be between 0 and 1. Setting back to default.');
|
|
453
|
+
this.config.warningThreshold = defaultConfig.warningThreshold;
|
|
454
|
+
}
|
|
455
|
+
// Set 5MB limit
|
|
456
|
+
var cacheLimit = 5 * 1024 * 1024;
|
|
457
|
+
if (this.config.capacityInBytes > cacheLimit) {
|
|
458
|
+
logger.error('Cache Capacity should be less than 5MB. Setting back to default. Setting back to default.');
|
|
459
|
+
this.config.capacityInBytes = defaultConfig.capacityInBytes;
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
/**
|
|
463
|
+
* increase current size of the cache
|
|
464
|
+
*
|
|
465
|
+
* @param amount - the amount of the cache szie which need to be increased
|
|
466
|
+
*/
|
|
467
|
+
StorageCacheCommon.prototype.increaseCurrentSizeInBytes = function (amount) {
|
|
468
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
469
|
+
var size;
|
|
470
|
+
return __generator(this, function (_a) {
|
|
471
|
+
switch (_a.label) {
|
|
472
|
+
case 0: return [4 /*yield*/, this.getCurrentCacheSize()];
|
|
473
|
+
case 1:
|
|
474
|
+
size = _a.sent();
|
|
475
|
+
return [4 /*yield*/, this.getStorage().setItem(getCurrentSizeKey(this.config.keyPrefix), (size + amount).toString())];
|
|
476
|
+
case 2:
|
|
477
|
+
_a.sent();
|
|
478
|
+
return [2 /*return*/];
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
};
|
|
483
|
+
/**
|
|
484
|
+
* decrease current size of the cache
|
|
485
|
+
*
|
|
486
|
+
* @param amount - the amount of the cache size which needs to be decreased
|
|
487
|
+
*/
|
|
488
|
+
StorageCacheCommon.prototype.decreaseCurrentSizeInBytes = function (amount) {
|
|
489
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
490
|
+
var size;
|
|
491
|
+
return __generator(this, function (_a) {
|
|
492
|
+
switch (_a.label) {
|
|
493
|
+
case 0: return [4 /*yield*/, this.getCurrentCacheSize()];
|
|
494
|
+
case 1:
|
|
495
|
+
size = _a.sent();
|
|
496
|
+
return [4 /*yield*/, this.getStorage().setItem(getCurrentSizeKey(this.config.keyPrefix), (size - amount).toString())];
|
|
497
|
+
case 2:
|
|
498
|
+
_a.sent();
|
|
499
|
+
return [2 /*return*/];
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
};
|
|
504
|
+
/**
|
|
505
|
+
* update the visited time if item has been visited
|
|
506
|
+
*
|
|
507
|
+
* @param item - the item which need to be updated
|
|
508
|
+
* @param prefixedKey - the key of the item
|
|
509
|
+
*
|
|
510
|
+
* @return the updated item
|
|
511
|
+
*/
|
|
512
|
+
StorageCacheCommon.prototype.updateVisitedTime = function (item, prefixedKey) {
|
|
513
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
514
|
+
return __generator(this, function (_a) {
|
|
515
|
+
switch (_a.label) {
|
|
516
|
+
case 0:
|
|
517
|
+
item.visitedTime = getCurrentTime();
|
|
518
|
+
return [4 /*yield*/, this.getStorage().setItem(prefixedKey, JSON.stringify(item))];
|
|
519
|
+
case 1:
|
|
520
|
+
_a.sent();
|
|
521
|
+
return [2 /*return*/, item];
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
};
|
|
217
526
|
/**
|
|
218
527
|
* put item into cache
|
|
219
|
-
*
|
|
528
|
+
*
|
|
220
529
|
* @param prefixedKey - the key of the item
|
|
221
530
|
* @param itemData - the value of the item
|
|
222
531
|
* @param itemSizeInBytes - the byte size of the item
|
|
223
532
|
*/
|
|
224
|
-
|
|
533
|
+
StorageCacheCommon.prototype.setCacheItem = function (prefixedKey, item) {
|
|
225
534
|
return __awaiter(this, void 0, void 0, function () {
|
|
226
535
|
var setItemErr_1;
|
|
227
536
|
return __generator(this, function (_a) {
|
|
228
537
|
switch (_a.label) {
|
|
229
538
|
case 0:
|
|
230
539
|
// first try to update the current size of the cache.
|
|
231
|
-
return [4 /*yield*/, this.
|
|
540
|
+
return [4 /*yield*/, this.increaseCurrentSizeInBytes(item.byteSize)];
|
|
232
541
|
case 1:
|
|
233
542
|
// first try to update the current size of the cache.
|
|
234
543
|
_a.sent();
|
|
235
544
|
_a.label = 2;
|
|
236
545
|
case 2:
|
|
237
546
|
_a.trys.push([2, 4, , 6]);
|
|
238
|
-
return [4 /*yield*/,
|
|
547
|
+
return [4 /*yield*/, this.getStorage().setItem(prefixedKey, JSON.stringify(item))];
|
|
239
548
|
case 3:
|
|
240
549
|
_a.sent();
|
|
241
550
|
return [3 /*break*/, 6];
|
|
242
551
|
case 4:
|
|
243
552
|
setItemErr_1 = _a.sent();
|
|
244
553
|
// if some error happened, we need to rollback the current size
|
|
245
|
-
return [4 /*yield*/, this.
|
|
554
|
+
return [4 /*yield*/, this.decreaseCurrentSizeInBytes(item.byteSize)];
|
|
246
555
|
case 5:
|
|
247
556
|
// if some error happened, we need to rollback the current size
|
|
248
557
|
_a.sent();
|
|
@@ -255,23 +564,21 @@ var AsyncStorageCache = /** @class */ (function (_super) {
|
|
|
255
564
|
};
|
|
256
565
|
/**
|
|
257
566
|
* total space needed when poping out items
|
|
258
|
-
*
|
|
567
|
+
*
|
|
259
568
|
* @param itemSize
|
|
260
569
|
*
|
|
261
570
|
* @return total space needed
|
|
262
571
|
*/
|
|
263
|
-
|
|
572
|
+
StorageCacheCommon.prototype.sizeToPop = function (itemSize) {
|
|
264
573
|
return __awaiter(this, void 0, void 0, function () {
|
|
265
|
-
var spaceItemNeed, cacheThresholdSpace;
|
|
574
|
+
var cur, spaceItemNeed, cacheThresholdSpace;
|
|
266
575
|
return __generator(this, function (_a) {
|
|
267
576
|
switch (_a.label) {
|
|
268
|
-
case 0: return [4 /*yield*/, this.
|
|
577
|
+
case 0: return [4 /*yield*/, this.getCurrentCacheSize()];
|
|
269
578
|
case 1:
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
cacheThresholdSpace = (1 - this.cacheConfig.warningThreshold) *
|
|
274
|
-
this.cacheConfig.capacityInBytes;
|
|
579
|
+
cur = _a.sent();
|
|
580
|
+
spaceItemNeed = cur + itemSize - this.config.capacityInBytes;
|
|
581
|
+
cacheThresholdSpace = (1 - this.config.warningThreshold) * this.config.capacityInBytes;
|
|
275
582
|
return [2 /*return*/, spaceItemNeed > cacheThresholdSpace
|
|
276
583
|
? spaceItemNeed
|
|
277
584
|
: cacheThresholdSpace];
|
|
@@ -281,63 +588,20 @@ var AsyncStorageCache = /** @class */ (function (_super) {
|
|
|
281
588
|
};
|
|
282
589
|
/**
|
|
283
590
|
* see whether cache is full
|
|
284
|
-
*
|
|
591
|
+
*
|
|
285
592
|
* @param itemSize
|
|
286
593
|
*
|
|
287
594
|
* @return true if cache is full
|
|
288
595
|
*/
|
|
289
|
-
|
|
596
|
+
StorageCacheCommon.prototype.isCacheFull = function (itemSize) {
|
|
290
597
|
return __awaiter(this, void 0, void 0, function () {
|
|
291
|
-
var
|
|
292
|
-
return __generator(this, function (_b) {
|
|
293
|
-
switch (_b.label) {
|
|
294
|
-
case 0:
|
|
295
|
-
_a = itemSize;
|
|
296
|
-
return [4 /*yield*/, this.getCacheCurSize()];
|
|
297
|
-
case 1: return [2 /*return*/, (_a + (_b.sent()) >
|
|
298
|
-
this.cacheConfig.capacityInBytes)];
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
};
|
|
303
|
-
/**
|
|
304
|
-
* scan the storage and find out all the keys owned by this cache
|
|
305
|
-
* also clean the expired keys while scanning
|
|
306
|
-
* @private
|
|
307
|
-
* @return array of keys
|
|
308
|
-
*/
|
|
309
|
-
AsyncStorageCache.prototype._findValidKeys = function () {
|
|
310
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
311
|
-
var keys, keyInCache, i, key;
|
|
598
|
+
var cur;
|
|
312
599
|
return __generator(this, function (_a) {
|
|
313
600
|
switch (_a.label) {
|
|
314
|
-
case 0:
|
|
315
|
-
keys = [];
|
|
316
|
-
keyInCache = [];
|
|
317
|
-
return [4 /*yield*/, AsyncStorage.getAllKeys()];
|
|
601
|
+
case 0: return [4 /*yield*/, this.getCurrentCacheSize()];
|
|
318
602
|
case 1:
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
_a.label = 2;
|
|
322
|
-
case 2:
|
|
323
|
-
if (!(i < keyInCache.length)) return [3 /*break*/, 7];
|
|
324
|
-
key = keyInCache[i];
|
|
325
|
-
if (!(key.indexOf(this.cacheConfig.keyPrefix) === 0 &&
|
|
326
|
-
key !== getCurrSizeKey(this.cacheConfig.keyPrefix))) return [3 /*break*/, 6];
|
|
327
|
-
return [4 /*yield*/, this._isExpired(key)];
|
|
328
|
-
case 3:
|
|
329
|
-
if (!_a.sent()) return [3 /*break*/, 5];
|
|
330
|
-
return [4 /*yield*/, this._removeItem(key)];
|
|
331
|
-
case 4:
|
|
332
|
-
_a.sent();
|
|
333
|
-
return [3 /*break*/, 6];
|
|
334
|
-
case 5:
|
|
335
|
-
keys.push(key);
|
|
336
|
-
_a.label = 6;
|
|
337
|
-
case 6:
|
|
338
|
-
i += 1;
|
|
339
|
-
return [3 /*break*/, 2];
|
|
340
|
-
case 7: return [2 /*return*/, keys];
|
|
603
|
+
cur = _a.sent();
|
|
604
|
+
return [2 /*return*/, itemSize + cur > this.config.capacityInBytes];
|
|
341
605
|
}
|
|
342
606
|
});
|
|
343
607
|
});
|
|
@@ -350,7 +614,7 @@ var AsyncStorageCache = /** @class */ (function (_super) {
|
|
|
350
614
|
* @param keys - all the keys in this cache
|
|
351
615
|
* @param sizeToPop - the total size of the items which needed to be poped out
|
|
352
616
|
*/
|
|
353
|
-
|
|
617
|
+
StorageCacheCommon.prototype.popOutItems = function (keys, sizeToPop) {
|
|
354
618
|
return __awaiter(this, void 0, void 0, function () {
|
|
355
619
|
var items, remainedSize, i, val, item, i;
|
|
356
620
|
return __generator(this, function (_a) {
|
|
@@ -362,7 +626,7 @@ var AsyncStorageCache = /** @class */ (function (_super) {
|
|
|
362
626
|
_a.label = 1;
|
|
363
627
|
case 1:
|
|
364
628
|
if (!(i < keys.length)) return [3 /*break*/, 4];
|
|
365
|
-
return [4 /*yield*/,
|
|
629
|
+
return [4 /*yield*/, this.getStorage().getItem(keys[i])];
|
|
366
630
|
case 2:
|
|
367
631
|
val = _a.sent();
|
|
368
632
|
if (val != null) {
|
|
@@ -396,7 +660,7 @@ var AsyncStorageCache = /** @class */ (function (_super) {
|
|
|
396
660
|
case 5:
|
|
397
661
|
if (!(i < items.length)) return [3 /*break*/, 8];
|
|
398
662
|
// pop out items until we have enough room for new item
|
|
399
|
-
return [4 /*yield*/, this.
|
|
663
|
+
return [4 /*yield*/, this.removeCacheItem(items[i].key, items[i].byteSize)];
|
|
400
664
|
case 6:
|
|
401
665
|
// pop out items until we have enough room for new item
|
|
402
666
|
_a.sent();
|
|
@@ -414,324 +678,117 @@ var AsyncStorageCache = /** @class */ (function (_super) {
|
|
|
414
678
|
});
|
|
415
679
|
};
|
|
416
680
|
/**
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
* The cache will pop out items if it is full
|
|
421
|
-
* You can specify the cache item options. The cache will abort and output a warning:
|
|
422
|
-
* If the key is invalid
|
|
423
|
-
* If the size of the item exceeds itemMaxSize.
|
|
424
|
-
* If the value is undefined
|
|
425
|
-
* If incorrect cache item configuration
|
|
426
|
-
* If error happened with browser storage
|
|
681
|
+
* Scan the storage and combine the following operations for efficiency
|
|
682
|
+
* 1. Clear out all expired keys owned by this cache, not including the size key.
|
|
683
|
+
* 2. Return the remaining keys.
|
|
427
684
|
*
|
|
428
|
-
* @
|
|
429
|
-
* @param {Object} value - the value of the item
|
|
430
|
-
* @param {Object} [options] - optional, the specified meta-data
|
|
431
|
-
* @return {Promise}
|
|
685
|
+
* @return The remaining valid keys
|
|
432
686
|
*/
|
|
433
|
-
|
|
687
|
+
StorageCacheCommon.prototype.clearInvalidAndGetRemainingKeys = function () {
|
|
434
688
|
return __awaiter(this, void 0, void 0, function () {
|
|
435
|
-
var
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
logger.debug("Set item: key is ".concat(key, ", value is ").concat(value, " with options: ").concat(options));
|
|
440
|
-
prefixedKey = this.cacheConfig.keyPrefix + key;
|
|
441
|
-
// invalid keys
|
|
442
|
-
if (prefixedKey === this.cacheConfig.keyPrefix ||
|
|
443
|
-
prefixedKey === getCurrSizeKey(this.cacheConfig.keyPrefix)) {
|
|
444
|
-
logger.warn("Invalid key: should not be empty or 'CurSize'");
|
|
445
|
-
return [2 /*return*/];
|
|
446
|
-
}
|
|
447
|
-
if (typeof value === 'undefined') {
|
|
448
|
-
logger.warn("The value of item should not be undefined!");
|
|
449
|
-
return [2 /*return*/];
|
|
450
|
-
}
|
|
451
|
-
cacheItemOptions = {
|
|
452
|
-
priority: options && options.priority !== undefined
|
|
453
|
-
? options.priority
|
|
454
|
-
: this.cacheConfig.defaultPriority,
|
|
455
|
-
expires: options && options.expires !== undefined
|
|
456
|
-
? options.expires
|
|
457
|
-
: this.cacheConfig.defaultTTL + getCurrTime(),
|
|
458
|
-
};
|
|
459
|
-
if (cacheItemOptions.priority < 1 || cacheItemOptions.priority > 5) {
|
|
460
|
-
logger.warn("Invalid parameter: priority due to out or range. It should be within 1 and 5.");
|
|
461
|
-
return [2 /*return*/];
|
|
462
|
-
}
|
|
463
|
-
item = this.fillCacheItem(prefixedKey, value, cacheItemOptions);
|
|
464
|
-
// check wether this item is too big;
|
|
465
|
-
if (item.byteSize > this.cacheConfig.itemMaxSize) {
|
|
466
|
-
logger.warn("Item with key: ".concat(key, " you are trying to put into is too big!"));
|
|
467
|
-
return [2 /*return*/];
|
|
468
|
-
}
|
|
469
|
-
_a.label = 1;
|
|
470
|
-
case 1:
|
|
471
|
-
_a.trys.push([1, 12, , 13]);
|
|
472
|
-
return [4 /*yield*/, AsyncStorage.getItem(prefixedKey)];
|
|
473
|
-
case 2:
|
|
474
|
-
val = _a.sent();
|
|
475
|
-
if (!val) return [3 /*break*/, 4];
|
|
476
|
-
return [4 /*yield*/, this._removeItem(prefixedKey, JSON.parse(val).byteSize)];
|
|
477
|
-
case 3:
|
|
478
|
-
_a.sent();
|
|
479
|
-
_a.label = 4;
|
|
480
|
-
case 4: return [4 /*yield*/, this._isCacheFull(item.byteSize)];
|
|
481
|
-
case 5:
|
|
482
|
-
if (!_a.sent()) return [3 /*break*/, 10];
|
|
483
|
-
return [4 /*yield*/, this._findValidKeys()];
|
|
484
|
-
case 6:
|
|
485
|
-
validKeys = _a.sent();
|
|
486
|
-
return [4 /*yield*/, this._isCacheFull(item.byteSize)];
|
|
487
|
-
case 7:
|
|
488
|
-
if (!_a.sent()) return [3 /*break*/, 10];
|
|
489
|
-
return [4 /*yield*/, this._sizeToPop(item.byteSize)];
|
|
490
|
-
case 8:
|
|
491
|
-
sizeToPop = _a.sent();
|
|
492
|
-
return [4 /*yield*/, this._popOutItems(validKeys, sizeToPop)];
|
|
493
|
-
case 9:
|
|
494
|
-
_a.sent();
|
|
495
|
-
_a.label = 10;
|
|
496
|
-
case 10:
|
|
497
|
-
// put item in the cache
|
|
498
|
-
return [4 /*yield*/, this._setItem(prefixedKey, item)];
|
|
499
|
-
case 11:
|
|
500
|
-
// put item in the cache
|
|
501
|
-
_a.sent();
|
|
502
|
-
return [3 /*break*/, 13];
|
|
503
|
-
case 12:
|
|
504
|
-
e_1 = _a.sent();
|
|
505
|
-
logger.warn("setItem failed! ".concat(e_1));
|
|
506
|
-
return [3 /*break*/, 13];
|
|
507
|
-
case 13: return [2 /*return*/];
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
});
|
|
511
|
-
};
|
|
512
|
-
/**
|
|
513
|
-
* Get item from cache. It will return null if item doesn’t exist or it has been expired.
|
|
514
|
-
* If you specified callback function in the options,
|
|
515
|
-
* then the function will be executed if no such item in the cache
|
|
516
|
-
* and finally put the return value into cache.
|
|
517
|
-
* Please make sure the callback function will return the value you want to put into the cache.
|
|
518
|
-
* The cache will abort output a warning:
|
|
519
|
-
* If the key is invalid
|
|
520
|
-
* If error happened with AsyncStorage
|
|
521
|
-
*
|
|
522
|
-
* @param {String} key - the key of the item
|
|
523
|
-
* @param {Object} [options] - the options of callback function
|
|
524
|
-
* @return {Promise} - return a promise resolves to be the value of the item
|
|
525
|
-
*/
|
|
526
|
-
AsyncStorageCache.prototype.getItem = function (key, options) {
|
|
527
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
528
|
-
var ret, prefixedKey, item, val, e_2;
|
|
529
|
-
return __generator(this, function (_a) {
|
|
530
|
-
switch (_a.label) {
|
|
689
|
+
var remainingKeys, keys, keys_1, keys_1_1, key, e_5_1;
|
|
690
|
+
var e_5, _a;
|
|
691
|
+
return __generator(this, function (_b) {
|
|
692
|
+
switch (_b.label) {
|
|
531
693
|
case 0:
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
prefixedKey === getCurrSizeKey(this.cacheConfig.keyPrefix)) {
|
|
537
|
-
logger.warn("Invalid key: should not be empty or 'CurSize'");
|
|
538
|
-
return [2 /*return*/, null];
|
|
539
|
-
}
|
|
540
|
-
_a.label = 1;
|
|
694
|
+
remainingKeys = [];
|
|
695
|
+
return [4 /*yield*/, this.getAllCacheKeys({
|
|
696
|
+
omitSizeKey: true,
|
|
697
|
+
})];
|
|
541
698
|
case 1:
|
|
542
|
-
|
|
543
|
-
|
|
699
|
+
keys = _b.sent();
|
|
700
|
+
_b.label = 2;
|
|
544
701
|
case 2:
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
702
|
+
_b.trys.push([2, 9, 10, 11]);
|
|
703
|
+
keys_1 = __values(keys), keys_1_1 = keys_1.next();
|
|
704
|
+
_b.label = 3;
|
|
548
705
|
case 3:
|
|
549
|
-
if (
|
|
550
|
-
|
|
551
|
-
return [4 /*yield*/, this.
|
|
706
|
+
if (!!keys_1_1.done) return [3 /*break*/, 8];
|
|
707
|
+
key = keys_1_1.value;
|
|
708
|
+
return [4 /*yield*/, this.isExpired(key)];
|
|
552
709
|
case 4:
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
return [3 /*break*/, 7];
|
|
710
|
+
if (!_b.sent()) return [3 /*break*/, 6];
|
|
711
|
+
return [4 /*yield*/, this.removeCacheItem(key)];
|
|
556
712
|
case 5:
|
|
557
|
-
|
|
558
|
-
return [
|
|
713
|
+
_b.sent();
|
|
714
|
+
return [3 /*break*/, 7];
|
|
559
715
|
case 6:
|
|
560
|
-
|
|
561
|
-
|
|
716
|
+
remainingKeys.push(key);
|
|
717
|
+
_b.label = 7;
|
|
562
718
|
case 7:
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
logger.warn("getItem failed! ".concat(e_2));
|
|
574
|
-
return [2 /*return*/, null];
|
|
575
|
-
case 9: return [2 /*return*/];
|
|
576
|
-
}
|
|
577
|
-
});
|
|
578
|
-
});
|
|
579
|
-
};
|
|
580
|
-
/**
|
|
581
|
-
* remove item from the cache
|
|
582
|
-
* The cache will abort output a warning:
|
|
583
|
-
* If error happened with AsyncStorage
|
|
584
|
-
* @param {String} key - the key of the item
|
|
585
|
-
* @return {Promise}
|
|
586
|
-
*/
|
|
587
|
-
AsyncStorageCache.prototype.removeItem = function (key) {
|
|
588
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
589
|
-
var prefixedKey, val, e_3;
|
|
590
|
-
return __generator(this, function (_a) {
|
|
591
|
-
switch (_a.label) {
|
|
592
|
-
case 0:
|
|
593
|
-
logger.debug("Remove item: key is ".concat(key));
|
|
594
|
-
prefixedKey = this.cacheConfig.keyPrefix + key;
|
|
595
|
-
if (prefixedKey === this.cacheConfig.keyPrefix ||
|
|
596
|
-
prefixedKey === getCurrSizeKey(this.cacheConfig.keyPrefix)) {
|
|
597
|
-
return [2 /*return*/];
|
|
719
|
+
keys_1_1 = keys_1.next();
|
|
720
|
+
return [3 /*break*/, 3];
|
|
721
|
+
case 8: return [3 /*break*/, 11];
|
|
722
|
+
case 9:
|
|
723
|
+
e_5_1 = _b.sent();
|
|
724
|
+
e_5 = { error: e_5_1 };
|
|
725
|
+
return [3 /*break*/, 11];
|
|
726
|
+
case 10:
|
|
727
|
+
try {
|
|
728
|
+
if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
|
|
598
729
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
return [4 /*yield*/, AsyncStorage.getItem(prefixedKey)];
|
|
603
|
-
case 2:
|
|
604
|
-
val = _a.sent();
|
|
605
|
-
if (!val) return [3 /*break*/, 4];
|
|
606
|
-
return [4 /*yield*/, this._removeItem(prefixedKey, JSON.parse(val).byteSize)];
|
|
607
|
-
case 3:
|
|
608
|
-
_a.sent();
|
|
609
|
-
_a.label = 4;
|
|
610
|
-
case 4: return [3 /*break*/, 6];
|
|
611
|
-
case 5:
|
|
612
|
-
e_3 = _a.sent();
|
|
613
|
-
logger.warn("removeItem failed! ".concat(e_3));
|
|
614
|
-
return [3 /*break*/, 6];
|
|
615
|
-
case 6: return [2 /*return*/];
|
|
730
|
+
finally { if (e_5) throw e_5.error; }
|
|
731
|
+
return [7 /*endfinally*/];
|
|
732
|
+
case 11: return [2 /*return*/, remainingKeys];
|
|
616
733
|
}
|
|
617
734
|
});
|
|
618
735
|
});
|
|
619
736
|
};
|
|
620
737
|
/**
|
|
621
738
|
* clear the entire cache
|
|
622
|
-
* The cache will abort output a warning
|
|
623
|
-
* If error happened with AsyncStorage
|
|
739
|
+
* The cache will abort and output a warning if error occurs
|
|
624
740
|
* @return {Promise}
|
|
625
741
|
*/
|
|
626
|
-
|
|
742
|
+
StorageCacheCommon.prototype.clear = function () {
|
|
627
743
|
return __awaiter(this, void 0, void 0, function () {
|
|
628
|
-
var keys,
|
|
629
|
-
|
|
630
|
-
|
|
744
|
+
var keys, keys_2, keys_2_1, key, e_6_1, e_7;
|
|
745
|
+
var e_6, _a;
|
|
746
|
+
return __generator(this, function (_b) {
|
|
747
|
+
switch (_b.label) {
|
|
631
748
|
case 0:
|
|
632
749
|
logger.debug("Clear Cache");
|
|
633
|
-
|
|
750
|
+
_b.label = 1;
|
|
634
751
|
case 1:
|
|
635
|
-
|
|
636
|
-
return [4 /*yield*/,
|
|
752
|
+
_b.trys.push([1, 11, , 12]);
|
|
753
|
+
return [4 /*yield*/, this.getAllKeys()];
|
|
637
754
|
case 2:
|
|
638
|
-
keys =
|
|
639
|
-
|
|
640
|
-
for (i = 0; i < keys.length; i += 1) {
|
|
641
|
-
if (keys[i].indexOf(this.cacheConfig.keyPrefix) === 0) {
|
|
642
|
-
keysToRemove.push(keys[i]);
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
i = 0;
|
|
646
|
-
_a.label = 3;
|
|
755
|
+
keys = _b.sent();
|
|
756
|
+
_b.label = 3;
|
|
647
757
|
case 3:
|
|
648
|
-
|
|
649
|
-
|
|
758
|
+
_b.trys.push([3, 8, 9, 10]);
|
|
759
|
+
keys_2 = __values(keys), keys_2_1 = keys_2.next();
|
|
760
|
+
_b.label = 4;
|
|
650
761
|
case 4:
|
|
651
|
-
|
|
652
|
-
|
|
762
|
+
if (!!keys_2_1.done) return [3 /*break*/, 7];
|
|
763
|
+
key = keys_2_1.value;
|
|
764
|
+
return [4 /*yield*/, this.getStorage().removeItem(key)];
|
|
653
765
|
case 5:
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
case 6:
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
* return the current size of the cache
|
|
668
|
-
* @return {Promise}
|
|
669
|
-
*/
|
|
670
|
-
AsyncStorageCache.prototype.getCacheCurSize = function () {
|
|
671
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
672
|
-
var ret;
|
|
673
|
-
return __generator(this, function (_a) {
|
|
674
|
-
switch (_a.label) {
|
|
675
|
-
case 0: return [4 /*yield*/, AsyncStorage.getItem(getCurrSizeKey(this.cacheConfig.keyPrefix))];
|
|
676
|
-
case 1:
|
|
677
|
-
ret = _a.sent();
|
|
678
|
-
if (!!ret) return [3 /*break*/, 3];
|
|
679
|
-
return [4 /*yield*/, AsyncStorage.setItem(getCurrSizeKey(this.cacheConfig.keyPrefix), '0')];
|
|
680
|
-
case 2:
|
|
681
|
-
_a.sent();
|
|
682
|
-
ret = '0';
|
|
683
|
-
_a.label = 3;
|
|
684
|
-
case 3: return [2 /*return*/, Number(ret)];
|
|
685
|
-
}
|
|
686
|
-
});
|
|
687
|
-
});
|
|
688
|
-
};
|
|
689
|
-
/**
|
|
690
|
-
* Return all the keys in the cache.
|
|
691
|
-
* Will return an empty array if error happend.
|
|
692
|
-
* @return {Promise}
|
|
693
|
-
*/
|
|
694
|
-
AsyncStorageCache.prototype.getAllKeys = function () {
|
|
695
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
696
|
-
var keys, retKeys, i, e_5;
|
|
697
|
-
return __generator(this, function (_a) {
|
|
698
|
-
switch (_a.label) {
|
|
699
|
-
case 0:
|
|
700
|
-
_a.trys.push([0, 2, , 3]);
|
|
701
|
-
return [4 /*yield*/, AsyncStorage.getAllKeys()];
|
|
702
|
-
case 1:
|
|
703
|
-
keys = _a.sent();
|
|
704
|
-
retKeys = [];
|
|
705
|
-
for (i = 0; i < keys.length; i += 1) {
|
|
706
|
-
if (keys[i].indexOf(this.cacheConfig.keyPrefix) === 0 &&
|
|
707
|
-
keys[i] !== getCurrSizeKey(this.cacheConfig.keyPrefix)) {
|
|
708
|
-
retKeys.push(keys[i].substring(this.cacheConfig.keyPrefix.length));
|
|
709
|
-
}
|
|
766
|
+
_b.sent();
|
|
767
|
+
_b.label = 6;
|
|
768
|
+
case 6:
|
|
769
|
+
keys_2_1 = keys_2.next();
|
|
770
|
+
return [3 /*break*/, 4];
|
|
771
|
+
case 7: return [3 /*break*/, 10];
|
|
772
|
+
case 8:
|
|
773
|
+
e_6_1 = _b.sent();
|
|
774
|
+
e_6 = { error: e_6_1 };
|
|
775
|
+
return [3 /*break*/, 10];
|
|
776
|
+
case 9:
|
|
777
|
+
try {
|
|
778
|
+
if (keys_2_1 && !keys_2_1.done && (_a = keys_2.return)) _a.call(keys_2);
|
|
710
779
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
780
|
+
finally { if (e_6) throw e_6.error; }
|
|
781
|
+
return [7 /*endfinally*/];
|
|
782
|
+
case 10: return [3 /*break*/, 12];
|
|
783
|
+
case 11:
|
|
784
|
+
e_7 = _b.sent();
|
|
785
|
+
logger.warn("clear failed! ".concat(e_7));
|
|
786
|
+
return [3 /*break*/, 12];
|
|
787
|
+
case 12: return [2 /*return*/];
|
|
717
788
|
}
|
|
718
789
|
});
|
|
719
790
|
});
|
|
720
791
|
};
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
* @return {Object} - the new instance of Cache
|
|
725
|
-
*/
|
|
726
|
-
AsyncStorageCache.prototype.createInstance = function (config) {
|
|
727
|
-
if (config.keyPrefix === defaultConfig.keyPrefix) {
|
|
728
|
-
logger.error('invalid keyPrefix, setting keyPrefix with timeStamp');
|
|
729
|
-
config.keyPrefix = getCurrTime.toString();
|
|
730
|
-
}
|
|
731
|
-
return new AsyncStorageCache(config);
|
|
732
|
-
};
|
|
733
|
-
return AsyncStorageCache;
|
|
734
|
-
}(StorageCache));
|
|
735
|
-
export { AsyncStorageCache };
|
|
736
|
-
var instance = new AsyncStorageCache();
|
|
737
|
-
export { AsyncStorage, instance as Cache };
|
|
792
|
+
return StorageCacheCommon;
|
|
793
|
+
}());
|
|
794
|
+
export { StorageCacheCommon };
|