@aws-amplify/core 6.0.1-console-preview.5f040a2.0 → 6.0.1-console-preview.23dc225.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 (260) 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/Cache/{AsyncStorageCache.d.ts → StorageCacheCommon.d.ts} +124 -99
  6. package/lib/Cache/{AsyncStorageCache.js → StorageCacheCommon.js} +497 -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/Hub/index.d.ts +7 -0
  23. package/lib/Hub/index.js +8 -1
  24. package/lib/Platform/customUserAgent.d.ts +16 -0
  25. package/lib/Platform/customUserAgent.js +70 -0
  26. package/lib/Platform/index.js +10 -1
  27. package/lib/Platform/types.d.ts +33 -1
  28. package/lib/Platform/types.js +1 -0
  29. package/lib/Platform/version.d.ts +1 -1
  30. package/lib/Platform/version.js +1 -1
  31. package/lib/Reachability/Reachability.d.ts +1 -0
  32. package/lib/Reachability/Reachability.js +36 -0
  33. package/lib/Signer/Signer.js +3 -2
  34. package/lib/awsClients/cognitoIdentity/base.js +2 -1
  35. package/lib/awsClients/pinpoint/base.js +2 -1
  36. package/lib/awsClients/pinpoint/getInAppMessages.js +2 -1
  37. package/lib/awsClients/pinpoint/putEvents.js +2 -1
  38. package/lib/awsClients/pinpoint/updateEndpoint.js +2 -1
  39. package/lib/clients/middleware/signing/signer/signatureV4/index.d.ts +0 -1
  40. package/lib/clients/middleware/signing/signer/signatureV4/index.js +0 -1
  41. package/lib/clients/middleware/signing/signer/signatureV4/presignUrl.js +2 -1
  42. package/lib/index.d.ts +2 -5
  43. package/lib/index.js +3 -6
  44. package/lib/libraryUtils.d.ts +7 -5
  45. package/lib/libraryUtils.js +11 -6
  46. package/lib/parseAWSExports.js +75 -14
  47. package/lib/providers/pinpoint/apis/flushEvents.d.ts +2 -2
  48. package/lib/providers/pinpoint/apis/record.js +3 -3
  49. package/lib/providers/pinpoint/apis/updateEndpoint.js +6 -6
  50. package/lib/singleton/API/types.d.ts +4 -3
  51. package/lib/singleton/Amplify.d.ts +2 -2
  52. package/lib/singleton/Amplify.js +6 -5
  53. package/lib/singleton/Auth/types.d.ts +28 -1
  54. package/lib/singleton/Cache/types.d.ts +18 -0
  55. package/lib/singleton/Cache/types.js +4 -0
  56. package/lib/singleton/types.d.ts +3 -1
  57. package/lib/storage/DefaultStorage.js +1 -1
  58. package/lib/storage/utils.d.ts +1 -1
  59. package/lib/storage/utils.js +3 -3
  60. package/lib/tsconfig.tsbuildinfo +1 -1
  61. package/lib/utils/amplifyUrl/index.d.ts +13 -0
  62. package/lib/utils/amplifyUrl/index.js +10 -0
  63. package/lib/utils/amplifyUrl/polyfill.d.ts +0 -0
  64. package/lib/utils/amplifyUrl/polyfill.js +4 -0
  65. package/lib/utils/amplifyUrl/polyfill.native.d.ts +1 -0
  66. package/lib/utils/amplifyUuid/index.d.ts +3 -0
  67. package/lib/utils/amplifyUuid/index.js +9 -0
  68. package/lib/utils/amplifyUuid/polyfill.d.ts +0 -0
  69. package/lib/utils/amplifyUuid/polyfill.js +4 -0
  70. package/lib/utils/amplifyUuid/polyfill.native.d.ts +1 -0
  71. package/lib/utils/amplifyUuid/polyfill.native.js +6 -0
  72. package/lib/utils/deepFreeze.d.ts +1 -0
  73. package/lib/utils/deepFreeze.js +38 -0
  74. package/lib/{ClientDevice/android.d.ts → utils/getClientInfo/getClientInfo.android.d.ts} +1 -1
  75. package/lib/{ClientDevice/android.js → utils/getClientInfo/getClientInfo.android.js} +4 -4
  76. package/lib/{ClientDevice/browser.d.ts → utils/getClientInfo/getClientInfo.d.ts} +1 -9
  77. package/lib/{ClientDevice/ios.d.ts → utils/getClientInfo/getClientInfo.ios.d.ts} +1 -1
  78. package/lib/{ClientDevice/ios.js → utils/getClientInfo/getClientInfo.ios.js} +4 -4
  79. package/lib/{ClientDevice/browser.js → utils/getClientInfo/getClientInfo.js} +6 -18
  80. package/lib/utils/getClientInfo/index.d.ts +1 -0
  81. package/lib/utils/getClientInfo/index.js +7 -0
  82. package/lib/utils/index.d.ts +2 -0
  83. package/lib/utils/index.js +5 -1
  84. package/lib-esm/Cache/StorageCache.d.ts +14 -31
  85. package/lib-esm/Cache/StorageCache.js +97 -102
  86. package/lib-esm/Cache/StorageCache.native.d.ts +19 -0
  87. package/lib-esm/Cache/StorageCache.native.js +161 -0
  88. package/lib-esm/Cache/{AsyncStorageCache.d.ts → StorageCacheCommon.d.ts} +124 -99
  89. package/lib-esm/Cache/{AsyncStorageCache.js → StorageCacheCommon.js} +496 -430
  90. package/lib-esm/Cache/constants.d.ts +6 -0
  91. package/lib-esm/Cache/constants.js +14 -0
  92. package/lib-esm/Cache/index.d.ts +2 -0
  93. package/lib-esm/Cache/index.js +4 -0
  94. package/lib-esm/Cache/types/cache.d.ts +38 -0
  95. package/lib-esm/Cache/types/index.d.ts +1 -1
  96. package/lib-esm/Cache/types/index.js +1 -1
  97. package/lib-esm/Cache/{Utils → utils}/CacheList.d.ts +1 -1
  98. package/lib-esm/Cache/{Utils → utils}/CacheList.js +1 -1
  99. package/lib-esm/Cache/utils/cacheHelpers.d.ts +14 -0
  100. package/lib-esm/Cache/utils/cacheHelpers.js +44 -0
  101. package/lib-esm/Cache/{Utils → utils}/errorHelpers.d.ts +0 -1
  102. package/lib-esm/Cache/{Utils → utils}/errorHelpers.js +0 -4
  103. package/lib-esm/Cache/utils/index.d.ts +2 -0
  104. package/lib-esm/Cache/utils/index.js +4 -0
  105. package/lib-esm/Hub/index.d.ts +7 -0
  106. package/lib-esm/Hub/index.js +7 -0
  107. package/lib-esm/Platform/customUserAgent.d.ts +16 -0
  108. package/lib-esm/Platform/customUserAgent.js +65 -0
  109. package/lib-esm/Platform/index.js +10 -1
  110. package/lib-esm/Platform/types.d.ts +33 -1
  111. package/lib-esm/Platform/types.js +1 -0
  112. package/lib-esm/Platform/version.d.ts +1 -1
  113. package/lib-esm/Platform/version.js +1 -1
  114. package/lib-esm/Reachability/Reachability.d.ts +1 -0
  115. package/lib-esm/Reachability/Reachability.js +36 -0
  116. package/lib-esm/Signer/Signer.js +3 -2
  117. package/lib-esm/awsClients/cognitoIdentity/base.js +2 -1
  118. package/lib-esm/awsClients/pinpoint/base.js +2 -1
  119. package/lib-esm/awsClients/pinpoint/getInAppMessages.js +2 -1
  120. package/lib-esm/awsClients/pinpoint/putEvents.js +2 -1
  121. package/lib-esm/awsClients/pinpoint/updateEndpoint.js +2 -1
  122. package/lib-esm/clients/middleware/signing/signer/signatureV4/index.d.ts +0 -1
  123. package/lib-esm/clients/middleware/signing/signer/signatureV4/index.js +0 -1
  124. package/lib-esm/clients/middleware/signing/signer/signatureV4/presignUrl.js +2 -1
  125. package/lib-esm/index.d.ts +2 -5
  126. package/lib-esm/index.js +1 -4
  127. package/lib-esm/libraryUtils.d.ts +7 -5
  128. package/lib-esm/libraryUtils.js +5 -3
  129. package/lib-esm/parseAWSExports.js +75 -14
  130. package/lib-esm/providers/pinpoint/apis/flushEvents.d.ts +2 -2
  131. package/lib-esm/providers/pinpoint/apis/record.js +3 -3
  132. package/lib-esm/providers/pinpoint/apis/updateEndpoint.js +6 -6
  133. package/lib-esm/singleton/API/types.d.ts +4 -3
  134. package/lib-esm/singleton/Amplify.d.ts +2 -2
  135. package/lib-esm/singleton/Amplify.js +6 -5
  136. package/lib-esm/singleton/Auth/types.d.ts +28 -1
  137. package/lib-esm/singleton/Cache/types.d.ts +18 -0
  138. package/lib-esm/singleton/Cache/types.js +3 -0
  139. package/lib-esm/singleton/types.d.ts +3 -1
  140. package/lib-esm/storage/DefaultStorage.js +2 -2
  141. package/lib-esm/storage/utils.d.ts +1 -1
  142. package/lib-esm/storage/utils.js +1 -1
  143. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  144. package/lib-esm/utils/amplifyUrl/index.d.ts +13 -0
  145. package/lib-esm/utils/amplifyUrl/index.js +6 -0
  146. package/lib-esm/utils/amplifyUuid/index.d.ts +3 -0
  147. package/lib-esm/utils/amplifyUuid/index.js +6 -0
  148. package/lib-esm/utils/amplifyUuid/polyfill.native.js +4 -0
  149. package/lib-esm/utils/deepFreeze.d.ts +1 -0
  150. package/lib-esm/utils/deepFreeze.js +34 -0
  151. package/lib-esm/{ClientDevice/android.d.ts → utils/getClientInfo/getClientInfo.android.d.ts} +1 -1
  152. package/lib-esm/{ClientDevice/android.js → utils/getClientInfo/getClientInfo.android.js} +2 -2
  153. package/lib-esm/{ClientDevice/browser.d.ts → utils/getClientInfo/getClientInfo.d.ts} +1 -9
  154. package/lib-esm/{ClientDevice/ios.d.ts → utils/getClientInfo/getClientInfo.ios.d.ts} +1 -1
  155. package/lib-esm/{ClientDevice/ios.js → utils/getClientInfo/getClientInfo.ios.js} +2 -2
  156. package/lib-esm/{ClientDevice/browser.js → utils/getClientInfo/getClientInfo.js} +4 -14
  157. package/lib-esm/utils/getClientInfo/index.d.ts +1 -0
  158. package/lib-esm/utils/getClientInfo/index.js +3 -0
  159. package/lib-esm/utils/index.d.ts +2 -0
  160. package/lib-esm/utils/index.js +2 -0
  161. package/package.json +7 -17
  162. package/src/Cache/StorageCache.native.ts +65 -0
  163. package/src/Cache/StorageCache.ts +61 -158
  164. package/src/Cache/StorageCacheCommon.ts +581 -0
  165. package/src/Cache/constants.ts +18 -0
  166. package/src/Cache/index.ts +6 -0
  167. package/src/Cache/types/cache.ts +51 -0
  168. package/src/Cache/types/index.ts +1 -1
  169. package/src/Cache/{Utils → utils}/CacheList.ts +185 -185
  170. package/src/Cache/utils/cacheHelpers.ts +52 -0
  171. package/src/Cache/{Utils → utils}/errorHelpers.ts +0 -4
  172. package/src/Cache/{Utils → utils}/index.ts +4 -5
  173. package/src/Hub/index.ts +8 -0
  174. package/src/Platform/customUserAgent.ts +75 -0
  175. package/src/Platform/index.ts +14 -1
  176. package/src/Platform/types.ts +45 -1
  177. package/src/Platform/version.ts +1 -1
  178. package/src/Reachability/Reachability.ts +14 -0
  179. package/src/Signer/Signer.ts +3 -2
  180. package/src/awsClients/cognitoIdentity/base.ts +4 -1
  181. package/src/awsClients/pinpoint/base.ts +2 -1
  182. package/src/awsClients/pinpoint/getInAppMessages.ts +2 -1
  183. package/src/awsClients/pinpoint/putEvents.ts +2 -1
  184. package/src/awsClients/pinpoint/updateEndpoint.ts +2 -1
  185. package/src/clients/middleware/signing/signer/signatureV4/index.ts +0 -2
  186. package/src/clients/middleware/signing/signer/signatureV4/presignUrl.ts +2 -1
  187. package/src/index.ts +3 -4
  188. package/src/libraryUtils.ts +17 -10
  189. package/src/parseAWSExports.ts +76 -13
  190. package/src/providers/pinpoint/apis/flushEvents.ts +2 -2
  191. package/src/providers/pinpoint/apis/record.ts +3 -3
  192. package/src/providers/pinpoint/apis/updateEndpoint.ts +6 -6
  193. package/src/singleton/API/types.ts +4 -3
  194. package/src/singleton/Amplify.ts +10 -8
  195. package/src/singleton/Auth/types.ts +50 -1
  196. package/src/singleton/Cache/types.ts +27 -0
  197. package/src/singleton/types.ts +3 -1
  198. package/src/storage/DefaultStorage.ts +2 -2
  199. package/src/storage/utils.ts +1 -1
  200. package/src/utils/amplifyUrl/index.ts +9 -0
  201. package/src/{clients/middleware/signing/signer/signatureV4/polyfills/index.native.ts → utils/amplifyUrl/polyfill.native.ts} +1 -0
  202. package/src/utils/amplifyUuid/index.ts +9 -0
  203. package/src/utils/amplifyUuid/polyfill.native.ts +6 -0
  204. package/src/utils/amplifyUuid/polyfill.ts +4 -0
  205. package/src/utils/deepFreeze.ts +16 -0
  206. package/src/{ClientDevice/android.ts → utils/getClientInfo/getClientInfo.android.ts} +2 -2
  207. package/src/{ClientDevice/ios.ts → utils/getClientInfo/getClientInfo.ios.ts} +3 -3
  208. package/src/{ClientDevice/browser.ts → utils/getClientInfo/getClientInfo.ts} +4 -16
  209. package/src/utils/getClientInfo/index.ts +4 -0
  210. package/src/utils/index.ts +2 -0
  211. package/lib/Cache/BrowserStorageCache.d.ts +0 -166
  212. package/lib/Cache/BrowserStorageCache.js +0 -456
  213. package/lib/Cache/InMemoryCache.d.ts +0 -129
  214. package/lib/Cache/InMemoryCache.js +0 -342
  215. package/lib/Cache/Utils/CacheUtils.d.ts +0 -25
  216. package/lib/Cache/Utils/CacheUtils.js +0 -86
  217. package/lib/Cache/Utils/index.d.ts +0 -2
  218. package/lib/Cache/Utils/index.js +0 -16
  219. package/lib/Cache/reactnative.d.ts +0 -3
  220. package/lib/Cache/reactnative.js +0 -8
  221. package/lib/Cache/types/Cache.d.ts +0 -55
  222. package/lib/ClientDevice/index.d.ts +0 -23
  223. package/lib/ClientDevice/index.js +0 -18
  224. package/lib/ClientDevice/reactnative.d.ts +0 -7
  225. package/lib/ClientDevice/reactnative.js +0 -24
  226. package/lib-esm/Cache/BrowserStorageCache.d.ts +0 -166
  227. package/lib-esm/Cache/BrowserStorageCache.js +0 -453
  228. package/lib-esm/Cache/InMemoryCache.d.ts +0 -129
  229. package/lib-esm/Cache/InMemoryCache.js +0 -339
  230. package/lib-esm/Cache/Utils/CacheUtils.d.ts +0 -25
  231. package/lib-esm/Cache/Utils/CacheUtils.js +0 -79
  232. package/lib-esm/Cache/Utils/index.d.ts +0 -2
  233. package/lib-esm/Cache/Utils/index.js +0 -4
  234. package/lib-esm/Cache/reactnative.d.ts +0 -3
  235. package/lib-esm/Cache/reactnative.js +0 -6
  236. package/lib-esm/Cache/types/Cache.d.ts +0 -55
  237. package/lib-esm/ClientDevice/index.d.ts +0 -23
  238. package/lib-esm/ClientDevice/index.js +0 -15
  239. package/lib-esm/ClientDevice/reactnative.d.ts +0 -7
  240. package/lib-esm/ClientDevice/reactnative.js +0 -21
  241. package/src/Cache/AsyncStorageCache.ts +0 -495
  242. package/src/Cache/BrowserStorageCache.ts +0 -504
  243. package/src/Cache/CHANGELOG.md +0 -1239
  244. package/src/Cache/InMemoryCache.ts +0 -347
  245. package/src/Cache/Utils/CacheUtils.ts +0 -90
  246. package/src/Cache/reactnative.ts +0 -9
  247. package/src/Cache/types/Cache.ts +0 -75
  248. package/src/ClientDevice/index.ts +0 -14
  249. package/src/ClientDevice/reactnative.ts +0 -18
  250. package/lib/Cache/types/{Cache.js → cache.js} +0 -0
  251. package/lib/{clients/middleware/signing/signer/signatureV4/polyfills/index.native.js → utils/amplifyUrl/polyfill.native.js} +1 -1
  252. /package/lib-esm/Cache/types/{Cache.js → cache.js} +0 -0
  253. /package/lib-esm/{clients/middleware/signing/signer/signatureV4/polyfills/index.d.ts → utils/amplifyUrl/polyfill.d.ts} +0 -0
  254. /package/lib-esm/{clients/middleware/signing/signer/signatureV4/polyfills/index.js → utils/amplifyUrl/polyfill.js} +0 -0
  255. /package/lib-esm/{clients/middleware/signing/signer/signatureV4/polyfills/index.native.d.ts → utils/amplifyUrl/polyfill.native.d.ts} +0 -0
  256. /package/lib-esm/{clients/middleware/signing/signer/signatureV4/polyfills/index.native.js → utils/amplifyUrl/polyfill.native.js} +0 -0
  257. /package/{lib/clients/middleware/signing/signer/signatureV4/polyfills/index.d.ts → lib-esm/utils/amplifyUuid/polyfill.d.ts} +0 -0
  258. /package/{lib/clients/middleware/signing/signer/signatureV4/polyfills/index.js → lib-esm/utils/amplifyUuid/polyfill.js} +0 -0
  259. /package/{lib/clients/middleware/signing/signer/signatureV4/polyfills/index.native.d.ts → lib-esm/utils/amplifyUuid/polyfill.native.d.ts} +0 -0
  260. /package/src/{clients/middleware/signing/signer/signatureV4/polyfills/index.ts → utils/amplifyUrl/polyfill.ts} +0 -0
