@aws-amplify/core 6.12.4-unstable.e5a8569.0 → 6.13.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 (240) hide show
  1. package/dist/cjs/BackgroundProcessManager/BackgroundManagerNotOpenError.js.map +1 -1
  2. package/dist/cjs/BackgroundProcessManager/BackgroundProcessManager.js.map +1 -1
  3. package/dist/cjs/BackgroundProcessManager/index.js.map +1 -1
  4. package/dist/cjs/Cache/StorageCache.js.map +1 -1
  5. package/dist/cjs/Cache/StorageCache.native.js.map +1 -1
  6. package/dist/cjs/Cache/StorageCacheCommon.js.map +1 -1
  7. package/dist/cjs/Cache/utils/CacheList.js.map +1 -1
  8. package/dist/cjs/Cache/utils/cacheHelpers.js.map +1 -1
  9. package/dist/cjs/Cache/utils/index.js.map +1 -1
  10. package/dist/cjs/Hub/index.js.map +1 -1
  11. package/dist/cjs/I18n/I18n.js.map +1 -1
  12. package/dist/cjs/I18n/index.js.map +1 -1
  13. package/dist/cjs/I18n/types.js.map +1 -1
  14. package/dist/cjs/Logger/ConsoleLogger.js.map +1 -1
  15. package/dist/cjs/Logger/index.js.map +1 -1
  16. package/dist/cjs/Mutex/Mutex.js.map +1 -1
  17. package/dist/cjs/Mutex/index.js.map +1 -1
  18. package/dist/cjs/Platform/customUserAgent.js.map +1 -1
  19. package/dist/cjs/Platform/detectFramework.js.map +1 -1
  20. package/dist/cjs/Platform/detection/React.js.map +1 -1
  21. package/dist/cjs/Platform/index.js.map +1 -1
  22. package/dist/cjs/Platform/version.js +1 -1
  23. package/dist/cjs/Platform/version.js.map +1 -1
  24. package/dist/cjs/Reachability/Reachability.js.map +1 -1
  25. package/dist/cjs/Reachability/Reachability.native.js.map +1 -1
  26. package/dist/cjs/Reachability/index.js.map +1 -1
  27. package/dist/cjs/ServiceWorker/ServiceWorker.js.map +1 -1
  28. package/dist/cjs/ServiceWorker/index.js.map +1 -1
  29. package/dist/cjs/Signer/DateUtils.js.map +1 -1
  30. package/dist/cjs/Signer/Signer.js.map +1 -1
  31. package/dist/cjs/Signer/index.js.map +1 -1
  32. package/dist/cjs/adapterCore/error/AmplifyServerContextError.js.map +1 -1
  33. package/dist/cjs/adapterCore/error/index.js.map +1 -1
  34. package/dist/cjs/adapterCore/index.js.map +1 -1
  35. package/dist/cjs/adapterCore/serverContext/index.js.map +1 -1
  36. package/dist/cjs/adapterCore/serverContext/serverContext.js.map +1 -1
  37. package/dist/cjs/adapterCore/serverContext/serverContextRegistry.js.map +1 -1
  38. package/dist/cjs/awsClients/pinpoint/base.js.map +1 -1
  39. package/dist/cjs/awsClients/pinpoint/getInAppMessages.js.map +1 -1
  40. package/dist/cjs/awsClients/pinpoint/index.js.map +1 -1
  41. package/dist/cjs/awsClients/pinpoint/putEvents.js.map +1 -1
  42. package/dist/cjs/awsClients/pinpoint/updateEndpoint.js.map +1 -1
  43. package/dist/cjs/clients/endpoints/getDnsSuffix.js.map +1 -1
  44. package/dist/cjs/clients/endpoints/index.js.map +1 -1
  45. package/dist/cjs/clients/handlers/fetch.js +1 -1
  46. package/dist/cjs/clients/handlers/fetch.js.map +1 -1
  47. package/dist/cjs/clients/index.js.map +1 -1
  48. package/dist/cjs/clients/internal/composeServiceApi.js.map +1 -1
  49. package/dist/cjs/clients/internal/composeTransferHandler.js.map +1 -1
  50. package/dist/cjs/clients/internal/index.js.map +1 -1
  51. package/dist/cjs/clients/middleware/retry/amzSdkInvocationIdHeaderMiddleware.js.map +1 -1
  52. package/dist/cjs/clients/middleware/retry/amzSdkRequestHeaderMiddleware.js.map +1 -1
  53. package/dist/cjs/clients/middleware/retry/index.js.map +1 -1
  54. package/dist/cjs/clients/middleware/retry/retryMiddleware.js.map +1 -1
  55. package/dist/cjs/clients/middleware/signing/index.js.map +1 -1
  56. package/dist/cjs/clients/middleware/signing/middleware.js.map +1 -1
  57. package/dist/cjs/clients/middleware/signing/signer/signatureV4/index.js.map +1 -1
  58. package/dist/cjs/clients/middleware/signing/signer/signatureV4/presignUrl.js.map +1 -1
  59. package/dist/cjs/clients/middleware/signing/signer/signatureV4/signRequest.js.map +1 -1
  60. package/dist/cjs/clients/middleware/signing/signer/signatureV4/utils/getCanonicalQueryString.js.map +1 -1
  61. package/dist/cjs/clients/middleware/signing/signer/signatureV4/utils/getHashedPayload.js.map +1 -1
  62. package/dist/cjs/clients/middleware/signing/utils/getUpdatedSystemClockOffset.js.map +1 -1
  63. package/dist/cjs/clients/middleware/userAgent/index.js.map +1 -1
  64. package/dist/cjs/clients/middleware/userAgent/middleware.js.map +1 -1
  65. package/dist/cjs/clients/serde/index.js.map +1 -1
  66. package/dist/cjs/clients/serde/json.js.map +1 -1
  67. package/dist/cjs/clients/utils/memoization.js.map +1 -1
  68. package/dist/cjs/errors/APIError.js.map +1 -1
  69. package/dist/cjs/errors/AmplifyError.js.map +1 -1
  70. package/dist/cjs/errors/PlatformNotSupportedError.js.map +1 -1
  71. package/dist/cjs/errors/createAssertionFunction.js.map +1 -1
  72. package/dist/cjs/errors/index.js.map +1 -1
  73. package/dist/cjs/foundation/factories/middleware/index.js.map +1 -1
  74. package/dist/cjs/foundation/factories/serviceClients/cognitoIdentity/createGetCredentialsForIdentityClient.js.map +1 -1
  75. package/dist/cjs/foundation/factories/serviceClients/cognitoIdentity/createGetIdClient.js.map +1 -1
  76. package/dist/cjs/foundation/factories/serviceClients/cognitoIdentity/handler/index.js.map +1 -1
  77. package/dist/cjs/foundation/factories/serviceClients/cognitoIdentity/index.js.map +1 -1
  78. package/dist/cjs/foundation/factories/serviceClients/cognitoIdentity/serde/index.js.map +1 -1
  79. package/dist/cjs/index.js.map +1 -1
  80. package/dist/cjs/libraryUtils.js.map +1 -1
  81. package/dist/cjs/parseAWSExports.js.map +1 -1
  82. package/dist/cjs/parseAmplifyOutputs.js.map +1 -1
  83. package/dist/cjs/providers/pinpoint/apis/index.js.map +1 -1
  84. package/dist/cjs/providers/pinpoint/apis/record.js.map +1 -1
  85. package/dist/cjs/providers/pinpoint/apis/updateEndpoint.js.map +1 -1
  86. package/dist/cjs/providers/pinpoint/index.js.map +1 -1
  87. package/dist/cjs/providers/pinpoint/types/index.js.map +1 -1
  88. package/dist/cjs/providers/pinpoint/utils/PinpointEventBuffer.js.map +1 -1
  89. package/dist/cjs/providers/pinpoint/utils/createEndpointId.js.map +1 -1
  90. package/dist/cjs/providers/pinpoint/utils/getEventBuffer.js.map +1 -1
  91. package/dist/cjs/providers/pinpoint/utils/index.js.map +1 -1
  92. package/dist/cjs/providers/pinpoint/utils/resolveEndpointId.js.map +1 -1
  93. package/dist/cjs/server.js.map +1 -1
  94. package/dist/cjs/singleton/Amplify.js.map +1 -1
  95. package/dist/cjs/singleton/Auth/index.js +2 -2
  96. package/dist/cjs/singleton/Auth/index.js.map +1 -1
  97. package/dist/cjs/singleton/Auth/utils/index.js.map +1 -1
  98. package/dist/cjs/singleton/apis/fetchAuthSession.js +2 -2
  99. package/dist/cjs/singleton/apis/fetchAuthSession.js.map +1 -1
  100. package/dist/cjs/singleton/index.js.map +1 -1
  101. package/dist/cjs/storage/CookieStorage.js.map +1 -1
  102. package/dist/cjs/storage/DefaultStorage.js.map +1 -1
  103. package/dist/cjs/storage/DefaultStorage.native.js.map +1 -1
  104. package/dist/cjs/storage/InMemoryStorage.js.map +1 -1
  105. package/dist/cjs/storage/KeyValueStorage.js.map +1 -1
  106. package/dist/cjs/storage/SessionStorage.js.map +1 -1
  107. package/dist/cjs/storage/SyncKeyValueStorage.js.map +1 -1
  108. package/dist/cjs/storage/SyncSessionStorage.js.map +1 -1
  109. package/dist/cjs/storage/index.js.map +1 -1
  110. package/dist/cjs/storage/utils.js.map +1 -1
  111. package/dist/cjs/utils/WordArray.js.map +1 -1
  112. package/dist/cjs/utils/convert/base64/base64Decoder.js.map +1 -1
  113. package/dist/cjs/utils/convert/base64/base64Encoder.js.map +1 -1
  114. package/dist/cjs/utils/convert/index.js.map +1 -1
  115. package/dist/cjs/utils/deDupeAsyncFunction.js.map +1 -1
  116. package/dist/cjs/utils/deepFreeze.js.map +1 -1
  117. package/dist/cjs/utils/deviceName/index.js.map +1 -1
  118. package/dist/cjs/utils/generateRandomString.js.map +1 -1
  119. package/dist/cjs/utils/getClientInfo/getClientInfo.ios.js.map +1 -1
  120. package/dist/cjs/utils/getClientInfo/getClientInfo.js.map +1 -1
  121. package/dist/cjs/utils/getClientInfo/index.js.map +1 -1
  122. package/dist/cjs/utils/globalHelpers/index.js.map +1 -1
  123. package/dist/cjs/utils/globalHelpers/index.native.js.map +1 -1
  124. package/dist/cjs/utils/index.js.map +1 -1
  125. package/dist/cjs/utils/isWebWorker.js.map +1 -1
  126. package/dist/cjs/utils/parseAmplifyConfig.js.map +1 -1
  127. package/dist/cjs/utils/queuedStorage/createQueuedStorage.js.map +1 -1
  128. package/dist/cjs/utils/queuedStorage/createQueuedStorage.native.js.map +1 -1
  129. package/dist/cjs/utils/queuedStorage/index.js.map +1 -1
  130. package/dist/cjs/utils/retry/NonRetryableError.js.map +1 -1
  131. package/dist/cjs/utils/retry/index.js.map +1 -1
  132. package/dist/cjs/utils/retry/jitteredBackoff.js.map +1 -1
  133. package/dist/cjs/utils/retry/retry.js.map +1 -1
  134. package/dist/cjs/utils/sessionListener/SessionListener.js.map +1 -1
  135. package/dist/cjs/utils/sessionListener/SessionListener.native.js.map +1 -1
  136. package/dist/cjs/utils/sessionListener/index.js.map +1 -1
  137. package/dist/esm/BackgroundProcessManager/BackgroundManagerNotOpenError.mjs.map +1 -1
  138. package/dist/esm/BackgroundProcessManager/BackgroundProcessManager.mjs.map +1 -1
  139. package/dist/esm/Cache/StorageCache.mjs.map +1 -1
  140. package/dist/esm/Cache/StorageCache.native.mjs.map +1 -1
  141. package/dist/esm/Cache/StorageCacheCommon.mjs.map +1 -1
  142. package/dist/esm/Cache/utils/CacheList.mjs.map +1 -1
  143. package/dist/esm/Cache/utils/cacheHelpers.mjs.map +1 -1
  144. package/dist/esm/Hub/index.mjs.map +1 -1
  145. package/dist/esm/I18n/I18n.mjs.map +1 -1
  146. package/dist/esm/I18n/index.mjs.map +1 -1
  147. package/dist/esm/I18n/types.mjs.map +1 -1
  148. package/dist/esm/Logger/ConsoleLogger.mjs.map +1 -1
  149. package/dist/esm/Mutex/Mutex.mjs.map +1 -1
  150. package/dist/esm/Platform/customUserAgent.mjs.map +1 -1
  151. package/dist/esm/Platform/detectFramework.mjs.map +1 -1
  152. package/dist/esm/Platform/detection/React.mjs.map +1 -1
  153. package/dist/esm/Platform/index.mjs.map +1 -1
  154. package/dist/esm/Platform/version.d.ts +1 -1
  155. package/dist/esm/Platform/version.mjs +1 -1
  156. package/dist/esm/Platform/version.mjs.map +1 -1
  157. package/dist/esm/Reachability/Reachability.mjs.map +1 -1
  158. package/dist/esm/Reachability/Reachability.native.mjs.map +1 -1
  159. package/dist/esm/ServiceWorker/ServiceWorker.mjs.map +1 -1
  160. package/dist/esm/Signer/DateUtils.mjs.map +1 -1
  161. package/dist/esm/Signer/Signer.mjs.map +1 -1
  162. package/dist/esm/adapterCore/error/AmplifyServerContextError.mjs.map +1 -1
  163. package/dist/esm/adapterCore/serverContext/serverContext.mjs.map +1 -1
  164. package/dist/esm/adapterCore/serverContext/serverContextRegistry.mjs.map +1 -1
  165. package/dist/esm/awsClients/pinpoint/base.mjs.map +1 -1
  166. package/dist/esm/awsClients/pinpoint/getInAppMessages.mjs.map +1 -1
  167. package/dist/esm/awsClients/pinpoint/putEvents.mjs.map +1 -1
  168. package/dist/esm/awsClients/pinpoint/updateEndpoint.mjs.map +1 -1
  169. package/dist/esm/clients/endpoints/getDnsSuffix.mjs.map +1 -1
  170. package/dist/esm/clients/handlers/fetch.mjs +1 -1
  171. package/dist/esm/clients/handlers/fetch.mjs.map +1 -1
  172. package/dist/esm/clients/internal/composeServiceApi.mjs.map +1 -1
  173. package/dist/esm/clients/internal/composeTransferHandler.mjs.map +1 -1
  174. package/dist/esm/clients/middleware/retry/amzSdkInvocationIdHeaderMiddleware.mjs.map +1 -1
  175. package/dist/esm/clients/middleware/retry/amzSdkRequestHeaderMiddleware.mjs.map +1 -1
  176. package/dist/esm/clients/middleware/retry/retryMiddleware.mjs.map +1 -1
  177. package/dist/esm/clients/middleware/signing/middleware.mjs.map +1 -1
  178. package/dist/esm/clients/middleware/signing/signer/signatureV4/presignUrl.mjs.map +1 -1
  179. package/dist/esm/clients/middleware/signing/signer/signatureV4/signRequest.mjs.map +1 -1
  180. package/dist/esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalQueryString.mjs.map +1 -1
  181. package/dist/esm/clients/middleware/signing/signer/signatureV4/utils/getHashedPayload.mjs.map +1 -1
  182. package/dist/esm/clients/middleware/signing/utils/getUpdatedSystemClockOffset.mjs.map +1 -1
  183. package/dist/esm/clients/middleware/userAgent/middleware.mjs.map +1 -1
  184. package/dist/esm/clients/serde/json.mjs.map +1 -1
  185. package/dist/esm/clients/utils/memoization.mjs.map +1 -1
  186. package/dist/esm/errors/APIError.mjs.map +1 -1
  187. package/dist/esm/errors/AmplifyError.mjs.map +1 -1
  188. package/dist/esm/errors/PlatformNotSupportedError.mjs.map +1 -1
  189. package/dist/esm/errors/createAssertionFunction.mjs.map +1 -1
  190. package/dist/esm/foundation/factories/serviceClients/cognitoIdentity/createGetCredentialsForIdentityClient.mjs.map +1 -1
  191. package/dist/esm/foundation/factories/serviceClients/cognitoIdentity/createGetIdClient.mjs.map +1 -1
  192. package/dist/esm/parseAWSExports.mjs.map +1 -1
  193. package/dist/esm/parseAmplifyOutputs.mjs.map +1 -1
  194. package/dist/esm/providers/pinpoint/apis/record.mjs.map +1 -1
  195. package/dist/esm/providers/pinpoint/apis/updateEndpoint.mjs.map +1 -1
  196. package/dist/esm/providers/pinpoint/utils/PinpointEventBuffer.mjs.map +1 -1
  197. package/dist/esm/providers/pinpoint/utils/createEndpointId.mjs.map +1 -1
  198. package/dist/esm/providers/pinpoint/utils/getEventBuffer.mjs.map +1 -1
  199. package/dist/esm/providers/pinpoint/utils/resolveEndpointId.mjs.map +1 -1
  200. package/dist/esm/singleton/Amplify.mjs.map +1 -1
  201. package/dist/esm/singleton/Auth/index.d.ts +2 -2
  202. package/dist/esm/singleton/Auth/index.mjs +2 -2
  203. package/dist/esm/singleton/Auth/index.mjs.map +1 -1
  204. package/dist/esm/singleton/Auth/utils/index.mjs.map +1 -1
  205. package/dist/esm/singleton/apis/fetchAuthSession.d.ts +2 -2
  206. package/dist/esm/singleton/apis/fetchAuthSession.mjs +2 -2
  207. package/dist/esm/singleton/apis/fetchAuthSession.mjs.map +1 -1
  208. package/dist/esm/storage/CookieStorage.mjs.map +1 -1
  209. package/dist/esm/storage/DefaultStorage.mjs.map +1 -1
  210. package/dist/esm/storage/DefaultStorage.native.mjs.map +1 -1
  211. package/dist/esm/storage/InMemoryStorage.mjs.map +1 -1
  212. package/dist/esm/storage/KeyValueStorage.mjs.map +1 -1
  213. package/dist/esm/storage/SessionStorage.mjs.map +1 -1
  214. package/dist/esm/storage/SyncKeyValueStorage.mjs.map +1 -1
  215. package/dist/esm/storage/SyncSessionStorage.mjs.map +1 -1
  216. package/dist/esm/storage/utils.mjs.map +1 -1
  217. package/dist/esm/utils/WordArray.mjs.map +1 -1
  218. package/dist/esm/utils/convert/base64/base64Decoder.mjs.map +1 -1
  219. package/dist/esm/utils/convert/base64/base64Encoder.mjs.map +1 -1
  220. package/dist/esm/utils/deDupeAsyncFunction.mjs.map +1 -1
  221. package/dist/esm/utils/deepFreeze.mjs.map +1 -1
  222. package/dist/esm/utils/generateRandomString.mjs.map +1 -1
  223. package/dist/esm/utils/getClientInfo/getClientInfo.ios.mjs.map +1 -1
  224. package/dist/esm/utils/getClientInfo/getClientInfo.mjs.map +1 -1
  225. package/dist/esm/utils/globalHelpers/index.mjs.map +1 -1
  226. package/dist/esm/utils/globalHelpers/index.native.mjs.map +1 -1
  227. package/dist/esm/utils/isWebWorker.mjs.map +1 -1
  228. package/dist/esm/utils/parseAmplifyConfig.mjs.map +1 -1
  229. package/dist/esm/utils/queuedStorage/createQueuedStorage.mjs.map +1 -1
  230. package/dist/esm/utils/queuedStorage/createQueuedStorage.native.mjs.map +1 -1
  231. package/dist/esm/utils/retry/NonRetryableError.mjs.map +1 -1
  232. package/dist/esm/utils/retry/jitteredBackoff.mjs.map +1 -1
  233. package/dist/esm/utils/retry/retry.mjs.map +1 -1
  234. package/dist/esm/utils/sessionListener/SessionListener.mjs.map +1 -1
  235. package/dist/esm/utils/sessionListener/SessionListener.native.mjs.map +1 -1
  236. package/package.json +3 -3
  237. package/src/Platform/version.ts +1 -1
  238. package/src/clients/handlers/fetch.ts +1 -1
  239. package/src/singleton/Auth/index.ts +2 -2
  240. package/src/singleton/apis/fetchAuthSession.ts +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"BackgroundManagerNotOpenError.js","sources":["../../../src/BackgroundProcessManager/BackgroundManagerNotOpenError.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.BackgroundManagerNotOpenError = void 0;\nclass BackgroundManagerNotOpenError extends Error {\n constructor(message) {\n super(`BackgroundManagerNotOpenError: ${message}`);\n }\n}\nexports.BackgroundManagerNotOpenError = BackgroundManagerNotOpenError;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,6BAA6B,GAAG,MAAM;AAC9C,MAAM,6BAA6B,SAAS,KAAK,CAAC;AAClD,IAAI,WAAW,CAAC,OAAO,EAAE;AACzB,QAAQ,KAAK,CAAC,CAAC,+BAA+B,EAAE,OAAO,CAAC,CAAC,CAAC;AAC1D;AACA;AACA,OAAO,CAAC,6BAA6B,GAAG,6BAA6B;;"}
