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