@aws-amplify/core 6.0.1-api-v6-models.8035dfc.0 → 6.0.1-api-v6-models.3eb7748.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/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-esm/Cache/AsyncStorageCache.d.ts → lib/Cache/StorageCacheCommon.d.ts} +124 -99
- package/lib/Cache/{AsyncStorageCache.js → StorageCacheCommon.js} +494 -432
- 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 +2 -1
- package/lib/Cache/utils/cacheHelpers.d.ts +14 -0
- package/lib/Cache/utils/cacheHelpers.js +51 -0
- package/lib/Cache/{Utils → utils}/errorHelpers.d.ts +0 -1
- package/lib/Cache/{Utils → utils}/errorHelpers.js +0 -4
- package/lib/Cache/utils/index.d.ts +2 -0
- package/lib/Cache/utils/index.js +12 -0
- package/lib/I18n/I18n.js +1 -6
- package/lib/Platform/types.d.ts +18 -8
- package/lib/Platform/types.js +10 -2
- package/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/Reachability/Reachability.d.ts +1 -0
- package/lib/Reachability/Reachability.js +42 -1
- package/lib/ServiceWorker/ServiceWorker.js +69 -17
- package/lib/ServiceWorker/index.d.ts +0 -12
- package/lib/ServiceWorker/index.js +0 -12
- package/lib/Signer/Signer.js +3 -2
- package/lib/awsClients/cognitoIdentity/base.js +2 -1
- package/lib/awsClients/pinpoint/base.js +2 -1
- package/lib/awsClients/pinpoint/getInAppMessages.js +2 -1
- package/lib/awsClients/pinpoint/putEvents.js +2 -1
- package/lib/awsClients/pinpoint/updateEndpoint.js +2 -1
- package/lib/clients/middleware/signing/signer/signatureV4/index.d.ts +0 -1
- package/lib/clients/middleware/signing/signer/signatureV4/index.js +0 -1
- package/lib/clients/middleware/signing/signer/signatureV4/presignUrl.js +2 -1
- package/lib/errors/errorHelpers.d.ts +2 -0
- package/lib/errors/errorHelpers.js +20 -0
- package/lib/errors/index.d.ts +1 -0
- package/lib/errors/index.js +3 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.js +9 -6
- package/lib/libraryUtils.d.ts +8 -7
- package/lib/libraryUtils.js +17 -17
- package/lib/parseAWSExports.js +34 -19
- package/lib/providers/pinpoint/apis/flushEvents.d.ts +2 -2
- 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.js +6 -6
- package/lib/providers/pinpoint/index.d.ts +2 -2
- package/lib/providers/pinpoint/index.js +4 -2
- 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 +3 -3
- package/lib/providers/pinpoint/utils/index.d.ts +1 -0
- package/lib/providers/pinpoint/utils/index.js +3 -1
- package/lib/providers/pinpoint/utils/resolveEndpointId.d.ts +8 -0
- package/lib/providers/pinpoint/utils/resolveEndpointId.js +85 -0
- package/lib/singleton/Amplify.d.ts +2 -2
- package/lib/singleton/Amplify.js +6 -5
- package/lib/singleton/Auth/types.d.ts +3 -3
- package/lib/singleton/Cache/types.d.ts +18 -0
- package/lib/singleton/Cache/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/PushNotification/types.d.ts +2 -0
- package/lib/singleton/Notifications/PushNotification/types.js +4 -0
- package/lib/singleton/Notifications/types.d.ts +3 -1
- package/lib/singleton/types.d.ts +3 -3
- package/lib/storage/CookieStorage.js +8 -5
- package/lib/storage/DefaultStorage.js +1 -1
- package/lib/storage/utils.d.ts +1 -1
- package/lib/storage/utils.js +3 -3
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/errors.d.ts +1 -0
- package/lib/types/errors.js +1 -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/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/deepFreeze.d.ts +1 -0
- package/lib/utils/deepFreeze.js +38 -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/{ClientDevice/browser.d.ts → 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/index.d.ts +2 -0
- package/lib/utils/index.js +5 -1
- 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-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/Cache/AsyncStorageCache.d.ts → lib-esm/Cache/StorageCacheCommon.d.ts} +124 -99
- package/lib-esm/Cache/{AsyncStorageCache.js → StorageCacheCommon.js} +493 -430
- 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 +1 -1
- package/lib-esm/Cache/utils/cacheHelpers.d.ts +14 -0
- package/lib-esm/Cache/utils/cacheHelpers.js +44 -0
- package/lib-esm/Cache/{Utils → utils}/errorHelpers.d.ts +0 -1
- package/lib-esm/Cache/{Utils → utils}/errorHelpers.js +0 -4
- package/lib-esm/Cache/utils/index.d.ts +2 -0
- package/lib-esm/Cache/utils/index.js +4 -0
- package/lib-esm/I18n/I18n.js +1 -6
- package/lib-esm/Platform/types.d.ts +18 -8
- package/lib-esm/Platform/types.js +10 -2
- package/lib-esm/Platform/version.d.ts +1 -1
- package/lib-esm/Platform/version.js +1 -1
- package/lib-esm/Reachability/Reachability.d.ts +1 -0
- package/lib-esm/Reachability/Reachability.js +43 -2
- package/lib-esm/ServiceWorker/ServiceWorker.js +69 -17
- package/lib-esm/ServiceWorker/index.d.ts +0 -12
- package/lib-esm/ServiceWorker/index.js +0 -12
- package/lib-esm/Signer/Signer.js +3 -2
- package/lib-esm/awsClients/cognitoIdentity/base.js +2 -1
- package/lib-esm/awsClients/pinpoint/base.js +2 -1
- package/lib-esm/awsClients/pinpoint/getInAppMessages.js +2 -1
- package/lib-esm/awsClients/pinpoint/putEvents.js +2 -1
- package/lib-esm/awsClients/pinpoint/updateEndpoint.js +2 -1
- package/lib-esm/clients/middleware/signing/signer/signatureV4/index.d.ts +0 -1
- package/lib-esm/clients/middleware/signing/signer/signatureV4/index.js +0 -1
- package/lib-esm/clients/middleware/signing/signer/signatureV4/presignUrl.js +2 -1
- package/lib-esm/errors/errorHelpers.d.ts +2 -0
- package/lib-esm/errors/errorHelpers.js +17 -0
- package/lib-esm/errors/index.d.ts +1 -0
- package/lib-esm/errors/index.js +1 -0
- package/lib-esm/index.d.ts +4 -4
- package/lib-esm/index.js +5 -4
- package/lib-esm/libraryUtils.d.ts +8 -7
- package/lib-esm/libraryUtils.js +7 -7
- package/lib-esm/parseAWSExports.js +34 -19
- package/lib-esm/providers/pinpoint/apis/flushEvents.d.ts +2 -2
- 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.js +6 -6
- package/lib-esm/providers/pinpoint/index.d.ts +2 -2
- package/lib-esm/providers/pinpoint/index.js +2 -1
- 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 +3 -3
- 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/resolveEndpointId.d.ts +8 -0
- package/lib-esm/providers/pinpoint/utils/resolveEndpointId.js +81 -0
- package/lib-esm/singleton/Amplify.d.ts +2 -2
- package/lib-esm/singleton/Amplify.js +6 -5
- package/lib-esm/singleton/Auth/types.d.ts +3 -3
- package/lib-esm/singleton/Cache/types.d.ts +18 -0
- package/lib-esm/singleton/Cache/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/PushNotification/types.d.ts +2 -0
- package/lib-esm/singleton/Notifications/PushNotification/types.js +3 -0
- package/lib-esm/singleton/Notifications/types.d.ts +3 -1
- package/lib-esm/singleton/types.d.ts +3 -3
- package/lib-esm/storage/CookieStorage.js +5 -5
- package/lib-esm/storage/DefaultStorage.js +2 -2
- package/lib-esm/storage/utils.d.ts +1 -1
- package/lib-esm/storage/utils.js +1 -1
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/errors.d.ts +1 -0
- package/lib-esm/types/errors.js +1 -0
- package/lib-esm/utils/amplifyUrl/index.d.ts +13 -0
- package/lib-esm/utils/amplifyUrl/index.js +6 -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.native.js +4 -0
- package/lib-esm/utils/deepFreeze.d.ts +1 -0
- package/lib-esm/utils/deepFreeze.js +34 -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-esm/{ClientDevice/browser.d.ts → 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/index.d.ts +2 -0
- package/lib-esm/utils/index.js +2 -0
- 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/package.json +9 -19
- 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 -185
- package/src/Cache/utils/cacheHelpers.ts +52 -0
- package/src/Cache/{Utils → utils}/errorHelpers.ts +0 -4
- package/src/Cache/{Utils → utils}/index.ts +4 -5
- package/src/I18n/I18n.ts +1 -6
- package/src/Platform/types.ts +20 -11
- package/src/Platform/version.ts +1 -1
- package/src/Reachability/Reachability.ts +22 -2
- package/src/ServiceWorker/ServiceWorker.ts +20 -17
- package/src/ServiceWorker/index.ts +0 -12
- package/src/Signer/Signer.ts +3 -2
- package/src/awsClients/cognitoIdentity/base.ts +4 -1
- package/src/awsClients/pinpoint/base.ts +2 -1
- package/src/awsClients/pinpoint/getInAppMessages.ts +2 -1
- package/src/awsClients/pinpoint/putEvents.ts +2 -1
- package/src/awsClients/pinpoint/updateEndpoint.ts +2 -1
- package/src/clients/middleware/signing/signer/signatureV4/index.ts +0 -2
- package/src/clients/middleware/signing/signer/signatureV4/presignUrl.ts +2 -1
- package/src/errors/errorHelpers.ts +20 -0
- package/src/errors/index.ts +1 -0
- package/src/index.ts +8 -4
- package/src/libraryUtils.ts +17 -11
- package/src/parseAWSExports.ts +28 -9
- package/src/providers/pinpoint/apis/flushEvents.ts +2 -2
- package/src/providers/pinpoint/apis/record.ts +14 -28
- package/src/providers/pinpoint/apis/updateEndpoint.ts +6 -6
- package/src/providers/pinpoint/index.ts +6 -2
- 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 +3 -2
- package/src/providers/pinpoint/utils/index.ts +1 -0
- package/src/providers/pinpoint/utils/resolveEndpointId.ts +46 -0
- package/src/singleton/Amplify.ts +10 -8
- package/src/singleton/Auth/types.ts +3 -3
- package/src/singleton/Cache/types.ts +27 -0
- package/src/singleton/Interactions/types.ts +29 -0
- package/src/singleton/Notifications/PushNotification/types.ts +6 -0
- package/src/singleton/Notifications/types.ts +3 -1
- package/src/singleton/types.ts +3 -5
- package/src/storage/CookieStorage.ts +5 -9
- package/src/storage/DefaultStorage.ts +2 -2
- package/src/storage/utils.ts +1 -1
- package/src/types/errors.ts +1 -0
- package/src/utils/amplifyUrl/index.ts +9 -0
- package/src/{clients/middleware/signing/signer/signatureV4/polyfills/index.native.ts → utils/amplifyUrl/polyfill.native.ts} +1 -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/deepFreeze.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/index.ts +2 -0
- 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/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 -456
- package/lib/Cache/InMemoryCache.d.ts +0 -129
- package/lib/Cache/InMemoryCache.js +0 -342
- package/lib/Cache/Utils/CacheUtils.d.ts +0 -25
- package/lib/Cache/Utils/CacheUtils.js +0 -86
- 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-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 -453
- package/lib-esm/Cache/InMemoryCache.d.ts +0 -129
- package/lib-esm/Cache/InMemoryCache.js +0 -339
- package/lib-esm/Cache/Utils/CacheUtils.d.ts +0 -25
- package/lib-esm/Cache/Utils/CacheUtils.js +0 -79
- 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/src/Amplify.ts +0 -106
- package/src/Cache/AsyncStorageCache.ts +0 -495
- package/src/Cache/BrowserStorageCache.ts +0 -504
- package/src/Cache/CHANGELOG.md +0 -1239
- package/src/Cache/InMemoryCache.ts +0 -347
- package/src/Cache/Utils/CacheUtils.ts +0 -90
- 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/lib/Cache/types/{Cache.js → cache.js} +0 -0
- package/lib/{clients/middleware/signing/signer/signatureV4/polyfills/index.native.js → utils/amplifyUrl/polyfill.native.js} +1 -1
- /package/lib-esm/Cache/types/{Cache.js → cache.js} +0 -0
- /package/lib-esm/{clients/middleware/signing/signer/signatureV4/polyfills/index.d.ts → utils/amplifyUrl/polyfill.d.ts} +0 -0
- /package/lib-esm/{clients/middleware/signing/signer/signatureV4/polyfills/index.js → utils/amplifyUrl/polyfill.js} +0 -0
- /package/lib-esm/{clients/middleware/signing/signer/signatureV4/polyfills/index.native.d.ts → utils/amplifyUrl/polyfill.native.d.ts} +0 -0
- /package/lib-esm/{clients/middleware/signing/signer/signatureV4/polyfills/index.native.js → utils/amplifyUrl/polyfill.native.js} +0 -0
- /package/{lib/clients/middleware/signing/signer/signatureV4/polyfills/index.d.ts → lib-esm/utils/amplifyUuid/polyfill.d.ts} +0 -0
- /package/{lib/clients/middleware/signing/signer/signatureV4/polyfills/index.js → lib-esm/utils/amplifyUuid/polyfill.js} +0 -0
- /package/{lib/clients/middleware/signing/signer/signatureV4/polyfills/index.native.d.ts → lib-esm/utils/amplifyUuid/polyfill.native.d.ts} +0 -0
- /package/src/{clients/middleware/signing/signer/signatureV4/polyfills/index.ts → utils/amplifyUrl/polyfill.ts} +0 -0
|
@@ -1,118 +1,113 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
3
|
+
var __extends = (this && this.__extends) || (function () {
|
|
4
|
+
var extendStatics = function (d, b) {
|
|
5
|
+
extendStatics = Object.setPrototypeOf ||
|
|
6
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
7
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
8
|
+
return extendStatics(d, b);
|
|
9
|
+
};
|
|
10
|
+
return function (d, b) {
|
|
11
|
+
if (typeof b !== "function" && b !== null)
|
|
12
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
13
|
+
extendStatics(d, b);
|
|
14
|
+
function __() { this.constructor = d; }
|
|
15
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
16
|
+
};
|
|
17
|
+
})();
|
|
18
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
19
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
20
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
21
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
22
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
23
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
24
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
28
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
29
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
30
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
31
|
+
function step(op) {
|
|
32
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
33
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
34
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
35
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
36
|
+
switch (op[0]) {
|
|
37
|
+
case 0: case 1: t = op; break;
|
|
38
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
39
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
40
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
41
|
+
default:
|
|
42
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
43
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
44
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
45
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
46
|
+
if (t[2]) _.ops.pop();
|
|
47
|
+
_.trys.pop(); continue;
|
|
48
|
+
}
|
|
49
|
+
op = body.call(thisArg, _);
|
|
50
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
51
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
52
|
+
}
|
|
53
|
+
};
|
|
4
54
|
import { ConsoleLogger as Logger } from '../Logger';
|
|
5
|
-
|
|
55
|
+
import { KeyValueStorage } from '../storage/KeyValueStorage';
|
|
56
|
+
import { getLocalStorageWithFallback } from '../storage/utils';
|
|
57
|
+
import { defaultConfig } from './constants';
|
|
58
|
+
import { StorageCacheCommon } from './StorageCacheCommon';
|
|
59
|
+
import { getCurrentSizeKey, getCurrentTime } from './utils';
|
|
60
|
+
var logger = new Logger('Cache');
|
|
6
61
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
62
|
+
* Customized storage based on the SessionStorage or LocalStorage with LRU implemented
|
|
9
63
|
*/
|
|
10
|
-
var StorageCache = /** @class */ (function () {
|
|
64
|
+
var StorageCache = /** @class */ (function (_super) {
|
|
65
|
+
__extends(StorageCache, _super);
|
|
11
66
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* @param config - Custom configuration for this instance.
|
|
67
|
+
* initialize the cache
|
|
68
|
+
* @param config - the configuration of the cache
|
|
15
69
|
*/
|
|
16
70
|
function StorageCache(config) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
71
|
+
var _this = this;
|
|
72
|
+
var storage = getLocalStorageWithFallback();
|
|
73
|
+
_this = _super.call(this, { config: config, keyValueStorage: new KeyValueStorage(storage) }) || this;
|
|
74
|
+
_this.storage = storage;
|
|
75
|
+
_this.getItem = _this.getItem.bind(_this);
|
|
76
|
+
_this.setItem = _this.setItem.bind(_this);
|
|
77
|
+
_this.removeItem = _this.removeItem.bind(_this);
|
|
78
|
+
return _this;
|
|
22
79
|
}
|
|
23
|
-
StorageCache.prototype.
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
// Set 5MB limit
|
|
43
|
-
var cacheLimit = 5 * 1024 * 1024;
|
|
44
|
-
if (this.cacheConfig.capacityInBytes > cacheLimit) {
|
|
45
|
-
logger.error('Cache Capacity should be less than 5MB. Setting back to default. Setting back to default.');
|
|
46
|
-
tempInstanceConfig.capacityInBytes = defaultConfig.capacityInBytes;
|
|
47
|
-
}
|
|
48
|
-
// Apply sanitized values to the instance config
|
|
49
|
-
if (Object.keys(tempInstanceConfig).length > 0) {
|
|
50
|
-
this.instanceConfig = tempInstanceConfig;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* produce a JSON object with meta-data and data value
|
|
55
|
-
* @param value - the value of the item
|
|
56
|
-
* @param options - optional, the specified meta-data
|
|
57
|
-
*
|
|
58
|
-
* @return - the item which has the meta-data and the value
|
|
59
|
-
*/
|
|
60
|
-
StorageCache.prototype.fillCacheItem = function (key, value, options) {
|
|
61
|
-
var _a, _b;
|
|
62
|
-
var ret = {
|
|
63
|
-
key: key,
|
|
64
|
-
data: value,
|
|
65
|
-
timestamp: getCurrTime(),
|
|
66
|
-
visitedTime: getCurrTime(),
|
|
67
|
-
priority: (_a = options.priority) !== null && _a !== void 0 ? _a : 0,
|
|
68
|
-
expires: (_b = options.expires) !== null && _b !== void 0 ? _b : 0,
|
|
69
|
-
type: typeof value,
|
|
70
|
-
byteSize: 0,
|
|
71
|
-
};
|
|
72
|
-
ret.byteSize = getByteLength(JSON.stringify(ret));
|
|
73
|
-
// for accurate size
|
|
74
|
-
ret.byteSize = getByteLength(JSON.stringify(ret));
|
|
75
|
-
return ret;
|
|
80
|
+
StorageCache.prototype.getAllCacheKeys = function (options) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
+
var omitSizeKey, keys, i, key;
|
|
83
|
+
return __generator(this, function (_a) {
|
|
84
|
+
omitSizeKey = (options !== null && options !== void 0 ? options : {}).omitSizeKey;
|
|
85
|
+
keys = [];
|
|
86
|
+
for (i = 0; i < this.storage.length; i++) {
|
|
87
|
+
key = this.storage.key(i);
|
|
88
|
+
if (omitSizeKey && key === getCurrentSizeKey(this.config.keyPrefix)) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (key === null || key === void 0 ? void 0 : key.startsWith(this.config.keyPrefix)) {
|
|
92
|
+
keys.push(key.substring(this.config.keyPrefix.length));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return [2 /*return*/, keys];
|
|
96
|
+
});
|
|
97
|
+
});
|
|
76
98
|
};
|
|
77
99
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* @
|
|
81
|
-
*
|
|
82
|
-
* @return - the current configuration
|
|
100
|
+
* Return a new instance of cache with customized configuration.
|
|
101
|
+
* @param {Object} config - the customized configuration
|
|
102
|
+
* @return {Object} - the new instance of Cache
|
|
83
103
|
*/
|
|
84
|
-
StorageCache.prototype.
|
|
85
|
-
if (config) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
this.instanceConfig = this.instanceConfig
|
|
90
|
-
? Object.assign({}, this.instanceConfig, config)
|
|
91
|
-
: config;
|
|
104
|
+
StorageCache.prototype.createInstance = function (config) {
|
|
105
|
+
if (!config.keyPrefix || config.keyPrefix === defaultConfig.keyPrefix) {
|
|
106
|
+
logger.error('invalid keyPrefix, setting keyPrefix with timeStamp');
|
|
107
|
+
config.keyPrefix = getCurrentTime.toString();
|
|
92
108
|
}
|
|
93
|
-
|
|
94
|
-
return this.cacheConfig;
|
|
109
|
+
return new StorageCache(config);
|
|
95
110
|
};
|
|
96
|
-
Object.defineProperty(StorageCache.prototype, "cacheConfig", {
|
|
97
|
-
/**
|
|
98
|
-
* Returns an appropriate configuration for the Cache instance. Will apply any custom configuration for this
|
|
99
|
-
* instance on top of the global configuration. Default configuration will be applied in all cases.
|
|
100
|
-
*
|
|
101
|
-
* @internal
|
|
102
|
-
*/
|
|
103
|
-
get: function () {
|
|
104
|
-
// const globalCacheConfig = Amplify.getConfig().Cache || {};
|
|
105
|
-
var globalCacheConfig = {};
|
|
106
|
-
if (this.instanceConfig) {
|
|
107
|
-
return Object.assign({}, defaultConfig, globalCacheConfig, this.instanceConfig);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
return Object.assign({}, defaultConfig, globalCacheConfig);
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
enumerable: false,
|
|
114
|
-
configurable: true
|
|
115
|
-
});
|
|
116
111
|
return StorageCache;
|
|
117
|
-
}());
|
|
112
|
+
}(StorageCacheCommon));
|
|
118
113
|
export { StorageCache };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { StorageCacheCommon } from './StorageCacheCommon';
|
|
2
|
+
import { Cache, CacheConfig } from './types';
|
|
3
|
+
export declare class StorageCache extends StorageCacheCommon implements Cache {
|
|
4
|
+
/**
|
|
5
|
+
* initialize the cache
|
|
6
|
+
* @param config - the configuration of the cache
|
|
7
|
+
*/
|
|
8
|
+
constructor(config?: CacheConfig);
|
|
9
|
+
protected getAllCacheKeys(options?: {
|
|
10
|
+
omitSizeKey?: boolean;
|
|
11
|
+
}): Promise<string[]>;
|
|
12
|
+
protected getAllStorageKeys(): Promise<readonly string[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Return a new instance of cache with customized configuration.
|
|
15
|
+
* @param {Object} config - the customized configuration
|
|
16
|
+
* @return {Object} - the new instance of Cache
|
|
17
|
+
*/
|
|
18
|
+
createInstance(config: CacheConfig): Cache;
|
|
19
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
var __extends = (this && this.__extends) || (function () {
|
|
4
|
+
var extendStatics = function (d, b) {
|
|
5
|
+
extendStatics = Object.setPrototypeOf ||
|
|
6
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
7
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
8
|
+
return extendStatics(d, b);
|
|
9
|
+
};
|
|
10
|
+
return function (d, b) {
|
|
11
|
+
if (typeof b !== "function" && b !== null)
|
|
12
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
13
|
+
extendStatics(d, b);
|
|
14
|
+
function __() { this.constructor = d; }
|
|
15
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
16
|
+
};
|
|
17
|
+
})();
|
|
18
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
19
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
20
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
21
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
22
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
23
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
24
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
28
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
29
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
30
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
31
|
+
function step(op) {
|
|
32
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
33
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
34
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
35
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
36
|
+
switch (op[0]) {
|
|
37
|
+
case 0: case 1: t = op; break;
|
|
38
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
39
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
40
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
41
|
+
default:
|
|
42
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
43
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
44
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
45
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
46
|
+
if (t[2]) _.ops.pop();
|
|
47
|
+
_.trys.pop(); continue;
|
|
48
|
+
}
|
|
49
|
+
op = body.call(thisArg, _);
|
|
50
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
51
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var __values = (this && this.__values) || function(o) {
|
|
55
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
56
|
+
if (m) return m.call(o);
|
|
57
|
+
if (o && typeof o.length === "number") return {
|
|
58
|
+
next: function () {
|
|
59
|
+
if (o && i >= o.length) o = void 0;
|
|
60
|
+
return { value: o && o[i++], done: !o };
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
64
|
+
};
|
|
65
|
+
import { loadAsyncStorage } from '@aws-amplify/react-native';
|
|
66
|
+
import { ConsoleLogger as Logger } from '../Logger';
|
|
67
|
+
import { defaultConfig } from './constants';
|
|
68
|
+
import { StorageCacheCommon } from './StorageCacheCommon';
|
|
69
|
+
import { getCurrentSizeKey, getCurrentTime } from './utils';
|
|
70
|
+
var logger = new Logger('StorageCache');
|
|
71
|
+
var AsyncStorage = loadAsyncStorage();
|
|
72
|
+
/*
|
|
73
|
+
* Customized cache which based on the AsyncStorage with LRU implemented
|
|
74
|
+
*/
|
|
75
|
+
var StorageCache = /** @class */ (function (_super) {
|
|
76
|
+
__extends(StorageCache, _super);
|
|
77
|
+
/**
|
|
78
|
+
* initialize the cache
|
|
79
|
+
* @param config - the configuration of the cache
|
|
80
|
+
*/
|
|
81
|
+
function StorageCache(config) {
|
|
82
|
+
var _this = _super.call(this, { config: config, keyValueStorage: AsyncStorage }) || this;
|
|
83
|
+
_this.getItem = _this.getItem.bind(_this);
|
|
84
|
+
_this.setItem = _this.setItem.bind(_this);
|
|
85
|
+
_this.removeItem = _this.removeItem.bind(_this);
|
|
86
|
+
return _this;
|
|
87
|
+
}
|
|
88
|
+
StorageCache.prototype.getAllCacheKeys = function (options) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
+
var omitSizeKey, keys, _a, _b, key, e_1_1;
|
|
91
|
+
var e_1, _c;
|
|
92
|
+
return __generator(this, function (_d) {
|
|
93
|
+
switch (_d.label) {
|
|
94
|
+
case 0:
|
|
95
|
+
omitSizeKey = (options !== null && options !== void 0 ? options : {}).omitSizeKey;
|
|
96
|
+
keys = [];
|
|
97
|
+
_d.label = 1;
|
|
98
|
+
case 1:
|
|
99
|
+
_d.trys.push([1, 6, 7, 8]);
|
|
100
|
+
return [4 /*yield*/, AsyncStorage.getAllKeys()];
|
|
101
|
+
case 2:
|
|
102
|
+
_a = __values.apply(void 0, [_d.sent()]), _b = _a.next();
|
|
103
|
+
_d.label = 3;
|
|
104
|
+
case 3:
|
|
105
|
+
if (!!_b.done) return [3 /*break*/, 5];
|
|
106
|
+
key = _b.value;
|
|
107
|
+
if (omitSizeKey && key === getCurrentSizeKey(this.config.keyPrefix)) {
|
|
108
|
+
return [3 /*break*/, 4];
|
|
109
|
+
}
|
|
110
|
+
if (key === null || key === void 0 ? void 0 : key.startsWith(this.config.keyPrefix)) {
|
|
111
|
+
keys.push(key.substring(this.config.keyPrefix.length));
|
|
112
|
+
}
|
|
113
|
+
_d.label = 4;
|
|
114
|
+
case 4:
|
|
115
|
+
_b = _a.next();
|
|
116
|
+
return [3 /*break*/, 3];
|
|
117
|
+
case 5: return [3 /*break*/, 8];
|
|
118
|
+
case 6:
|
|
119
|
+
e_1_1 = _d.sent();
|
|
120
|
+
e_1 = { error: e_1_1 };
|
|
121
|
+
return [3 /*break*/, 8];
|
|
122
|
+
case 7:
|
|
123
|
+
try {
|
|
124
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
125
|
+
}
|
|
126
|
+
finally { if (e_1) throw e_1.error; }
|
|
127
|
+
return [7 /*endfinally*/];
|
|
128
|
+
case 8: return [2 /*return*/, keys];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
StorageCache.prototype.getAllStorageKeys = function () {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
135
|
+
return __generator(this, function (_a) {
|
|
136
|
+
try {
|
|
137
|
+
return [2 /*return*/, AsyncStorage.getAllKeys()];
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
logger.warn("getAllKeys failed! ".concat(e));
|
|
141
|
+
return [2 /*return*/, []];
|
|
142
|
+
}
|
|
143
|
+
return [2 /*return*/];
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Return a new instance of cache with customized configuration.
|
|
149
|
+
* @param {Object} config - the customized configuration
|
|
150
|
+
* @return {Object} - the new instance of Cache
|
|
151
|
+
*/
|
|
152
|
+
StorageCache.prototype.createInstance = function (config) {
|
|
153
|
+
if (!config.keyPrefix || config.keyPrefix === defaultConfig.keyPrefix) {
|
|
154
|
+
logger.error('invalid keyPrefix, setting keyPrefix with timeStamp');
|
|
155
|
+
config.keyPrefix = getCurrentTime.toString();
|
|
156
|
+
}
|
|
157
|
+
return new StorageCache(config);
|
|
158
|
+
};
|
|
159
|
+
return StorageCache;
|
|
160
|
+
}(StorageCacheCommon));
|
|
161
|
+
export { StorageCache };
|
|
@@ -1,89 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CacheConfig, CacheItem, CacheItemOptions
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { KeyValueStorageInterface } from '../types';
|
|
2
|
+
import { CacheConfig, CacheItem, CacheItemOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Initialization of the cache
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class StorageCacheCommon {
|
|
8
|
+
protected config: CacheConfig;
|
|
9
|
+
protected keyValueStorage: KeyValueStorageInterface;
|
|
10
|
+
/**
|
|
11
|
+
* Initialize the cache
|
|
7
12
|
*
|
|
8
|
-
* @param
|
|
9
|
-
*/
|
|
10
|
-
constructor(config
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
* @param amount - the amount of the cache szie which need to be increased
|
|
21
|
-
*/
|
|
22
|
-
_increaseCurSizeInBytes(amount: number): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* update the visited time if item has been visited
|
|
25
|
-
* @private
|
|
26
|
-
* @param item - the item which need to be refreshed
|
|
27
|
-
* @param prefixedKey - the key of the item
|
|
13
|
+
* @param config - Custom configuration for this instance.
|
|
14
|
+
*/
|
|
15
|
+
constructor({ config, keyValueStorage, }: {
|
|
16
|
+
config?: CacheConfig;
|
|
17
|
+
keyValueStorage: KeyValueStorageInterface;
|
|
18
|
+
});
|
|
19
|
+
protected abstract getAllCacheKeys(options?: {
|
|
20
|
+
omitSizeKey?: boolean;
|
|
21
|
+
}): Promise<string[]>;
|
|
22
|
+
getModuleName(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Set custom configuration for the cache instance.
|
|
28
25
|
*
|
|
29
|
-
* @
|
|
30
|
-
*/
|
|
31
|
-
_refreshItem(item: CacheItem, prefixedKey: string): Promise<CacheItem>;
|
|
32
|
-
/**
|
|
33
|
-
* check wether item is expired
|
|
34
|
-
* @private
|
|
35
|
-
* @param key - the key of the item
|
|
26
|
+
* @param config - customized configuration (without keyPrefix, which can't be changed)
|
|
36
27
|
*
|
|
37
|
-
* @return
|
|
38
|
-
*/
|
|
39
|
-
_isExpired(key: string): Promise<boolean>;
|
|
40
|
-
/**
|
|
41
|
-
* delete item from cache
|
|
42
|
-
* @private
|
|
43
|
-
* @param prefixedKey - the key of the item
|
|
44
|
-
* @param size - optional, the byte size of the item
|
|
45
|
-
*/
|
|
46
|
-
_removeItem(prefixedKey: string, size?: number): Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* put item into cache
|
|
49
|
-
* @private
|
|
50
|
-
* @param prefixedKey - the key of the item
|
|
51
|
-
* @param itemData - the value of the item
|
|
52
|
-
* @param itemSizeInBytes - the byte size of the item
|
|
28
|
+
* @return - the current configuration
|
|
53
29
|
*/
|
|
54
|
-
|
|
30
|
+
configure(config?: Omit<CacheConfig, 'keyPrefix'>): CacheConfig;
|
|
55
31
|
/**
|
|
56
|
-
*
|
|
57
|
-
* @
|
|
58
|
-
* @param itemSize
|
|
59
|
-
*
|
|
60
|
-
* @return total space needed
|
|
61
|
-
*/
|
|
62
|
-
_sizeToPop(itemSize: number): Promise<number>;
|
|
63
|
-
/**
|
|
64
|
-
* see whether cache is full
|
|
65
|
-
* @private
|
|
66
|
-
* @param itemSize
|
|
67
|
-
*
|
|
68
|
-
* @return true if cache is full
|
|
69
|
-
*/
|
|
70
|
-
_isCacheFull(itemSize: number): Promise<boolean>;
|
|
71
|
-
/**
|
|
72
|
-
* scan the storage and find out all the keys owned by this cache
|
|
73
|
-
* also clean the expired keys while scanning
|
|
74
|
-
* @private
|
|
75
|
-
* @return array of keys
|
|
76
|
-
*/
|
|
77
|
-
_findValidKeys(): Promise<string[]>;
|
|
78
|
-
/**
|
|
79
|
-
* get all the items we have, sort them by their priority,
|
|
80
|
-
* if priority is same, sort them by their last visited time
|
|
81
|
-
* pop out items from the low priority (5 is the lowest)
|
|
82
|
-
* @private
|
|
83
|
-
* @param keys - all the keys in this cache
|
|
84
|
-
* @param sizeToPop - the total size of the items which needed to be poped out
|
|
32
|
+
* return the current size of the cache
|
|
33
|
+
* @return {Promise}
|
|
85
34
|
*/
|
|
86
|
-
|
|
35
|
+
getCurrentCacheSize(): Promise<number>;
|
|
87
36
|
/**
|
|
88
37
|
* Set item into cache. You can put number, string, boolean or object.
|
|
89
38
|
* The cache will first check whether has the same key.
|
|
@@ -99,9 +48,10 @@ export declare class AsyncStorageCache extends StorageCache implements ICache {
|
|
|
99
48
|
* @param {String} key - the key of the item
|
|
100
49
|
* @param {Object} value - the value of the item
|
|
101
50
|
* @param {Object} [options] - optional, the specified meta-data
|
|
51
|
+
*
|
|
102
52
|
* @return {Promise}
|
|
103
53
|
*/
|
|
104
|
-
setItem(key: string, value: any, options
|
|
54
|
+
setItem(key: string, value: any, options?: Record<string, any>): Promise<void>;
|
|
105
55
|
/**
|
|
106
56
|
* Get item from cache. It will return null if item doesn’t exist or it has been expired.
|
|
107
57
|
* If you specified callback function in the options,
|
|
@@ -114,9 +64,10 @@ export declare class AsyncStorageCache extends StorageCache implements ICache {
|
|
|
114
64
|
*
|
|
115
65
|
* @param {String} key - the key of the item
|
|
116
66
|
* @param {Object} [options] - the options of callback function
|
|
67
|
+
*
|
|
117
68
|
* @return {Promise} - return a promise resolves to be the value of the item
|
|
118
69
|
*/
|
|
119
|
-
getItem(key: string, options
|
|
70
|
+
getItem(key: string, options?: CacheItemOptions): Promise<CacheItem['data']>;
|
|
120
71
|
/**
|
|
121
72
|
* remove item from the cache
|
|
122
73
|
* The cache will abort output a warning:
|
|
@@ -126,29 +77,103 @@ export declare class AsyncStorageCache extends StorageCache implements ICache {
|
|
|
126
77
|
*/
|
|
127
78
|
removeItem(key: string): Promise<void>;
|
|
128
79
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
80
|
+
* Return all the keys owned by this cache.
|
|
81
|
+
* Will return an empty array if error occurred.
|
|
82
|
+
*
|
|
132
83
|
* @return {Promise}
|
|
133
84
|
*/
|
|
134
|
-
|
|
85
|
+
getAllKeys(): Promise<string[]>;
|
|
86
|
+
protected getStorage(): KeyValueStorageInterface;
|
|
135
87
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
88
|
+
* check whether item is expired
|
|
89
|
+
*
|
|
90
|
+
* @param key - the key of the item
|
|
91
|
+
*
|
|
92
|
+
* @return true if the item is expired.
|
|
138
93
|
*/
|
|
139
|
-
|
|
94
|
+
protected isExpired(key: string): Promise<boolean>;
|
|
140
95
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* @
|
|
96
|
+
* delete item from cache
|
|
97
|
+
*
|
|
98
|
+
* @param prefixedKey - the key of the item
|
|
99
|
+
* @param size - optional, the byte size of the item
|
|
144
100
|
*/
|
|
145
|
-
|
|
101
|
+
protected removeCacheItem(prefixedKey: string, size?: number): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* produce a JSON object with meta-data and data value
|
|
104
|
+
* @param value - the value of the item
|
|
105
|
+
* @param options - optional, the specified meta-data
|
|
106
|
+
*
|
|
107
|
+
* @return - the item which has the meta-data and the value
|
|
108
|
+
*/
|
|
109
|
+
protected fillCacheItem(key: string, value: object | number | string | boolean, options: CacheItemOptions): CacheItem;
|
|
110
|
+
private sanitizeConfig;
|
|
111
|
+
/**
|
|
112
|
+
* increase current size of the cache
|
|
113
|
+
*
|
|
114
|
+
* @param amount - the amount of the cache szie which need to be increased
|
|
115
|
+
*/
|
|
116
|
+
private increaseCurrentSizeInBytes;
|
|
117
|
+
/**
|
|
118
|
+
* decrease current size of the cache
|
|
119
|
+
*
|
|
120
|
+
* @param amount - the amount of the cache size which needs to be decreased
|
|
121
|
+
*/
|
|
122
|
+
private decreaseCurrentSizeInBytes;
|
|
123
|
+
/**
|
|
124
|
+
* update the visited time if item has been visited
|
|
125
|
+
*
|
|
126
|
+
* @param item - the item which need to be updated
|
|
127
|
+
* @param prefixedKey - the key of the item
|
|
128
|
+
*
|
|
129
|
+
* @return the updated item
|
|
130
|
+
*/
|
|
131
|
+
private updateVisitedTime;
|
|
132
|
+
/**
|
|
133
|
+
* put item into cache
|
|
134
|
+
*
|
|
135
|
+
* @param prefixedKey - the key of the item
|
|
136
|
+
* @param itemData - the value of the item
|
|
137
|
+
* @param itemSizeInBytes - the byte size of the item
|
|
138
|
+
*/
|
|
139
|
+
private setCacheItem;
|
|
146
140
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* @
|
|
141
|
+
* total space needed when poping out items
|
|
142
|
+
*
|
|
143
|
+
* @param itemSize
|
|
144
|
+
*
|
|
145
|
+
* @return total space needed
|
|
146
|
+
*/
|
|
147
|
+
private sizeToPop;
|
|
148
|
+
/**
|
|
149
|
+
* see whether cache is full
|
|
150
|
+
*
|
|
151
|
+
* @param itemSize
|
|
152
|
+
*
|
|
153
|
+
* @return true if cache is full
|
|
150
154
|
*/
|
|
151
|
-
|
|
155
|
+
private isCacheFull;
|
|
156
|
+
/**
|
|
157
|
+
* get all the items we have, sort them by their priority,
|
|
158
|
+
* if priority is same, sort them by their last visited time
|
|
159
|
+
* pop out items from the low priority (5 is the lowest)
|
|
160
|
+
* @private
|
|
161
|
+
* @param keys - all the keys in this cache
|
|
162
|
+
* @param sizeToPop - the total size of the items which needed to be poped out
|
|
163
|
+
*/
|
|
164
|
+
private popOutItems;
|
|
165
|
+
/**
|
|
166
|
+
* Scan the storage and combine the following operations for efficiency
|
|
167
|
+
* 1. Clear out all expired keys owned by this cache, not including the size key.
|
|
168
|
+
* 2. Return the remaining keys.
|
|
169
|
+
*
|
|
170
|
+
* @return The remaining valid keys
|
|
171
|
+
*/
|
|
172
|
+
private clearInvalidAndGetRemainingKeys;
|
|
173
|
+
/**
|
|
174
|
+
* clear the entire cache
|
|
175
|
+
* The cache will abort and output a warning if error occurs
|
|
176
|
+
* @return {Promise}
|
|
177
|
+
*/
|
|
178
|
+
clear(): Promise<void>;
|
|
152
179
|
}
|
|
153
|
-
declare const instance: ICache;
|
|
154
|
-
export { AsyncStorage, instance as Cache };
|