@webiny/api-sync-system 0.0.0-unstable.a4637c5ce6 → 0.0.0-unstable.a4f3e4ea8b

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 (321) hide show
  1. package/README.md +6 -108
  2. package/constants.js +2 -7
  3. package/constants.js.map +1 -1
  4. package/index.js +3 -40
  5. package/package.json +29 -26
  6. package/resolver/app/RecordHandler.d.ts +6 -6
  7. package/resolver/app/RecordHandler.js +84 -114
  8. package/resolver/app/RecordHandler.js.map +1 -1
  9. package/resolver/app/RecordsValidation.js +13 -24
  10. package/resolver/app/RecordsValidation.js.map +1 -1
  11. package/resolver/app/ResolverApplication.d.ts +1 -1
  12. package/resolver/app/ResolverApplication.js +27 -42
  13. package/resolver/app/ResolverApplication.js.map +1 -1
  14. package/resolver/app/abstractions/RecordHandler.d.ts +1 -1
  15. package/resolver/app/abstractions/RecordHandler.js +0 -7
  16. package/resolver/app/abstractions/RecordsValidation.d.ts +2 -2
  17. package/resolver/app/abstractions/RecordsValidation.js +0 -7
  18. package/resolver/app/abstractions/ResolverApplication.js +0 -7
  19. package/resolver/app/abstractions/ResolverRecord.d.ts +1 -1
  20. package/resolver/app/abstractions/ResolverRecord.js +0 -7
  21. package/resolver/app/bundler/BaseBundle.d.ts +6 -6
  22. package/resolver/app/bundler/BaseBundle.js +16 -22
  23. package/resolver/app/bundler/BaseBundle.js.map +1 -1
  24. package/resolver/app/bundler/Bundler.d.ts +1 -1
  25. package/resolver/app/bundler/Bundler.js +12 -25
  26. package/resolver/app/bundler/Bundler.js.map +1 -1
  27. package/resolver/app/bundler/Bundles.d.ts +2 -2
  28. package/resolver/app/bundler/Bundles.js +20 -33
  29. package/resolver/app/bundler/Bundles.js.map +1 -1
  30. package/resolver/app/bundler/CommandBundle.d.ts +1 -1
  31. package/resolver/app/bundler/CommandBundle.js +8 -25
  32. package/resolver/app/bundler/CommandBundle.js.map +1 -1
  33. package/resolver/app/bundler/TableBundle.d.ts +1 -1
  34. package/resolver/app/bundler/TableBundle.js +7 -22
  35. package/resolver/app/bundler/TableBundle.js.map +1 -1
  36. package/resolver/app/bundler/types.d.ts +2 -2
  37. package/resolver/app/bundler/types.js +0 -7
  38. package/resolver/app/commandHandler/DeleteCommandHandler.d.ts +3 -3
  39. package/resolver/app/commandHandler/DeleteCommandHandler.js +21 -35
  40. package/resolver/app/commandHandler/DeleteCommandHandler.js.map +1 -1
  41. package/resolver/app/commandHandler/PutCommandHandler.d.ts +4 -4
  42. package/resolver/app/commandHandler/PutCommandHandler.js +15 -28
  43. package/resolver/app/commandHandler/PutCommandHandler.js.map +1 -1
  44. package/resolver/app/commandHandler/delete.d.ts +1 -1
  45. package/resolver/app/commandHandler/delete.js +13 -21
  46. package/resolver/app/commandHandler/delete.js.map +1 -1
  47. package/resolver/app/commandHandler/put.d.ts +1 -1
  48. package/resolver/app/commandHandler/put.js +13 -21
  49. package/resolver/app/commandHandler/put.js.map +1 -1
  50. package/resolver/app/data/SourceDataContainer.d.ts +3 -3
  51. package/resolver/app/data/SourceDataContainer.js +27 -36
  52. package/resolver/app/data/SourceDataContainer.js.map +1 -1
  53. package/resolver/app/data/types.d.ts +2 -2
  54. package/resolver/app/data/types.js +0 -7
  55. package/resolver/app/fetcher/Fetcher.d.ts +3 -3
  56. package/resolver/app/fetcher/Fetcher.js +87 -121
  57. package/resolver/app/fetcher/Fetcher.js.map +1 -1
  58. package/resolver/app/fetcher/types.d.ts +2 -2
  59. package/resolver/app/fetcher/types.js +0 -7
  60. package/resolver/app/ingestor/Ingestor.d.ts +1 -1
  61. package/resolver/app/ingestor/Ingestor.js +26 -39
  62. package/resolver/app/ingestor/Ingestor.js.map +1 -1
  63. package/resolver/app/ingestor/IngestorResult.js +27 -39
  64. package/resolver/app/ingestor/IngestorResult.js.map +1 -1
  65. package/resolver/app/ingestor/types.d.ts +2 -2
  66. package/resolver/app/ingestor/types.js +0 -7
  67. package/resolver/app/storer/Storer.d.ts +3 -3
  68. package/resolver/app/storer/Storer.js +73 -95
  69. package/resolver/app/storer/Storer.js.map +1 -1
  70. package/resolver/app/storer/types.d.ts +2 -2
  71. package/resolver/app/storer/types.js +0 -7
  72. package/resolver/app/transform/TransformHandler.d.ts +4 -4
  73. package/resolver/app/transform/TransformHandler.js +46 -64
  74. package/resolver/app/transform/TransformHandler.js.map +1 -1
  75. package/resolver/app/transform/middleware.d.ts +1 -1
  76. package/resolver/app/transform/middleware.js +12 -25
  77. package/resolver/app/transform/middleware.js.map +1 -1
  78. package/resolver/app/utils/Retry.js +21 -32
  79. package/resolver/app/utils/Retry.js.map +1 -1
  80. package/resolver/app/utils/sleep.js +4 -12
  81. package/resolver/app/utils/sleep.js.map +1 -1
  82. package/resolver/app/validation/body.d.ts +25 -124
  83. package/resolver/app/validation/body.js +31 -44
  84. package/resolver/app/validation/body.js.map +1 -1
  85. package/resolver/app/validation/createJsonTransform.d.ts +1 -1
  86. package/resolver/app/validation/createJsonTransform.js +13 -22
  87. package/resolver/app/validation/createJsonTransform.js.map +1 -1
  88. package/resolver/app/validation/detail.d.ts +19 -72
  89. package/resolver/app/validation/detail.js +33 -46
  90. package/resolver/app/validation/detail.js.map +1 -1
  91. package/resolver/app/validation/event.d.ts +29 -188
  92. package/resolver/app/validation/event.js +21 -30
  93. package/resolver/app/validation/event.js.map +1 -1
  94. package/resolver/app/validation/numericString.d.ts +1 -1
  95. package/resolver/app/validation/numericString.js +9 -20
  96. package/resolver/app/validation/numericString.js.map +1 -1
  97. package/resolver/app/validation/system.d.ts +2 -14
  98. package/resolver/app/validation/system.js +9 -18
  99. package/resolver/app/validation/system.js.map +1 -1
  100. package/resolver/createEventHandlerPlugin.d.ts +2 -1
  101. package/resolver/createEventHandlerPlugin.js +85 -121
  102. package/resolver/createEventHandlerPlugin.js.map +1 -1
  103. package/resolver/createResolverHandler.d.ts +1 -1
  104. package/resolver/createResolverHandler.js +60 -75
  105. package/resolver/createResolverHandler.js.map +1 -1
  106. package/resolver/deployment/Deployment.d.ts +2 -3
  107. package/resolver/deployment/Deployment.js +27 -44
  108. package/resolver/deployment/Deployment.js.map +1 -1
  109. package/resolver/deployment/Deployments.js +19 -30
  110. package/resolver/deployment/Deployments.js.map +1 -1
  111. package/resolver/deployment/DeploymentsFetcher.js +82 -102
  112. package/resolver/deployment/DeploymentsFetcher.js.map +1 -1
  113. package/resolver/deployment/types.d.ts +4 -6
  114. package/resolver/deployment/types.js +0 -7
  115. package/resolver/lambda/LambdaTrigger.js +25 -34
  116. package/resolver/lambda/LambdaTrigger.js.map +1 -1
  117. package/resolver/plugins/CommandHandlerPlugin.d.ts +3 -3
  118. package/resolver/plugins/CommandHandlerPlugin.js +17 -24
  119. package/resolver/plugins/CommandHandlerPlugin.js.map +1 -1
  120. package/resolver/plugins/StorerAfterEachPlugin.d.ts +2 -2
  121. package/resolver/plugins/StorerAfterEachPlugin.js +21 -29
  122. package/resolver/plugins/StorerAfterEachPlugin.js.map +1 -1
  123. package/resolver/plugins/TransformRecordPlugin.d.ts +3 -3
  124. package/resolver/plugins/TransformRecordPlugin.js +20 -27
  125. package/resolver/plugins/TransformRecordPlugin.js.map +1 -1
  126. package/resolver/recordTypes/fileManager/CopyFile.js +44 -74
  127. package/resolver/recordTypes/fileManager/CopyFile.js.map +1 -1
  128. package/resolver/recordTypes/fileManager/DeleteFile.d.ts +1 -1
  129. package/resolver/recordTypes/fileManager/DeleteFile.js +40 -65
  130. package/resolver/recordTypes/fileManager/DeleteFile.js.map +1 -1
  131. package/resolver/recordTypes/fileManager/fileManager.d.ts +1 -1
  132. package/resolver/recordTypes/fileManager/fileManager.js +7 -12
  133. package/resolver/recordTypes/fileManager/fileManager.js.map +1 -1
  134. package/resolver/recordTypes/fileManager/fileManagerOnDelete.d.ts +1 -1
  135. package/resolver/recordTypes/fileManager/fileManagerOnDelete.js +27 -45
  136. package/resolver/recordTypes/fileManager/fileManagerOnDelete.js.map +1 -1
  137. package/resolver/recordTypes/fileManager/fileManagerOnPut.d.ts +1 -1
  138. package/resolver/recordTypes/fileManager/fileManagerOnPut.js +27 -45
  139. package/resolver/recordTypes/fileManager/fileManagerOnPut.js.map +1 -1
  140. package/resolver/recordTypes/fileManager/shouldBeHandled.d.ts +1 -1
  141. package/resolver/recordTypes/fileManager/shouldBeHandled.js +10 -34
  142. package/resolver/recordTypes/fileManager/shouldBeHandled.js.map +1 -1
  143. package/resolver/recordTypes/fileManager/types.d.ts +2 -2
  144. package/resolver/recordTypes/fileManager/types.js +0 -7
  145. package/resolver/recordTypes/users/CopyUser.d.ts +2 -2
  146. package/resolver/recordTypes/users/CopyUser.js +44 -61
  147. package/resolver/recordTypes/users/CopyUser.js.map +1 -1
  148. package/resolver/recordTypes/users/DeleteUser.d.ts +2 -2
  149. package/resolver/recordTypes/users/DeleteUser.js +40 -58
  150. package/resolver/recordTypes/users/DeleteUser.js.map +1 -1
  151. package/resolver/recordTypes/users/shouldBeHandled.d.ts +1 -1
  152. package/resolver/recordTypes/users/shouldBeHandled.js +10 -33
  153. package/resolver/recordTypes/users/shouldBeHandled.js.map +1 -1
  154. package/resolver/recordTypes/users/types.d.ts +1 -1
  155. package/resolver/recordTypes/users/types.js +0 -7
  156. package/resolver/recordTypes/users/users.js +7 -12
  157. package/resolver/recordTypes/users/users.js.map +1 -1
  158. package/resolver/recordTypes/users/usersOnDelete.d.ts +2 -2
  159. package/resolver/recordTypes/users/usersOnDelete.js +26 -44
  160. package/resolver/recordTypes/users/usersOnDelete.js.map +1 -1
  161. package/resolver/recordTypes/users/usersOnPut.d.ts +2 -2
  162. package/resolver/recordTypes/users/usersOnPut.js +27 -45
  163. package/resolver/recordTypes/users/usersOnPut.js.map +1 -1
  164. package/sync/FilterOutRecord.d.ts +2 -2
  165. package/sync/FilterOutRecord.js +8 -24
  166. package/sync/FilterOutRecord.js.map +1 -1
  167. package/sync/attachToDynamoDbDocument.d.ts +1 -1
  168. package/sync/attachToDynamoDbDocument.js +48 -75
  169. package/sync/attachToDynamoDbDocument.js.map +1 -1
  170. package/sync/createHandler.js +44 -60
  171. package/sync/createHandler.js.map +1 -1
  172. package/sync/createSendDataToEventBridgeOnRequestEnd.js +34 -46
  173. package/sync/createSendDataToEventBridgeOnRequestEnd.js.map +1 -1
  174. package/sync/createSyncSystem.d.ts +1 -1
  175. package/sync/createSyncSystem.js +27 -36
  176. package/sync/createSyncSystem.js.map +1 -1
  177. package/sync/filter/createDefaultFilterOutRecordPlugins.d.ts +1 -1
  178. package/sync/filter/createDefaultFilterOutRecordPlugins.js +37 -86
  179. package/sync/filter/createDefaultFilterOutRecordPlugins.js.map +1 -1
  180. package/sync/handler/Handler.d.ts +2 -2
  181. package/sync/handler/Handler.js +66 -86
  182. package/sync/handler/Handler.js.map +1 -1
  183. package/sync/handler/HandlerConverter.js +20 -36
  184. package/sync/handler/HandlerConverter.js.map +1 -1
  185. package/sync/handler/converter/BatchGetCommandConverter.js +13 -20
  186. package/sync/handler/converter/BatchGetCommandConverter.js.map +1 -1
  187. package/sync/handler/converter/BatchWriteCommandConverter.js +13 -20
  188. package/sync/handler/converter/BatchWriteCommandConverter.js.map +1 -1
  189. package/sync/handler/converter/DeleteCommandConverter.js +13 -20
  190. package/sync/handler/converter/DeleteCommandConverter.js.map +1 -1
  191. package/sync/handler/converter/GetCommandConverter.js +13 -20
  192. package/sync/handler/converter/GetCommandConverter.js.map +1 -1
  193. package/sync/handler/converter/PutCommandConverter.js +13 -20
  194. package/sync/handler/converter/PutCommandConverter.js.map +1 -1
  195. package/sync/handler/converter/QueryCommandConverter.js +13 -20
  196. package/sync/handler/converter/QueryCommandConverter.js.map +1 -1
  197. package/sync/handler/converter/ScanCommandConverter.js +13 -20
  198. package/sync/handler/converter/ScanCommandConverter.js.map +1 -1
  199. package/sync/handler/converter/UpdateCommandConverter.js +13 -20
  200. package/sync/handler/converter/UpdateCommandConverter.js.map +1 -1
  201. package/sync/handler/converter/commands/BatchWriteCommandValue.d.ts +2 -2
  202. package/sync/handler/converter/commands/BatchWriteCommandValue.js +34 -44
  203. package/sync/handler/converter/commands/BatchWriteCommandValue.js.map +1 -1
  204. package/sync/handler/converter/commands/DeleteCommandValue.d.ts +2 -2
  205. package/sync/handler/converter/commands/DeleteCommandValue.js +19 -23
  206. package/sync/handler/converter/commands/DeleteCommandValue.js.map +1 -1
  207. package/sync/handler/converter/commands/NullCommandValue.d.ts +1 -1
  208. package/sync/handler/converter/commands/NullCommandValue.js +7 -14
  209. package/sync/handler/converter/commands/NullCommandValue.js.map +1 -1
  210. package/sync/handler/converter/commands/PutCommandValue.d.ts +2 -2
  211. package/sync/handler/converter/commands/PutCommandValue.js +19 -23
  212. package/sync/handler/converter/commands/PutCommandValue.js.map +1 -1
  213. package/sync/handler/converter/commands/UpdateCommandValue.d.ts +2 -2
  214. package/sync/handler/converter/commands/UpdateCommandValue.js +19 -23
  215. package/sync/handler/converter/commands/UpdateCommandValue.js.map +1 -1
  216. package/sync/handler/types.d.ts +3 -3
  217. package/sync/handler/types.js +0 -7
  218. package/sync/plugins/FilterOutRecordPlugin.d.ts +1 -1
  219. package/sync/plugins/FilterOutRecordPlugin.js +18 -28
  220. package/sync/plugins/FilterOutRecordPlugin.js.map +1 -1
  221. package/sync/requestPlugin.d.ts +1 -1
  222. package/sync/requestPlugin.js +39 -55
  223. package/sync/requestPlugin.js.map +1 -1
  224. package/sync/types.js +0 -7
  225. package/sync/utils/getTableType.js +11 -19
  226. package/sync/utils/getTableType.js.map +1 -1
  227. package/sync/utils/manifest.d.ts +3 -7
  228. package/sync/utils/manifest.js +30 -47
  229. package/sync/utils/manifest.js.map +1 -1
  230. package/sync/utils/validateSystemInput.d.ts +1 -1
  231. package/sync/utils/validateSystemInput.js +22 -37
  232. package/sync/utils/validateSystemInput.js.map +1 -1
  233. package/types.d.ts +3 -5
  234. package/types.js +6 -12
  235. package/types.js.map +1 -1
  236. package/utils/createSystemName.js +5 -10
  237. package/utils/createSystemName.js.map +1 -1
  238. package/worker/actions/copyFile/CopyFile.js +185 -268
  239. package/worker/actions/copyFile/CopyFile.js.map +1 -1
  240. package/worker/actions/copyFile/copyFileAction.d.ts +1 -1
  241. package/worker/actions/copyFile/copyFileAction.js +30 -45
  242. package/worker/actions/copyFile/copyFileAction.js.map +1 -1
  243. package/worker/actions/copyFile/copyFileSchema.d.ts +6 -38
  244. package/worker/actions/copyFile/copyFileSchema.js +14 -23
  245. package/worker/actions/copyFile/copyFileSchema.js.map +1 -1
  246. package/worker/actions/copyFile/types.js +0 -7
  247. package/worker/actions/createUser/CreateUser.d.ts +1 -1
  248. package/worker/actions/createUser/CreateUser.js +53 -83
  249. package/worker/actions/createUser/CreateUser.js.map +1 -1
  250. package/worker/actions/createUser/createUserAction.d.ts +2 -2
  251. package/worker/actions/createUser/createUserAction.js +28 -39
  252. package/worker/actions/createUser/createUserAction.js.map +1 -1
  253. package/worker/actions/createUser/createUserSchema.d.ts +6 -38
  254. package/worker/actions/createUser/createUserSchema.js +14 -23
  255. package/worker/actions/createUser/createUserSchema.js.map +1 -1
  256. package/worker/actions/createUser/types.js +0 -7
  257. package/worker/actions/deleteFile/DeleteFile.js +52 -74
  258. package/worker/actions/deleteFile/DeleteFile.js.map +1 -1
  259. package/worker/actions/deleteFile/deleteFileAction.d.ts +1 -1
  260. package/worker/actions/deleteFile/deleteFileAction.js +25 -40
  261. package/worker/actions/deleteFile/deleteFileAction.js.map +1 -1
  262. package/worker/actions/deleteFile/deleteFileSchema.d.ts +6 -38
  263. package/worker/actions/deleteFile/deleteFileSchema.js +14 -23
  264. package/worker/actions/deleteFile/deleteFileSchema.js.map +1 -1
  265. package/worker/actions/deleteFile/types.js +0 -7
  266. package/worker/actions/deleteUser/DeleteUser.d.ts +2 -2
  267. package/worker/actions/deleteUser/DeleteUser.js +39 -60
  268. package/worker/actions/deleteUser/DeleteUser.js.map +1 -1
  269. package/worker/actions/deleteUser/deleteUserAction.d.ts +1 -1
  270. package/worker/actions/deleteUser/deleteUserAction.js +26 -37
  271. package/worker/actions/deleteUser/deleteUserAction.js.map +1 -1
  272. package/worker/actions/deleteUser/deleteUserSchema.d.ts +5 -23
  273. package/worker/actions/deleteUser/deleteUserSchema.js +13 -22
  274. package/worker/actions/deleteUser/deleteUserSchema.js.map +1 -1
  275. package/worker/actions/deleteUser/types.js +0 -7
  276. package/worker/actions/logValidationError.js +6 -14
  277. package/worker/actions/logValidationError.js.map +1 -1
  278. package/worker/actions/removeCognitoUserAttributes.js +9 -22
  279. package/worker/actions/removeCognitoUserAttributes.js.map +1 -1
  280. package/worker/actions/updateUser/UpdateUser.d.ts +1 -1
  281. package/worker/actions/updateUser/UpdateUser.js +50 -74
  282. package/worker/actions/updateUser/UpdateUser.js.map +1 -1
  283. package/worker/actions/updateUser/types.js +0 -7
  284. package/worker/actions/updateUser/updateUserAction.d.ts +2 -2
  285. package/worker/actions/updateUser/updateUserAction.js +28 -39
  286. package/worker/actions/updateUser/updateUserAction.js.map +1 -1
  287. package/worker/actions/updateUser/updateUserSchema.d.ts +6 -38
  288. package/worker/actions/updateUser/updateUserSchema.js +14 -23
  289. package/worker/actions/updateUser/updateUserSchema.js.map +1 -1
  290. package/worker/createWorkerHandler.js +32 -45
  291. package/worker/createWorkerHandler.js.map +1 -1
  292. package/worker/handler/WorkerActionHandler.d.ts +2 -2
  293. package/worker/handler/WorkerActionHandler.js +19 -28
  294. package/worker/handler/WorkerActionHandler.js.map +1 -1
  295. package/worker/handler/eventHandler.js +18 -27
  296. package/worker/handler/eventHandler.js.map +1 -1
  297. package/worker/plugins/WorkerActionPlugin.d.ts +1 -1
  298. package/worker/plugins/WorkerActionPlugin.js +18 -25
  299. package/worker/plugins/WorkerActionPlugin.js.map +1 -1
  300. package/worker/types.js +0 -7
  301. package/index.js.map +0 -1
  302. package/resolver/app/abstractions/RecordHandler.js.map +0 -1
  303. package/resolver/app/abstractions/RecordsValidation.js.map +0 -1
  304. package/resolver/app/abstractions/ResolverApplication.js.map +0 -1
  305. package/resolver/app/abstractions/ResolverRecord.js.map +0 -1
  306. package/resolver/app/bundler/types.js.map +0 -1
  307. package/resolver/app/data/types.js.map +0 -1
  308. package/resolver/app/fetcher/types.js.map +0 -1
  309. package/resolver/app/ingestor/types.js.map +0 -1
  310. package/resolver/app/storer/types.js.map +0 -1
  311. package/resolver/deployment/types.js.map +0 -1
  312. package/resolver/recordTypes/fileManager/types.js.map +0 -1
  313. package/resolver/recordTypes/users/types.js.map +0 -1
  314. package/sync/handler/types.js.map +0 -1
  315. package/sync/types.js.map +0 -1
  316. package/worker/actions/copyFile/types.js.map +0 -1
  317. package/worker/actions/createUser/types.js.map +0 -1
  318. package/worker/actions/deleteFile/types.js.map +0 -1
  319. package/worker/actions/deleteUser/types.js.map +0 -1
  320. package/worker/actions/updateUser/types.js.map +0 -1
  321. package/worker/types.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import type { IIngestor, IIngestorIngestParams, IIngestorResult } from "./types.js";
