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