1
+ {"version":3,"file":"BackgroundManagerNotOpenError.js","sources":["../../../src/BackgroundProcessManager/BackgroundManagerNotOpenError.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.BackgroundManagerNotOpenError = void 0;\nclass BackgroundManagerNotOpenError extends Error {\n constructor(message) {\n super(`BackgroundManagerNotOpenError: ${message}`);\n }\n}\nexports.BackgroundManagerNotOpenError = BackgroundManagerNotOpenError;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,6BAA6B,GAAG,MAAM;AAC9C,MAAM,6BAA6B,SAAS,KAAK,CAAC;AAClD,IAAI,WAAW,CAAC,OAAO,EAAE;AACzB,QAAQ,KAAK,CAAC,CAAC,+BAA+B,EAAE,OAAO,CAAC,CAAC,CAAC;AAC1D,IAAI;AACJ;AACA,OAAO,CAAC,6BAA6B,GAAG,6BAA6B;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"BackgroundProcessManager.js","sources":["../../../src/BackgroundProcessManager/BackgroundProcessManager.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.BackgroundProcessManager = void 0;\nconst BackgroundManagerNotOpenError_1 = require(\"./BackgroundManagerNotOpenError\");\nconst types_1 = require(\"./types\");\n/**\n * @private For internal Amplify use.\n *\n * Creates a new scope for promises, observables, and other types of work or\n * processes that may be running in the background. This manager provides\n * an singular entrypoint to request termination and await completion.\n *\n * As work completes on its own prior to close, the manager removes them\n * from the registry to avoid holding references to completed jobs.\n */\nclass BackgroundProcessManager {\n constructor() {\n /**\n * A string indicating whether the manager is accepting new work (\"Open\"),\n * waiting for work to complete (\"Closing\"), or fully done with all\n * submitted work and *not* accepting new jobs (\"Closed\").\n */\n this._state = types_1.BackgroundProcessManagerState.Open;\n /**\n * The list of outstanding jobs we'll need to wait for upon `close()`\n */\n this.jobs = new Set();\n }\n add(jobOrDescription, optionalDescription) {\n let job;\n let description;\n if (typeof jobOrDescription === 'string') {\n job = undefined;\n description = jobOrDescription;\n }\n else {\n job = jobOrDescription;\n description = optionalDescription;\n }\n const error = this.closedFailure(description);\n if (error)\n return error;\n if (job === undefined) {\n return this.addHook(description);\n }\n else if (typeof job === 'function') {\n return this.addFunction(job, description);\n }\n else if (job instanceof BackgroundProcessManager) {\n this.addManager(job, description);\n }\n else {\n throw new Error('If `job` is provided, it must be an Observable, Function, or BackgroundProcessManager.');\n }\n }\n /**\n * Adds a **cleaner** function that doesn't immediately get executed.\n * Instead, the caller gets a **terminate** function back. The *cleaner* is\n * invoked only once the mananger *closes* or the returned **terminate**\n * function is called.\n *\n * @param clean The cleanup function.\n * @param description Optional description to help identify pending jobs.\n * @returns A terminate function.\n */\n addCleaner(clean, description) {\n const { resolve, onTerminate } = this.addHook(description);\n const proxy = async () => {\n await clean();\n resolve();\n };\n onTerminate.then(proxy);\n return proxy;\n }\n addFunction(job, description) {\n // the function we call when we want to try to terminate this job.\n let terminate;\n // the promise the job can opt into listening to for termination.\n const onTerminate = new Promise(resolve => {\n terminate = resolve;\n });\n // finally! start the job.\n const jobResult = job(onTerminate);\n // depending on what the job gives back, register the result\n // so we can monitor for completion.\n if (typeof jobResult?.then === 'function') {\n this.registerPromise(jobResult, terminate, description);\n }\n // At the end of the day, or you know, method call, it doesn't matter\n // what the return value is at all; we just pass it through to the\n // caller.\n return jobResult;\n }\n addManager(manager, description) {\n this.addCleaner(async () => manager.close(), description);\n }\n /**\n * Creates and registers a fabricated job for processes that need to operate\n * with callbacks/hooks. The returned `resolve` and `reject`\n * functions can be used to signal the job is done successfully or not.\n * The returned `onTerminate` is a promise that will resolve when the\n * manager is requesting the termination of the job.\n *\n * @param description Optional description to help identify pending jobs.\n * @returns `{ resolve, reject, onTerminate }`\n */\n addHook(description) {\n // the resolve/reject functions we'll provide to the caller to signal\n // the state of the job.\n let promiseResolve;\n let promiseReject;\n // the underlying promise we'll use to manage it, pretty much like\n // any other promise.\n const promise = new Promise((resolve, reject) => {\n promiseResolve = resolve;\n promiseReject = reject;\n });\n // the function we call when we want to try to terminate this job.\n let terminate;\n // the promise the job can opt into listening to for termination.\n const onTerminate = new Promise(resolve => {\n terminate = resolve;\n });\n this.registerPromise(promise, terminate, description);\n return {\n resolve: promiseResolve,\n reject: promiseReject,\n onTerminate,\n };\n }\n /**\n * Adds a Promise based job to the list of jobs for monitoring and listens\n * for either a success or failure, upon which the job is considered \"done\"\n * and removed from the registry.\n *\n * @param promise A promise that is on its way to being returned to a\n * caller, which needs to be tracked as a background job.\n * @param terminate The termination function to register, which can be\n * invoked to request the job stop.\n * @param description Optional description to help identify pending jobs.\n */\n registerPromise(promise, terminate, description) {\n const jobEntry = { promise, terminate, description };\n this.jobs.add(jobEntry);\n // in all of my testing, it is safe to multi-subscribe to a promise.\n // so, rather than create another layer of promising, we're just going\n // to hook into the promise we already have, and when it's done\n // (successfully or not), we no longer need to wait for it upon close.\n //\n // sorry this is a bit hand-wavy:\n //\n // i believe we use `.then` and `.catch` instead of `.finally` because\n // `.finally` is invoked in a different order in the sequence, and this\n // breaks assumptions throughout and causes failures.\n promise\n .then(() => {\n this.jobs.delete(jobEntry);\n })\n .catch(() => {\n this.jobs.delete(jobEntry);\n });\n }\n /**\n * The number of jobs being waited on.\n *\n * We don't use this for anything. It's just informational for the caller,\n * and can be used in logging and testing.\n *\n * @returns the number of jobs.\n */\n get length() {\n return this.jobs.size;\n }\n /**\n * The execution state of the manager. One of:\n *\n * 1. \"Open\" -> Accepting new jobs\n * 1. \"Closing\" -> Not accepting new work. Waiting for jobs to complete.\n * 1. \"Closed\" -> Not accepting new work. All submitted jobs are complete.\n */\n get state() {\n return this._state;\n }\n /**\n * The registered `description` of all still-pending jobs.\n *\n * @returns descriptions as an array.\n */\n get pending() {\n return Array.from(this.jobs).map(job => job.description);\n }\n /**\n * Whether the manager is accepting new jobs.\n */\n get isOpen() {\n return this._state === types_1.BackgroundProcessManagerState.Open;\n }\n /**\n * Whether the manager is rejecting new work, but still waiting for\n * submitted work to complete.\n */\n get isClosing() {\n return this._state === types_1.BackgroundProcessManagerState.Closing;\n }\n /**\n * Whether the manager is rejecting work and done waiting for submitted\n * work to complete.\n */\n get isClosed() {\n return this._state === types_1.BackgroundProcessManagerState.Closed;\n }\n closedFailure(description) {\n if (!this.isOpen) {\n return Promise.reject(new BackgroundManagerNotOpenError_1.BackgroundManagerNotOpenError([\n `The manager is ${this.state}.`,\n `You tried to add \"${description}\".`,\n `Pending jobs: [\\n${this.pending\n .map(t => ' ' + t)\n .join(',\\n')}\\n]`,\n ].join('\\n')));\n }\n }\n /**\n * Signals jobs to stop (for those that accept interruptions) and waits\n * for confirmation that jobs have stopped.\n *\n * This immediately puts the manager into a closing state and just begins\n * to reject new work. After all work in the manager is complete, the\n * manager goes into a `Completed` state and `close()` returns.\n *\n * This call is idempotent.\n *\n * If the manager is already closing or closed, `finalCleaup` is not executed.\n *\n * @param onClosed\n * @returns The settled results of each still-running job's promise. If the\n * manager is already closed, this will contain the results as of when the\n * manager's `close()` was called in an `Open` state.\n */\n async close() {\n if (this.isOpen) {\n this._state = types_1.BackgroundProcessManagerState.Closing;\n for (const job of Array.from(this.jobs)) {\n try {\n job.terminate();\n }\n catch (error) {\n // Due to potential races with a job's natural completion, it's\n // reasonable to expect the termination call to fail. Hence,\n // not logging as an error.\n // eslint-disable-next-line no-console\n console.warn(`Failed to send termination signal to job. Error: ${error.message}`, job);\n }\n }\n // Use `allSettled()` because we want to wait for all to finish. We do\n // not want to stop waiting if there is a failure.\n this._closingPromise = Promise.allSettled(Array.from(this.jobs).map(j => j.promise));\n await this._closingPromise;\n this._state = types_1.BackgroundProcessManagerState.Closed;\n }\n return this._closingPromise;\n }\n /**\n * Signals the manager to start accepting work (again) and returns once\n * the manager is ready to do so.\n *\n * If the state is already `Open`, this call is a no-op.\n *\n * If the state is `Closed`, this call simply updates state and returns.\n *\n * If the state is `Closing`, this call waits for completion before it\n * updates the state and returns.\n */\n async open() {\n if (this.isClosing) {\n await this.close();\n }\n this._state = types_1.BackgroundProcessManagerState.Open;\n }\n}\nexports.BackgroundProcessManager = BackgroundProcessManager;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,wBAAwB,GAAG,MAAM;AACzC,MAAM,+BAA+B,GAAG,OAAO,CAAC,iCAAiC,CAAC;AAClF,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,wBAAwB,CAAC;AAC/B,IAAI,WAAW,GAAG;AAClB;AACA;AACA;AACA;AACA;AACA,QAAQ,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,6BAA6B,CAAC,IAAI;AAChE;AACA;AACA;AACA,QAAQ,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,EAAE;AAC7B;AACA,IAAI,GAAG,CAAC,gBAAgB,EAAE,mBAAmB,EAAE;AAC/C,QAAQ,IAAI,GAAG;AACf,QAAQ,IAAI,WAAW;AACvB,QAAQ,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE;AAClD,YAAY,GAAG,GAAG,SAAS;AAC3B,YAAY,WAAW,GAAG,gBAAgB;AAC1C;AACA,aAAa;AACb,YAAY,GAAG,GAAG,gBAAgB;AAClC,YAAY,WAAW,GAAG,mBAAmB;AAC7C;AACA,QAAQ,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC;AACrD,QAAQ,IAAI,KAAK;AACjB,YAAY,OAAO,KAAK;AACxB,QAAQ,IAAI,GAAG,KAAK,SAAS,EAAE;AAC/B,YAAY,OAAO,IAAI,CAAC,OAAO,CA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,GAAG,wBAAwB;;"}
1
+ {"version":3,"file":"BackgroundProcessManager.js","sources":["../../../src/BackgroundProcessManager/BackgroundProcessManager.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.BackgroundProcessManager = void 0;\nconst BackgroundManagerNotOpenError_1 = require(\"./BackgroundManagerNotOpenError\");\nconst types_1 = require(\"./types\");\n/**\n * @private For internal Amplify use.\n *\n * Creates a new scope for promises, observables, and other types of work or\n * processes that may be running in the background. This manager provides\n * an singular entrypoint to request termination and await completion.\n *\n * As work completes on its own prior to close, the manager removes them\n * from the registry to avoid holding references to completed jobs.\n */\nclass BackgroundProcessManager {\n constructor() {\n /**\n * A string indicating whether the manager is accepting new work (\"Open\"),\n * waiting for work to complete (\"Closing\"), or fully done with all\n * submitted work and *not* accepting new jobs (\"Closed\").\n */\n this._state = types_1.BackgroundProcessManagerState.Open;\n /**\n * The list of outstanding jobs we'll need to wait for upon `close()`\n */\n this.jobs = new Set();\n }\n add(jobOrDescription, optionalDescription) {\n let job;\n let description;\n if (typeof jobOrDescription === 'string') {\n job = undefined;\n description = jobOrDescription;\n }\n else {\n job = jobOrDescription;\n description = optionalDescription;\n }\n const error = this.closedFailure(description);\n if (error)\n return error;\n if (job === undefined) {\n return this.addHook(description);\n }\n else if (typeof job === 'function') {\n return this.addFunction(job, description);\n }\n else if (job instanceof BackgroundProcessManager) {\n this.addManager(job, description);\n }\n else {\n throw new Error('If `job` is provided, it must be an Observable, Function, or BackgroundProcessManager.');\n }\n }\n /**\n * Adds a **cleaner** function that doesn't immediately get executed.\n * Instead, the caller gets a **terminate** function back. The *cleaner* is\n * invoked only once the mananger *closes* or the returned **terminate**\n * function is called.\n *\n * @param clean The cleanup function.\n * @param description Optional description to help identify pending jobs.\n * @returns A terminate function.\n */\n addCleaner(clean, description) {\n const { resolve, onTerminate } = this.addHook(description);\n const proxy = async () => {\n await clean();\n resolve();\n };\n onTerminate.then(proxy);\n return proxy;\n }\n addFunction(job, description) {\n // the function we call when we want to try to terminate this job.\n let terminate;\n // the promise the job can opt into listening to for termination.\n const onTerminate = new Promise(resolve => {\n terminate = resolve;\n });\n // finally! start the job.\n const jobResult = job(onTerminate);\n // depending on what the job gives back, register the result\n // so we can monitor for completion.\n if (typeof jobResult?.then === 'function') {\n this.registerPromise(jobResult, terminate, description);\n }\n // At the end of the day, or you know, method call, it doesn't matter\n // what the return value is at all; we just pass it through to the\n // caller.\n return jobResult;\n }\n addManager(manager, description) {\n this.addCleaner(async () => manager.close(), description);\n }\n /**\n * Creates and registers a fabricated job for processes that need to operate\n * with callbacks/hooks. The returned `resolve` and `reject`\n * functions can be used to signal the job is done successfully or not.\n * The returned `onTerminate` is a promise that will resolve when the\n * manager is requesting the termination of the job.\n *\n * @param description Optional description to help identify pending jobs.\n * @returns `{ resolve, reject, onTerminate }`\n */\n addHook(description) {\n // the resolve/reject functions we'll provide to the caller to signal\n // the state of the job.\n let promiseResolve;\n let promiseReject;\n // the underlying promise we'll use to manage it, pretty much like\n // any other promise.\n const promise = new Promise((resolve, reject) => {\n promiseResolve = resolve;\n promiseReject = reject;\n });\n // the function we call when we want to try to terminate this job.\n let terminate;\n // the promise the job can opt into listening to for termination.\n const onTerminate = new Promise(resolve => {\n terminate = resolve;\n });\n this.registerPromise(promise, terminate, description);\n return {\n resolve: promiseResolve,\n reject: promiseReject,\n onTerminate,\n };\n }\n /**\n * Adds a Promise based job to the list of jobs for monitoring and listens\n * for either a success or failure, upon which the job is considered \"done\"\n * and removed from the registry.\n *\n * @param promise A promise that is on its way to being returned to a\n * caller, which needs to be tracked as a background job.\n * @param terminate The termination function to register, which can be\n * invoked to request the job stop.\n * @param description Optional description to help identify pending jobs.\n */\n registerPromise(promise, terminate, description) {\n const jobEntry = { promise, terminate, description };\n this.jobs.add(jobEntry);\n // in all of my testing, it is safe to multi-subscribe to a promise.\n // so, rather than create another layer of promising, we're just going\n // to hook into the promise we already have, and when it's done\n // (successfully or not), we no longer need to wait for it upon close.\n //\n // sorry this is a bit hand-wavy:\n //\n // i believe we use `.then` and `.catch` instead of `.finally` because\n // `.finally` is invoked in a different order in the sequence, and this\n // breaks assumptions throughout and causes failures.\n promise\n .then(() => {\n this.jobs.delete(jobEntry);\n })\n .catch(() => {\n this.jobs.delete(jobEntry);\n });\n }\n /**\n * The number of jobs being waited on.\n *\n * We don't use this for anything. It's just informational for the caller,\n * and can be used in logging and testing.\n *\n * @returns the number of jobs.\n */\n get length() {\n return this.jobs.size;\n }\n /**\n * The execution state of the manager. One of:\n *\n * 1. \"Open\" -> Accepting new jobs\n * 1. \"Closing\" -> Not accepting new work. Waiting for jobs to complete.\n * 1. \"Closed\" -> Not accepting new work. All submitted jobs are complete.\n */\n get state() {\n return this._state;\n }\n /**\n * The registered `description` of all still-pending jobs.\n *\n * @returns descriptions as an array.\n */\n get pending() {\n return Array.from(this.jobs).map(job => job.description);\n }\n /**\n * Whether the manager is accepting new jobs.\n */\n get isOpen() {\n return this._state === types_1.BackgroundProcessManagerState.Open;\n }\n /**\n * Whether the manager is rejecting new work, but still waiting for\n * submitted work to complete.\n */\n get isClosing() {\n return this._state === types_1.BackgroundProcessManagerState.Closing;\n }\n /**\n * Whether the manager is rejecting work and done waiting for submitted\n * work to complete.\n */\n get isClosed() {\n return this._state === types_1.BackgroundProcessManagerState.Closed;\n }\n closedFailure(description) {\n if (!this.isOpen) {\n return Promise.reject(new BackgroundManagerNotOpenError_1.BackgroundManagerNotOpenError([\n `The manager is ${this.state}.`,\n `You tried to add \"${description}\".`,\n `Pending jobs: [\\n${this.pending\n .map(t => ' ' + t)\n .join(',\\n')}\\n]`,\n ].join('\\n')));\n }\n }\n /**\n * Signals jobs to stop (for those that accept interruptions) and waits\n * for confirmation that jobs have stopped.\n *\n * This immediately puts the manager into a closing state and just begins\n * to reject new work. After all work in the manager is complete, the\n * manager goes into a `Completed` state and `close()` returns.\n *\n * This call is idempotent.\n *\n * If the manager is already closing or closed, `finalCleaup` is not executed.\n *\n * @param onClosed\n * @returns The settled results of each still-running job's promise. If the\n * manager is already closed, this will contain the results as of when the\n * manager's `close()` was called in an `Open` state.\n */\n async close() {\n if (this.isOpen) {\n this._state = types_1.BackgroundProcessManagerState.Closing;\n for (const job of Array.from(this.jobs)) {\n try {\n job.terminate();\n }\n catch (error) {\n // Due to potential races with a job's natural completion, it's\n // reasonable to expect the termination call to fail. Hence,\n // not logging as an error.\n // eslint-disable-next-line no-console\n console.warn(`Failed to send termination signal to job. Error: ${error.message}`, job);\n }\n }\n // Use `allSettled()` because we want to wait for all to finish. We do\n // not want to stop waiting if there is a failure.\n this._closingPromise = Promise.allSettled(Array.from(this.jobs).map(j => j.promise));\n await this._closingPromise;\n this._state = types_1.BackgroundProcessManagerState.Closed;\n }\n return this._closingPromise;\n }\n /**\n * Signals the manager to start accepting work (again) and returns once\n * the manager is ready to do so.\n *\n * If the state is already `Open`, this call is a no-op.\n *\n * If the state is `Closed`, this call simply updates state and returns.\n *\n * If the state is `Closing`, this call waits for completion before it\n * updates the state and returns.\n */\n async open() {\n if (this.isClosing) {\n await this.close();\n }\n this._state = types_1.BackgroundProcessManagerState.Open;\n }\n}\nexports.BackgroundProcessManager = BackgroundProcessManager;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,wBAAwB,GAAG,MAAM;AACzC,MAAM,+BAA+B,GAAG,OAAO,CAAC,iCAAiC,CAAC;AAClF,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,wBAAwB,CAAC;AAC/B,IAAI,WAAW,GAAG;AAClB;AACA;AACA;AACA;AACA;AACA,QAAQ,IAAI,CAAC,MAAM,GAAG,OAAO,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B,GAAG,CAAC,SAAS,EAAE;AACnC,gBAAgB;AAChB,gBAAgB,OAAO,KAAK,EAAE;AAC9B;AACA;AACA;AACA;AACA,oBAAoB,OAAO,CAAC,IAAI,CAAC,CAAC,iDAAiD,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC;AAC1G,gBAAgB;AAChB,YAAY;AACZ;AACA;AACA,YAAY,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;AAChG,YAAY,MAAM,IAAI,CAAC,eAAe;AACtC,YAAY,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,6BAA6B,CAAC,MAAM;AACtE,QAAQ;AACR,QAAQ,OAAO,IAAI,CAAC,eAAe;AACnC,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE;AAC5B,YAAY,MAAM,IAAI,CAAC,KAAK,EAAE;AAC9B,QAAQ;AACR,QAAQ,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,6BAA6B,CAAC,IAAI;AAChE,IAAI;AACJ;AACA,OAAO,CAAC,wBAAwB,GAAG,wBAAwB;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/BackgroundProcessManager/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.BackgroundProcessManager = void 0;\nvar BackgroundProcessManager_1 = require(\"./BackgroundProcessManager\");\nObject.defineProperty(exports, \"BackgroundProcessManager\", { enumerable: true, get: function () { return BackgroundProcessManager_1.BackgroundProcessManager; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,wBAAwB,GAAG,MAAM;AACzC,IAAI,0BAA0B,GAAG,OAAO,CAAC,4BAA4B,CAAC;AACtE,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,0BAA0B,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,0BAA0B,CAAC,wBAAwB,CAAC,EAAE,EAAE,CAAC;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/BackgroundProcessManager/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.BackgroundProcessManager = void 0;\nvar BackgroundProcessManager_1 = require(\"./BackgroundProcessManager\");\nObject.defineProperty(exports, \"BackgroundProcessManager\", { enumerable: true, get: function () { return BackgroundProcessManager_1.BackgroundProcessManager; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,wBAAwB,GAAG,MAAM;AACzC,IAAI,0BAA0B,GAAG,OAAO,CAAC,4BAA4B,CAAC;AACtE,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,0BAA0B,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,0BAA0B,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,CAAC;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"StorageCache.js","sources":["../../../src/Cache/StorageCache.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.StorageCache = void 0;\nconst Logger_1 = require(\"../Logger\");\nconst KeyValueStorage_1 = require(\"../storage/KeyValueStorage\");\nconst utils_1 = require(\"../storage/utils\");\nconst constants_1 = require(\"./constants\");\nconst StorageCacheCommon_1 = require(\"./StorageCacheCommon\");\nconst utils_2 = require(\"./utils\");\nconst logger = new Logger_1.ConsoleLogger('StorageCache');\n/**\n * Customized storage based on the SessionStorage or LocalStorage with LRU implemented\n */\nclass StorageCache extends StorageCacheCommon_1.StorageCacheCommon {\n /**\n * initialize the cache\n * @param config - the configuration of the cache\n */\n constructor(config) {\n const storage = (0, utils_1.getLocalStorageWithFallback)();\n super({ config, keyValueStorage: new KeyValueStorage_1.KeyValueStorage(storage) });\n this.storage = storage;\n this.getItem = this.getItem.bind(this);\n this.setItem = this.setItem.bind(this);\n this.removeItem = this.removeItem.bind(this);\n }\n async getAllCacheKeys(options) {\n const { omitSizeKey } = options ?? {};\n const keys = [];\n for (let i = 0; i < this.storage.length; i++) {\n const key = this.storage.key(i);\n if (omitSizeKey && key === (0, utils_2.getCurrentSizeKey)(this.config.keyPrefix)) {\n continue;\n }\n if (key?.startsWith(this.config.keyPrefix)) {\n keys.push(key.substring(this.config.keyPrefix.length));\n }\n }\n return keys;\n }\n /**\n * Return a new instance of cache with customized configuration.\n * @param {Object} config - the customized configuration\n * @return {Object} - the new instance of Cache\n */\n createInstance(config) {\n if (!config.keyPrefix || config.keyPrefix === constants_1.defaultConfig.keyPrefix) {\n logger.error('invalid keyPrefix, setting keyPrefix with timeStamp');\n config.keyPrefix = utils_2.getCurrentTime.toString();\n }\n return new StorageCache(config);\n }\n}\nexports.StorageCache = StorageCache;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,YAAY,GAAG,MAAM;AAC7B,MAAM,QAAQ,G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AAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;AAC3C,YAAY,IAAI,WAAW,IAAI,GAAG,KAAK,IAAI,OAAO,CAAC,iBAAiB,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;AAC9F,gBAAgB;AAChB;AACA,YAAY,IAAI,GAAG,EAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;AACxD,gBAAgB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AACtE;AACA;AACA,QAAQ,OAAO,IAAI;AACnB;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,cAAc,CAAC,MAAM,EAAE;AAC3B,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,KAAK,WAAW,CAAC,aAAa,CAAC,SAAS,EAAE;AAC3F,YAAY,MAAM,CAAC,KAAK,CAAC,qDAAqD,CAAC;AAC/E,YAAY,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE;AAChE;AACA,QAAQ,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC;AACvC;AACA;AACA,OAAO,CAAC,YAAY,GAAG,YAAY;;"}
1
+ {"version":3,"file":"StorageCache.js","sources":["../../../src/Cache/StorageCache.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.StorageCache = void 0;\nconst Logger_1 = require(\"../Logger\");\nconst KeyValueStorage_1 = require(\"../storage/KeyValueStorage\");\nconst utils_1 = require(\"../storage/utils\");\nconst constants_1 = require(\"./constants\");\nconst StorageCacheCommon_1 = require(\"./StorageCacheCommon\");\nconst utils_2 = require(\"./utils\");\nconst logger = new Logger_1.ConsoleLogger('StorageCache');\n/**\n * Customized storage based on the SessionStorage or LocalStorage with LRU implemented\n */\nclass StorageCache extends StorageCacheCommon_1.StorageCacheCommon {\n /**\n * initialize the cache\n * @param config - the configuration of the cache\n */\n constructor(config) {\n const storage = (0, utils_1.getLocalStorageWithFallback)();\n super({ config, keyValueStorage: new KeyValueStorage_1.KeyValueStorage(storage) });\n this.storage = storage;\n this.getItem = this.getItem.bind(this);\n this.setItem = this.setItem.bind(this);\n this.removeItem = this.removeItem.bind(this);\n }\n async getAllCacheKeys(options) {\n const { omitSizeKey } = options ?? {};\n const keys = [];\n for (let i = 0; i < this.storage.length; i++) {\n const key = this.storage.key(i);\n if (omitSizeKey && key === (0, utils_2.getCurrentSizeKey)(this.config.keyPrefix)) {\n continue;\n }\n if (key?.startsWith(this.config.keyPrefix)) {\n keys.push(key.substring(this.config.keyPrefix.length));\n }\n }\n return keys;\n }\n /**\n * Return a new instance of cache with customized configuration.\n * @param {Object} config - the customized configuration\n * @return {Object} - the new instance of Cache\n */\n createInstance(config) {\n if (!config.keyPrefix || config.keyPrefix === constants_1.defaultConfig.keyPrefix) {\n logger.error('invalid keyPrefix, setting keyPrefix with timeStamp');\n config.keyPrefix = utils_2.getCurrentTime.toString();\n }\n return new StorageCache(config);\n }\n}\nexports.StorageCache = StorageCache;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,YAAY,GAAG,MAAM;AAC7B,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;AACrC,MAAM,iBAAiB,GAAG,OAAO,CAAC,4BAA4B,CAAC;AAC/D,MAAM,OAAO,GAAG,OAAO,CAAC,kBAAkB,CAAC;AAC3C,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;AAC1C,MAAM,oBAAoB,GAAG,OAAO,CAAC,sBAAsB,CAAC;AAC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,EAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;AACxD,gBAAgB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AACtE,YAAY;AACZ,QAAQ;AACR,QAAQ,OAAO,IAAI;AACnB,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA,IAAI,cAAc,CAAC,MAAM,EAAE;AAC3B,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,KAAK,WAAW,CAAC,aAAa,CAAC,SAAS,EAAE;AAC3F,YAAY,MAAM,CAAC,KAAK,CAAC,qDAAqD,CAAC;AAC/E,YAAY,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE;AAChE,QAAQ;AACR,QAAQ,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC;AACvC,IAAI;AACJ;AACA,OAAO,CAAC,YAAY,GAAG,YAAY;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"StorageCache.native.js","sources":["../../../src/Cache/StorageCache.native.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.StorageCache = void 0;\nconst react_native_1 = require(\"@aws-amplify/react-native\");\nconst Logger_1 = require(\"../Logger\");\nconst constants_1 = require(\"./constants\");\nconst StorageCacheCommon_1 = require(\"./StorageCacheCommon\");\nconst utils_1 = require(\"./utils\");\nconst logger = new Logger_1.ConsoleLogger('StorageCache');\nconst AsyncStorage = (0, react_native_1.loadAsyncStorage)();\n/*\n * Customized cache which based on the AsyncStorage with LRU implemented\n */\nclass StorageCache extends StorageCacheCommon_1.StorageCacheCommon {\n /**\n * initialize the cache\n * @param config - the configuration of the cache\n */\n constructor(config) {\n super({ config, keyValueStorage: AsyncStorage });\n this.getItem = this.getItem.bind(this);\n this.setItem = this.setItem.bind(this);\n this.removeItem = this.removeItem.bind(this);\n }\n async getAllCacheKeys(options) {\n const { omitSizeKey } = options ?? {};\n const keys = [];\n for (const key of await AsyncStorage.getAllKeys()) {\n if (omitSizeKey && key === (0, utils_1.getCurrentSizeKey)(this.config.keyPrefix)) {\n continue;\n }\n if (key?.startsWith(this.config.keyPrefix)) {\n keys.push(key.substring(this.config.keyPrefix.length));\n }\n }\n return keys;\n }\n async getAllStorageKeys() {\n try {\n return AsyncStorage.getAllKeys();\n }\n catch (e) {\n logger.warn(`getAllKeys failed! ${e}`);\n return [];\n }\n }\n /**\n * Return a new instance of cache with customized configuration.\n * @param {Object} config - the customized configuration\n * @return {Object} - the new instance of Cache\n */\n createInstance(config) {\n if (!config.keyPrefix || config.keyPrefix === constants_1.defaultConfig.keyPrefix) {\n logger.error('invalid keyPrefix, setting keyPrefix with timeStamp');\n config.keyPrefix = utils_1.getCurrentTime.toString();\n }\n return new StorageCache(config);\n }\n}\nexports.StorageCache = StorageCache;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,YAAY,GAAG,MAAM;AAC7B,MAAM,cAAc,GAAG,OAAO,CAAC,2BAA2B,CAAC;AAC3D,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;AACrC,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;AAC1C,MAAM,oBAAoB,GAAG,OAAO,CAAC,sBAAsB,CAAC;AAC5D,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;AAClC,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAC;AACzD,MAAM,YAAY,GAAG,IAAI,cAAc,CAAC,gBAAgB,GAAG;AAC3D;AACA;AACA;AACA,MAAM,YAAY,SAAS,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D,YAAY,OAAO,EAAE;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,cAAc,CAAC,MAAM,EAAE;AAC3B,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,KAAK,WAAW,CAAC,aAAa,CAAC,SAAS,EAAE;AAC3F,YAAY,MAAM,CAAC,KAAK,CAAC,qDAAqD,CAAC;AAC/E,YAAY,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE;AAChE;AACA,QAAQ,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC;AACvC;AACA;AACA,OAAO,CAAC,YAAY,GAAG,YAAY;;"}
1
+ {"version":3,"file":"StorageCache.native.js","sources":["../../../src/Cache/StorageCache.native.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.StorageCache = void 0;\nconst react_native_1 = require(\"@aws-amplify/react-native\");\nconst Logger_1 = require(\"../Logger\");\nconst constants_1 = require(\"./constants\");\nconst StorageCacheCommon_1 = require(\"./StorageCacheCommon\");\nconst utils_1 = require(\"./utils\");\nconst logger = new Logger_1.ConsoleLogger('StorageCache');\nconst AsyncStorage = (0, react_native_1.loadAsyncStorage)();\n/*\n * Customized cache which based on the AsyncStorage with LRU implemented\n */\nclass StorageCache extends StorageCacheCommon_1.StorageCacheCommon {\n /**\n * initialize the cache\n * @param config - the configuration of the cache\n */\n constructor(config) {\n super({ config, keyValueStorage: AsyncStorage });\n this.getItem = this.getItem.bind(this);\n this.setItem = this.setItem.bind(this);\n this.removeItem = this.removeItem.bind(this);\n }\n async getAllCacheKeys(options) {\n const { omitSizeKey } = options ?? {};\n const keys = [];\n for (const key of await AsyncStorage.getAllKeys()) {\n if (omitSizeKey && key === (0, utils_1.getCurrentSizeKey)(this.config.keyPrefix)) {\n continue;\n }\n if (key?.startsWith(this.config.keyPrefix)) {\n keys.push(key.substring(this.config.keyPrefix.length));\n }\n }\n return keys;\n }\n async getAllStorageKeys() {\n try {\n return AsyncStorage.getAllKeys();\n }\n catch (e) {\n logger.warn(`getAllKeys failed! ${e}`);\n return [];\n }\n }\n /**\n * Return a new instance of cache with customized configuration.\n * @param {Object} config - the customized configuration\n * @return {Object} - the new instance of Cache\n */\n createInstance(config) {\n if (!config.keyPrefix || config.keyPrefix === constants_1.defaultConfig.keyPrefix) {\n logger.error('invalid keyPrefix, setting keyPrefix with timeStamp');\n config.keyPrefix = utils_1.getCurrentTime.toString();\n }\n return new StorageCache(config);\n }\n}\nexports.StorageCache = StorageCache;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,YAAY,GAAG,MAAM;AAC7B,MAAM,cAAc,GAAG,OAAO,CAAC,2BAA2B,CAAC;AAC3D,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;AACrC,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;AAC1C,MAAM,oBAAoB,GAAG,OAAO,CAAC,sBAAsB,CAAC;AAC5D,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;AAClC,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAC;AACzD,MAAM,YAAY,GAAG,IAAI,cAAc,CAAC,gBAAgB,GAAG;AAC3D;AACA;AACA;AACA,MAAM,YAAY,SAAS,oBAAoB,CAAC,kBAAkB,CAAC;AACnE;AACA;AACA;AACA;AACA,IAAI,WAAW,CAAC,MAAM,EAAE;AACxB,QAAQ,KAAK,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,YAAY,EAAE,CAAC;AACxD,QAAQ,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,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Aa,CAAC,SAAS,EAAE;AAC3F,YAAY,MAAM,CAAC,KAAK,CAAC,qDAAqD,CAAC;AAC/E,YAAY,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE;AAChE,QAAQ;AACR,QAAQ,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC;AACvC,IAAI;AACJ;AACA,OAAO,CAAC,YAAY,GAAG,YAAY;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"StorageCacheCommon.js","sources":["../../../src/Cache/StorageCacheCommon.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.StorageCacheCommon = void 0;\nconst Logger_1 = require(\"../Logger\");\nconst constants_1 = require(\"./constants\");\nconst utils_1 = require(\"./utils\");\nconst errorHelpers_1 = require(\"./utils/errorHelpers\");\nconst logger = new Logger_1.ConsoleLogger('StorageCache');\n/**\n * Initialization of the cache\n *\n */\nclass StorageCacheCommon {\n /**\n * Initialize the cache\n *\n * @param config - Custom configuration for this instance.\n */\n constructor({ config, keyValueStorage, }) {\n this.config = {\n ...constants_1.defaultConfig,\n ...config,\n };\n this.keyValueStorage = keyValueStorage;\n this.sanitizeConfig();\n }\n getModuleName() {\n return 'Cache';\n }\n /**\n * Set custom configuration for the cache instance.\n *\n * @param config - customized configuration (without keyPrefix, which can't be changed)\n *\n * @return - the current configuration\n */\n configure(config) {\n if (config) {\n if (config.keyPrefix) {\n logger.warn('keyPrefix can not be re-configured on an existing Cache instance.');\n }\n this.config = {\n ...this.config,\n ...config,\n };\n }\n this.sanitizeConfig();\n return this.config;\n }\n /**\n * return the current size of the cache\n * @return {Promise}\n */\n async getCurrentCacheSize() {\n let size = await this.getStorage().getItem((0, utils_1.getCurrentSizeKey)(this.config.keyPrefix));\n if (!size) {\n await this.getStorage().setItem((0, utils_1.getCurrentSizeKey)(this.config.keyPrefix), '0');\n size = '0';\n }\n return Number(size);\n }\n /**\n * Set item into cache. You can put number, string, boolean or object.\n * The cache will first check whether has the same key.\n * If it has, it will delete the old item and then put the new item in\n * The cache will pop out items if it is full\n * You can specify the cache item options. The cache will abort and output a warning:\n * If the key is invalid\n * If the size of the item exceeds itemMaxSize.\n * If the value is undefined\n * If incorrect cache item configuration\n * If error happened with browser storage\n *\n * @param {String} key - the key of the item\n * @param {Object} value - the value of the item\n * @param {Object} [options] - optional, the specified meta-data\n *\n * @return {Promise}\n */\n async setItem(key, value, options) {\n logger.debug(`Set item: key is ${key}, value is ${value} with options: ${options}`);\n if (!key || key === constants_1.currentSizeKey) {\n logger.warn(`Invalid key: should not be empty or reserved key: '${constants_1.currentSizeKey}'`);\n return;\n }\n if (typeof value === 'undefined') {\n logger.warn(`The value of item should not be undefined!`);\n return;\n }\n const cacheItemOptions = {\n priority: options?.priority !== undefined\n ? options.priority\n : this.config.defaultPriority,\n expires: options?.expires !== undefined\n ? options.expires\n : this.config.defaultTTL + (0, utils_1.getCurrentTime)(),\n };\n if (cacheItemOptions.priority < 1 || cacheItemOptions.priority > 5) {\n logger.warn(`Invalid parameter: priority due to out or range. It should be within 1 and 5.`);\n return;\n }\n const prefixedKey = `${this.config.keyPrefix}${key}`;\n const item = this.fillCacheItem(prefixedKey, value, cacheItemOptions);\n // check whether this item is too big;\n if (item.byteSize > this.config.itemMaxSize) {\n logger.warn(`Item with key: ${key} you are trying to put into is too big!`);\n return;\n }\n try {\n // first look into the storage, if it exists, delete it.\n const val = await this.getStorage().getItem(prefixedKey);\n if (val) {\n await this.removeCacheItem(prefixedKey, JSON.parse(val).byteSize);\n }\n // check whether the cache is full\n if (await this.isCacheFull(item.byteSize)) {\n const validKeys = await this.clearInvalidAndGetRemainingKeys();\n if (await this.isCacheFull(item.byteSize)) {\n const sizeToPop = await this.sizeToPop(item.byteSize);\n await this.popOutItems(validKeys, sizeToPop);\n }\n }\n // put item in the cache\n return this.setCacheItem(prefixedKey, item);\n }\n catch (e) {\n logger.warn(`setItem failed! ${e}`);\n }\n }\n /**\n * Get item from cache. It will return null if item doesn’t exist or it has been expired.\n * If you specified callback function in the options,\n * then the function will be executed if no such item in the cache\n * and finally put the return value into cache.\n * Please make sure the callback function will return the value you want to put into the cache.\n * The cache will abort output a warning:\n * If the key is invalid\n * If error happened with AsyncStorage\n *\n * @param {String} key - the key of the item\n * @param {Object} [options] - the options of callback function\n *\n * @return {Promise} - return a promise resolves to be the value of the item\n */\n async getItem(key, options) {\n logger.debug(`Get item: key is ${key} with options ${options}`);\n let cached;\n if (!key || key === constants_1.currentSizeKey) {\n logger.warn(`Invalid key: should not be empty or reserved key: '${constants_1.currentSizeKey}'`);\n return null;\n }\n const prefixedKey = `${this.config.keyPrefix}${key}`;\n try {\n cached = await this.getStorage().getItem(prefixedKey);\n if (cached != null) {\n if (await this.isExpired(prefixedKey)) {\n // if expired, remove that item and return null\n await this.removeCacheItem(prefixedKey, JSON.parse(cached).byteSize);\n }\n else {\n // if not expired, update its visitedTime and return the value\n const item = await this.updateVisitedTime(JSON.parse(cached), prefixedKey);\n return item.data;\n }\n }\n if (options?.callback) {\n const val = options.callback();\n if (val !== null) {\n await this.setItem(key, val, options);\n }\n return val;\n }\n return null;\n }\n catch (e) {\n logger.warn(`getItem failed! ${e}`);\n return null;\n }\n }\n /**\n * remove item from the cache\n * The cache will abort output a warning:\n * If error happened with AsyncStorage\n * @param {String} key - the key of the item\n * @return {Promise}\n */\n async removeItem(key) {\n logger.debug(`Remove item: key is ${key}`);\n if (!key || key === constants_1.currentSizeKey) {\n logger.warn(`Invalid key: should not be empty or reserved key: '${constants_1.currentSizeKey}'`);\n return;\n }\n const prefixedKey = `${this.config.keyPrefix}${key}`;\n try {\n const val = await this.getStorage().getItem(prefixedKey);\n if (val) {\n await this.removeCacheItem(prefixedKey, JSON.parse(val).byteSize);\n }\n }\n catch (e) {\n logger.warn(`removeItem failed! ${e}`);\n }\n }\n /**\n * Return all the keys owned by this cache.\n * Will return an empty array if error occurred.\n *\n * @return {Promise}\n */\n async getAllKeys() {\n try {\n return await this.getAllCacheKeys();\n }\n catch (e) {\n logger.warn(`getAllkeys failed! ${e}`);\n return [];\n }\n }\n getStorage() {\n return this.keyValueStorage;\n }\n /**\n * check whether item is expired\n *\n * @param key - the key of the item\n *\n * @return true if the item is expired.\n */\n async isExpired(key) {\n const text = await this.getStorage().getItem(key);\n (0, errorHelpers_1.assert)(text !== null, errorHelpers_1.CacheErrorCode.NoCacheItem, `Key: ${key}`);\n const item = JSON.parse(text);\n if ((0, utils_1.getCurrentTime)() >= item.expires) {\n return true;\n }\n return false;\n }\n /**\n * delete item from cache\n *\n * @param prefixedKey - the key of the item\n * @param size - optional, the byte size of the item\n */\n async removeCacheItem(prefixedKey, size) {\n const item = await this.getStorage().getItem(prefixedKey);\n (0, errorHelpers_1.assert)(item !== null, errorHelpers_1.CacheErrorCode.NoCacheItem, `Key: ${prefixedKey}`);\n const itemSize = size ?? JSON.parse(item).byteSize;\n // first try to update the current size of the cache\n await this.decreaseCurrentSizeInBytes(itemSize);\n // try to remove the item from cache\n try {\n await this.getStorage().removeItem(prefixedKey);\n }\n catch (removeItemError) {\n // if some error happened, we need to rollback the current size\n await this.increaseCurrentSizeInBytes(itemSize);\n logger.error(`Failed to remove item: ${removeItemError}`);\n }\n }\n /**\n * produce a JSON object with meta-data and data value\n * @param value - the value of the item\n * @param options - optional, the specified meta-data\n *\n * @return - the item which has the meta-data and the value\n */\n fillCacheItem(key, value, options) {\n const item = {\n key,\n data: value,\n timestamp: (0, utils_1.getCurrentTime)(),\n visitedTime: (0, utils_1.getCurrentTime)(),\n priority: options.priority ?? 0,\n expires: options.expires ?? 0,\n type: typeof value,\n byteSize: 0,\n };\n // calculate byte size\n item.byteSize = (0, utils_1.getByteLength)(JSON.stringify(item));\n // re-calculate using cache item with updated byteSize property\n item.byteSize = (0, utils_1.getByteLength)(JSON.stringify(item));\n return item;\n }\n sanitizeConfig() {\n if (this.config.itemMaxSize > this.config.capacityInBytes) {\n logger.error('Invalid parameter: itemMaxSize. It should be smaller than capacityInBytes. Setting back to default.');\n this.config.itemMaxSize = constants_1.defaultConfig.itemMaxSize;\n }\n if (this.config.defaultPriority > 5 || this.config.defaultPriority < 1) {\n logger.error('Invalid parameter: defaultPriority. It should be between 1 and 5. Setting back to default.');\n this.config.defaultPriority = constants_1.defaultConfig.defaultPriority;\n }\n if (Number(this.config.warningThreshold) > 1 ||\n Number(this.config.warningThreshold) < 0) {\n logger.error('Invalid parameter: warningThreshold. It should be between 0 and 1. Setting back to default.');\n this.config.warningThreshold = constants_1.defaultConfig.warningThreshold;\n }\n // Set 5MB limit\n const cacheLimit = 5 * 1024 * 1024;\n if (this.config.capacityInBytes > cacheLimit) {\n logger.error('Cache Capacity should be less than 5MB. Setting back to default. Setting back to default.');\n this.config.capacityInBytes = constants_1.defaultConfig.capacityInBytes;\n }\n }\n /**\n * increase current size of the cache\n *\n * @param amount - the amount of the cache szie which need to be increased\n */\n async increaseCurrentSizeInBytes(amount) {\n const size = await this.getCurrentCacheSize();\n await this.getStorage().setItem((0, utils_1.getCurrentSizeKey)(this.config.keyPrefix), (size + amount).toString());\n }\n /**\n * decrease current size of the cache\n *\n * @param amount - the amount of the cache size which needs to be decreased\n */\n async decreaseCurrentSizeInBytes(amount) {\n const size = await this.getCurrentCacheSize();\n await this.getStorage().setItem((0, utils_1.getCurrentSizeKey)(this.config.keyPrefix), (size - amount).toString());\n }\n /**\n * update the visited time if item has been visited\n *\n * @param item - the item which need to be updated\n * @param prefixedKey - the key of the item\n *\n * @return the updated item\n */\n async updateVisitedTime(item, prefixedKey) {\n item.visitedTime = (0, utils_1.getCurrentTime)();\n await this.getStorage().setItem(prefixedKey, JSON.stringify(item));\n return item;\n }\n /**\n * put item into cache\n *\n * @param prefixedKey - the key of the item\n * @param itemData - the value of the item\n * @param itemSizeInBytes - the byte size of the item\n */\n async setCacheItem(prefixedKey, item) {\n // first try to update the current size of the cache.\n await this.increaseCurrentSizeInBytes(item.byteSize);\n // try to add the item into cache\n try {\n await this.getStorage().setItem(prefixedKey, JSON.stringify(item));\n }\n catch (setItemErr) {\n // if some error happened, we need to rollback the current size\n await this.decreaseCurrentSizeInBytes(item.byteSize);\n logger.error(`Failed to set item ${setItemErr}`);\n }\n }\n /**\n * total space needed when poping out items\n *\n * @param itemSize\n *\n * @return total space needed\n */\n async sizeToPop(itemSize) {\n const cur = await this.getCurrentCacheSize();\n const spaceItemNeed = cur + itemSize - this.config.capacityInBytes;\n const cacheThresholdSpace = (1 - this.config.warningThreshold) * this.config.capacityInBytes;\n return spaceItemNeed > cacheThresholdSpace\n ? spaceItemNeed\n : cacheThresholdSpace;\n }\n /**\n * see whether cache is full\n *\n * @param itemSize\n *\n * @return true if cache is full\n */\n async isCacheFull(itemSize) {\n const cur = await this.getCurrentCacheSize();\n return itemSize + cur > this.config.capacityInBytes;\n }\n /**\n * get all the items we have, sort them by their priority,\n * if priority is same, sort them by their last visited time\n * pop out items from the low priority (5 is the lowest)\n * @private\n * @param keys - all the keys in this cache\n * @param sizeToPop - the total size of the items which needed to be poped out\n */\n async popOutItems(keys, sizeToPop) {\n const items = [];\n let remainedSize = sizeToPop;\n for (const key of keys) {\n const val = await this.getStorage().getItem(key);\n if (val != null) {\n const item = JSON.parse(val);\n items.push(item);\n }\n }\n // first compare priority\n // then compare visited time\n items.sort((a, b) => {\n if (a.priority > b.priority) {\n return -1;\n }\n else if (a.priority < b.priority) {\n return 1;\n }\n else {\n if (a.visitedTime < b.visitedTime) {\n return -1;\n }\n else\n return 1;\n }\n });\n for (const item of items) {\n // pop out items until we have enough room for new item\n await this.removeCacheItem(item.key, item.byteSize);\n remainedSize -= item.byteSize;\n if (remainedSize <= 0) {\n return;\n }\n }\n }\n /**\n * Scan the storage and combine the following operations for efficiency\n * 1. Clear out all expired keys owned by this cache, not including the size key.\n * 2. Return the remaining keys.\n *\n * @return The remaining valid keys\n */\n async clearInvalidAndGetRemainingKeys() {\n const remainingKeys = [];\n const keys = await this.getAllCacheKeys({\n omitSizeKey: true,\n });\n for (const key of keys) {\n if (await this.isExpired(key)) {\n await this.removeCacheItem(key);\n }\n else {\n remainingKeys.push(key);\n }\n }\n return remainingKeys;\n }\n /**\n * clear the entire cache\n * The cache will abort and output a warning if error occurs\n * @return {Promise}\n */\n async clear() {\n logger.debug(`Clear Cache`);\n try {\n const keys = await this.getAllKeys();\n for (const key of keys) {\n const prefixedKey = `${this.config.keyPrefix}${key}`;\n await this.getStorage().removeItem(prefixedKey);\n }\n }\n catch (e) {\n logger.warn(`clear failed! ${e}`);\n }\n }\n}\nexports.StorageCacheCommon = StorageCacheCommon;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,kBAAkB,GAAG,MAAM;AACnC,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;AACrC,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;AAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;AAClC,MAAM,cAAc,GAAG,OAAO,CAAC,sBAAsB,CAAC;AACtD,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAC;AACzD;AACA;AACA;AACA;AACA,MAAM,kBAAkB,CAAC;AACzB;AACA;AACA;AACA;AACA;AACA,IAAI,WAAW,CAAC,EAAE,MAAM,EAAE,eAAe,GAAG,EAAE;AAC9C,QAAQ,IAAI,CAAC,MAAM,GAAG;AACtB,YAAY,GAAG,WAAW,CAAC,aAAa;AACxC,YAAY,GAAG,MAAM;AACrB,SAAS;AACT,QAAQ,IAAI,CAAC,eAAe,GAAG,eAAe;AAC9C,QAAQ,IAAI,CAAC,cAAc,EAAE;AAC7B;AACA,IAAI,aAAa,GAAG;AACpB,QAAQ,OAAO,OAAO;AACtB;AACA;AACA;AACA;AACA;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,+BAA+B,GAAG;AAC5C,QAAQ,MAAM,aAAa,GAAG,EAAE;AAChC,QAAQ,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC;AAChD,YAAY,WAAW,EAAE,IAAI;AAC7B,SAAS,CAAC;AACV,QAAQ,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;AAChC,YAAY,IAAI,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;AAC3C,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC;AAC/C;AACA,iBAAiB;AACjB,gBAAgB,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC;AACvC;AACA;AACA,QAAQ,OAAO,aAAa;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,KAAK,GAAG;AAClB,QAAQ,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,CAAC;AACnC,QAAQ,IAAI;AACZ,YAAY,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE;AAChD,YAAY,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;AACpC,gBAAgB,MAAM,WAAW,GAAG,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC;AACpE,gBAAgB,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;AAC/D;AACA;AACA,QAAQ,OAAO,CAAC,EAAE;AAClB,YAAY,MAAM,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,CAAC;AAC7C;AACA;AACA;AACA,OAAO,CAAC,kBAAkB,GAAG,kBAAkB;;"}
1
+ {"version":3,"file":"StorageCacheCommon.js","sources":["../../../src/Cache/StorageCacheCommon.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.StorageCacheCommon = void 0;\nconst Logger_1 = require(\"../Logger\");\nconst constants_1 = require(\"./constants\");\nconst utils_1 = require(\"./utils\");\nconst errorHelpers_1 = require(\"./utils/errorHelpers\");\nconst logger = new Logger_1.ConsoleLogger('StorageCache');\n/**\n * Initialization of the cache\n *\n */\nclass StorageCacheCommon {\n /**\n * Initialize the cache\n *\n * @param config - Custom configuration for this instance.\n */\n constructor({ config, keyValueStorage, }) {\n this.config = {\n ...constants_1.defaultConfig,\n ...config,\n };\n this.keyValueStorage = keyValueStorage;\n this.sanitizeConfig();\n }\n getModuleName() {\n return 'Cache';\n }\n /**\n * Set custom configuration for the cache instance.\n *\n * @param config - customized configuration (without keyPrefix, which can't be changed)\n *\n * @return - the current configuration\n */\n configure(config) {\n if (config) {\n if (config.keyPrefix) {\n logger.warn('keyPrefix can not be re-configured on an existing Cache instance.');\n }\n this.config = {\n ...this.config,\n ...config,\n };\n }\n this.sanitizeConfig();\n return this.config;\n }\n /**\n * return the current size of the cache\n * @return {Promise}\n */\n async getCurrentCacheSize() {\n let size = await this.getStorage().getItem((0, utils_1.getCurrentSizeKey)(this.config.keyPrefix));\n if (!size) {\n await this.getStorage().setItem((0, utils_1.getCurrentSizeKey)(this.config.keyPrefix), '0');\n size = '0';\n }\n return Number(size);\n }\n /**\n * Set item into cache. You can put number, string, boolean or object.\n * The cache will first check whether has the same key.\n * If it has, it will delete the old item and then put the new item in\n * The cache will pop out items if it is full\n * You can specify the cache item options. The cache will abort and output a warning:\n * If the key is invalid\n * If the size of the item exceeds itemMaxSize.\n * If the value is undefined\n * If incorrect cache item configuration\n * If error happened with browser storage\n *\n * @param {String} key - the key of the item\n * @param {Object} value - the value of the item\n * @param {Object} [options] - optional, the specified meta-data\n *\n * @return {Promise}\n */\n async setItem(key, value, options) {\n logger.debug(`Set item: key is ${key}, value is ${value} with options: ${options}`);\n if (!key || key === constants_1.currentSizeKey) {\n logger.warn(`Invalid key: should not be empty or reserved key: '${constants_1.currentSizeKey}'`);\n return;\n }\n if (typeof value === 'undefined') {\n logger.warn(`The value of item should not be undefined!`);\n return;\n }\n const cacheItemOptions = {\n priority: options?.priority !== undefined\n ? options.priority\n : this.config.defaultPriority,\n expires: options?.expires !== undefined\n ? options.expires\n : this.config.defaultTTL + (0, utils_1.getCurrentTime)(),\n };\n if (cacheItemOptions.priority < 1 || cacheItemOptions.priority > 5) {\n logger.warn(`Invalid parameter: priority due to out or range. It should be within 1 and 5.`);\n return;\n }\n const prefixedKey = `${this.config.keyPrefix}${key}`;\n const item = this.fillCacheItem(prefixedKey, value, cacheItemOptions);\n // check whether this item is too big;\n if (item.byteSize > this.config.itemMaxSize) {\n logger.warn(`Item with key: ${key} you are trying to put into is too big!`);\n return;\n }\n try {\n // first look into the storage, if it exists, delete it.\n const val = await this.getStorage().getItem(prefixedKey);\n if (val) {\n await this.removeCacheItem(prefixedKey, JSON.parse(val).byteSize);\n }\n // check whether the cache is full\n if (await this.isCacheFull(item.byteSize)) {\n const validKeys = await this.clearInvalidAndGetRemainingKeys();\n if (await this.isCacheFull(item.byteSize)) {\n const sizeToPop = await this.sizeToPop(item.byteSize);\n await this.popOutItems(validKeys, sizeToPop);\n }\n }\n // put item in the cache\n return this.setCacheItem(prefixedKey, item);\n }\n catch (e) {\n logger.warn(`setItem failed! ${e}`);\n }\n }\n /**\n * Get item from cache. It will return null if item doesn’t exist or it has been expired.\n * If you specified callback function in the options,\n * then the function will be executed if no such item in the cache\n * and finally put the return value into cache.\n * Please make sure the callback function will return the value you want to put into the cache.\n * The cache will abort output a warning:\n * If the key is invalid\n * If error happened with AsyncStorage\n *\n * @param {String} key - the key of the item\n * @param {Object} [options] - the options of callback function\n *\n * @return {Promise} - return a promise resolves to be the value of the item\n */\n async getItem(key, options) {\n logger.debug(`Get item: key is ${key} with options ${options}`);\n let cached;\n if (!key || key === constants_1.currentSizeKey) {\n logger.warn(`Invalid key: should not be empty or reserved key: '${constants_1.currentSizeKey}'`);\n return null;\n }\n const prefixedKey = `${this.config.keyPrefix}${key}`;\n try {\n cached = await this.getStorage().getItem(prefixedKey);\n if (cached != null) {\n if (await this.isExpired(prefixedKey)) {\n // if expired, remove that item and return null\n await this.removeCacheItem(prefixedKey, JSON.parse(cached).byteSize);\n }\n else {\n // if not expired, update its visitedTime and return the value\n const item = await this.updateVisitedTime(JSON.parse(cached), prefixedKey);\n return item.data;\n }\n }\n if (options?.callback) {\n const val = options.callback();\n if (val !== null) {\n await this.setItem(key, val, options);\n }\n return val;\n }\n return null;\n }\n catch (e) {\n logger.warn(`getItem failed! ${e}`);\n return null;\n }\n }\n /**\n * remove item from the cache\n * The cache will abort output a warning:\n * If error happened with AsyncStorage\n * @param {String} key - the key of the item\n * @return {Promise}\n */\n async removeItem(key) {\n logger.debug(`Remove item: key is ${key}`);\n if (!key || key === constants_1.currentSizeKey) {\n logger.warn(`Invalid key: should not be empty or reserved key: '${constants_1.currentSizeKey}'`);\n return;\n }\n const prefixedKey = `${this.config.keyPrefix}${key}`;\n try {\n const val = await this.getStorage().getItem(prefixedKey);\n if (val) {\n await this.removeCacheItem(prefixedKey, JSON.parse(val).byteSize);\n }\n }\n catch (e) {\n logger.warn(`removeItem failed! ${e}`);\n }\n }\n /**\n * Return all the keys owned by this cache.\n * Will return an empty array if error occurred.\n *\n * @return {Promise}\n */\n async getAllKeys() {\n try {\n return await this.getAllCacheKeys();\n }\n catch (e) {\n logger.warn(`getAllkeys failed! ${e}`);\n return [];\n }\n }\n getStorage() {\n return this.keyValueStorage;\n }\n /**\n * check whether item is expired\n *\n * @param key - the key of the item\n *\n * @return true if the item is expired.\n */\n async isExpired(key) {\n const text = await this.getStorage().getItem(key);\n (0, errorHelpers_1.assert)(text !== null, errorHelpers_1.CacheErrorCode.NoCacheItem, `Key: ${key}`);\n const item = JSON.parse(text);\n if ((0, utils_1.getCurrentTime)() >= item.expires) {\n return true;\n }\n return false;\n }\n /**\n * delete item from cache\n *\n * @param prefixedKey - the key of the item\n * @param size - optional, the byte size of the item\n */\n async removeCacheItem(prefixedKey, size) {\n const item = await this.getStorage().getItem(prefixedKey);\n (0, errorHelpers_1.assert)(item !== null, errorHelpers_1.CacheErrorCode.NoCacheItem, `Key: ${prefixedKey}`);\n const itemSize = size ?? JSON.parse(item).byteSize;\n // first try to update the current size of the cache\n await this.decreaseCurrentSizeInBytes(itemSize);\n // try to remove the item from cache\n try {\n await this.getStorage().removeItem(prefixedKey);\n }\n catch (removeItemError) {\n // if some error happened, we need to rollback the current size\n await this.increaseCurrentSizeInBytes(itemSize);\n logger.error(`Failed to remove item: ${removeItemError}`);\n }\n }\n /**\n * produce a JSON object with meta-data and data value\n * @param value - the value of the item\n * @param options - optional, the specified meta-data\n *\n * @return - the item which has the meta-data and the value\n */\n fillCacheItem(key, value, options) {\n const item = {\n key,\n data: value,\n timestamp: (0, utils_1.getCurrentTime)(),\n visitedTime: (0, utils_1.getCurrentTime)(),\n priority: options.priority ?? 0,\n expires: options.expires ?? 0,\n type: typeof value,\n byteSize: 0,\n };\n // calculate byte size\n item.byteSize = (0, utils_1.getByteLength)(JSON.stringify(item));\n // re-calculate using cache item with updated byteSize property\n item.byteSize = (0, utils_1.getByteLength)(JSON.stringify(item));\n return item;\n }\n sanitizeConfig() {\n if (this.config.itemMaxSize > this.config.capacityInBytes) {\n logger.error('Invalid parameter: itemMaxSize. It should be smaller than capacityInBytes. Setting back to default.');\n this.config.itemMaxSize = constants_1.defaultConfig.itemMaxSize;\n }\n if (this.config.defaultPriority > 5 || this.config.defaultPriority < 1) {\n logger.error('Invalid parameter: defaultPriority. It should be between 1 and 5. Setting back to default.');\n this.config.defaultPriority = constants_1.defaultConfig.defaultPriority;\n }\n if (Number(this.config.warningThreshold) > 1 ||\n Number(this.config.warningThreshold) < 0) {\n logger.error('Invalid parameter: warningThreshold. It should be between 0 and 1. Setting back to default.');\n this.config.warningThreshold = constants_1.defaultConfig.warningThreshold;\n }\n // Set 5MB limit\n const cacheLimit = 5 * 1024 * 1024;\n if (this.config.capacityInBytes > cacheLimit) {\n logger.error('Cache Capacity should be less than 5MB. Setting back to default. Setting back to default.');\n this.config.capacityInBytes = constants_1.defaultConfig.capacityInBytes;\n }\n }\n /**\n * increase current size of the cache\n *\n * @param amount - the amount of the cache szie which need to be increased\n */\n async increaseCurrentSizeInBytes(amount) {\n const size = await this.getCurrentCacheSize();\n await this.getStorage().setItem((0, utils_1.getCurrentSizeKey)(this.config.keyPrefix), (size + amount).toString());\n }\n /**\n * decrease current size of the cache\n *\n * @param amount - the amount of the cache size which needs to be decreased\n */\n async decreaseCurrentSizeInBytes(amount) {\n const size = await this.getCurrentCacheSize();\n await this.getStorage().setItem((0, utils_1.getCurrentSizeKey)(this.config.keyPrefix), (size - amount).toString());\n }\n /**\n * update the visited time if item has been visited\n *\n * @param item - the item which need to be updated\n * @param prefixedKey - the key of the item\n *\n * @return the updated item\n */\n async updateVisitedTime(item, prefixedKey) {\n item.visitedTime = (0, utils_1.getCurrentTime)();\n await this.getStorage().setItem(prefixedKey, JSON.stringify(item));\n return item;\n }\n /**\n * put item into cache\n *\n * @param prefixedKey - the key of the item\n * @param itemData - the value of the item\n * @param itemSizeInBytes - the byte size of the item\n */\n async setCacheItem(prefixedKey, item) {\n // first try to update the current size of the cache.\n await this.increaseCurrentSizeInBytes(item.byteSize);\n // try to add the item into cache\n try {\n await this.getStorage().setItem(prefixedKey, JSON.stringify(item));\n }\n catch (setItemErr) {\n // if some error happened, we need to rollback the current size\n await this.decreaseCurrentSizeInBytes(item.byteSize);\n logger.error(`Failed to set item ${setItemErr}`);\n }\n }\n /**\n * total space needed when poping out items\n *\n * @param itemSize\n *\n * @return total space needed\n */\n async sizeToPop(itemSize) {\n const cur = await this.getCurrentCacheSize();\n const spaceItemNeed = cur + itemSize - this.config.capacityInBytes;\n const cacheThresholdSpace = (1 - this.config.warningThreshold) * this.config.capacityInBytes;\n return spaceItemNeed > cacheThresholdSpace\n ? spaceItemNeed\n : cacheThresholdSpace;\n }\n /**\n * see whether cache is full\n *\n * @param itemSize\n *\n * @return true if cache is full\n */\n async isCacheFull(itemSize) {\n const cur = await this.getCurrentCacheSize();\n return itemSize + cur > this.config.capacityInBytes;\n }\n /**\n * get all the items we have, sort them by their priority,\n * if priority is same, sort them by their last visited time\n * pop out items from the low priority (5 is the lowest)\n * @private\n * @param keys - all the keys in this cache\n * @param sizeToPop - the total size of the items which needed to be poped out\n */\n async popOutItems(keys, sizeToPop) {\n const items = [];\n let remainedSize = sizeToPop;\n for (const key of keys) {\n const val = await this.getStorage().getItem(key);\n if (val != null) {\n const item = JSON.parse(val);\n items.push(item);\n }\n }\n // first compare priority\n // then compare visited time\n items.sort((a, b) => {\n if (a.priority > b.priority) {\n return -1;\n }\n else if (a.priority < b.priority) {\n return 1;\n }\n else {\n if (a.visitedTime < b.visitedTime) {\n return -1;\n }\n else\n return 1;\n }\n });\n for (const item of items) {\n // pop out items until we have enough room for new item\n await this.removeCacheItem(item.key, item.byteSize);\n remainedSize -= item.byteSize;\n if (remainedSize <= 0) {\n return;\n }\n }\n }\n /**\n * Scan the storage and combine the following operations for efficiency\n * 1. Clear out all expired keys owned by this cache, not including the size key.\n * 2. Return the remaining keys.\n *\n * @return The remaining valid keys\n */\n async clearInvalidAndGetRemainingKeys() {\n const remainingKeys = [];\n const keys = await this.getAllCacheKeys({\n omitSizeKey: true,\n });\n for (const key of keys) {\n if (await this.isExpired(key)) {\n await this.removeCacheItem(key);\n }\n else {\n remainingKeys.push(key);\n }\n }\n return remainingKeys;\n }\n /**\n * clear the entire cache\n * The cache will abort and output a warning if error occurs\n * @return {Promise}\n */\n async clear() {\n logger.debug(`Clear Cache`);\n try {\n const keys = await this.getAllKeys();\n for (const key of keys) {\n const prefixedKey = `${this.config.keyPrefix}${key}`;\n await this.getStorage().removeItem(prefixedKey);\n }\n }\n catch (e) {\n logger.warn(`clear failed! ${e}`);\n }\n }\n}\nexports.StorageCacheCommon = StorageCacheCommon;\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 +1 @@
1
- {"version":3,"file":"CacheList.js","sources":["../../../../src/Cache/utils/CacheList.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.CacheList = void 0;\nconst errorHelpers_1 = require(\"./errorHelpers\");\nclass DoubleLinkedNode {\n constructor(keyVal) {\n this.key = keyVal || '';\n this.prevNode = null;\n this.nextNode = null;\n }\n}\n/**\n * double linked list plus a hash table inside\n * each key in the cache stored as a node in the list\n * recently visited node will be rotated to the head\n * so the Last Recently Visited node will be at the tail\n *\n * @member head - dummy head of the linked list\n * @member tail - dummy tail of the linked list\n * @member hashtable - the hashtable which maps cache key to list node\n * @member length - length of the list\n */\nclass CacheList {\n /**\n * initialization\n */\n constructor() {\n this.head = new DoubleLinkedNode();\n this.tail = new DoubleLinkedNode();\n this.hashtable = {};\n this.length = 0;\n this.head.nextNode = this.tail;\n this.tail.prevNode = this.head;\n }\n /**\n * insert node to the head of the list\n *\n * @param node\n */\n insertNodeToHead(node) {\n const tmp = this.head.nextNode;\n this.head.nextNode = node;\n node.nextNode = tmp;\n node.prevNode = this.head;\n (0, errorHelpers_1.assert)(tmp !== null, errorHelpers_1.CacheErrorCode.NullPreviousNode);\n tmp.prevNode = node;\n this.length = this.length + 1;\n }\n /**\n * remove node\n *\n * @param node\n */\n removeNode(node) {\n (0, errorHelpers_1.assert)(node.prevNode !== null, errorHelpers_1.CacheErrorCode.NullPreviousNode);\n (0, errorHelpers_1.assert)(node.nextNode !== null, errorHelpers_1.CacheErrorCode.NullNextNode);\n node.prevNode.nextNode = node.nextNode;\n node.nextNode.prevNode = node.prevNode;\n node.prevNode = null;\n node.nextNode = null;\n this.length = this.length - 1;\n }\n /**\n * @return true if list is empty\n */\n isEmpty() {\n return this.length === 0;\n }\n /**\n * refresh node so it is rotated to the head\n *\n * @param key - key of the node\n */\n refresh(key) {\n const node = this.hashtable[key];\n this.removeNode(node);\n this.insertNodeToHead(node);\n }\n /**\n * insert new node to the head and add it in the hashtable\n *\n * @param key - the key of the node\n */\n insertItem(key) {\n const node = new DoubleLinkedNode(key);\n this.hashtable[key] = node;\n this.insertNodeToHead(node);\n }\n /**\n * @return the LAST Recently Visited key\n */\n getLastItem() {\n (0, errorHelpers_1.assert)(this.tail.prevNode !== null, errorHelpers_1.CacheErrorCode.NullPreviousNode);\n return this.tail.prevNode.key;\n }\n /**\n * remove the cache key from the list and hashtable\n * @param key - the key of the node\n */\n removeItem(key) {\n const removedItem = this.hashtable[key];\n this.removeNode(removedItem);\n delete this.hashtable[key];\n }\n /**\n * @return length of the list\n */\n getSize() {\n return this.length;\n }\n /**\n * @return true if the key is in the hashtable\n * @param key\n */\n containsKey(key) {\n return key in this.hashtable;\n }\n /**\n * clean up the list and hashtable\n */\n clearList() {\n for (const key of Object.keys(this.hashtable)) {\n if (Object.prototype.hasOwnProperty.call(this.hashtable, key)) {\n delete this.hashtable[key];\n }\n }\n this.head.nextNode = this.tail;\n this.tail.prevNode = this.head;\n this.length = 0;\n }\n /**\n * @return all keys in the hashtable\n */\n getKeys() {\n return Object.keys(this.hashtable);\n }\n /**\n * mainly for test\n *\n * @param key\n * @return true if key is the head node\n */\n isHeadNode(key) {\n const node = this.hashtable[key];\n return node.prevNode === this.head;\n }\n /**\n * mainly for test\n *\n * @param key\n * @return true if key is the tail node\n */\n isTailNode(key) {\n const node = this.hashtable[key];\n return node.nextNode === this.tail;\n }\n}\nexports.CacheList = CacheList;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,SAAS,GAAG,MAAM;AAC1B,MAAM,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC;AAChD,MAAM,gBAAgB,CAAC;AACvB,IAAI,WAAW,CAAC,MAAM,EAAE;AACxB,QAA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,QAAQ,OAAO,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,IAAI;AAC1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,UAAU,CAAC,GAAG,EAAE;AACpB,QAAQ,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;AACxC,QAAQ,OAAO,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,IAAI;AAC1C;AACA;AACA,OAAO,CAAC,SAAS,GAAG,SAAS;;"}
1
+ {"version":3,"file":"CacheList.js","sources":["../../../../src/Cache/utils/CacheList.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.CacheList = void 0;\nconst errorHelpers_1 = require(\"./errorHelpers\");\nclass DoubleLinkedNode {\n constructor(keyVal) {\n this.key = keyVal || '';\n this.prevNode = null;\n this.nextNode = null;\n }\n}\n/**\n * double linked list plus a hash table inside\n * each key in the cache stored as a node in the list\n * recently visited node will be rotated to the head\n * so the Last Recently Visited node will be at the tail\n *\n * @member head - dummy head of the linked list\n * @member tail - dummy tail of the linked list\n * @member hashtable - the hashtable which maps cache key to list node\n * @member length - length of the list\n */\nclass CacheList {\n /**\n * initialization\n */\n constructor() {\n this.head = new DoubleLinkedNode();\n this.tail = new DoubleLinkedNode();\n this.hashtable = {};\n this.length = 0;\n this.head.nextNode = this.tail;\n this.tail.prevNode = this.head;\n }\n /**\n * insert node to the head of the list\n *\n * @param node\n */\n insertNodeToHead(node) {\n const tmp = this.head.nextNode;\n this.head.nextNode = node;\n node.nextNode = tmp;\n node.prevNode = this.head;\n (0, errorHelpers_1.assert)(tmp !== null, errorHelpers_1.CacheErrorCode.NullPreviousNode);\n tmp.prevNode = node;\n this.length = this.length + 1;\n }\n /**\n * remove node\n *\n * @param node\n */\n removeNode(node) {\n (0, errorHelpers_1.assert)(node.prevNode !== null, errorHelpers_1.CacheErrorCode.NullPreviousNode);\n (0, errorHelpers_1.assert)(node.nextNode !== null, errorHelpers_1.CacheErrorCode.NullNextNode);\n node.prevNode.nextNode = node.nextNode;\n node.nextNode.prevNode = node.prevNode;\n node.prevNode = null;\n node.nextNode = null;\n this.length = this.length - 1;\n }\n /**\n * @return true if list is empty\n */\n isEmpty() {\n return this.length === 0;\n }\n /**\n * refresh node so it is rotated to the head\n *\n * @param key - key of the node\n */\n refresh(key) {\n const node = this.hashtable[key];\n this.removeNode(node);\n this.insertNodeToHead(node);\n }\n /**\n * insert new node to the head and add it in the hashtable\n *\n * @param key - the key of the node\n */\n insertItem(key) {\n const node = new DoubleLinkedNode(key);\n this.hashtable[key] = node;\n this.insertNodeToHead(node);\n }\n /**\n * @return the LAST Recently Visited key\n */\n getLastItem() {\n (0, errorHelpers_1.assert)(this.tail.prevNode !== null, errorHelpers_1.CacheErrorCode.NullPreviousNode);\n return this.tail.prevNode.key;\n }\n /**\n * remove the cache key from the list and hashtable\n * @param key - the key of the node\n */\n removeItem(key) {\n const removedItem = this.hashtable[key];\n this.removeNode(removedItem);\n delete this.hashtable[key];\n }\n /**\n * @return length of the list\n */\n getSize() {\n return this.length;\n }\n /**\n * @return true if the key is in the hashtable\n * @param key\n */\n containsKey(key) {\n return key in this.hashtable;\n }\n /**\n * clean up the list and hashtable\n */\n clearList() {\n for (const key of Object.keys(this.hashtable)) {\n if (Object.prototype.hasOwnProperty.call(this.hashtable, key)) {\n delete this.hashtable[key];\n }\n }\n this.head.nextNode = this.tail;\n this.tail.prevNode = this.head;\n this.length = 0;\n }\n /**\n * @return all keys in the hashtable\n */\n getKeys() {\n return Object.keys(this.hashtable);\n }\n /**\n * mainly for test\n *\n * @param key\n * @return true if key is the head node\n */\n isHeadNode(key) {\n const node = this.hashtable[key];\n return node.prevNode === this.head;\n }\n /**\n * mainly for test\n *\n * @param key\n * @return true if key is the tail node\n */\n isTailNode(key) {\n const node = this.hashtable[key];\n return node.nextNode === this.tail;\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,QAAQ,GAAG,IAAI,CAAC,IAAI;AACtC,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI;AACtC,QAAQ,IAAI,CAAC,MAAM,GAAG,CAAC;AACvB,IAAI;AACJ;AACA;AACA;AACA,IAAI,OAAO,GAAG;AACd,QAAQ,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;AAC1C,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,UAAU,CAAC,GAAG,EAAE;AACpB,QAAQ,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;AACxC,QAAQ,OAAO,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,IAAI;AAC1C,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,UAAU,CAAC,GAAG,EAAE;AACpB,QAAQ,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;AACxC,QAAQ,OAAO,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,IAAI;AAC1C,IAAI;AACJ;AACA,OAAO,CAAC,SAAS,GAAG,SAAS;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"cacheHelpers.js","sources":["../../../../src/Cache/utils/cacheHelpers.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getCurrentSizeKey = void 0;\nexports.getByteLength = getByteLength;\nexports.getCurrentTime = getCurrentTime;\nexports.isInteger = isInteger;\nconst constants_1 = require(\"../constants\");\n/**\n * return the byte size of the string\n * @param str\n */\nfunction getByteLength(str) {\n let ret = 0;\n ret = str.length;\n for (let i = str.length; i >= 0; i -= 1) {\n const charCode = str.charCodeAt(i);\n if (charCode > 0x7f && charCode <= 0x7ff) {\n ret += 1;\n }\n else if (charCode > 0x7ff && charCode <= 0xffff) {\n ret += 2;\n }\n // trail surrogate\n if (charCode >= 0xdc00 && charCode <= 0xdfff) {\n i -= 1;\n }\n }\n return ret;\n}\n/**\n * get current time\n */\nfunction getCurrentTime() {\n const currentTime = new Date();\n return currentTime.getTime();\n}\n/**\n * check if passed value is an integer\n */\nfunction isInteger(value) {\n if (Number.isInteger) {\n return Number.isInteger(value);\n }\n return (typeof value === 'number' && isFinite(value) && Math.floor(value) === value);\n}\nconst getCurrentSizeKey = (keyPrefix) => `${keyPrefix}${constants_1.currentSizeKey}`;\nexports.getCurrentSizeKey = getCurrentSizeKey;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,iBAAiB,GAAG,MAAM;AAClC,OAAO,CAAC,aAAa,GAAG,aAAa;AACrC,OAAO,CAAC,cAAc,GAAG,cAAc;AACvC,OAAO,CAAC,SAAS,GAAG,SAAS;AAC7B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC;AAC3C;AACA;AACA;AACA;AACA,SAAS,aAAa,CAAC,GAAG,EAAE;AAC5B,IAAI,IAAI,GAAG,GAAG,CAAC;AACf,IAAI,GAAG,GAAG,GAAG,CAAC,MAAM;AACpB,IAAI,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE;AAC7C,QAAQ,MAAM,QAAQ,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AAC1C,QAAQ,IAAI,QAAQ,GAAG,IAAI,IAAI,QAAQ,IAAI,KAAK,EAAE;AAClD,YAAY,GAAG,IAAI,CAAC;AACpB;AACA,aAAa,IAAI,QAAQ,GAAG,KAAK,IAAI,QAAQ,IAAI,MAAM,EAAE;AACzD,YAAY,GAAG,IAAI,CAAC;AACpB;AACA;AACA,QAAQ,IAAI,QAAQ,IAAI,MAAM,IAAI,QAAQ,IAAI,MAAM,EAAE;AACtD,YAAY,CAAC,IAAI,CAAC;AAClB;AACA;AACA,IAAI,OAAO,GAAG;AACd;AACA;AACA;AACA;AACA,SAAS,cAAc,GAAG;AAC1B,IAAI,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE;AAClC,IAAI,OAAO,WAAW,CAAC,OAAO,EAAE;AAChC;AACA;AACA;AACA;AACA,SAAS,SAAS,CAAC,KAAK,EAAE;AAC1B,IAAI,IAAI,MAAM,CAAC,SAAS,EAAE;AAC1B,QAAQ,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;AACtC;AACA,IAAI,QAAQ,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK;AACvF;AACA,MAAM,iBAAiB,GAAG,CAAC,SAAS,KAAK,CAAC,EAAE,SAAS,CAAC,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC;AACpF,OAAO,CAAC,iBAAiB,GAAG,iBAAiB;;"}
1
+ {"version":3,"file":"cacheHelpers.js","sources":["../../../../src/Cache/utils/cacheHelpers.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getCurrentSizeKey = void 0;\nexports.getByteLength = getByteLength;\nexports.getCurrentTime = getCurrentTime;\nexports.isInteger = isInteger;\nconst constants_1 = require(\"../constants\");\n/**\n * return the byte size of the string\n * @param str\n */\nfunction getByteLength(str) {\n let ret = 0;\n ret = str.length;\n for (let i = str.length; i >= 0; i -= 1) {\n const charCode = str.charCodeAt(i);\n if (charCode > 0x7f && charCode <= 0x7ff) {\n ret += 1;\n }\n else if (charCode > 0x7ff && charCode <= 0xffff) {\n ret += 2;\n }\n // trail surrogate\n if (charCode >= 0xdc00 && charCode <= 0xdfff) {\n i -= 1;\n }\n }\n return ret;\n}\n/**\n * get current time\n */\nfunction getCurrentTime() {\n const currentTime = new Date();\n return currentTime.getTime();\n}\n/**\n * check if passed value is an integer\n */\nfunction isInteger(value) {\n if (Number.isInteger) {\n return Number.isInteger(value);\n }\n return (typeof value === 'number' && isFinite(value) && Math.floor(value) === value);\n}\nconst getCurrentSizeKey = (keyPrefix) => `${keyPrefix}${constants_1.currentSizeKey}`;\nexports.getCurrentSizeKey = getCurrentSizeKey;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,iBAAiB,GAAG,MAAM;AAClC,OAAO,CAAC,aAAa,GAAG,aAAa;AACrC,OAAO,CAAC,cAAc,GAAG,cAAc;AACvC,OAAO,CAAC,SAAS,GAAG,SAAS;AAC7B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC;AAC3C;AACA;AACA;AACA;AACA,SAAS,aAAa,CAAC,GAAG,EAAE;AAC5B,IAAI,IAAI,GAAG,GAAG,CAAC;AACf,IAAI,GAAG,GAAG,GAAG,CAAC,MAAM;AACpB,IAAI,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE;AAC7C,QAAQ,MAAM,QAAQ,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AAC1C,QAAQ,IAAI,QAAQ,GAAG,IAAI,IAAI,QAAQ,IAAI,KAAK,EAAE;AAClD,YAAY,GAAG,IAAI,CAAC;AACpB,QAAQ;AACR,aAAa,IAAI,QAAQ,GAAG,KAAK,IAAI,QAAQ,IAAI,MAAM,EAAE;AACzD,YAAY,GAAG,IAAI,CAAC;AACpB,QAAQ;AACR;AACA,QAAQ,IAAI,QAAQ,IAAI,MAAM,IAAI,QAAQ,IAAI,MAAM,EAAE;AACtD,YAAY,CAAC,IAAI,CAAC;AAClB,QAAQ;AACR,IAAI;AACJ,IAAI,OAAO,GAAG;AACd;AACA;AACA;AACA;AACA,SAAS,cAAc,GAAG;AAC1B,IAAI,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE;AAClC,IAAI,OAAO,WAAW,CAAC,OAAO,EAAE;AAChC;AACA;AACA;AACA;AACA,SAAS,SAAS,CAAC,KAAK,EAAE;AAC1B,IAAI,IAAI,MAAM,CAAC,SAAS,EAAE;AAC1B,QAAQ,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;AACtC,IAAI;AACJ,IAAI,QAAQ,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK;AACvF;AACA,MAAM,iBAAiB,GAAG,CAAC,SAAS,KAAK,CAAC,EAAE,SAAS,CAAC,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC;AACpF,OAAO,CAAC,iBAAiB,GAAG,iBAAiB;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/Cache/utils/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.CacheList = exports.isInteger = exports.getCurrentTime = exports.getCurrentSizeKey = exports.getByteLength = void 0;\nvar cacheHelpers_1 = require(\"./cacheHelpers\");\nObject.defineProperty(exports, \"getByteLength\", { enumerable: true, get: function () { return cacheHelpers_1.getByteLength; } });\nObject.defineProperty(exports, \"getCurrentSizeKey\", { enumerable: true, get: function () { return cacheHelpers_1.getCurrentSizeKey; } });\nObject.defineProperty(exports, \"getCurrentTime\", { enumerable: true, get: function () { return cacheHelpers_1.getCurrentTime; } });\nObject.defineProperty(exports, \"isInteger\", { enumerable: true, get: function () { return cacheHelpers_1.isInteger; } });\nvar CacheList_1 = require(\"./CacheList\");\nObject.defineProperty(exports, \"CacheList\", { enumerable: true, get: function () { return CacheList_1.CacheList; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,iBAAiB,GAAG,OAAO,CAAC,aAAa,GAAG,MAAM;AAC3H,IAAI,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC;AAC9C,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,cAAc,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;AAChI,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,mBAAmB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,cAAc,CAAC,iBAAiB,CAAC,EAAE,EAAE,CAAC;AACxI,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,cAAc,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC;AAClI,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,cAAc,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC;AACxH,IAAI,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;AACxC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,WAAW,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/Cache/utils/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.CacheList = exports.isInteger = exports.getCurrentTime = exports.getCurrentSizeKey = exports.getByteLength = void 0;\nvar cacheHelpers_1 = require(\"./cacheHelpers\");\nObject.defineProperty(exports, \"getByteLength\", { enumerable: true, get: function () { return cacheHelpers_1.getByteLength; } });\nObject.defineProperty(exports, \"getCurrentSizeKey\", { enumerable: true, get: function () { return cacheHelpers_1.getCurrentSizeKey; } });\nObject.defineProperty(exports, \"getCurrentTime\", { enumerable: true, get: function () { return cacheHelpers_1.getCurrentTime; } });\nObject.defineProperty(exports, \"isInteger\", { enumerable: true, get: function () { return cacheHelpers_1.isInteger; } });\nvar CacheList_1 = require(\"./CacheList\");\nObject.defineProperty(exports, \"CacheList\", { enumerable: true, get: function () { return CacheList_1.CacheList; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,iBAAiB,GAAG,OAAO,CAAC,aAAa,GAAG,MAAM;AAC3H,IAAI,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC;AAC9C,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,cAAc,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;AAChI,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,mBAAmB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC;AACxI,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;AAClI,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;AACxH,IAAI,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;AACxC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/Hub/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.HubInternal = exports.Hub = exports.HubClass = exports.AMPLIFY_SYMBOL = void 0;\nconst Logger_1 = require(\"../Logger\");\nconst constants_1 = require(\"../constants\");\nconst errors_1 = require(\"../errors\");\nexports.AMPLIFY_SYMBOL = (typeof Symbol !== 'undefined'\n ? Symbol('amplify_default')\n : '@@amplify_default');\nconst logger = new Logger_1.ConsoleLogger('Hub');\nclass HubClass {\n constructor(name) {\n this.listeners = new Map();\n this.protectedChannels = [\n 'core',\n 'auth',\n 'api',\n 'analytics',\n 'interactions',\n 'pubsub',\n 'storage',\n 'ui',\n 'xr',\n ];\n this.name = name;\n }\n /**\n * Used internally to remove a Hub listener.\n *\n * @remarks\n * This private method is for internal use only. Instead of calling Hub.remove, call the result of Hub.listen.\n */\n _remove(channel, listener) {\n const holder = this.listeners.get(channel);\n if (!holder) {\n logger.warn(`No listeners for ${channel}`);\n return;\n }\n this.listeners.set(channel, [\n ...holder.filter(({ callback }) => callback !== listener),\n ]);\n }\n dispatch(channel, payload, source, ampSymbol) {\n if (typeof channel === 'string' &&\n this.protectedChannels.indexOf(channel) > -1) {\n const hasAccess = ampSymbol === exports.AMPLIFY_SYMBOL;\n if (!hasAccess) {\n logger.warn(`WARNING: ${channel} is protected and dispatching on it can have unintended consequences`);\n }\n }\n const capsule = {\n channel,\n payload: { ...payload },\n source,\n patternInfo: [],\n };\n try {\n this._toListeners(capsule);\n }\n catch (e) {\n logger.error(e);\n }\n }\n listen(channel, callback, listenerName = 'noname') {\n let cb;\n if (typeof callback !== 'function') {\n throw new errors_1.AmplifyError({\n name: constants_1.NO_HUBCALLBACK_PROVIDED_EXCEPTION,\n message: 'No callback supplied to Hub',\n });\n }\n else {\n // Needs to be casted as a more generic type\n cb = callback;\n }\n let holder = this.listeners.get(channel);\n if (!holder) {\n holder = [];\n this.listeners.set(channel, holder);\n }\n holder.push({\n name: listenerName,\n callback: cb,\n });\n return () => {\n this._remove(channel, cb);\n };\n }\n _toListeners(capsule) {\n const { channel, payload } = capsule;\n const holder = this.listeners.get(channel);\n if (holder) {\n holder.forEach(listener => {\n logger.debug(`Dispatching to ${channel} with `, payload);\n try {\n listener.callback(capsule);\n }\n catch (e) {\n logger.error(e);\n }\n });\n }\n }\n}\nexports.HubClass = HubClass;\n/* We export a __default__ instance of HubClass to use it as a\npseudo Singleton for the main messaging bus, however you can still create\nyour own instance of HubClass() for a separate \"private bus\" of events. */\nexports.Hub = new HubClass('__default__');\n/**\n * @internal\n *\n * Internal hub used for core Amplify functionality. Not intended for use outside of Amplify.\n *\n */\nexports.HubInternal = new HubClass('internal-hub');\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI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AAQ,IAAI,CAAC,MAAM,EAAE;AACrB,YAAY,MAAM,GAAG,EAAE;AACvB,YAAY,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC;AAC/C;AACA,QAAQ,MAAM,CAAC,IAAI,CAAC;AACpB,YAAY,IAAI,EAAE,YAAY;AAC9B,YAAY,QAAQ,EAAE,EAAE;AACxB,SAAS,CAAC;AACV,QAAQ,OAAO,MAAM;AACrB,YAAY,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;AACrC,SAAS;AACT;AACA,IAAI,YAAY,CAAC,OAAO,EAAE;AAC1B,QAAQ,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,OAAO;AAC5C,QAAQ,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC;AAClD,QAAQ,IAAI,MAAM,EAAE;AACpB,YAAY,MAAM,CAAC,OAAO,CAAC,QAAQ,IAAI;AACvC,gBAAgB,MAAM,CAAC,KAAK,CAAC,CAAC,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;AACxE,gBAAgB,IAAI;AACpB,oBAAoB,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC;AAC9C;AACA,gBAAgB,OAAO,CAAC,EAAE;AAC1B,oBAAoB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACnC;AACA,aAAa,CAAC;AACd;AACA;AACA;AACA,OAAO,CAAC,QAAQ,GAAG,QAAQ;AAC3B;AACA;AACA;AACA,OAAO,CAAC,GAAG,GAAG,IAAI,QAAQ,CAAC,aAAa,CAAC;AACzC;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,CAAC,WAAW,GAAG,IAAI,QAAQ,CAAC,cAAc,CAAC;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/Hub/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.HubInternal = exports.Hub = exports.HubClass = exports.AMPLIFY_SYMBOL = void 0;\nconst Logger_1 = require(\"../Logger\");\nconst constants_1 = require(\"../constants\");\nconst errors_1 = require(\"../errors\");\nexports.AMPLIFY_SYMBOL = (typeof Symbol !== 'undefined'\n ? Symbol('amplify_default')\n : '@@amplify_default');\nconst logger = new Logger_1.ConsoleLogger('Hub');\nclass HubClass {\n constructor(name) {\n this.listeners = new Map();\n this.protectedChannels = [\n 'core',\n 'auth',\n 'api',\n 'analytics',\n 'interactions',\n 'pubsub',\n 'storage',\n 'ui',\n 'xr',\n ];\n this.name = name;\n }\n /**\n * Used internally to remove a Hub listener.\n *\n * @remarks\n * This private method is for internal use only. Instead of calling Hub.remove, call the result of Hub.listen.\n */\n _remove(channel, listener) {\n const holder = this.listeners.get(channel);\n if (!holder) {\n logger.warn(`No listeners for ${channel}`);\n return;\n }\n this.listeners.set(channel, [\n ...holder.filter(({ callback }) => callback !== listener),\n ]);\n }\n dispatch(channel, payload, source, ampSymbol) {\n if (typeof channel === 'string' &&\n this.protectedChannels.indexOf(channel) > -1) {\n const hasAccess = ampSymbol === exports.AMPLIFY_SYMBOL;\n if (!hasAccess) {\n logger.warn(`WARNING: ${channel} is protected and dispatching on it can have unintended consequences`);\n }\n }\n const capsule = {\n channel,\n payload: { ...payload },\n source,\n patternInfo: [],\n };\n try {\n this._toListeners(capsule);\n }\n catch (e) {\n logger.error(e);\n }\n }\n listen(channel, callback, listenerName = 'noname') {\n let cb;\n if (typeof callback !== 'function') {\n throw new errors_1.AmplifyError({\n name: constants_1.NO_HUBCALLBACK_PROVIDED_EXCEPTION,\n message: 'No callback supplied to Hub',\n });\n }\n else {\n // Needs to be casted as a more generic type\n cb = callback;\n }\n let holder = this.listeners.get(channel);\n if (!holder) {\n holder = [];\n this.listeners.set(channel, holder);\n }\n holder.push({\n name: listenerName,\n callback: cb,\n });\n return () => {\n this._remove(channel, cb);\n };\n }\n _toListeners(capsule) {\n const { channel, payload } = capsule;\n const holder = this.listeners.get(channel);\n if (holder) {\n holder.forEach(listener => {\n logger.debug(`Dispatching to ${channel} with `, payload);\n try {\n listener.callback(capsule);\n }\n catch (e) {\n logger.error(e);\n }\n });\n }\n }\n}\nexports.HubClass = HubClass;\n/* We export a __default__ instance of HubClass to use it as a\npseudo Singleton for the main messaging bus, however you can still create\nyour own instance of HubClass() for a separate \"private bus\" of events. */\nexports.Hub = new HubClass('__default__');\n/**\n * @internal\n *\n * Internal hub used for core Amplify functionality. Not intended for use outside of Amplify.\n *\n */\nexports.HubInternal = new HubClass('internal-hub');\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,cAAc,GAAG,MAAM;AACtF,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;AACrC,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC;AAC3C,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;AACrC,OAAO,CAAC,cAAc,IAAI,OAAO,MAAM,KAAK;AAC5C,MAAM,MAAM,CAAC,iBAAiB;AAC9B,MAAM,mBAAmB,CAAC;AAC1B,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC;AAChD,MAAM,QAAQ,CAAC;AACf,IAAI,WAAW,CAAC,IAAI,EAAE;AACtB,QAAQ,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE;AAClC,QAAQ,IAAI,CAAC,iBAAiB,GAAG;AACjC,YAAY,MAAM;AAClB,YAAY,MAAM;AAClB,YAAY,KAAK;AACjB,YAAY,WAAW;AACvB,YAAY,cAAc;AAC1B,YAAY,QA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ACvC,gBAAgB,MAAM,CAAC,KAAK,CAAC,CAAC,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;AACxE,gBAAgB,IAAI;AACpB,oBAAoB,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC;AAC9C,gBAAgB;AAChB,gBAAgB,OAAO,CAAC,EAAE;AAC1B,oBAAoB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACnC,gBAAgB;AAChB,YAAY,CAAC,CAAC;AACd,QAAQ;AACR,IAAI;AACJ;AACA,OAAO,CAAC,QAAQ,GAAG,QAAQ;AAC3B;AACA;AACA;AACA,OAAO,CAAC,GAAG,GAAG,IAAI,QAAQ,CAAC,aAAa,CAAC;AACzC;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,CAAC,WAAW,GAAG,IAAI,QAAQ,CAAC,cAAc,CAAC;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"I18n.js","sources":["../../../src/I18n/I18n.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.I18n = void 0;\nconst Logger_1 = require(\"../Logger\");\nconst logger = new Logger_1.ConsoleLogger('I18n');\n/**\n * Language translation utility.\n */\nclass I18n {\n constructor() {\n /**\n * @private\n */\n this._options = null;\n /**\n * @private\n */\n this._lang = null;\n /**\n * @private\n */\n this._dict = {};\n }\n /**\n * Sets the default language from the configuration when required.\n */\n setDefaultLanguage() {\n // Default to window language if not set in instance\n if (!this._lang &&\n typeof window !== 'undefined' &&\n window &&\n window.navigator) {\n this._lang = window.navigator.language;\n }\n logger.debug(this._lang);\n }\n /**\n * @method\n * Explicitly setting language\n * @param {String} lang\n */\n setLanguage(lang) {\n this._lang = lang;\n }\n /**\n * @method\n * Get value\n * @param {String} key\n * @param {String} defVal - Default value\n */\n get(key, defVal = undefined) {\n this.setDefaultLanguage();\n if (!this._lang) {\n return typeof defVal !== 'undefined' ? defVal : key;\n }\n const lang = this._lang;\n let val = this.getByLanguage(key, lang);\n if (val) {\n return val;\n }\n if (lang.indexOf('-') > 0) {\n val = this.getByLanguage(key, lang.split('-')[0]);\n }\n if (val) {\n return val;\n }\n return typeof defVal !== 'undefined' ? defVal : key;\n }\n /**\n * @method\n * Get value according to specified language\n * @param {String} key\n * @param {String} language - Specified langurage to be used\n * @param {String} defVal - Default value\n */\n getByLanguage(key, language, defVal = null) {\n if (!language) {\n return defVal;\n }\n const langDict = this._dict[language];\n if (!langDict) {\n return defVal;\n }\n return langDict[key];\n }\n /**\n * @method\n * Add vocabularies for one language\n * @param {String} language - Language of the dictionary\n * @param {Object} vocabularies - Object that has key-value as dictionary entry\n */\n putVocabulariesForLanguage(language, vocabularies) {\n let langDict = this._dict[language];\n if (!langDict) {\n langDict = this._dict[language] = {};\n }\n this._dict[language] = { ...langDict, ...vocabularies };\n }\n /**\n * @method\n * Add vocabularies for one language\n * @param {Object} vocabularies - Object that has language as key,\n * vocabularies of each language as value\n */\n putVocabularies(vocabularies) {\n Object.keys(vocabularies).forEach(key => {\n this.putVocabulariesForLanguage(key, vocabularies[key]);\n });\n }\n}\nexports.I18n = I18n;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,IAAI,GAAG,MAAM;AACrB,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;AACrC,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC;AACjD;AACA;AACA;AACA,MAAM,IAAI,CAAC;AACX,IAAI,WAAW,GAAG;AAClB;AACA;AACA;AACA,QAAQ,IAAI,CAAC,QAAQ,GAAG,IAAI;AAC5B;AACA;AACA;AACA,QAAQ,IAAI,CAAC,KAAK,GAAG,IAAI;AACzB;AACA;AACA;A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AG,GAAG;AAC3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,aAAa,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE;AAChD,QAAQ,IAAI,CAAC,QAAQ,EAAE;AACvB,YAAY,OAAO,MAAM;AACzB;AACA,QAAQ,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;AAC7C,QAAQ,IAAI,CAAC,QAAQ,EAAE;AACvB,YAAY,OAAO,MAAM;AACzB;AACA,QAAQ,OAAO,QAAQ,CAAC,GAAG,CAAC;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,0BAA0B,CAAC,QAAQ,EAAE,YAAY,EAAE;AACvD,QAAQ,IAAI,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;AAC3C,QAAQ,IAAI,CAAC,QAAQ,EAAE;AACvB,YAAY,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE;AAChD;AACA,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,YAAY,EAAE;AAC/D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,eAAe,CAAC,YAAY,EAAE;AAClC,QAAQ,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,GAAG,IAAI;AACjD,YAAY,IAAI,CAAC,0BAA0B,CAAC,GAAG,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;AACnE,SAAS,CAAC;AACV;AACA;AACA,OAAO,CAAC,IAAI,GAAG,IAAI;;"}
1
+ {"version":3,"file":"I18n.js","sources":["../../../src/I18n/I18n.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.I18n = void 0;\nconst Logger_1 = require(\"../Logger\");\nconst logger = new Logger_1.ConsoleLogger('I18n');\n/**\n * Language translation utility.\n */\nclass I18n {\n constructor() {\n /**\n * @private\n */\n this._options = null;\n /**\n * @private\n */\n this._lang = null;\n /**\n * @private\n */\n this._dict = {};\n }\n /**\n * Sets the default language from the configuration when required.\n */\n setDefaultLanguage() {\n // Default to window language if not set in instance\n if (!this._lang &&\n typeof window !== 'undefined' &&\n window &&\n window.navigator) {\n this._lang = window.navigator.language;\n }\n logger.debug(this._lang);\n }\n /**\n * @method\n * Explicitly setting language\n * @param {String} lang\n */\n setLanguage(lang) {\n this._lang = lang;\n }\n /**\n * @method\n * Get value\n * @param {String} key\n * @param {String} defVal - Default value\n */\n get(key, defVal = undefined) {\n this.setDefaultLanguage();\n if (!this._lang) {\n return typeof defVal !== 'undefined' ? defVal : key;\n }\n const lang = this._lang;\n let val = this.getByLanguage(key, lang);\n if (val) {\n return val;\n }\n if (lang.indexOf('-') > 0) {\n val = this.getByLanguage(key, lang.split('-')[0]);\n }\n if (val) {\n return val;\n }\n return typeof defVal !== 'undefined' ? defVal : key;\n }\n /**\n * @method\n * Get value according to specified language\n * @param {String} key\n * @param {String} language - Specified langurage to be used\n * @param {String} defVal - Default value\n */\n getByLanguage(key, language, defVal = null) {\n if (!language) {\n return defVal;\n }\n const langDict = this._dict[language];\n if (!langDict) {\n return defVal;\n }\n return langDict[key];\n }\n /**\n * @method\n * Add vocabularies for one language\n * @param {String} language - Language of the dictionary\n * @param {Object} vocabularies - Object that has key-value as dictionary entry\n */\n putVocabulariesForLanguage(language, vocabularies) {\n let langDict = this._dict[language];\n if (!langDict) {\n langDict = this._dict[language] = {};\n }\n this._dict[language] = { ...langDict, ...vocabularies };\n }\n /**\n * @method\n * Add vocabularies for one language\n * @param {Object} vocabularies - Object that has language as key,\n * vocabularies of each language as value\n */\n putVocabularies(vocabularies) {\n Object.keys(vocabularies).forEach(key => {\n this.putVocabulariesForLanguage(key, vocabularies[key]);\n });\n }\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R,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,YAAY,EAAE;AAC/D,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,eAAe,CAAC,YAAY,EAAE;AAClC,QAAQ,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,GAAG,IAAI;AACjD,YAAY,IAAI,CAAC,0BAA0B,CAAC,GAAG,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;AACnE,QAAQ,CAAC,CAAC;AACV,IAAI;AACJ;AACA,OAAO,CAAC,IAAI,GAAG,IAAI;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/I18n/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.I18n = void 0;\nconst Logger_1 = require(\"../Logger\");\nconst I18n_1 = require(\"./I18n\");\nconst errorHelpers_1 = require(\"./errorHelpers\");\nconst logger = new Logger_1.ConsoleLogger('I18n');\nlet _config = { language: null };\nlet _i18n = null;\n/**\n * Export I18n APIs\n */\nclass I18n {\n /**\n * @static\n * @method\n * Configure I18n part\n * @param {Object} config - Configuration of the I18n\n */\n static configure(config) {\n logger.debug('configure I18n');\n if (!config) {\n return _config;\n }\n _config = Object.assign({}, _config, config.I18n || config);\n I18n.createInstance();\n return _config;\n }\n static getModuleName() {\n return 'I18n';\n }\n /**\n * @static\n * @method\n * Create an instance of I18n for the library\n */\n static createInstance() {\n logger.debug('create I18n instance');\n if (_i18n) {\n return;\n }\n _i18n = new I18n_1.I18n();\n }\n /**\n * @static @method\n * Explicitly setting language\n * @param {String} lang\n */\n static setLanguage(lang) {\n I18n.checkConfig();\n (0, errorHelpers_1.assert)(!!_i18n, errorHelpers_1.I18nErrorCode.NotConfigured);\n _i18n.setLanguage(lang);\n }\n /**\n * @static @method\n * Get value\n * @param {String} key\n * @param {String} defVal - Default value\n */\n static get(key, defVal) {\n if (!I18n.checkConfig()) {\n return typeof defVal === 'undefined' ? key : defVal;\n }\n (0, errorHelpers_1.assert)(!!_i18n, errorHelpers_1.I18nErrorCode.NotConfigured);\n return _i18n.get(key, defVal);\n }\n /**\n * @static\n * @method\n * Add vocabularies for one language\n * @param {String} language - Language of the dictionary\n * @param {Object} vocabularies - Object that has key-value as dictionary entry\n */\n static putVocabulariesForLanguage(language, vocabularies) {\n I18n.checkConfig();\n (0, errorHelpers_1.assert)(!!_i18n, errorHelpers_1.I18nErrorCode.NotConfigured);\n _i18n.putVocabulariesForLanguage(language, vocabularies);\n }\n /**\n * @static\n * @method\n * Add vocabularies for one language\n * @param {Object} vocabularies - Object that has language as key,\n * vocabularies of each language as value\n */\n static putVocabularies(vocabularies) {\n I18n.checkConfig();\n (0, errorHelpers_1.assert)(!!_i18n, errorHelpers_1.I18nErrorCode.NotConfigured);\n _i18n.putVocabularies(vocabularies);\n }\n static checkConfig() {\n if (!_i18n) {\n I18n.createInstance();\n }\n return true;\n }\n}\nexports.I18n = I18n;\n// Create an instance of I18n in the static class\nI18n.createInstance();\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,IAAI,GAAG,MAAM;AACrB,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;AACrC,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;AAChC,MAAM,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC;AAChD,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC;AACjD,IAAI,OAAO,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE;AAChC,IAAI,KAAK,GAAG,IAAI;AAChB;AACA;AACA;AACA,MAAM,I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AAC;AACvF,QAAQ,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC;AACrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,OAAO,0BAA0B,CAAC,QAAQ,EAAE,YAAY,EAAE;AAC9D,QAAQ,IAAI,CAAC,WAAW,EAAE;AAC1B,QAAQ,IAAI,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,EAAE,cAAc,CAAC,aAAa,CAAC,aAAa,CAAC;AACvF,QAAQ,KAAK,CAAC,0BAA0B,CAAC,QAAQ,EAAE,YAAY,CAAC;AAChE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,OAAO,eAAe,CAAC,YAAY,EAAE;AACzC,QAAQ,IAAI,CAAC,WAAW,EAAE;AAC1B,QAAQ,IAAI,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,EAAE,cAAc,CAAC,aAAa,CAAC,aAAa,CAAC;AACvF,QAAQ,KAAK,CAAC,eAAe,CAAC,YAAY,CAAC;AAC3C;AACA,IAAI,OAAO,WAAW,GAAG;AACzB,QAAQ,IAAI,CAAC,KAAK,EAAE;AACpB,YAAY,IAAI,CAAC,cAAc,EAAE;AACjC;AACA,QAAQ,OAAO,IAAI;AACnB;AACA;AACA,OAAO,CAAC,IAAI,GAAG,IAAI;AACnB;AACA,IAAI,CAAC,cAAc,EAAE;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/I18n/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.I18n = void 0;\nconst Logger_1 = require(\"../Logger\");\nconst I18n_1 = require(\"./I18n\");\nconst errorHelpers_1 = require(\"./errorHelpers\");\nconst logger = new Logger_1.ConsoleLogger('I18n');\nlet _config = { language: null };\nlet _i18n = null;\n/**\n * Export I18n APIs\n */\nclass I18n {\n /**\n * @static\n * @method\n * Configure I18n part\n * @param {Object} config - Configuration of the I18n\n */\n static configure(config) {\n logger.debug('configure I18n');\n if (!config) {\n return _config;\n }\n _config = Object.assign({}, _config, config.I18n || config);\n I18n.createInstance();\n return _config;\n }\n static getModuleName() {\n return 'I18n';\n }\n /**\n * @static\n * @method\n * Create an instance of I18n for the library\n */\n static createInstance() {\n logger.debug('create I18n instance');\n if (_i18n) {\n return;\n }\n _i18n = new I18n_1.I18n();\n }\n /**\n * @static @method\n * Explicitly setting language\n * @param {String} lang\n */\n static setLanguage(lang) {\n I18n.checkConfig();\n (0, errorHelpers_1.assert)(!!_i18n, errorHelpers_1.I18nErrorCode.NotConfigured);\n _i18n.setLanguage(lang);\n }\n /**\n * @static @method\n * Get value\n * @param {String} key\n * @param {String} defVal - Default value\n */\n static get(key, defVal) {\n if (!I18n.checkConfig()) {\n return typeof defVal === 'undefined' ? key : defVal;\n }\n (0, errorHelpers_1.assert)(!!_i18n, errorHelpers_1.I18nErrorCode.NotConfigured);\n return _i18n.get(key, defVal);\n }\n /**\n * @static\n * @method\n * Add vocabularies for one language\n * @param {String} language - Language of the dictionary\n * @param {Object} vocabularies - Object that has key-value as dictionary entry\n */\n static putVocabulariesForLanguage(language, vocabularies) {\n I18n.checkConfig();\n (0, errorHelpers_1.assert)(!!_i18n, errorHelpers_1.I18nErrorCode.NotConfigured);\n _i18n.putVocabulariesForLanguage(language, vocabularies);\n }\n /**\n * @static\n * @method\n * Add vocabularies for one language\n * @param {Object} vocabularies - Object that has language as key,\n * vocabularies of each language as value\n */\n static putVocabularies(vocabularies) {\n I18n.checkConfig();\n (0, errorHelpers_1.assert)(!!_i18n, errorHelpers_1.I18nErrorCode.NotConfigured);\n _i18n.putVocabularies(vocabularies);\n }\n static checkConfig() {\n if (!_i18n) {\n I18n.createInstance();\n }\n return true;\n }\n}\nexports.I18n = I18n;\n// Create an instance of I18n in the static class\nI18n.createInstance();\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,C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EAAE;AACpB,YAAY,IAAI,CAAC,cAAc,EAAE;AACjC,QAAQ;AACR,QAAQ,OAAO,IAAI;AACnB,IAAI;AACJ;AACA,OAAO,CAAC,IAAI,GAAG,IAAI;AACnB;AACA,IAAI,CAAC,cAAc,EAAE;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../../../src/I18n/types.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.I18nConfig = void 0;\nclass I18nConfig {\n constructor() {\n this.language = null;\n }\n}\nexports.I18nConfig = I18nConfig;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,UAAU,GAAG,MAAM;AAC3B,MAAM,UAAU,CAAC;AACjB,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,CAAC,QAAQ,GAAG,IAAI;AAC5B;AACA;AACA,OAAO,CAAC,UAAU,GAAG,UAAU;;"}
1
+ {"version":3,"file":"types.js","sources":["../../../src/I18n/types.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.I18nConfig = void 0;\nclass I18nConfig {\n constructor() {\n this.language = null;\n }\n}\nexports.I18nConfig = I18nConfig;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,UAAU,GAAG,MAAM;AAC3B,MAAM,UAAU,CAAC;AACjB,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,CAAC,QAAQ,GAAG,IAAI;AAC5B,IAAI;AACJ;AACA,OAAO,CAAC,UAAU,GAAG,UAAU;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ConsoleLogger.js","sources":["../../../src/Logger/ConsoleLogger.ts"],"sourcesContent":["\"use strict\";\n/* eslint-disable no-console */\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ConsoleLogger = void 0;\nconst constants_1 = require(\"../constants\");\nconst types_1 = require(\"./types\");\nconst LOG_LEVELS = {\n VERBOSE: 1,\n DEBUG: 2,\n INFO: 3,\n WARN: 4,\n ERROR: 5,\n NONE: 6,\n};\n/**\n * Write logs\n * @class Logger\n */\nclass ConsoleLogger {\n /**\n * @constructor\n * @param {string} name - Name of the logger\n */\n constructor(name, level = types_1.LogType.WARN) {\n this.name = name;\n this.level = level;\n this._pluggables = [];\n }\n _padding(n) {\n return n < 10 ? '0' + n : '' + n;\n }\n _ts() {\n const dt = new Date();\n return ([this._padding(dt.getMinutes()), this._padding(dt.getSeconds())].join(':') +\n '.' +\n dt.getMilliseconds());\n }\n configure(config) {\n if (!config)\n return this._config;\n this._config = config;\n return this._config;\n }\n /**\n * Write log\n * @method\n * @memeberof Logger\n * @param {LogType|string} type - log type, default INFO\n * @param {string|object} msg - Logging message or object\n */\n _log(type, ...msg) {\n let loggerLevelName = this.level;\n if (ConsoleLogger.LOG_LEVEL) {\n loggerLevelName = ConsoleLogger.LOG_LEVEL;\n }\n if (typeof window !== 'undefined' && window.LOG_LEVEL) {\n loggerLevelName = window.LOG_LEVEL;\n }\n const loggerLevel = LOG_LEVELS[loggerLevelName];\n const typeLevel = LOG_LEVELS[type];\n if (!(typeLevel >= loggerLevel)) {\n // Do nothing if type is not greater than or equal to logger level (handle undefined)\n return;\n }\n let log = console.log.bind(console);\n if (type === types_1.LogType.ERROR && console.error) {\n log = console.error.bind(console);\n }\n if (type === types_1.LogType.WARN && console.warn) {\n log = console.warn.bind(console);\n }\n if (ConsoleLogger.BIND_ALL_LOG_LEVELS) {\n if (type === types_1.LogType.INFO && console.info) {\n log = console.info.bind(console);\n }\n if (type === types_1.LogType.DEBUG && console.debug) {\n log = console.debug.bind(console);\n }\n }\n const prefix = `[${type}] ${this._ts()} ${this.name}`;\n let message = '';\n if (msg.length === 1 && typeof msg[0] === 'string') {\n message = `${prefix} - ${msg[0]}`;\n log(message);\n }\n else if (msg.length === 1) {\n message = `${prefix} ${msg[0]}`;\n log(prefix, msg[0]);\n }\n else if (typeof msg[0] === 'string') {\n let obj = msg.slice(1);\n if (obj.length === 1) {\n obj = obj[0];\n }\n message = `${prefix} - ${msg[0]} ${obj}`;\n log(`${prefix} - ${msg[0]}`, obj);\n }\n else {\n message = `${prefix} ${msg}`;\n log(prefix, msg);\n }\n for (const plugin of this._pluggables) {\n const logEvent = { message, timestamp: Date.now() };\n plugin.pushLogs([logEvent]);\n }\n }\n /**\n * Write General log. Default to INFO\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n log(...msg) {\n this._log(types_1.LogType.INFO, ...msg);\n }\n /**\n * Write INFO log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n info(...msg) {\n this._log(types_1.LogType.INFO, ...msg);\n }\n /**\n * Write WARN log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n warn(...msg) {\n this._log(types_1.LogType.WARN, ...msg);\n }\n /**\n * Write ERROR log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n error(...msg) {\n this._log(types_1.LogType.ERROR, ...msg);\n }\n /**\n * Write DEBUG log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n debug(...msg) {\n this._log(types_1.LogType.DEBUG, ...msg);\n }\n /**\n * Write VERBOSE log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n verbose(...msg) {\n this._log(types_1.LogType.VERBOSE, ...msg);\n }\n addPluggable(pluggable) {\n if (pluggable && pluggable.getCategoryName() === constants_1.AWS_CLOUDWATCH_CATEGORY) {\n this._pluggables.push(pluggable);\n pluggable.configure(this._config);\n }\n }\n listPluggables() {\n return this._pluggables;\n }\n}\nexports.ConsoleLogger = ConsoleLogger;\nConsoleLogger.LOG_LEVEL = null;\nConsoleLogger.BIND_ALL_LOG_LEVELS = false;\n"],"names":[],"mappings":";;AACA;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,aAAa,GAAG,MAAM;AAC9B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC;AAC3C,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;AAClC,MAAM,UAAU,GAAG;AACnB,IAAI,OAAO,EAAE,CAAC;AACd,IAAI,KAAK,EAAE,CAAC;AACZ,IAAI,IAAI,EAAE,CAAC;AACX,IAAI,IAAI,EAAE,CAAC;AACX,IAAI,KAAK,EAAE,CAAC;AACZ,IAAI,IAAI,EAAE,CAAC;AACX,CAAC;AACD;AACA;AACA;AACA;AACA,MAAM,aAAa,CAAC;AACpB;AACA;AACA;AACA;AACA,IAAI,WAAW,CAAC,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE;AACpD,QAAQ,IAAI,CAAC,IAAI,GAAG,IAAI;AACxB,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK;AAC1B,QAAQ,IAAI,CAAC,WAAW,GAAG,EAAE;AAC7B;AACA,IAAI,QAAQ,CAAC,CAAC,EAAE;AAChB,QAAQ,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC;AACxC;AACA,IAAI,GAAG,GAAG;AACV,QAAQ,MAAM,EAAE,GAAG,IAAI,IAAI,EAAE;AAC7B,QAAQ,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,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C,OAAO,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC;AAC/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,KAAK,CAAC,GAAG,GAAG,EAAE;AAClB,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC;AAChD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,KAAK,CAAC,GAAG,GAAG,EAAE;AAClB,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC;AAChD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,OAAO,CAAC,GAAG,GAAG,EAAE;AACpB,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,GAAG,CAAC;AAClD;AACA,IAAI,YAAY,CAAC,SAAS,EAAE;AAC5B,QAAQ,IAAI,SAAS,IAAI,SAAS,CAAC,eAAe,EAAE,KAAK,WAAW,CAAC,uBAAuB,EAAE;AAC9F,YAAY,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC;AAC5C,YAAY,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC;AAC7C;AACA;AACA,IAAI,cAAc,GAAG;AACrB,QAAQ,OAAO,IAAI,CAAC,WAAW;AAC/B;AACA;AACA,OAAO,CAAC,aAAa,GAAG,aAAa;AACrC,aAAa,CAAC,SAAS,GAAG,IAAI;AAC9B,aAAa,CAAC,mBAAmB,GAAG,KAAK;;"}
1
+ {"version":3,"file":"ConsoleLogger.js","sources":["../../../src/Logger/ConsoleLogger.ts"],"sourcesContent":["\"use strict\";\n/* eslint-disable no-console */\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ConsoleLogger = void 0;\nconst constants_1 = require(\"../constants\");\nconst types_1 = require(\"./types\");\nconst LOG_LEVELS = {\n VERBOSE: 1,\n DEBUG: 2,\n INFO: 3,\n WARN: 4,\n ERROR: 5,\n NONE: 6,\n};\n/**\n * Write logs\n * @class Logger\n */\nclass ConsoleLogger {\n /**\n * @constructor\n * @param {string} name - Name of the logger\n */\n constructor(name, level = types_1.LogType.WARN) {\n this.name = name;\n this.level = level;\n this._pluggables = [];\n }\n _padding(n) {\n return n < 10 ? '0' + n : '' + n;\n }\n _ts() {\n const dt = new Date();\n return ([this._padding(dt.getMinutes()), this._padding(dt.getSeconds())].join(':') +\n '.' +\n dt.getMilliseconds());\n }\n configure(config) {\n if (!config)\n return this._config;\n this._config = config;\n return this._config;\n }\n /**\n * Write log\n * @method\n * @memeberof Logger\n * @param {LogType|string} type - log type, default INFO\n * @param {string|object} msg - Logging message or object\n */\n _log(type, ...msg) {\n let loggerLevelName = this.level;\n if (ConsoleLogger.LOG_LEVEL) {\n loggerLevelName = ConsoleLogger.LOG_LEVEL;\n }\n if (typeof window !== 'undefined' && window.LOG_LEVEL) {\n loggerLevelName = window.LOG_LEVEL;\n }\n const loggerLevel = LOG_LEVELS[loggerLevelName];\n const typeLevel = LOG_LEVELS[type];\n if (!(typeLevel >= loggerLevel)) {\n // Do nothing if type is not greater than or equal to logger level (handle undefined)\n return;\n }\n let log = console.log.bind(console);\n if (type === types_1.LogType.ERROR && console.error) {\n log = console.error.bind(console);\n }\n if (type === types_1.LogType.WARN && console.warn) {\n log = console.warn.bind(console);\n }\n if (ConsoleLogger.BIND_ALL_LOG_LEVELS) {\n if (type === types_1.LogType.INFO && console.info) {\n log = console.info.bind(console);\n }\n if (type === types_1.LogType.DEBUG && console.debug) {\n log = console.debug.bind(console);\n }\n }\n const prefix = `[${type}] ${this._ts()} ${this.name}`;\n let message = '';\n if (msg.length === 1 && typeof msg[0] === 'string') {\n message = `${prefix} - ${msg[0]}`;\n log(message);\n }\n else if (msg.length === 1) {\n message = `${prefix} ${msg[0]}`;\n log(prefix, msg[0]);\n }\n else if (typeof msg[0] === 'string') {\n let obj = msg.slice(1);\n if (obj.length === 1) {\n obj = obj[0];\n }\n message = `${prefix} - ${msg[0]} ${obj}`;\n log(`${prefix} - ${msg[0]}`, obj);\n }\n else {\n message = `${prefix} ${msg}`;\n log(prefix, msg);\n }\n for (const plugin of this._pluggables) {\n const logEvent = { message, timestamp: Date.now() };\n plugin.pushLogs([logEvent]);\n }\n }\n /**\n * Write General log. Default to INFO\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n log(...msg) {\n this._log(types_1.LogType.INFO, ...msg);\n }\n /**\n * Write INFO log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n info(...msg) {\n this._log(types_1.LogType.INFO, ...msg);\n }\n /**\n * Write WARN log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n warn(...msg) {\n this._log(types_1.LogType.WARN, ...msg);\n }\n /**\n * Write ERROR log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n error(...msg) {\n this._log(types_1.LogType.ERROR, ...msg);\n }\n /**\n * Write DEBUG log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n debug(...msg) {\n this._log(types_1.LogType.DEBUG, ...msg);\n }\n /**\n * Write VERBOSE log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n verbose(...msg) {\n this._log(types_1.LogType.VERBOSE, ...msg);\n }\n addPluggable(pluggable) {\n if (pluggable && pluggable.getCategoryName() === constants_1.AWS_CLOUDWATCH_CATEGORY) {\n this._pluggables.push(pluggable);\n pluggable.configure(this._config);\n }\n }\n listPluggables() {\n return this._pluggables;\n }\n}\nexports.ConsoleLogger = ConsoleLogger;\nConsoleLogger.LOG_LEVEL = null;\nConsoleLogger.BIND_ALL_LOG_LEVELS = false;\n"],"names":[],"mappings":";;AACA;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,E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AI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC;AAChD,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,KAAK,CAAC,GAAG,GAAG,EAAE;AAClB,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC;AAChD,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,OAAO,CAAC,GAAG,GAAG,EAAE;AACpB,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,GAAG,CAAC;AAClD,IAAI;AACJ,IAAI,YAAY,CAAC,SAAS,EAAE;AAC5B,QAAQ,IAAI,SAAS,IAAI,SAAS,CAAC,eAAe,EAAE,KAAK,WAAW,CAAC,uBAAuB,EAAE;AAC9F,YAAY,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC;AAC5C,YAAY,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC;AAC7C,QAAQ;AACR,IAAI;AACJ,IAAI,cAAc,GAAG;AACrB,QAAQ,OAAO,IAAI,CAAC,WAAW;AAC/B,IAAI;AACJ;AACA,OAAO,CAAC,aAAa,GAAG,aAAa;AACrC,aAAa,CAAC,SAAS,GAAG,IAAI;AAC9B,aAAa,CAAC,mBAAmB,GAAG,KAAK;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/Logger/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ConsoleLogger = void 0;\nvar ConsoleLogger_1 = require(\"./ConsoleLogger\");\nObject.defineProperty(exports, \"ConsoleLogger\", { enumerable: true, get: function () { return ConsoleLogger_1.ConsoleLogger; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,aAAa,GAAG,MAAM;AAC9B,IAAI,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC;AAChD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,eAAe,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/Logger/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ConsoleLogger = void 0;\nvar ConsoleLogger_1 = require(\"./ConsoleLogger\");\nObject.defineProperty(exports, \"ConsoleLogger\", { enumerable: true, get: function () { return ConsoleLogger_1.ConsoleLogger; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,aAAa,GAAG,MAAM;AAC9B,IAAI,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC;AAChD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,eAAe,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"Mutex.js","sources":["../../../src/Mutex/Mutex.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/*!\n * The MIT License (MIT)\n *\n * Copyright (c) 2016 Christian Speckner <cnspeckn@googlemail.com>\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Mutex = void 0;\nclass Mutex {\n constructor() {\n this._queue = [];\n this._pending = false;\n }\n isLocked() {\n return this._pending;\n }\n acquire() {\n const ticket = new Promise(resolve => this._queue.push(resolve));\n if (!this._pending) {\n this._dispatchNext();\n }\n return ticket;\n }\n runExclusive(callback) {\n return this.acquire().then(release => {\n let result;\n try {\n result = callback();\n }\n catch (e) {\n release();\n throw e;\n }\n return Promise.resolve(result).then((x) => {\n release();\n return x;\n }, e => {\n release();\n throw e;\n });\n });\n }\n _dispatchNext() {\n if (this._queue.length > 0) {\n this._pending = true;\n this._queue.shift()(this._dispatchNext.bind(this));\n }\n else {\n this._pending = false;\n }\n }\n}\nexports.Mutex = Mutex;\n"],"names":[],"mappings":";;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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M,CAAC,MAAM,GAAG,CAAC,EAAE;AACpC,YAAY,IAAI,CAAC,QAAQ,GAAG,IAAI;AAChC,YAAY,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9D;AACA,aAAa;AACb,YAAY,IAAI,CAAC,QAAQ,GAAG,KAAK;AACjC;AACA;AACA;AACA,OAAO,CAAC,KAAK,GAAG,KAAK;;"}
1
+ {"version":3,"file":"Mutex.js","sources":["../../../src/Mutex/Mutex.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/*!\n * The MIT License (MIT)\n *\n * Copyright (c) 2016 Christian Speckner <cnspeckn@googlemail.com>\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Mutex = void 0;\nclass Mutex {\n constructor() {\n this._queue = [];\n this._pending = false;\n }\n isLocked() {\n return this._pending;\n }\n acquire() {\n const ticket = new Promise(resolve => this._queue.push(resolve));\n if (!this._pending) {\n this._dispatchNext();\n }\n return ticket;\n }\n runExclusive(callback) {\n return this.acquire().then(release => {\n let result;\n try {\n result = callback();\n }\n catch (e) {\n release();\n throw e;\n }\n return Promise.resolve(result).then((x) => {\n release();\n return x;\n }, e => {\n release();\n throw e;\n });\n });\n }\n _dispatchNext() {\n if (this._queue.length > 0) {\n this._pending = true;\n this._queue.shift()(this._dispatchNext.bind(this));\n }\n else {\n this._pending = false;\n }\n }\n}\nexports.Mutex = Mutex;\n"],"names":[],"mappings":";;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,KAAK,GAAG,MAAM;AACtB,MAAM,KAAK,CAAC;AACZ,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,CAAC,MAAM,GAAG,EAAE;AACxB,QAAQ,IAAI,CAAC,QAAQ,GAAG,KAAK;AAC7B,IAAI;AACJ,IAAI,QAAQ,GAAG;AACf,QAAQ,OAAO,IAAI,CAAC,QAAQ;AAC5B,IAAI;AACJ,IAAI,OAAO,GAAG;AACd,QAAQ,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACxE,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;AAC5B,YAAY,IAAI,CAAC,aAAa,EAAE;AAChC,QAAQ;AACR,QAAQ,OAAO,MAAM;AACrB,IAAI;AACJ,IAAI,YAAY,CAAC,QAAQ,EAAE;AAC3B,QAAQ,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,OAAO,IAAI;AAC9C,YAAY,IAAI,MAAM;AACtB,YAAY,IAAI;AAChB,gBAAgB,MAAM,GAAG,QAAQ,EAAE;AACnC,YAAY;AACZ,YAAY,OAAO,CAAC,EAAE;AACtB,gBAAgB,OAAO,EAAE;AACzB,gBAAgB,MAAM,CAAC;AACvB,YAAY;AACZ,YAAY,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK;AACvD,gBAAgB,OAAO,EAAE;AACzB,gBAAgB,OAAO,CAAC;AACxB,YAAY,CAAC,EAAE,CAAC,IAAI;AACpB,gBAAgB,OAAO,EAAE;AACzB,gBAAgB,MAAM,CAAC;AACvB,YAAY,CAAC,CAAC;AACd,QAAQ,CAAC,CAAC;AACV,IAAI;AACJ,IAAI,aAAa,GAAG;AACpB,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;AACpC,YAAY,IAAI,CAAC,QAAQ,GAAG,IAAI;AAChC,YAAY,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9D,QAAQ;AACR,aAAa;AACb,YAAY,IAAI,CAAC,QAAQ,GAAG,KAAK;AACjC,QAAQ;AACR,IAAI;AACJ;AACA,OAAO,CAAC,KAAK,GAAG,KAAK;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/Mutex/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Mutex = void 0;\nvar Mutex_1 = require(\"./Mutex\");\nObject.defineProperty(exports, \"Mutex\", { enumerable: true, get: function () { return Mutex_1.Mutex; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,KAAK,GAAG,MAAM;AACtB,IAAI,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;AAChC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/Mutex/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Mutex = void 0;\nvar Mutex_1 = require(\"./Mutex\");\nObject.defineProperty(exports, \"Mutex\", { enumerable: true, get: function () { return Mutex_1.Mutex; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,KAAK,GAAG,MAAM;AACtB,IAAI,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;AAChC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;;"}