2
- import type { IDeployment } from "../../deployment/types.js";
2
+ import type { IDeployment } from "../../../resolver/deployment/types.js";
3
3
  export interface IIngestorParams {
4
4
  createIngestorResult: () => IIngestorResult;
5
5
  getSource: (name: string) => IDeployment | null;
@@ -1,44 +1,31 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createIngestor = exports.Ingestor = void 0;
7
1
  class Ingestor {
8
- constructor(params) {
9
- this.createIngestorResult = params.createIngestorResult;
10
- this.getSource = params.getSource;
11
- }
12
- async ingest(params) {
13
- const {
14
- records
15
- } = params;
16
- const result = this.createIngestorResult();
17
- for (const record of records) {
18
- const detail = record.body.detail;
19
- const source = this.getSource(detail.source.name);
20
- if (!source) {
21
- console.error(`Could not find deployment for SQS Record source: ${detail.source.name}. More info in next log line.`);
22
- console.log(JSON.stringify({
23
- source: detail.source,
24
- items: detail.items
25
- }));
26
- continue;
27
- }
28
- for (const item of detail.items) {
29
- result.add({
30
- item,
31
- source
32
- });
33
- }
2
+ constructor(params){
3
+ this.createIngestorResult = params.createIngestorResult;
4
+ this.getSource = params.getSource;
5
+ }
6
+ async ingest(params) {
7
+ const { records } = params;
8
+ const result = this.createIngestorResult();
9
+ for (const record of records){
10
+ const detail = record.body.detail;
11
+ const source = this.getSource(detail.source.name);
12
+ if (!source) {
13
+ console.error(`Could not find deployment for SQS Record source: ${detail.source.name}. More info in next log line.`);
14
+ console.log(JSON.stringify({
15
+ source: detail.source,
16
+ items: detail.items
17
+ }));
18
+ continue;
19
+ }
20
+ for (const item of detail.items)result.add({
21
+ item,
22
+ source
23
+ });
24
+ }
25
+ return result;
34
26
  }
35
- return result;
36
- }
37
27
  }
38
- exports.Ingestor = Ingestor;
39
- const createIngestor = params => {
40
- return new Ingestor(params);
41
- };
42
- exports.createIngestor = createIngestor;
28
+ const createIngestor = (params)=>new Ingestor(params);
29
+ export { Ingestor, createIngestor };
43
30
 
44
31
  //# sourceMappingURL=Ingestor.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Ingestor","constructor","params","createIngestorResult","getSource","ingest","records","result","record","detail","body","source","name","console","error","log","JSON","stringify","items","item","add","exports","createIngestor"],"sources":["Ingestor.ts"],"sourcesContent":["import type { IIngestor, IIngestorIngestParams, IIngestorResult } from \"./types.js\";\nimport type { IDeployment } from \"~/resolver/deployment/types.js\";\n\nexport interface IIngestorParams {\n createIngestorResult: () => IIngestorResult;\n getSource: (name: string) => IDeployment | null;\n}\n\nexport class Ingestor implements IIngestor {\n private readonly createIngestorResult: () => IIngestorResult;\n private readonly getSource: (name: string) => IDeployment | null;\n\n public constructor(params: IIngestorParams) {\n this.createIngestorResult = params.createIngestorResult;\n this.getSource = params.getSource;\n }\n\n public async ingest(params: IIngestorIngestParams): Promise<IIngestorResult> {\n const { records } = params;\n\n const result = this.createIngestorResult();\n\n for (const record of records) {\n const detail = record.body.detail;\n const source = this.getSource(detail.source.name);\n if (!source) {\n console.error(\n `Could not find deployment for SQS Record source: ${detail.source.name}. More info in next log line.`\n );\n console.log(\n JSON.stringify({\n source: detail.source,\n items: detail.items\n })\n );\n continue;\n }\n\n for (const item of detail.items) {\n result.add({\n item,\n source\n });\n }\n }\n\n return result;\n }\n}\n\nexport const createIngestor = (params: IIngestorParams): IIngestor => {\n return new Ingestor(params);\n};\n"],"mappings":";;;;;;AAQO,MAAMA,QAAQ,CAAsB;EAIhCC,WAAWA,CAACC,MAAuB,EAAE;IACxC,IAAI,CAACC,oBAAoB,GAAGD,MAAM,CAACC,oBAAoB;IACvD,IAAI,CAACC,SAAS,GAAGF,MAAM,CAACE,SAAS;EACrC;EAEA,MAAaC,MAAMA,CAACH,MAA6B,EAA4B;IACzE,MAAM;MAAEI;IAAQ,CAAC,GAAGJ,MAAM;IAE1B,MAAMK,MAAM,GAAG,IAAI,CAACJ,oBAAoB,CAAC,CAAC;IAE1C,KAAK,MAAMK,MAAM,IAAIF,OAAO,EAAE;MAC1B,MAAMG,MAAM,GAAGD,MAAM,CAACE,IAAI,CAACD,MAAM;MACjC,MAAME,MAAM,GAAG,IAAI,CAACP,SAAS,CAACK,MAAM,CAACE,MAAM,CAACC,IAAI,CAAC;MACjD,IAAI,CAACD,MAAM,EAAE;QACTE,OAAO,CAACC,KAAK,CACT,oDAAoDL,MAAM,CAACE,MAAM,CAACC,IAAI,+BAC1E,CAAC;QACDC,OAAO,CAACE,GAAG,CACPC,IAAI,CAACC,SAAS,CAAC;UACXN,MAAM,EAAEF,MAAM,CAACE,MAAM;UACrBO,KAAK,EAAET,MAAM,CAACS;QAClB,CAAC,CACL,CAAC;QACD;MACJ;MAEA,KAAK,MAAMC,IAAI,IAAIV,MAAM,CAACS,KAAK,EAAE;QAC7BX,MAAM,CAACa,GAAG,CAAC;UACPD,IAAI;UACJR;QACJ,CAAC,CAAC;MACN;IACJ;IAEA,OAAOJ,MAAM;EACjB;AACJ;AAACc,OAAA,CAAArB,QAAA,GAAAA,QAAA;AAEM,MAAMsB,cAAc,GAAIpB,MAAuB,IAAgB;EAClE,OAAO,IAAIF,QAAQ,CAACE,MAAM,CAAC;AAC/B,CAAC;AAACmB,OAAA,CAAAC,cAAA,GAAAA,cAAA","ignoreList":[]}
1
+ {"version":3,"file":"resolver/app/ingestor/Ingestor.js","sources":["../../../../src/resolver/app/ingestor/Ingestor.ts"],"sourcesContent":["import type { IIngestor, IIngestorIngestParams, IIngestorResult } from \"./types.js\";\nimport type { IDeployment } from \"~/resolver/deployment/types.js\";\n\nexport interface IIngestorParams {\n createIngestorResult: () => IIngestorResult;\n getSource: (name: string) => IDeployment | null;\n}\n\nexport class Ingestor implements IIngestor {\n private readonly createIngestorResult: () => IIngestorResult;\n private readonly getSource: (name: string) => IDeployment | null;\n\n public constructor(params: IIngestorParams) {\n this.createIngestorResult = params.createIngestorResult;\n this.getSource = params.getSource;\n }\n\n public async ingest(params: IIngestorIngestParams): Promise<IIngestorResult> {\n const { records } = params;\n\n const result = this.createIngestorResult();\n\n for (const record of records) {\n const detail = record.body.detail;\n const source = this.getSource(detail.source.name);\n if (!source) {\n console.error(\n `Could not find deployment for SQS Record source: ${detail.source.name}. More info in next log line.`\n );\n console.log(\n JSON.stringify({\n source: detail.source,\n items: detail.items\n })\n );\n continue;\n }\n\n for (const item of detail.items) {\n result.add({\n item,\n source\n });\n }\n }\n\n return result;\n }\n}\n\nexport const createIngestor = (params: IIngestorParams): IIngestor => {\n return new Ingestor(params);\n};\n"],"names":["Ingestor","params","records","result","record","detail","source","console","JSON","item","createIngestor"],"mappings":"AAQO,MAAMA;IAIT,YAAmBC,MAAuB,CAAE;QACxC,IAAI,CAAC,oBAAoB,GAAGA,OAAO,oBAAoB;QACvD,IAAI,CAAC,SAAS,GAAGA,OAAO,SAAS;IACrC;IAEA,MAAa,OAAOA,MAA6B,EAA4B;QACzE,MAAM,EAAEC,OAAO,EAAE,GAAGD;QAEpB,MAAME,SAAS,IAAI,CAAC,oBAAoB;QAExC,KAAK,MAAMC,UAAUF,QAAS;YAC1B,MAAMG,SAASD,OAAO,IAAI,CAAC,MAAM;YACjC,MAAME,SAAS,IAAI,CAAC,SAAS,CAACD,OAAO,MAAM,CAAC,IAAI;YAChD,IAAI,CAACC,QAAQ;gBACTC,QAAQ,KAAK,CACT,CAAC,iDAAiD,EAAEF,OAAO,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC;gBAEzGE,QAAQ,GAAG,CACPC,KAAK,SAAS,CAAC;oBACX,QAAQH,OAAO,MAAM;oBACrB,OAAOA,OAAO,KAAK;gBACvB;gBAEJ;YACJ;YAEA,KAAK,MAAMI,QAAQJ,OAAO,KAAK,CAC3BF,OAAO,GAAG,CAAC;gBACPM;gBACAH;YACJ;QAER;QAEA,OAAOH;IACX;AACJ;AAEO,MAAMO,iBAAiB,CAACT,SACpB,IAAID,SAASC"}
@@ -1,45 +1,33 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createIngestorResult = exports.IngestorResult = void 0;
7
1
  class IngestorResult {
8
- items = new Map();
9
- add(params) {
10
- const {
11
- item,
12
- source
13
- } = params;
14
- let table;
15
- try {
16
- table = source.getTable(item.tableType);
17
- } catch (ex) {
18
- console.error(`Could not find table for SQS Record source: ${item.tableName} / ${item.tableType}. More info in next log line.`);
19
- console.log(JSON.stringify(item));
20
- return;
2
+ add(params) {
3
+ const { item, source } = params;
4
+ let table;
5
+ try {
6
+ table = source.getTable(item.tableType);
7
+ } catch {
8
+ console.error(`Could not find table for SQS Record source: ${item.tableName} / ${item.tableType}. More info in next log line.`);
9
+ console.log(JSON.stringify(item));
10
+ return;
11
+ }
12
+ const command = "delete" === item.command ? "delete" : "put";
13
+ const key = `PK:${item.PK}#SK:${item.SK}#cmd:${command}#source:${source.name}`;
14
+ if (this.items.has(key)) return;
15
+ this.items.set(key, {
16
+ PK: item.PK,
17
+ SK: item.SK,
18
+ source,
19
+ command,
20
+ table
21
+ });
22
+ }
23
+ getItems() {
24
+ return Array.from(this.items.values());
21
25
  }
22
- const command = item.command === "delete" ? "delete" : "put";
23
- const key = `PK:${item.PK}#SK:${item.SK}#cmd:${command}#source:${source.name}`;
24
- if (this.items.has(key)) {
25
- return;
26
+ constructor(){
27
+ this.items = new Map();
26
28
  }
27
- this.items.set(key, {
28
- PK: item.PK,
29
- SK: item.SK,
30
- source,
31
- command,
32
- table
33
- });
34
- }
35
- getItems() {
36
- return Array.from(this.items.values());
37
- }
38
29
  }
39
- exports.IngestorResult = IngestorResult;
40
- const createIngestorResult = () => {
41
- return new IngestorResult();
42
- };
43
- exports.createIngestorResult = createIngestorResult;
30
+ const createIngestorResult = ()=>new IngestorResult();
31
+ export { IngestorResult, createIngestorResult };
44
32
 
45
33
  //# sourceMappingURL=IngestorResult.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["IngestorResult","items","Map","add","params","item","source","table","getTable","tableType","ex","console","error","tableName","log","JSON","stringify","command","key","PK","SK","name","has","set","getItems","Array","from","values","exports","createIngestorResult"],"sources":["IngestorResult.ts"],"sourcesContent":["import type { IIngestorResult, IIngestorResultAddParams, IIngestorResultItem } from \"./types.js\";\nimport type { ITable } from \"~/sync/types.js\";\n\nexport class IngestorResult implements IIngestorResult {\n private readonly items: Map<string, IIngestorResultItem> = new Map();\n\n public add(params: IIngestorResultAddParams): void {\n const { item, source } = params;\n let table: ITable;\n try {\n table = source.getTable(item.tableType);\n } catch (ex) {\n console.error(\n `Could not find table for SQS Record source: ${item.tableName} / ${item.tableType}. More info in next log line.`\n );\n console.log(JSON.stringify(item));\n return;\n }\n\n const command = item.command === \"delete\" ? \"delete\" : \"put\";\n\n const key = `PK:${item.PK}#SK:${item.SK}#cmd:${command}#source:${source.name}`;\n\n if (this.items.has(key)) {\n return;\n }\n\n this.items.set(key, {\n PK: item.PK,\n SK: item.SK,\n source,\n command,\n table\n });\n }\n\n public getItems(): IIngestorResultItem[] {\n return Array.from(this.items.values());\n }\n}\n\nexport const createIngestorResult = (): IIngestorResult => {\n return new IngestorResult();\n};\n"],"mappings":";;;;;;AAGO,MAAMA,cAAc,CAA4B;EAClCC,KAAK,GAAqC,IAAIC,GAAG,CAAC,CAAC;EAE7DC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/IngestorResult.js","sources":["../../../../src/resolver/app/ingestor/IngestorResult.ts"],"sourcesContent":["import type { IIngestorResult, IIngestorResultAddParams, IIngestorResultItem } from \"./types.js\";\nimport type { ITable } from \"~/sync/types.js\";\n\nexport class IngestorResult implements IIngestorResult {\n private readonly items: Map<string, IIngestorResultItem> = new Map();\n\n public add(params: IIngestorResultAddParams): void {\n const { item, source } = params;\n let table: ITable;\n try {\n table = source.getTable(item.tableType);\n } catch {\n console.error(\n `Could not find table for SQS Record source: ${item.tableName} / ${item.tableType}. More info in next log line.`\n );\n console.log(JSON.stringify(item));\n return;\n }\n\n const command = item.command === \"delete\" ? \"delete\" : \"put\";\n\n const key = `PK:${item.PK}#SK:${item.SK}#cmd:${command}#source:${source.name}`;\n\n if (this.items.has(key)) {\n return;\n }\n\n this.items.set(key, {\n PK: item.PK,\n SK: item.SK,\n source,\n command,\n table\n });\n }\n\n public getItems(): IIngestorResultItem[] {\n return Array.from(this.items.values());\n }\n}\n\nexport const createIngestorResult = (): IIngestorResult => {\n return new IngestorResult();\n};\n"],"names":["IngestorResult","params","item","source","table","console","JSON","command","key","Array","Map","createIngestorResult"],"mappings":"AAGO,MAAMA;IAGF,IAAIC,MAAgC,EAAQ;QAC/C,MAAM,EAAEC,IAAI,EAAEC,MAAM,EAAE,GAAGF;QACzB,IAAIG;QACJ,IAAI;YACAA,QAAQD,OAAO,QAAQ,CAACD,KAAK,SAAS;QAC1C,EAAE,OAAM;YACJG,QAAQ,KAAK,CACT,CAAC,4CAA4C,EAAEH,KAAK,SAAS,CAAC,GAAG,EAAEA,KAAK,SAAS,CAAC,6BAA6B,CAAC;YAEpHG,QAAQ,GAAG,CAACC,KAAK,SAAS,CAACJ;YAC3B;QACJ;QAEA,MAAMK,UAAUL,AAAiB,aAAjBA,KAAK,OAAO,GAAgB,WAAW;QAEvD,MAAMM,MAAM,CAAC,GAAG,EAAEN,KAAK,EAAE,CAAC,IAAI,EAAEA,KAAK,EAAE,CAAC,KAAK,EAAEK,QAAQ,QAAQ,EAAEJ,OAAO,IAAI,EAAE;QAE9E,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAACK,MACf;QAGJ,IAAI,CAAC,KAAK,CAAC,GAAG,CAACA,KAAK;YAChB,IAAIN,KAAK,EAAE;YACX,IAAIA,KAAK,EAAE;YACXC;YACAI;YACAH;QACJ;IACJ;IAEO,WAAkC;QACrC,OAAOK,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM;IACvC;;aAlCiB,KAAK,GAAqC,IAAIC;;AAmCnE;AAEO,MAAMC,uBAAuB,IACzB,IAAIX"}
@@ -1,8 +1,8 @@
1
1
  import type { CommandType } from "../../../types.js";
2
- import type { IResolverSQSRecord } from "../abstractions/ResolverRecord.js";
2
+ import type { IResolverSQSRecord } from "../../../resolver/app/abstractions/ResolverRecord.js";
3
3
  import type { IDetailItem } from "../../../sync/handler/types.js";
4
4
  import type { ITable } from "../../../sync/types.js";
5
- import type { IDeployment } from "../../deployment/types.js";
5
+ import type { IDeployment } from "../../../resolver/deployment/types.js";
6
6
  export interface IIngestorIngestParams {
7
7
  records: IResolverSQSRecord[];
8
8
  }
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- //# sourceMappingURL=types.js.map
@@ -1,7 +1,7 @@
1
- import type { IStoreItem, IStorer, IStorerExecParams } from "./types";
2
- import type { IDeployment } from "../../deployment/types.js";
1
+ import type { IStoreItem, IStorer, IStorerExecParams } from "./types.js";
2
+ import type { IDeployment } from "../../../resolver/deployment/types.js";
3
3
  import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
4
- import type { CommandType } from "../../../types";
4
+ import type { CommandType } from "../../../types.js";
5
5
  import type { ITable } from "../../../sync/types.js";
6
6
  export interface IStorerParamsCreateDocumentClientCallable {
7
7
  (deployment: Pick<IDeployment, "region">): Pick<DynamoDBDocument, "send">;
@@ -1,103 +1,81 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createStorer = exports.Storer = void 0;
7
- var _index = require("@webiny/aws-sdk/client-dynamodb/index.js");
8
- var _Retry = require("../utils/Retry");
9
- var _utils = require("@webiny/utils");
1
+ import { DeleteCommand, PutCommand } from "@webiny/aws-sdk/client-dynamodb/index.js";
2
+ import { createRetry } from "../utils/Retry.js";
3
+ import { convertException } from "@webiny/utils";
10
4
  class Storer {
11
- constructor(params) {
12
- this.maxRetries = params.maxRetries || 10;
13
- this.retryDelay = params.retryDelay || 1000;
14
- this.createDocumentClient = params.createDocumentClient;
15
- this.afterEach = params.afterEach;
16
- this.onError = params.onError;
17
- }
18
- async store(params) {
19
- const {
20
- deployment,
21
- bundle,
22
- table,
23
- command,
24
- items
25
- } = params;
26
- if (items.length === 0) {
27
- return;
5
+ constructor(params){
6
+ this.maxRetries = params.maxRetries || 10;
7
+ this.retryDelay = params.retryDelay || 1000;
8
+ this.createDocumentClient = params.createDocumentClient;
9
+ this.afterEach = params.afterEach;
10
+ this.onError = params.onError;
28
11
  }
29
- const client = this.createDocumentClient({
30
- region: deployment.region
31
- });
32
- const retry = (0, _Retry.createRetry)({
33
- maxRetries: this.maxRetries,
34
- retryDelay: this.retryDelay
35
- });
36
- for (const item of items) {
37
- const result = await retry.retry(async () => {
38
- switch (command) {
39
- case "delete":
40
- return await client.send(new _index.DeleteCommand({
41
- TableName: table.name,
42
- Key: {
43
- PK: item.PK,
44
- SK: item.SK
45
- }
46
- }));
47
- case "put":
48
- return await client.send(new _index.PutCommand({
49
- TableName: table.name,
50
- Item: item
51
- }));
52
- default:
53
- console.error(`Unsupported command type: ${command}`);
54
- return null;
55
- }
56
- }, {
57
- onFail: async error => {
58
- console.error("Error executing batch write command.");
59
- console.log((0, _utils.convertException)(error));
60
- if (!this.onError) {
61
- return;
62
- }
63
- try {
64
- await this.onError({
65
- item,
66
- command,
67
- table,
68
- error
69
- });
70
- } catch (ex) {
71
- console.error(`Error in onError callback for command: ${command}`);
72
- console.log({
73
- original: (0, _utils.convertException)(error),
74
- error: (0, _utils.convertException)(ex)
12
+ async store(params) {
13
+ const { deployment, bundle, table, command, items } = params;
14
+ if (0 === items.length) return;
15
+ const client = this.createDocumentClient({
16
+ region: deployment.region
17
+ });
18
+ const retry = createRetry({
19
+ maxRetries: this.maxRetries,
20
+ retryDelay: this.retryDelay
21
+ });
22
+ for (const item of items){
23
+ const result = await retry.retry(async ()=>{
24
+ switch(command){
25
+ case "delete":
26
+ return await client.send(new DeleteCommand({
27
+ TableName: table.name,
28
+ Key: {
29
+ PK: item.PK,
30
+ SK: item.SK
31
+ }
32
+ }));
33
+ case "put":
34
+ return await client.send(new PutCommand({
35
+ TableName: table.name,
36
+ Item: item
37
+ }));
38
+ default:
39
+ console.error(`Unsupported command type: ${command}`);
40
+ return null;
41
+ }
42
+ }, {
43
+ onFail: async (error)=>{
44
+ console.error("Error executing batch write command.");
45
+ console.log(convertException(error));
46
+ if (!this.onError) return;
47
+ try {
48
+ await this.onError({
49
+ item,
50
+ command,
51
+ table,
52
+ error
53
+ });
54
+ } catch (ex) {
55
+ console.error(`Error in onError callback for command: ${command}`);
56
+ console.log({
57
+ original: convertException(error),
58
+ error: convertException(ex)
59
+ });
60
+ }
61
+ }
75
62
  });
76
- }
63
+ if (result && this.afterEach) try {
64
+ await this.afterEach({
65
+ table,
66
+ command,
67
+ item,
68
+ source: bundle.source,
69
+ target: deployment
70
+ });
71
+ } catch (ex) {
72
+ console.error(`Error in afterEach callback for command: ${command}`);
73
+ console.log(convertException(ex));
74
+ }
77
75
  }
78
- });
79
- if (!result || !this.afterEach) {
80
- continue;
81
- }
82
- try {
83
- await this.afterEach({
84
- table,
85
- command,
86
- item,
87
- source: bundle.source,
88
- target: deployment
89
- });
90
- } catch (ex) {
91
- console.error(`Error in afterEach callback for command: ${command}`);
92
- console.log((0, _utils.convertException)(ex));
93
- }
94
76
  }
95
- }
96
77
  }
97
- exports.Storer = Storer;
98
- const createStorer = params => {
99
- return new Storer(params);
100
- };
101
- exports.createStorer = createStorer;
78
+ const createStorer = (params)=>new Storer(params);
79
+ export { Storer, createStorer };
102
80
 
103
81
  //# sourceMappingURL=Storer.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_index","require","_Retry","_utils","Storer","constructor","params","maxRetries","retryDelay","createDocumentClient","afterEach","onError","store","deployment","bundle","table","command","items","length","client","region","retry","createRetry","item","result","send","DeleteCommand","TableName","name","Key","PK","SK","PutCommand","Item","console","error","onFail","log","convertException","ex","original","source","target","exports","createStorer"],"sources":["Storer.ts"],"sourcesContent":["import type { IStoreItem, IStorer, IStorerExecParams } from \"./types\";\nimport type { IDeployment } from \"~/resolver/deployment/types.js\";\nimport type {\n DeleteCommandOutput,\n DynamoDBDocument,\n PutCommandOutput\n} from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { DeleteCommand, PutCommand } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { CommandType } from \"~/types\";\nimport type { ITable } from \"~/sync/types.js\";\nimport { createRetry } from \"../utils/Retry\";\nimport { convertException } from \"@webiny/utils\";\n\nexport interface IStorerParamsCreateDocumentClientCallable {\n (deployment: Pick<IDeployment, \"region\">): Pick<DynamoDBDocument, \"send\">;\n}\n\nexport interface IStorerOnErrorParams {\n command: CommandType;\n item: IStoreItem;\n table: ITable;\n error: Error;\n}\n\nexport interface IStorerOnErrorCb {\n (params: IStorerOnErrorParams): Promise<void>;\n}\n\nexport interface ISingleStorerAfterEachParams {\n command: CommandType;\n target: IDeployment;\n source: IDeployment;\n table: ITable;\n item: IStoreItem;\n}\n\nexport interface IStorerAfterEachCb {\n (params: ISingleStorerAfterEachParams): Promise<void>;\n}\n\nexport interface IStorerParams {\n maxRetries?: number;\n retryDelay?: number;\n createDocumentClient: IStorerParamsCreateDocumentClientCallable;\n onError?: IStorerOnErrorCb;\n afterEach?: IStorerAfterEachCb;\n}\n\nexport class Storer implements IStorer {\n private readonly maxRetries: number;\n private readonly retryDelay: number;\n private readonly createDocumentClient: IStorerParamsCreateDocumentClientCallable;\n private readonly afterEach?: IStorerAfterEachCb;\n private readonly onError?: IStorerOnErrorCb;\n\n public constructor(params: IStorerParams) {\n this.maxRetries = params.maxRetries || 10;\n this.retryDelay = params.retryDelay || 1000;\n this.createDocumentClient = params.createDocumentClient;\n this.afterEach = params.afterEach;\n this.onError = params.onError;\n }\n\n public async store(params: IStorerExecParams): Promise<void> {\n const { deployment, bundle, table, command, items } = params;\n if (items.length === 0) {\n return;\n }\n const client = this.createDocumentClient({\n region: deployment.region\n });\n\n const retry = createRetry({\n maxRetries: this.maxRetries,\n retryDelay: this.retryDelay\n });\n\n for (const item of items) {\n const result = await retry.retry(\n async (): Promise<DeleteCommandOutput | PutCommandOutput | null> => {\n switch (command) {\n case \"delete\":\n return await client.send(\n new DeleteCommand({\n TableName: table.name,\n Key: {\n PK: item.PK,\n SK: item.SK\n }\n })\n );\n case \"put\":\n return await client.send(\n new PutCommand({\n TableName: table.name,\n Item: item\n })\n );\n\n default:\n console.error(`Unsupported command type: ${command}`);\n return null;\n }\n },\n {\n onFail: async error => {\n console.error(\"Error executing batch write command.\");\n console.log(convertException(error));\n if (!this.onError) {\n return;\n }\n try {\n await this.onError({\n item,\n command,\n table,\n error\n });\n } catch (ex) {\n console.error(`Error in onError callback for command: ${command}`);\n console.log({\n original: convertException(error),\n error: convertException(ex)\n });\n }\n }\n }\n );\n if (!result || !this.afterEach) {\n continue;\n }\n try {\n await this.afterEach({\n table,\n command,\n item,\n source: bundle.source,\n target: deployment\n });\n } catch (ex) {\n console.error(`Error in afterEach callback for command: ${command}`);\n console.log(convertException(ex));\n }\n }\n }\n}\n\nexport const createStorer = (params: IStorerParams): IStorer => {\n return new Storer(params);\n};\n"],"mappings":";;;;;;AAOA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAqCO,MAAMG,MAAM,CA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wC,YAAY,GAAItC,MAAqB,IAAc;EAC5D,OAAO,IAAIF,MAAM,CAACE,MAAM,CAAC;AAC7B,CAAC;AAACqC,OAAA,CAAAC,YAAA,GAAAA,YAAA","ignoreList":[]}
1
+ {"version":3,"file":"resolver/app/storer/Storer.js","sources":["../../../../src/resolver/app/storer/Storer.ts"],"sourcesContent":["import type { IStoreItem, IStorer, IStorerExecParams } from \"./types.js\";\nimport type { IDeployment } from \"~/resolver/deployment/types.js\";\nimport type {\n DeleteCommandOutput,\n DynamoDBDocument,\n PutCommandOutput\n} from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { DeleteCommand, PutCommand } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { CommandType } from \"~/types.js\";\nimport type { ITable } from \"~/sync/types.js\";\nimport { createRetry } from \"../utils/Retry.js\";\nimport { convertException } from \"@webiny/utils\";\n\nexport interface IStorerParamsCreateDocumentClientCallable {\n (deployment: Pick<IDeployment, \"region\">): Pick<DynamoDBDocument, \"send\">;\n}\n\nexport interface IStorerOnErrorParams {\n command: CommandType;\n item: IStoreItem;\n table: ITable;\n error: Error;\n}\n\nexport interface IStorerOnErrorCb {\n (params: IStorerOnErrorParams): Promise<void>;\n}\n\nexport interface ISingleStorerAfterEachParams {\n command: CommandType;\n target: IDeployment;\n source: IDeployment;\n table: ITable;\n item: IStoreItem;\n}\n\nexport interface IStorerAfterEachCb {\n (params: ISingleStorerAfterEachParams): Promise<void>;\n}\n\nexport interface IStorerParams {\n maxRetries?: number;\n retryDelay?: number;\n createDocumentClient: IStorerParamsCreateDocumentClientCallable;\n onError?: IStorerOnErrorCb;\n afterEach?: IStorerAfterEachCb;\n}\n\nexport class Storer implements IStorer {\n private readonly maxRetries: number;\n private readonly retryDelay: number;\n private readonly createDocumentClient: IStorerParamsCreateDocumentClientCallable;\n private readonly afterEach?: IStorerAfterEachCb;\n private readonly onError?: IStorerOnErrorCb;\n\n public constructor(params: IStorerParams) {\n this.maxRetries = params.maxRetries || 10;\n this.retryDelay = params.retryDelay || 1000;\n this.createDocumentClient = params.createDocumentClient;\n this.afterEach = params.afterEach;\n this.onError = params.onError;\n }\n\n public async store(params: IStorerExecParams): Promise<void> {\n const { deployment, bundle, table, command, items } = params;\n if (items.length === 0) {\n return;\n }\n const client = this.createDocumentClient({\n region: deployment.region\n });\n\n const retry = createRetry({\n maxRetries: this.maxRetries,\n retryDelay: this.retryDelay\n });\n\n for (const item of items) {\n const result = await retry.retry(\n async (): Promise<DeleteCommandOutput | PutCommandOutput | null> => {\n switch (command) {\n case \"delete\":\n return await client.send(\n new DeleteCommand({\n TableName: table.name,\n Key: {\n PK: item.PK,\n SK: item.SK\n }\n })\n );\n case \"put\":\n return await client.send(\n new PutCommand({\n TableName: table.name,\n Item: item\n })\n );\n\n default:\n console.error(`Unsupported command type: ${command}`);\n return null;\n }\n },\n {\n onFail: async error => {\n console.error(\"Error executing batch write command.\");\n console.log(convertException(error));\n if (!this.onError) {\n return;\n }\n try {\n await this.onError({\n item,\n command,\n table,\n error\n });\n } catch (ex) {\n console.error(`Error in onError callback for command: ${command}`);\n console.log({\n original: convertException(error),\n error: convertException(ex)\n });\n }\n }\n }\n );\n if (!result || !this.afterEach) {\n continue;\n }\n try {\n await this.afterEach({\n table,\n command,\n item,\n source: bundle.source,\n target: deployment\n });\n } catch (ex) {\n console.error(`Error in afterEach callback for command: ${command}`);\n console.log(convertException(ex));\n }\n }\n }\n}\n\nexport const createStorer = (params: IStorerParams): IStorer => {\n return new Storer(params);\n};\n"],"names":["Storer","params","deployment","bundle","table","command","items","client","retry","createRetry","item","result","DeleteCommand","PutCommand","console","error","convertException","ex","createStorer"],"mappings":";;;AAgDO,MAAMA;IAOT,YAAmBC,MAAqB,CAAE;QACtC,IAAI,CAAC,UAAU,GAAGA,OAAO,UAAU,IAAI;QACvC,IAAI,CAAC,UAAU,GAAGA,OAAO,UAAU,IAAI;QACvC,IAAI,CAAC,oBAAoB,GAAGA,OAAO,oBAAoB;QACvD,IA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3B,OAAOC,iBAAiBC;wBAC5B;oBACJ;gBACJ;YACJ;YAEJ,IAAI,AAACN,UAAW,IAAI,CAAC,SAAS,EAG9B,IAAI;gBACA,MAAM,IAAI,CAAC,SAAS,CAAC;oBACjBP;oBACAC;oBACAK;oBACA,QAAQP,OAAO,MAAM;oBACrB,QAAQD;gBACZ;YACJ,EAAE,OAAOe,IAAI;gBACTH,QAAQ,KAAK,CAAC,CAAC,yCAAyC,EAAET,SAAS;gBACnES,QAAQ,GAAG,CAACE,iBAAiBC;YACjC;QACJ;IACJ;AACJ;AAEO,MAAMC,eAAe,CAACjB,SAClB,IAAID,OAAOC"}
@@ -1,8 +1,8 @@
1
- import type { IDeployment } from "../../deployment/types.js";
1
+ import type { IDeployment } from "../../../resolver/deployment/types.js";
2
2
  import type { ITable } from "../../../sync/types.js";
3
3
  import type { CommandType } from "../../../types.js";
4
4
  import type { GenericRecord } from "@webiny/api/types.js";
5
- import type { IBundle } from "../bundler/types";
5
+ import type { IBundle } from "../bundler/types.js";
6
6
  export type StoreItemPossibleValues = string | number | boolean | undefined | null | GenericRecord | StoreItemPossibleValues[];
7
7
  export interface IStoreItem {
8
8
  PK: string;
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- //# sourceMappingURL=types.js.map
@@ -1,7 +1,7 @@
1
- import type { ITable } from "../../../sync/types";
2
- import type { IDeployment } from "../../deployment/types.js";
3
- import type { PluginsContainer } from "@webiny/plugins/types";
4
- import type { IStoreItem } from "../storer/types";
1
+ import type { ITable } from "../../../sync/types.js";
2
+ import type { IDeployment } from "../../../resolver/deployment/types.js";
3
+ import type { PluginsContainer } from "@webiny/plugins/types.js";
4
+ import type { IStoreItem } from "../storer/types.js";
5
5
  export interface IMiddlewareParams {
6
6
  readonly plugins: PluginsContainer;
7
7
  readonly record: IStoreItem;
@@ -1,70 +1,52 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.TransformHandler = void 0;
7
- var _TransformRecordPlugin = require("../../plugins/TransformRecordPlugin.js");
8
- var _middleware = require("./middleware.js");
1
+ import { TransformRecordPlugin } from "../../plugins/TransformRecordPlugin.js";
2
+ import { middleware } from "./middleware.js";
9
3
  class TransformHandler {
10
- constructor(params) {
11
- this.pluginsContainer = params.plugins;
12
- this.plugins = params.plugins.byType(_TransformRecordPlugin.TransformRecordPlugin.type);
13
- }
14
- async transform(params) {
15
- const {
16
- sourceTable,
17
- sourceDeployment,
18
- targetDeployment,
19
- targetTable,
20
- items
21
- } = params;
22
- if (this.plugins.length === 0) {
23
- process.env.DEBUG === "true" && console.log("There are no transform plugins registered in the system.");
24
- return {
25
- items
26
- };
4
+ constructor(params){
5
+ this.pluginsContainer = params.plugins;
6
+ this.plugins = params.plugins.byType(TransformRecordPlugin.type);
27
7
  }
28
- const plugins = this.plugins.filter(plugin => {
29
- if (plugin.isForTableType(sourceTable.type) === false) {
30
- return false;
31
- }
32
- return plugin.canTransform({
33
- from: sourceDeployment,
34
- to: targetDeployment
35
- });
36
- });
37
- if (plugins.length === 0) {
38
- process.env.DEBUG === "true" && console.log("There are no transform plugins registered for the given deployment versions or sourceTable type.", {
39
- sourceVersion: sourceDeployment.version.format(),
40
- targetVersion: targetDeployment.version.format(),
41
- sourceTable
42
- });
43
- return {
44
- items
45
- };
8
+ async transform(params) {
9
+ const { sourceTable, sourceDeployment, targetDeployment, targetTable, items } = params;
10
+ if (0 === this.plugins.length) {
11
+ "true" === process.env.DEBUG && console.log("There are no transform plugins registered in the system.");
12
+ return {
13
+ items
14
+ };
15
+ }
16
+ const plugins = this.plugins.filter((plugin)=>{
17
+ if (false === plugin.isForTableType(sourceTable.type)) return false;
18
+ return plugin.canTransform({
19
+ from: sourceDeployment,
20
+ to: targetDeployment
21
+ });
22
+ });
23
+ if (0 === plugins.length) {
24
+ "true" === process.env.DEBUG && console.log("There are no transform plugins registered for the given deployment versions or sourceTable type.", {
25
+ sourceVersion: sourceDeployment.version.format(),
26
+ targetVersion: targetDeployment.version.format(),
27
+ sourceTable
28
+ });
29
+ return {
30
+ items
31
+ };
32
+ }
33
+ const runner = middleware(plugins.map((plugin)=>async (params, next)=>await plugin.transform(params, next)));
34
+ const results = await Promise.all(items.map(async (input)=>{
35
+ const record = Object.freeze(input);
36
+ return await runner({
37
+ plugins: this.pluginsContainer,
38
+ sourceTable,
39
+ sourceDeployment,
40
+ targetDeployment,
41
+ targetTable,
42
+ record
43
+ }, record);
44
+ }));
45
+ return {
46
+ items: results.filter((item)=>!!item)
47
+ };
46
48
  }
47
- const runner = (0, _middleware.middleware)(plugins.map(plugin => {
48
- return async (params, next) => {
49
- return await plugin.transform(params, next);
50
- };
51
- }));
52
- const results = await Promise.all(items.map(async input => {
53
- const record = Object.freeze(input);
54
- return await runner({
55
- plugins: this.pluginsContainer,
56
- sourceTable,
57
- sourceDeployment,
58
- targetDeployment,
59
- targetTable,
60
- record
61
- }, record);
62
- }));
63
- return {
64
- items: results.filter(item => !!item)
65
- };
66
- }
67
49
  }
68
- exports.TransformHandler = TransformHandler;
50
+ export { TransformHandler };
69
51
 
70
52
  //# sourceMappingURL=TransformHandler.js.map