@@ -1,129 +0,0 @@
1
- import { StorageCache } from './StorageCache';
2
- import { ICache, CacheConfig, CacheItemOptions } from './types';
3
- /**
4
- * Customized in-memory cache with LRU implemented
5
- * @member cacheObj - object which store items
6
- * @member cacheList - list of keys in the cache with LRU
7
- * @member curSizeInBytes - current size of the cache
8
- * @member maxPriority - max of the priority
9
- */
10
- export declare class InMemoryCacheClass extends StorageCache implements ICache {
11
- private cacheList;
12
- private curSizeInBytes;
13
- private maxPriority;
14
- /**
15
- * initialize the cache
16
- *
17
- * @param config - the configuration of the cache
18
- */
19
- constructor(config?: CacheConfig);
20
- /**
21
- * decrease current size of the cache
22
- *
23
- * @param amount - the amount of the cache size which needs to be decreased
24
- */
25
- private _decreaseCurSizeInBytes;
26
- /**
27
- * increase current size of the cache
28
- *
29
- * @param amount - the amount of the cache szie which need to be increased
30
- */
31
- private _increaseCurSizeInBytes;
32
- /**
33
- * check whether item is expired
34
- *
35
- * @param key - the key of the item
36
- *
37
- * @return true if the item is expired.
38
- */
39
- private _isExpired;
40
- /**
41
- * delete item from cache
42
- *
43
- * @param prefixedKey - the key of the item
44
- * @param listIdx - indicates which cache list the key belongs to
45
- */
46
- private _removeItem;
47
- /**
48
- * put item into cache
49
- *
50
- * @param prefixedKey - the key of the item
51
- * @param itemData - the value of the item
52
- * @param itemSizeInBytes - the byte size of the item
53
- * @param listIdx - indicates which cache list the key belongs to
54
- */
55
- private _setItem;
56
- /**
57
- * see whether cache is full
58
- *
59
- * @param itemSize
60
- *
61
- * @return true if cache is full
62
- */
63
- private _isCacheFull;
64
- /**
65
- * check whether the cache contains the key
66
- *
67
- * @param key
68
- */
69
- private containsKey;
70
- /**
71
- * * Set item into cache. You can put number, string, boolean or object.
72
- * The cache will first check whether has the same key.
73
- * If it has, it will delete the old item and then put the new item in
74
- * The cache will pop out items if it is full
75
- * You can specify the cache item options. The cache will abort and output a warning:
76
- * If the key is invalid
77
- * If the size of the item exceeds itemMaxSize.
78
- * If the value is undefined
79
- * If incorrect cache item configuration
80
- * If error happened with browser storage
81
- *
82
- * @param key - the key of the item
83
- * @param value - the value of the item
84
- * @param options - optional, the specified meta-data
85
- *
86
- * @throws if the item is too big which exceeds the limit of single item size
87
- * @throws if the key is invalid
88
- */
89
- setItem(key: string, value: object | string | number | boolean, options?: CacheItemOptions): void;
90
- /**
91
- * Get item from cache. It will return null if item doesn’t exist or it has been expired.
92
- * If you specified callback function in the options,
93
- * then the function will be executed if no such item in the cache
94
- * and finally put the return value into cache.
95
- * Please make sure the callback function will return the value you want to put into the cache.
96
- * The cache will abort output a warning:
97
- * If the key is invalid
98
- *
99
- * @param key - the key of the item
100
- * @param options - the options of callback function
101
- */
102
- getItem(key: string, options?: CacheItemOptions): any;
103
- /**
104
- * remove item from the cache
105
- *
106
- * @param key - the key of the item
107
- */
108
- removeItem(key: string): void;
109
- /**
110
- * clear the entire cache
111
- */
112
- clear(): void;
113
- /**
114
- * Return all the keys in the cache.
115
- */
116
- getAllKeys(): string[];
117
- /**
118
- * return the current size of the cache
119
- *
120
- * @return the current size of the cache
121
- */
122
- getCacheCurSize(): number;
123
- /**
124
- * Return a new instance of cache with customized configuration.
125
- * @param config - the customized configuration
126
- */
127
- createInstance(config: CacheConfig): ICache;
128
- }
129
- export declare const InMemoryCache: ICache;
@@ -1,339 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- var __extends = (this && this.__extends) || (function () {
4
- var extendStatics = function (d, b) {
5
- extendStatics = Object.setPrototypeOf ||
6
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
- return extendStatics(d, b);
9
- };
10
- return function (d, b) {
11
- if (typeof b !== "function" && b !== null)
12
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
- extendStatics(d, b);
14
- function __() { this.constructor = d; }
15
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
- };
17
- })();
18
- var __values = (this && this.__values) || function(o) {
19
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
20
- if (m) return m.call(o);
21
- if (o && typeof o.length === "number") return {
22
- next: function () {
23
- if (o && i >= o.length) o = void 0;
24
- return { value: o && o[i++], done: !o };
25
- }
26
- };
27
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
28
- };
29
- import { CacheList, getCurrTime, CacheObject } from './Utils';
30
- import { StorageCache } from './StorageCache';
31
- import { ConsoleLogger as Logger } from '../Logger';
32
- import { getCurrSizeKey } from './Utils/CacheUtils';
33
- import { assert, CacheErrorCode } from './Utils/errorHelpers';
34
- var logger = new Logger('InMemoryCache');
35
- /**
36
- * Customized in-memory cache with LRU implemented
37
- * @member cacheObj - object which store items
38
- * @member cacheList - list of keys in the cache with LRU
39
- * @member curSizeInBytes - current size of the cache
40
- * @member maxPriority - max of the priority
41
- */
42
- var InMemoryCacheClass = /** @class */ (function (_super) {
43
- __extends(InMemoryCacheClass, _super);
44
- /**
45
- * initialize the cache
46
- *
47
- * @param config - the configuration of the cache
48
- */
49
- function InMemoryCacheClass(config) {
50
- var _this = _super.call(this, config) || this;
51
- _this.cacheList = [];
52
- _this.curSizeInBytes = 0;
53
- _this.maxPriority = 5;
54
- _this.getItem = _this.getItem.bind(_this);
55
- _this.setItem = _this.setItem.bind(_this);
56
- _this.removeItem = _this.removeItem.bind(_this);
57
- // initialize list for every priority
58
- for (var i = 0; i < _this.maxPriority; i += 1) {
59
- _this.cacheList[i] = new CacheList();
60
- }
61
- return _this;
62
- }
63
- /**
64
- * decrease current size of the cache
65
- *
66
- * @param amount - the amount of the cache size which needs to be decreased
67
- */
68
- InMemoryCacheClass.prototype._decreaseCurSizeInBytes = function (amount) {
69
- this.curSizeInBytes -= amount;
70
- };
71
- /**
72
- * increase current size of the cache
73
- *
74
- * @param amount - the amount of the cache szie which need to be increased
75
- */
76
- InMemoryCacheClass.prototype._increaseCurSizeInBytes = function (amount) {
77
- this.curSizeInBytes += amount;
78
- };
79
- /**
80
- * check whether item is expired
81
- *
82
- * @param key - the key of the item
83
- *
84
- * @return true if the item is expired.
85
- */
86
- InMemoryCacheClass.prototype._isExpired = function (key) {
87
- var text = CacheObject.getItem(key);
88
- assert(text !== null, CacheErrorCode.NoCacheItem, "Key: ".concat(key));
89
- var item = JSON.parse(text);
90
- if (getCurrTime() >= item.expires) {
91
- return true;
92
- }
93
- return false;
94
- };
95
- /**
96
- * delete item from cache
97
- *
98
- * @param prefixedKey - the key of the item
99
- * @param listIdx - indicates which cache list the key belongs to
100
- */
101
- InMemoryCacheClass.prototype._removeItem = function (prefixedKey, listIdx) {
102
- // delete the key from the list
103
- this.cacheList[listIdx].removeItem(prefixedKey);
104
- // decrease the current size of the cache
105
- var item = CacheObject.getItem(prefixedKey);
106
- assert(item !== null, CacheErrorCode.NoCacheItem, "Key: ".concat(prefixedKey));
107
- this._decreaseCurSizeInBytes(JSON.parse(item).byteSize);
108
- // finally remove the item from memory
109
- CacheObject.removeItem(prefixedKey);
110
- };
111
- /**
112
- * put item into cache
113
- *
114
- * @param prefixedKey - the key of the item
115
- * @param itemData - the value of the item
116
- * @param itemSizeInBytes - the byte size of the item
117
- * @param listIdx - indicates which cache list the key belongs to
118
- */
119
- InMemoryCacheClass.prototype._setItem = function (prefixedKey, item, listIdx) {
120
- // insert the key into the list
121
- this.cacheList[listIdx].insertItem(prefixedKey);
122
- // increase the current size of the cache
123
- this._increaseCurSizeInBytes(item.byteSize);
124
- // finally add the item into memory
125
- CacheObject.setItem(prefixedKey, JSON.stringify(item));
126
- };
127
- /**
128
- * see whether cache is full
129
- *
130
- * @param itemSize
131
- *
132
- * @return true if cache is full
133
- */
134
- InMemoryCacheClass.prototype._isCacheFull = function (itemSize) {
135
- return this.curSizeInBytes + itemSize > this.cacheConfig.capacityInBytes;
136
- };
137
- /**
138
- * check whether the cache contains the key
139
- *
140
- * @param key
141
- */
142
- InMemoryCacheClass.prototype.containsKey = function (key) {
143
- var prefixedKey = this.cacheConfig.keyPrefix + key;
144
- for (var i = 0; i < this.maxPriority; i += 1) {
145
- if (this.cacheList[i].containsKey(prefixedKey)) {
146
- return i + 1;
147
- }
148
- }
149
- return -1;
150
- };
151
- /**
152
- * * Set item into cache. You can put number, string, boolean or object.
153
- * The cache will first check whether has the same key.
154
- * If it has, it will delete the old item and then put the new item in
155
- * The cache will pop out items if it is full
156
- * You can specify the cache item options. The cache will abort and output a warning:
157
- * If the key is invalid
158
- * If the size of the item exceeds itemMaxSize.
159
- * If the value is undefined
160
- * If incorrect cache item configuration
161
- * If error happened with browser storage
162
- *
163
- * @param key - the key of the item
164
- * @param value - the value of the item
165
- * @param options - optional, the specified meta-data
166
- *
167
- * @throws if the item is too big which exceeds the limit of single item size
168
- * @throws if the key is invalid
169
- */
170
- InMemoryCacheClass.prototype.setItem = function (key, value, options) {
171
- var prefixedKey = this.cacheConfig.keyPrefix + key;
172
- // invalid keys
173
- if (prefixedKey === this.cacheConfig.keyPrefix ||
174
- prefixedKey === getCurrSizeKey(this.cacheConfig.keyPrefix)) {
175
- logger.warn("Invalid key: should not be empty or 'CurSize'");
176
- return;
177
- }
178
- if (typeof value === 'undefined') {
179
- logger.warn("The value of item should not be undefined!");
180
- return;
181
- }
182
- var cacheItemOptions = {
183
- priority: options && options.priority !== undefined
184
- ? options.priority
185
- : this.cacheConfig.defaultPriority,
186
- expires: options && options.expires !== undefined
187
- ? options.expires
188
- : this.cacheConfig.defaultTTL + getCurrTime(),
189
- };
190
- if (cacheItemOptions.priority < 1 || cacheItemOptions.priority > 5) {
191
- logger.warn("Invalid parameter: priority due to out or range. It should be within 1 and 5.");
192
- return;
193
- }
194
- var item = this.fillCacheItem(prefixedKey, value, cacheItemOptions);
195
- // check wether this item is too big;
196
- if (item.byteSize > this.cacheConfig.itemMaxSize) {
197
- logger.warn("Item with key: ".concat(key, " you are trying to put into is too big!"));
198
- return;
199
- }
200
- // if key already in the cache, then delete it.
201
- var presentKeyPrio = this.containsKey(key);
202
- if (presentKeyPrio !== -1) {
203
- this._removeItem(prefixedKey, presentKeyPrio - 1);
204
- }
205
- // pop out items in the cache when cache is full based on LRU
206
- // first start from lowest priority cache list
207
- var cacheListIdx = this.maxPriority - 1;
208
- while (this._isCacheFull(item.byteSize) && cacheListIdx >= 0) {
209
- if (!this.cacheList[cacheListIdx].isEmpty()) {
210
- var popedItemKey = this.cacheList[cacheListIdx].getLastItem();
211
- this._removeItem(popedItemKey, cacheListIdx);
212
- }
213
- else {
214
- cacheListIdx -= 1;
215
- }
216
- }
217
- this._setItem(prefixedKey, item, Number(item.priority) - 1);
218
- };
219
- /**
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
- *
228
- * @param key - the key of the item
229
- * @param options - the options of callback function
230
- */
231
- InMemoryCacheClass.prototype.getItem = function (key, options) {
232
- var _a;
233
- var ret = null;
234
- var prefixedKey = this.cacheConfig.keyPrefix + key;
235
- if (prefixedKey === this.cacheConfig.keyPrefix ||
236
- prefixedKey === getCurrSizeKey(this.cacheConfig.keyPrefix)) {
237
- logger.warn("Invalid key: should not be empty or 'CurSize'");
238
- return null;
239
- }
240
- // check whether it's in the cachelist
241
- var presentKeyPrio = this.containsKey(key);
242
- if (presentKeyPrio !== -1) {
243
- if (this._isExpired(prefixedKey)) {
244
- // if expired, remove that item and return null
245
- this._removeItem(prefixedKey, presentKeyPrio - 1);
246
- }
247
- else {
248
- // if not expired, great, return the value and refresh it
249
- ret = (_a = CacheObject.getItem(prefixedKey)) !== null && _a !== void 0 ? _a : '';
250
- var item = JSON.parse(ret);
251
- this.cacheList[item.priority - 1].refresh(prefixedKey);
252
- return item.data;
253
- }
254
- }
255
- if (options && options.callback !== undefined) {
256
- var val = options.callback();
257
- if (val !== null) {
258
- this.setItem(key, val, options);
259
- }
260
- return val;
261
- }
262
- return null;
263
- };
264
- /**
265
- * remove item from the cache
266
- *
267
- * @param key - the key of the item
268
- */
269
- InMemoryCacheClass.prototype.removeItem = function (key) {
270
- var prefixedKey = this.cacheConfig.keyPrefix + key;
271
- // check if the key is in the cache
272
- var presentKeyPrio = this.containsKey(key);
273
- if (presentKeyPrio !== -1) {
274
- this._removeItem(prefixedKey, presentKeyPrio - 1);
275
- }
276
- };
277
- /**
278
- * clear the entire cache
279
- */
280
- InMemoryCacheClass.prototype.clear = function () {
281
- var e_1, _a;
282
- for (var i = 0; i < this.maxPriority; i += 1) {
283
- try {
284
- for (var _b = (e_1 = void 0, __values(this.cacheList[i].getKeys())), _c = _b.next(); !_c.done; _c = _b.next()) {
285
- var key = _c.value;
286
- this._removeItem(key, i);
287
- }
288
- }
289
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
290
- finally {
291
- try {
292
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
293
- }
294
- finally { if (e_1) throw e_1.error; }
295
- }
296
- }
297
- };
298
- /**
299
- * Return all the keys in the cache.
300
- */
301
- InMemoryCacheClass.prototype.getAllKeys = function () {
302
- var e_2, _a;
303
- var keys = [];
304
- for (var i = 0; i < this.maxPriority; i += 1) {
305
- try {
306
- for (var _b = (e_2 = void 0, __values(this.cacheList[i].getKeys())), _c = _b.next(); !_c.done; _c = _b.next()) {
307
- var key = _c.value;
308
- keys.push(key.substring(this.cacheConfig.keyPrefix.length));
309
- }
310
- }
311
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
312
- finally {
313
- try {
314
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
315
- }
316
- finally { if (e_2) throw e_2.error; }
317
- }
318
- }
319
- return keys;
320
- };
321
- /**
322
- * return the current size of the cache
323
- *
324
- * @return the current size of the cache
325
- */
326
- InMemoryCacheClass.prototype.getCacheCurSize = function () {
327
- return this.curSizeInBytes;
328
- };
329
- /**
330
- * Return a new instance of cache with customized configuration.
331
- * @param config - the customized configuration
332
- */
333
- InMemoryCacheClass.prototype.createInstance = function (config) {
334
- return new InMemoryCacheClass(config);
335
- };
336
- return InMemoryCacheClass;
337
- }(StorageCache));
338
- export { InMemoryCacheClass };
339
- export var InMemoryCache = new InMemoryCacheClass();
@@ -1,25 +0,0 @@
1
- import { CacheConfig } from '../types';
2
- /**
3
- * Default cache config
4
- */
5
- export declare const defaultConfig: CacheConfig;
6
- /**
7
- * return the byte size of the string
8
- * @param str
9
- */
10
- export declare function getByteLength(str: string): number;
11
- /**
12
- * get current time
13
- */
14
- export declare function getCurrTime(): number;
15
- /**
16
- * check if passed value is an integer
17
- */
18
- export declare function isInteger(value?: number): boolean;
19
- export declare class CacheObject {
20
- static clear(): void;
21
- static getItem(key: string): string | null;
22
- static setItem(key: string, value: string): void;
23
- static removeItem(key: string): void;
24
- }
25
- export declare const getCurrSizeKey: (keyPrefix: string) => string;
@@ -1,79 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { getDefaultStorageWithFallback } from '../../storage/utils';
4
- /**
5
- * Default cache config
6
- */
7
- export var defaultConfig = {
8
- keyPrefix: 'aws-amplify-cache',
9
- capacityInBytes: 1048576,
10
- itemMaxSize: 210000,
11
- defaultTTL: 259200000,
12
- defaultPriority: 5,
13
- warningThreshold: 0.8,
14
- storage: getDefaultStorageWithFallback(),
15
- };
16
- /**
17
- * return the byte size of the string
18
- * @param str
19
- */
20
- export function getByteLength(str) {
21
- var ret = 0;
22
- ret = str.length;
23
- for (var i = str.length; i >= 0; i -= 1) {
24
- var charCode = str.charCodeAt(i);
25
- if (charCode > 0x7f && charCode <= 0x7ff) {
26
- ret += 1;
27
- }
28
- else if (charCode > 0x7ff && charCode <= 0xffff) {
29
- ret += 2;
30
- }
31
- // trail surrogate
32
- if (charCode >= 0xdc00 && charCode <= 0xdfff) {
33
- i -= 1;
34
- }
35
- }
36
- return ret;
37
- }
38
- /**
39
- * get current time
40
- */
41
- export function getCurrTime() {
42
- var currTime = new Date();
43
- return currTime.getTime();
44
- }
45
- /**
46
- * check if passed value is an integer
47
- */
48
- export function isInteger(value) {
49
- if (Number.isInteger) {
50
- return Number.isInteger(value);
51
- }
52
- return _isInteger(value);
53
- }
54
- function _isInteger(value) {
55
- return (typeof value === 'number' && isFinite(value) && Math.floor(value) === value);
56
- }
57
- /**
58
- * provide an object as the in-memory cache
59
- */
60
- var store = {};
61
- var CacheObject = /** @class */ (function () {
62
- function CacheObject() {
63
- }
64
- CacheObject.clear = function () {
65
- store = {};
66
- };
67
- CacheObject.getItem = function (key) {
68
- return store[key] || null;
69
- };
70
- CacheObject.setItem = function (key, value) {
71
- store[key] = value;
72
- };
73
- CacheObject.removeItem = function (key) {
74
- delete store[key];
75
- };
76
- return CacheObject;
77
- }());
78
- export { CacheObject };
79
- export var getCurrSizeKey = function (keyPrefix) { return keyPrefix + 'CurSize'; };
@@ -1,2 +0,0 @@
1
- export { CacheObject, defaultConfig, getByteLength, getCurrTime, isInteger, } from './CacheUtils';
2
- export { default as CacheList } from './CacheList';
@@ -1,4 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- export { CacheObject, defaultConfig, getByteLength, getCurrTime, isInteger, } from './CacheUtils';
4
- export { default as CacheList } from './CacheList';
@@ -1,3 +0,0 @@
1
- import { Cache, AsyncStorageCache } from './AsyncStorageCache';
2
- export { AsyncStorageCache };
3
- export { Cache };
@@ -1,6 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { Cache, AsyncStorageCache } from './AsyncStorageCache';
4
- export { AsyncStorageCache };
5
- // Standard `Cache` export to maintain interoperability with React Native
6
- export { Cache };
@@ -1,55 +0,0 @@
1
- /**
2
- * Cache Interface
3
- */
4
- export interface ICache {
5
- /** Put item into cache */
6
- setItem(key: string, value: any, options?: CacheItemOptions): void;
7
- /** Get item from cache */
8
- getItem(key: string, options?: CacheItemOptions): any;
9
- /** Remove item from cache */
10
- removeItem(key: string): void;
11
- /** Remove all items from cache */
12
- clear(): void;
13
- /** Get all keys form cache */
14
- getAllKeys(): string[] | Promise<string[]>;
15
- /** Get current size of the cache */
16
- getCacheCurSize(): number | Promise<number>;
17
- /** create a new instance with customized config */
18
- createInstance(config: CacheConfig): ICache;
19
- /** change current configuration */
20
- configure(config: CacheConfig): CacheConfig;
21
- }
22
- /**
23
- * Cache instance options
24
- */
25
- export interface CacheConfig {
26
- /** Prepend to key to avoid conflicts */
27
- keyPrefix: string;
28
- /** Cache capacity, in bytes */
29
- capacityInBytes: number;
30
- /** Max size of one item */
31
- itemMaxSize: number;
32
- /** Time to live, in milliseconds */
33
- defaultTTL: number;
34
- /** Warn when over threshold percentage of capacity, maximum 1 */
35
- warningThreshold: number;
36
- /** default priority number put on cached items */
37
- defaultPriority: number;
38
- storage?: Storage;
39
- Cache?: Cache;
40
- }
41
- export interface CacheItem {
42
- key: string;
43
- data: any;
44
- timestamp: number;
45
- visitedTime: number;
46
- priority: number;
47
- expires: number;
48
- type: string;
49
- byteSize: number;
50
- }
51
- export interface CacheItemOptions {
52
- priority?: number;
53
- expires?: number;
54
- callback?: Function;
55
- }
@@ -1,23 +0,0 @@
1
- export declare class ClientDevice {
2
- static clientInfo(): {
3
- platform?: undefined;
4
- make?: undefined;
5
- model?: undefined;
6
- version?: undefined;
7
- appVersion?: undefined;
8
- language?: undefined;
9
- timezone?: undefined;
10
- } | {
11
- platform: string;
12
- make: string;
13
- model: string;
14
- version: string;
15
- appVersion: string;
16
- language: string;
17
- timezone: string;
18
- };
19
- static dimension(): {
20
- width: number;
21
- height: number;
22
- };
23
- }
@@ -1,15 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { clientInfo, dimension } from './browser';
4
- var ClientDevice = /** @class */ (function () {
5
- function ClientDevice() {
6
- }
7
- ClientDevice.clientInfo = function () {
8
- return clientInfo();
9
- };
10
- ClientDevice.dimension = function () {
11
- return dimension();
12
- };
13
- return ClientDevice;
14
- }());
15
- export { ClientDevice };