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