@webiny/api-sync-system 0.0.0-unstable.c27f4d8a31 → 0.0.0-unstable.d0f34a8194

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 (276) hide show
  1. package/constants.js +2 -1
  2. package/constants.js.map +1 -1
  3. package/index.d.ts +11 -3
  4. package/index.js +8 -5
  5. package/package.json +29 -21
  6. package/resolver/SyncResolverConfig.d.ts +17 -0
  7. package/resolver/SyncResolverConfig.js +5 -0
  8. package/resolver/SyncResolverConfig.js.map +1 -0
  9. package/resolver/SyncResolverLambdaHandler.d.ts +14 -0
  10. package/resolver/SyncResolverLambdaHandler.js +159 -0
  11. package/resolver/SyncResolverLambdaHandler.js.map +1 -0
  12. package/resolver/app/RecordHandler.js +83 -105
  13. package/resolver/app/RecordHandler.js.map +1 -1
  14. package/resolver/app/RecordsValidation.js +11 -14
  15. package/resolver/app/RecordsValidation.js.map +1 -1
  16. package/resolver/app/ResolverApplication.js +24 -31
  17. package/resolver/app/ResolverApplication.js.map +1 -1
  18. package/resolver/app/abstractions/RecordHandler.js +0 -3
  19. package/resolver/app/abstractions/RecordsValidation.js +0 -3
  20. package/resolver/app/abstractions/ResolverApplication.js +0 -3
  21. package/resolver/app/abstractions/ResolverRecord.js +0 -3
  22. package/resolver/app/bundler/BaseBundle.js +17 -16
  23. package/resolver/app/bundler/BaseBundle.js.map +1 -1
  24. package/resolver/app/bundler/Bundler.js +13 -18
  25. package/resolver/app/bundler/Bundler.js.map +1 -1
  26. package/resolver/app/bundler/Bundles.js +21 -26
  27. package/resolver/app/bundler/Bundles.js.map +1 -1
  28. package/resolver/app/bundler/CommandBundle.js +7 -16
  29. package/resolver/app/bundler/CommandBundle.js.map +1 -1
  30. package/resolver/app/bundler/TableBundle.js +6 -13
  31. package/resolver/app/bundler/TableBundle.js.map +1 -1
  32. package/resolver/app/bundler/types.js +0 -3
  33. package/resolver/app/commandHandler/DeleteCommandHandler.js +22 -29
  34. package/resolver/app/commandHandler/DeleteCommandHandler.js.map +1 -1
  35. package/resolver/app/commandHandler/PutCommandHandler.js +16 -22
  36. package/resolver/app/commandHandler/PutCommandHandler.js.map +1 -1
  37. package/resolver/app/commandHandler/delete.js +11 -12
  38. package/resolver/app/commandHandler/delete.js.map +1 -1
  39. package/resolver/app/commandHandler/put.js +11 -12
  40. package/resolver/app/commandHandler/put.js.map +1 -1
  41. package/resolver/app/data/SourceDataContainer.js +28 -30
  42. package/resolver/app/data/SourceDataContainer.js.map +1 -1
  43. package/resolver/app/data/types.js +0 -3
  44. package/resolver/app/fetcher/Fetcher.js +84 -109
  45. package/resolver/app/fetcher/Fetcher.js.map +1 -1
  46. package/resolver/app/fetcher/types.js +0 -3
  47. package/resolver/app/ingestor/Ingestor.js +27 -32
  48. package/resolver/app/ingestor/Ingestor.js.map +1 -1
  49. package/resolver/app/ingestor/IngestorResult.js +28 -32
  50. package/resolver/app/ingestor/IngestorResult.js.map +1 -1
  51. package/resolver/app/ingestor/types.js +0 -3
  52. package/resolver/app/storer/Storer.js +71 -85
  53. package/resolver/app/storer/Storer.js.map +1 -1
  54. package/resolver/app/storer/types.js +0 -3
  55. package/resolver/app/transform/TransformHandler.js +45 -56
  56. package/resolver/app/transform/TransformHandler.js.map +1 -1
  57. package/resolver/app/transform/middleware.js +13 -20
  58. package/resolver/app/transform/middleware.js.map +1 -1
  59. package/resolver/app/utils/Retry.js +21 -24
  60. package/resolver/app/utils/Retry.js.map +1 -1
  61. package/resolver/app/utils/sleep.js +4 -5
  62. package/resolver/app/utils/sleep.js.map +1 -1
  63. package/resolver/app/validation/body.d.ts +5 -5
  64. package/resolver/app/validation/body.js +26 -31
  65. package/resolver/app/validation/body.js.map +1 -1
  66. package/resolver/app/validation/createJsonTransform.js +12 -13
  67. package/resolver/app/validation/createJsonTransform.js.map +1 -1
  68. package/resolver/app/validation/detail.d.ts +5 -5
  69. package/resolver/app/validation/detail.js +30 -35
  70. package/resolver/app/validation/detail.js.map +1 -1
  71. package/resolver/app/validation/event.d.ts +5 -5
  72. package/resolver/app/validation/event.js +17 -18
  73. package/resolver/app/validation/event.js.map +1 -1
  74. package/resolver/app/validation/numericString.js +8 -11
  75. package/resolver/app/validation/numericString.js.map +1 -1
  76. package/resolver/app/validation/system.js +8 -9
  77. package/resolver/app/validation/system.js.map +1 -1
  78. package/resolver/deployment/Deployment.js +28 -31
  79. package/resolver/deployment/Deployment.js.map +1 -1
  80. package/resolver/deployment/Deployments.js +20 -23
  81. package/resolver/deployment/Deployments.js.map +1 -1
  82. package/resolver/deployment/DeploymentsFetcher.js +75 -84
  83. package/resolver/deployment/DeploymentsFetcher.js.map +1 -1
  84. package/resolver/deployment/types.js +0 -3
  85. package/resolver/lambda/LambdaTrigger.js +24 -26
  86. package/resolver/lambda/LambdaTrigger.js.map +1 -1
  87. package/resolver/plugins/CommandHandlerPlugin.js +16 -15
  88. package/resolver/plugins/CommandHandlerPlugin.js.map +1 -1
  89. package/resolver/plugins/StorerAfterEachPlugin.js +20 -19
  90. package/resolver/plugins/StorerAfterEachPlugin.js.map +1 -1
  91. package/resolver/plugins/TransformRecordPlugin.js +19 -18
  92. package/resolver/plugins/TransformRecordPlugin.js.map +1 -1
  93. package/resolver/recordTypes/fileManager/CopyFile.js +44 -67
  94. package/resolver/recordTypes/fileManager/CopyFile.js.map +1 -1
  95. package/resolver/recordTypes/fileManager/DeleteFile.js +40 -58
  96. package/resolver/recordTypes/fileManager/DeleteFile.js.map +1 -1
  97. package/resolver/recordTypes/fileManager/fileManager.js +5 -3
  98. package/resolver/recordTypes/fileManager/fileManager.js.map +1 -1
  99. package/resolver/recordTypes/fileManager/fileManagerOnDelete.js +24 -35
  100. package/resolver/recordTypes/fileManager/fileManagerOnDelete.js.map +1 -1
  101. package/resolver/recordTypes/fileManager/fileManagerOnPut.js +24 -35
  102. package/resolver/recordTypes/fileManager/fileManagerOnPut.js.map +1 -1
  103. package/resolver/recordTypes/fileManager/shouldBeHandled.js +10 -27
  104. package/resolver/recordTypes/fileManager/shouldBeHandled.js.map +1 -1
  105. package/resolver/recordTypes/fileManager/types.js +0 -3
  106. package/resolver/recordTypes/users/CopyUser.js +44 -54
  107. package/resolver/recordTypes/users/CopyUser.js.map +1 -1
  108. package/resolver/recordTypes/users/DeleteUser.js +40 -51
  109. package/resolver/recordTypes/users/DeleteUser.js.map +1 -1
  110. package/resolver/recordTypes/users/shouldBeHandled.js +10 -26
  111. package/resolver/recordTypes/users/shouldBeHandled.js.map +1 -1
  112. package/resolver/recordTypes/users/types.js +0 -3
  113. package/resolver/recordTypes/users/users.js +5 -3
  114. package/resolver/recordTypes/users/users.js.map +1 -1
  115. package/resolver/recordTypes/users/usersOnDelete.js +23 -34
  116. package/resolver/recordTypes/users/usersOnDelete.js.map +1 -1
  117. package/resolver/recordTypes/users/usersOnPut.js +24 -35
  118. package/resolver/recordTypes/users/usersOnPut.js.map +1 -1
  119. package/sync/ApiGatewaySyncDecorator.d.ts +14 -0
  120. package/sync/ApiGatewaySyncDecorator.js +49 -0
  121. package/sync/ApiGatewaySyncDecorator.js.map +1 -0
  122. package/sync/FilterOutRecord.js +9 -17
  123. package/sync/FilterOutRecord.js.map +1 -1
  124. package/sync/SyncSystemConfig.d.ts +11 -0
  125. package/sync/SyncSystemConfig.js +5 -0
  126. package/sync/SyncSystemConfig.js.map +1 -0
  127. package/sync/attachToDynamoDbDocument.js +46 -65
  128. package/sync/attachToDynamoDbDocument.js.map +1 -1
  129. package/sync/createHandler.js +31 -40
  130. package/sync/createHandler.js.map +1 -1
  131. package/sync/filter/createDefaultFilterOutRecordPlugins.js +36 -76
  132. package/sync/filter/createDefaultFilterOutRecordPlugins.js.map +1 -1
  133. package/sync/handler/Handler.js +64 -76
  134. package/sync/handler/Handler.js.map +1 -1
  135. package/sync/handler/HandlerConverter.js +21 -29
  136. package/sync/handler/HandlerConverter.js.map +1 -1
  137. package/sync/handler/converter/BatchGetCommandConverter.js +12 -11
  138. package/sync/handler/converter/BatchGetCommandConverter.js.map +1 -1
  139. package/sync/handler/converter/BatchWriteCommandConverter.js +12 -11
  140. package/sync/handler/converter/BatchWriteCommandConverter.js.map +1 -1
  141. package/sync/handler/converter/DeleteCommandConverter.js +12 -11
  142. package/sync/handler/converter/DeleteCommandConverter.js.map +1 -1
  143. package/sync/handler/converter/GetCommandConverter.js +12 -11
  144. package/sync/handler/converter/GetCommandConverter.js.map +1 -1
  145. package/sync/handler/converter/PutCommandConverter.js +12 -11
  146. package/sync/handler/converter/PutCommandConverter.js.map +1 -1
  147. package/sync/handler/converter/QueryCommandConverter.js +12 -11
  148. package/sync/handler/converter/QueryCommandConverter.js.map +1 -1
  149. package/sync/handler/converter/ScanCommandConverter.js +12 -11
  150. package/sync/handler/converter/ScanCommandConverter.js.map +1 -1
  151. package/sync/handler/converter/UpdateCommandConverter.js +12 -11
  152. package/sync/handler/converter/UpdateCommandConverter.js.map +1 -1
  153. package/sync/handler/converter/commands/BatchWriteCommandValue.js +34 -37
  154. package/sync/handler/converter/commands/BatchWriteCommandValue.js.map +1 -1
  155. package/sync/handler/converter/commands/DeleteCommandValue.js +19 -16
  156. package/sync/handler/converter/commands/DeleteCommandValue.js.map +1 -1
  157. package/sync/handler/converter/commands/NullCommandValue.js +8 -8
  158. package/sync/handler/converter/commands/NullCommandValue.js.map +1 -1
  159. package/sync/handler/converter/commands/PutCommandValue.js +19 -16
  160. package/sync/handler/converter/commands/PutCommandValue.js.map +1 -1
  161. package/sync/handler/converter/commands/UpdateCommandValue.js +19 -16
  162. package/sync/handler/converter/commands/UpdateCommandValue.js.map +1 -1
  163. package/sync/handler/types.js +0 -3
  164. package/sync/plugins/FilterOutRecordPlugin.js +17 -19
  165. package/sync/plugins/FilterOutRecordPlugin.js.map +1 -1
  166. package/sync/types.js +0 -3
  167. package/sync/utils/getTableType.js +10 -9
  168. package/sync/utils/getTableType.js.map +1 -1
  169. package/sync/utils/manifest.d.ts +2 -6
  170. package/sync/utils/manifest.js +27 -36
  171. package/sync/utils/manifest.js.map +1 -1
  172. package/sync/utils/validateSystemInput.js +21 -29
  173. package/sync/utils/validateSystemInput.js.map +1 -1
  174. package/types.d.ts +0 -2
  175. package/types.js +6 -5
  176. package/types.js.map +1 -1
  177. package/utils/createSystemName.js +5 -3
  178. package/utils/createSystemName.js.map +1 -1
  179. package/worker/SyncWorkerConfig.d.ts +9 -0
  180. package/worker/SyncWorkerConfig.js +5 -0
  181. package/worker/SyncWorkerConfig.js.map +1 -0
  182. package/worker/SyncWorkerEventHandler.d.ts +14 -0
  183. package/worker/SyncWorkerEventHandler.js +5 -0
  184. package/worker/SyncWorkerEventHandler.js.map +1 -0
  185. package/worker/SyncWorkerEventType.d.ts +10 -0
  186. package/worker/SyncWorkerEventType.js +24 -0
  187. package/worker/SyncWorkerEventType.js.map +1 -0
  188. package/worker/SyncWorkerLambdaHandler.d.ts +13 -0
  189. package/worker/SyncWorkerLambdaHandler.js +61 -0
  190. package/worker/SyncWorkerLambdaHandler.js.map +1 -0
  191. package/worker/actions/copyFile/CopyFile.js +183 -258
  192. package/worker/actions/copyFile/CopyFile.js.map +1 -1
  193. package/worker/actions/copyFile/copyFileAction.js +26 -34
  194. package/worker/actions/copyFile/copyFileAction.js.map +1 -1
  195. package/worker/actions/copyFile/copyFileSchema.js +13 -14
  196. package/worker/actions/copyFile/copyFileSchema.js.map +1 -1
  197. package/worker/actions/copyFile/types.js +0 -3
  198. package/worker/actions/createUser/CreateUser.js +51 -74
  199. package/worker/actions/createUser/CreateUser.js.map +1 -1
  200. package/worker/actions/createUser/createUserAction.js +24 -28
  201. package/worker/actions/createUser/createUserAction.js.map +1 -1
  202. package/worker/actions/createUser/createUserSchema.js +13 -14
  203. package/worker/actions/createUser/createUserSchema.js.map +1 -1
  204. package/worker/actions/createUser/types.js +0 -3
  205. package/worker/actions/deleteFile/DeleteFile.js +52 -67
  206. package/worker/actions/deleteFile/DeleteFile.js.map +1 -1
  207. package/worker/actions/deleteFile/deleteFileAction.js +21 -29
  208. package/worker/actions/deleteFile/deleteFileAction.js.map +1 -1
  209. package/worker/actions/deleteFile/deleteFileSchema.js +13 -14
  210. package/worker/actions/deleteFile/deleteFileSchema.js.map +1 -1
  211. package/worker/actions/deleteFile/types.js +0 -3
  212. package/worker/actions/deleteUser/DeleteUser.js +38 -52
  213. package/worker/actions/deleteUser/DeleteUser.js.map +1 -1
  214. package/worker/actions/deleteUser/deleteUserAction.js +22 -26
  215. package/worker/actions/deleteUser/deleteUserAction.js.map +1 -1
  216. package/worker/actions/deleteUser/deleteUserSchema.js +12 -13
  217. package/worker/actions/deleteUser/deleteUserSchema.js.map +1 -1
  218. package/worker/actions/deleteUser/types.js +0 -3
  219. package/worker/actions/logValidationError.js +5 -6
  220. package/worker/actions/logValidationError.js.map +1 -1
  221. package/worker/actions/removeCognitoUserAttributes.js +9 -15
  222. package/worker/actions/removeCognitoUserAttributes.js.map +1 -1
  223. package/worker/actions/updateUser/UpdateUser.js +48 -65
  224. package/worker/actions/updateUser/UpdateUser.js.map +1 -1
  225. package/worker/actions/updateUser/types.js +0 -3
  226. package/worker/actions/updateUser/updateUserAction.js +24 -28
  227. package/worker/actions/updateUser/updateUserAction.js.map +1 -1
  228. package/worker/actions/updateUser/updateUserSchema.js +13 -14
  229. package/worker/actions/updateUser/updateUserSchema.js.map +1 -1
  230. package/worker/handler/WorkerActionHandler.js +19 -21
  231. package/worker/handler/WorkerActionHandler.js.map +1 -1
  232. package/worker/plugins/WorkerActionPlugin.js +17 -16
  233. package/worker/plugins/WorkerActionPlugin.js.map +1 -1
  234. package/worker/types.js +0 -3
  235. package/index.js.map +0 -1
  236. package/resolver/app/abstractions/RecordHandler.js.map +0 -1
  237. package/resolver/app/abstractions/RecordsValidation.js.map +0 -1
  238. package/resolver/app/abstractions/ResolverApplication.js.map +0 -1
  239. package/resolver/app/abstractions/ResolverRecord.js.map +0 -1
  240. package/resolver/app/bundler/types.js.map +0 -1
  241. package/resolver/app/data/types.js.map +0 -1
  242. package/resolver/app/fetcher/types.js.map +0 -1
  243. package/resolver/app/ingestor/types.js.map +0 -1
  244. package/resolver/app/storer/types.js.map +0 -1
  245. package/resolver/createEventHandlerPlugin.d.ts +0 -11
  246. package/resolver/createEventHandlerPlugin.js +0 -120
  247. package/resolver/createEventHandlerPlugin.js.map +0 -1
  248. package/resolver/createResolverHandler.d.ts +0 -21
  249. package/resolver/createResolverHandler.js +0 -72
  250. package/resolver/createResolverHandler.js.map +0 -1
  251. package/resolver/deployment/types.js.map +0 -1
  252. package/resolver/recordTypes/fileManager/types.js.map +0 -1
  253. package/resolver/recordTypes/users/types.js.map +0 -1
  254. package/sync/createSendDataToEventBridgeOnRequestEnd.d.ts +0 -2
  255. package/sync/createSendDataToEventBridgeOnRequestEnd.js +0 -44
  256. package/sync/createSendDataToEventBridgeOnRequestEnd.js.map +0 -1
  257. package/sync/createSyncSystem.d.ts +0 -16
  258. package/sync/createSyncSystem.js +0 -35
  259. package/sync/createSyncSystem.js.map +0 -1
  260. package/sync/handler/types.js.map +0 -1
  261. package/sync/requestPlugin.d.ts +0 -9
  262. package/sync/requestPlugin.js +0 -58
  263. package/sync/requestPlugin.js.map +0 -1
  264. package/sync/types.js.map +0 -1
  265. package/worker/actions/copyFile/types.js.map +0 -1
  266. package/worker/actions/createUser/types.js.map +0 -1
  267. package/worker/actions/deleteFile/types.js.map +0 -1
  268. package/worker/actions/deleteUser/types.js.map +0 -1
  269. package/worker/actions/updateUser/types.js.map +0 -1
  270. package/worker/createWorkerHandler.d.ts +0 -11
  271. package/worker/createWorkerHandler.js +0 -41
  272. package/worker/createWorkerHandler.js.map +0 -1
  273. package/worker/handler/eventHandler.d.ts +0 -1
  274. package/worker/handler/eventHandler.js +0 -24
  275. package/worker/handler/eventHandler.js.map +0 -1
  276. package/worker/types.js.map +0 -1
package/constants.js CHANGED
@@ -1,3 +1,4 @@
1
- export const SQS_EVENT_NAME = "synchronization-input";
1
+ const SQS_EVENT_NAME = "synchronization-input";
2
+ export { SQS_EVENT_NAME };
2
3
 
3
4
  //# sourceMappingURL=constants.js.map
package/constants.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["SQS_EVENT_NAME"],"sources":["constants.ts"],"sourcesContent":["export const SQS_EVENT_NAME = \"synchronization-input\" as const;\n"],"mappings":"AAAA,OAAO,MAAMA,cAAc,GAAG,uBAAgC","ignoreList":[]}
1
+ {"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const SQS_EVENT_NAME = \"synchronization-input\" as const;\n"],"names":["SQS_EVENT_NAME"],"mappings":"AAAO,MAAMA,iBAAiB"}
package/index.d.ts CHANGED
@@ -1,3 +1,11 @@
1
- export * from "./worker/createWorkerHandler.js";
2
- export * from "./sync/createSyncSystem.js";
3
- export * from "./resolver/createResolverHandler.js";
1
+ export { SyncResolverConfig } from "./resolver/SyncResolverConfig.js";
2
+ export type { ISyncResolverConfig } from "./resolver/SyncResolverConfig.js";
3
+ export { SyncResolverLambdaHandler } from "./resolver/SyncResolverLambdaHandler.js";
4
+ export { SyncWorkerConfig } from "./worker/SyncWorkerConfig.js";
5
+ export type { ISyncWorkerConfig } from "./worker/SyncWorkerConfig.js";
6
+ export { SyncWorkerEventType } from "./worker/SyncWorkerEventType.js";
7
+ export { SyncWorkerEventHandler } from "./worker/SyncWorkerEventHandler.js";
8
+ export { SyncWorkerLambdaHandler } from "./worker/SyncWorkerLambdaHandler.js";
9
+ export { SyncSystemConfig } from "./sync/SyncSystemConfig.js";
10
+ export type { ISyncSystemConfig } from "./sync/SyncSystemConfig.js";
11
+ export { ApiGatewaySyncDecorator } from "./sync/ApiGatewaySyncDecorator.js";
package/index.js CHANGED
@@ -1,5 +1,8 @@
1
- export * from "./worker/createWorkerHandler.js";
2
- export * from "./sync/createSyncSystem.js";
3
- export * from "./resolver/createResolverHandler.js";
4
-
5
- //# sourceMappingURL=index.js.map
1
+ export { SyncResolverConfig } from "./resolver/SyncResolverConfig.js";
2
+ export { SyncResolverLambdaHandler } from "./resolver/SyncResolverLambdaHandler.js";
3
+ export { SyncWorkerConfig } from "./worker/SyncWorkerConfig.js";
4
+ export { SyncWorkerEventType } from "./worker/SyncWorkerEventType.js";
5
+ export { SyncWorkerEventHandler } from "./worker/SyncWorkerEventHandler.js";
6
+ export { SyncWorkerLambdaHandler } from "./worker/SyncWorkerLambdaHandler.js";
7
+ export { SyncSystemConfig } from "./sync/SyncSystemConfig.js";
8
+ export { ApiGatewaySyncDecorator } from "./sync/ApiGatewaySyncDecorator.js";
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@webiny/api-sync-system",
3
- "version": "0.0.0-unstable.c27f4d8a31",
3
+ "version": "0.0.0-unstable.d0f34a8194",
4
4
  "type": "module",
5
- "main": "index.js",
5
+ "exports": {
6
+ ".": "./index.js",
7
+ "./*": "./*"
8
+ },
6
9
  "repository": {
7
10
  "type": "git",
8
11
  "url": "https://github.com/webiny/webiny-js.git"
@@ -11,32 +14,37 @@
11
14
  "author": "Webiny LTD",
12
15
  "license": "MIT",
13
16
  "dependencies": {
14
- "@webiny/api": "0.0.0-unstable.c27f4d8a31",
15
- "@webiny/aws-sdk": "0.0.0-unstable.c27f4d8a31",
16
- "@webiny/error": "0.0.0-unstable.c27f4d8a31",
17
- "@webiny/handler": "0.0.0-unstable.c27f4d8a31",
18
- "@webiny/handler-aws": "0.0.0-unstable.c27f4d8a31",
19
- "@webiny/plugins": "0.0.0-unstable.c27f4d8a31",
20
- "@webiny/utils": "0.0.0-unstable.c27f4d8a31",
17
+ "@webiny/api": "0.0.0-unstable.d0f34a8194",
18
+ "@webiny/api-core": "0.0.0-unstable.d0f34a8194",
19
+ "@webiny/aws-sdk": "0.0.0-unstable.d0f34a8194",
20
+ "@webiny/error": "0.0.0-unstable.d0f34a8194",
21
+ "@webiny/event-handler-aws": "0.0.0-unstable.d0f34a8194",
22
+ "@webiny/event-handler-core": "0.0.0-unstable.d0f34a8194",
23
+ "@webiny/feature": "0.0.0-unstable.d0f34a8194",
24
+ "@webiny/handler": "0.0.0-unstable.d0f34a8194",
25
+ "@webiny/plugins": "0.0.0-unstable.d0f34a8194",
26
+ "@webiny/utils": "0.0.0-unstable.d0f34a8194",
21
27
  "bytes": "3.1.2",
22
- "lodash": "4.17.23",
23
- "semver": "7.7.4",
24
- "zod": "4.3.6"
28
+ "lodash": "4.18.1",
29
+ "semver": "7.8.5",
30
+ "zod": "4.4.3"
25
31
  },
26
32
  "devDependencies": {
27
- "@faker-js/faker": "9.9.0",
28
- "@types/lodash": "4.17.24",
29
- "@webiny/build-tools": "0.0.0-unstable.c27f4d8a31",
30
- "@webiny/project-utils": "0.0.0-unstable.c27f4d8a31",
33
+ "@faker-js/faker": "10.6.0",
34
+ "@types/lodash": "4.17.25",
35
+ "@webiny/api-core-ddb": "0.0.0-unstable.d0f34a8194",
36
+ "@webiny/build-tools": "0.0.0-unstable.d0f34a8194",
37
+ "@webiny/db-dynamodb": "0.0.0-unstable.d0f34a8194",
31
38
  "aws-sdk-client-mock": "4.1.0",
32
39
  "jest-dynalite": "3.6.1",
33
40
  "rimraf": "6.1.3",
34
- "typescript": "5.9.3",
35
- "vitest": "4.0.18"
41
+ "typescript": "7.0.2",
42
+ "vitest": "4.1.11"
36
43
  },
37
44
  "publishConfig": {
38
- "access": "public",
39
- "directory": "dist"
45
+ "access": "public"
40
46
  },
41
- "gitHead": "c27f4d8a31c3af1570817797441855292b6c1f20"
47
+ "webiny": {
48
+ "publishFrom": "dist"
49
+ }
42
50
  }
@@ -0,0 +1,17 @@
1
+ import type { DynamoDBClientConfig, DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
2
+ import type { LambdaClient, LambdaClientConfig } from "@webiny/aws-sdk/client-lambda/index.js";
3
+ import type { S3Client, S3ClientConfig } from "@webiny/aws-sdk/client-s3/index.js";
4
+ import type { CognitoIdentityProvider, CognitoIdentityProviderClientConfig } from "@webiny/aws-sdk/client-cognito-identity-provider/index.js";
5
+ import type { TransformRecordPlugin } from "./plugins/TransformRecordPlugin.js";
6
+ import type { CommandHandlerPlugin } from "./plugins/CommandHandlerPlugin.js";
7
+ export type AllowedResolverPlugins = TransformRecordPlugin | CommandHandlerPlugin;
8
+ export interface ISyncResolverConfig {
9
+ tableName?: string;
10
+ awsWorkerLambdaArn?: string;
11
+ createDocumentClient(params: Partial<DynamoDBClientConfig>): Pick<DynamoDBDocument, "send">;
12
+ createLambdaClient?(config: Partial<LambdaClientConfig>): Pick<LambdaClient, "send">;
13
+ createS3Client?(config: S3ClientConfig): Pick<S3Client, "send">;
14
+ createCognitoIdentityProviderClient?(config: Partial<CognitoIdentityProviderClientConfig>): Pick<CognitoIdentityProvider, "send">;
15
+ plugins?: AllowedResolverPlugins[];
16
+ }
17
+ export declare const SyncResolverConfig: import("@webiny/di").Abstraction<ISyncResolverConfig>;
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const SyncResolverConfig = createAbstraction("SyncResolverConfig");
3
+ export { SyncResolverConfig };
4
+
5
+ //# sourceMappingURL=SyncResolverConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolver/SyncResolverConfig.js","sources":["../../src/resolver/SyncResolverConfig.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type {\n DynamoDBClientConfig,\n DynamoDBDocument\n} from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { LambdaClient, LambdaClientConfig } from \"@webiny/aws-sdk/client-lambda/index.js\";\nimport type { S3Client, S3ClientConfig } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport type {\n CognitoIdentityProvider,\n CognitoIdentityProviderClientConfig\n} from \"@webiny/aws-sdk/client-cognito-identity-provider/index.js\";\nimport type { TransformRecordPlugin } from \"./plugins/TransformRecordPlugin.js\";\nimport type { CommandHandlerPlugin } from \"./plugins/CommandHandlerPlugin.js\";\n\nexport type AllowedResolverPlugins = TransformRecordPlugin | CommandHandlerPlugin;\n\nexport interface ISyncResolverConfig {\n tableName?: string;\n awsWorkerLambdaArn?: string;\n createDocumentClient(params: Partial<DynamoDBClientConfig>): Pick<DynamoDBDocument, \"send\">;\n createLambdaClient?(config: Partial<LambdaClientConfig>): Pick<LambdaClient, \"send\">;\n createS3Client?(config: S3ClientConfig): Pick<S3Client, \"send\">;\n createCognitoIdentityProviderClient?(\n config: Partial<CognitoIdentityProviderClientConfig>\n ): Pick<CognitoIdentityProvider, \"send\">;\n plugins?: AllowedResolverPlugins[];\n}\n\nexport const SyncResolverConfig = createAbstraction<ISyncResolverConfig>(\"SyncResolverConfig\");\n"],"names":["SyncResolverConfig","createAbstraction"],"mappings":";AA4BO,MAAMA,qBAAqBC,kBAAuC"}
@@ -0,0 +1,14 @@
1
+ import { SqsEventHandler } from "@webiny/event-handler-aws/abstractions/handlers/SqsEventHandler.js";
2
+ import type { SqsResult } from "@webiny/event-handler-aws/abstractions/handlers/SqsEventHandler.js";
3
+ import type { EventContext, NextFunction } from "@webiny/event-handler-core";
4
+ import type { SQSEvent } from "@webiny/aws-sdk/types/index.js";
5
+ import type { ISyncResolverConfig } from "./SyncResolverConfig.js";
6
+ declare class SyncResolverLambdaHandlerImpl implements SqsEventHandler.Interface {
7
+ private config;
8
+ constructor(config: ISyncResolverConfig);
9
+ execute(eventCtx: EventContext<SQSEvent>, _next: NextFunction): Promise<SqsResult>;
10
+ }
11
+ export declare const SyncResolverLambdaHandler: typeof SyncResolverLambdaHandlerImpl & {
12
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/event-handler-aws/abstractions/handlers/SqsEventHandler.js").ISqsEventHandler>;
13
+ };
14
+ export {};
@@ -0,0 +1,159 @@
1
+ import { SqsEventHandler } from "@webiny/event-handler-aws/abstractions/handlers/SqsEventHandler.js";
2
+ import { PluginsContainer } from "@webiny/plugins";
3
+ import { WebinyError } from "@webiny/error";
4
+ import { convertException } from "@webiny/utils";
5
+ import { SyncResolverConfig } from "./SyncResolverConfig.js";
6
+ import { createFetcher } from "./app/fetcher/Fetcher.js";
7
+ import { createDeploymentsFetcher } from "./deployment/DeploymentsFetcher.js";
8
+ import { createStorer } from "./app/storer/Storer.js";
9
+ import { TransformHandler } from "./app/transform/TransformHandler.js";
10
+ import { createRecordHandler } from "./app/RecordHandler.js";
11
+ import { createResolverApp } from "./app/ResolverApplication.js";
12
+ import { createBundler } from "./app/bundler/Bundler.js";
13
+ import { createBundles } from "./app/bundler/Bundles.js";
14
+ import { createCommandBundle } from "./app/bundler/CommandBundle.js";
15
+ import { createTableBundle } from "./app/bundler/TableBundle.js";
16
+ import { SourceDataContainer } from "./app/data/SourceDataContainer.js";
17
+ import { StorerAfterEachPlugin } from "./plugins/StorerAfterEachPlugin.js";
18
+ import { createFileManagerPlugins } from "./recordTypes/fileManager/fileManager.js";
19
+ import { LambdaTrigger } from "./lambda/LambdaTrigger.js";
20
+ import { CopyFile } from "./recordTypes/fileManager/CopyFile.js";
21
+ import { DeleteFile } from "./recordTypes/fileManager/DeleteFile.js";
22
+ import { createUsersPlugins } from "./recordTypes/users/users.js";
23
+ import { CopyUser } from "./recordTypes/users/CopyUser.js";
24
+ import { DeleteUser } from "./recordTypes/users/DeleteUser.js";
25
+ import { createPutCommandHandlerPlugin } from "./app/commandHandler/put.js";
26
+ import { createDeleteCommandHandlerPlugin } from "./app/commandHandler/delete.js";
27
+ async function processResolverEvent(records, config, plugins) {
28
+ const tableName = config.tableName || process.env.DB_TABLE;
29
+ if (!tableName) throw new WebinyError({
30
+ message: "Table name variable is not set."
31
+ });
32
+ const fetcher = createFetcher({
33
+ maxRetries: 10,
34
+ retryDelay: 1000,
35
+ createDocumentClient: (deployment)=>config.createDocumentClient({
36
+ region: deployment.region
37
+ })
38
+ });
39
+ const deploymentsFetcher = createDeploymentsFetcher({
40
+ client: config.createDocumentClient({
41
+ region: process.env.AWS_REGION
42
+ }),
43
+ table: tableName
44
+ });
45
+ const deployments = await deploymentsFetcher.fetch();
46
+ const storerAfterEachPlugins = plugins.byType(StorerAfterEachPlugin.type);
47
+ const storer = createStorer({
48
+ createDocumentClient: (deployment)=>config.createDocumentClient({
49
+ region: deployment.region
50
+ }),
51
+ afterEach: async (params)=>{
52
+ for (const plugin of storerAfterEachPlugins)if (plugin.canHandle(params)) await plugin.handle(params);
53
+ }
54
+ });
55
+ const transformHandler = new TransformHandler({
56
+ plugins
57
+ });
58
+ const recordHandler = createRecordHandler({
59
+ plugins,
60
+ fetcher,
61
+ storer,
62
+ deployments,
63
+ transformHandler,
64
+ commandBundler: createBundler({
65
+ createBundles: ()=>createBundles({
66
+ createBundle: createCommandBundle
67
+ })
68
+ }),
69
+ tableBundler: createBundler({
70
+ createBundles: ()=>createBundles({
71
+ createBundle: createTableBundle
72
+ })
73
+ }),
74
+ createSourceDataContainer: ()=>SourceDataContainer.create()
75
+ });
76
+ const app = createResolverApp({
77
+ recordHandler,
78
+ deployments
79
+ });
80
+ await app.resolve({
81
+ records
82
+ });
83
+ }
84
+ class SyncResolverLambdaHandlerImpl {
85
+ constructor(config){
86
+ this.config = config;
87
+ }
88
+ async execute(eventCtx, _next) {
89
+ const { createLambdaClient, createS3Client, createCognitoIdentityProviderClient } = this.config;
90
+ const awsWorkerLambdaArn = this.config.awsWorkerLambdaArn || process.env.AWS_SYNC_WORKER_LAMBDA_ARN;
91
+ const copyFileTrigger = createLambdaClient && awsWorkerLambdaArn ? new LambdaTrigger({
92
+ arn: awsWorkerLambdaArn,
93
+ createLambdaClient
94
+ }) : void 0;
95
+ const deleteFileTrigger = createLambdaClient && awsWorkerLambdaArn ? new LambdaTrigger({
96
+ arn: awsWorkerLambdaArn,
97
+ createLambdaClient
98
+ }) : void 0;
99
+ const copyUserTrigger = createLambdaClient && awsWorkerLambdaArn ? new LambdaTrigger({
100
+ arn: awsWorkerLambdaArn,
101
+ createLambdaClient
102
+ }) : void 0;
103
+ const deleteUserTrigger = createLambdaClient && awsWorkerLambdaArn ? new LambdaTrigger({
104
+ arn: awsWorkerLambdaArn,
105
+ createLambdaClient
106
+ }) : void 0;
107
+ const copyFile = createS3Client && copyFileTrigger ? new CopyFile({
108
+ createS3Client,
109
+ getLambdaTrigger: ()=>copyFileTrigger
110
+ }) : void 0;
111
+ const deleteFile = createS3Client && deleteFileTrigger ? new DeleteFile({
112
+ createS3Client,
113
+ getLambdaTrigger: ()=>deleteFileTrigger
114
+ }) : void 0;
115
+ const copyUser = createCognitoIdentityProviderClient && copyUserTrigger ? new CopyUser({
116
+ createCognitoIdentityProviderClient,
117
+ getLambdaTrigger: ()=>copyUserTrigger
118
+ }) : void 0;
119
+ const deleteUser = createCognitoIdentityProviderClient && deleteUserTrigger ? new DeleteUser({
120
+ createCognitoIdentityProviderClient,
121
+ getLambdaTrigger: ()=>deleteUserTrigger
122
+ }) : void 0;
123
+ const plugins = new PluginsContainer([
124
+ ...copyFile && deleteFile ? createFileManagerPlugins({
125
+ copyFile,
126
+ deleteFile
127
+ }) : [],
128
+ ...copyUser && deleteUser ? createUsersPlugins({
129
+ copyUser,
130
+ deleteUser
131
+ }) : [],
132
+ createPutCommandHandlerPlugin(),
133
+ createDeleteCommandHandlerPlugin(),
134
+ ...this.config.plugins || []
135
+ ]);
136
+ try {
137
+ await processResolverEvent(eventCtx.event.Records, this.config, plugins);
138
+ return {
139
+ success: true
140
+ };
141
+ } catch (ex) {
142
+ const error = convertException(ex);
143
+ console.error(error);
144
+ return {
145
+ success: false,
146
+ message: error.message
147
+ };
148
+ }
149
+ }
150
+ }
151
+ const SyncResolverLambdaHandler = SqsEventHandler.createImplementation({
152
+ implementation: SyncResolverLambdaHandlerImpl,
153
+ dependencies: [
154
+ SyncResolverConfig
155
+ ]
156
+ });
157
+ export { SyncResolverLambdaHandler };
158
+
159
+ //# sourceMappingURL=SyncResolverLambdaHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolver/SyncResolverLambdaHandler.js","sources":["../../src/resolver/SyncResolverLambdaHandler.ts"],"sourcesContent":["import { SqsEventHandler } from \"@webiny/event-handler-aws/abstractions/handlers/SqsEventHandler.js\";\nimport type { SqsResult } from \"@webiny/event-handler-aws/abstractions/handlers/SqsEventHandler.js\";\nimport type { EventContext, NextFunction } from \"@webiny/event-handler-core\";\nimport type { SQSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { WebinyError } from \"@webiny/error\";\nimport { convertException } from \"@webiny/utils\";\nimport { SyncResolverConfig } from \"./SyncResolverConfig.js\";\nimport type { ISyncResolverConfig } from \"./SyncResolverConfig.js\";\nimport { createFetcher } from \"~/resolver/app/fetcher/Fetcher.js\";\nimport { createDeploymentsFetcher } from \"~/resolver/deployment/DeploymentsFetcher.js\";\nimport { createStorer } from \"~/resolver/app/storer/Storer.js\";\nimport { TransformHandler } from \"~/resolver/app/transform/TransformHandler.js\";\nimport { createRecordHandler } from \"~/resolver/app/RecordHandler.js\";\nimport { createResolverApp } from \"~/resolver/app/ResolverApplication.js\";\nimport { createBundler } from \"~/resolver/app/bundler/Bundler.js\";\nimport { createBundles } from \"~/resolver/app/bundler/Bundles.js\";\nimport { createCommandBundle } from \"~/resolver/app/bundler/CommandBundle.js\";\nimport { createTableBundle } from \"~/resolver/app/bundler/TableBundle.js\";\nimport { SourceDataContainer } from \"~/resolver/app/data/SourceDataContainer.js\";\nimport { StorerAfterEachPlugin } from \"~/resolver/plugins/StorerAfterEachPlugin.js\";\nimport { createFileManagerPlugins } from \"~/resolver/recordTypes/fileManager/fileManager.js\";\nimport { LambdaTrigger } from \"~/resolver/lambda/LambdaTrigger.js\";\nimport { CopyFile } from \"~/resolver/recordTypes/fileManager/CopyFile.js\";\nimport { DeleteFile } from \"~/resolver/recordTypes/fileManager/DeleteFile.js\";\nimport { createUsersPlugins } from \"~/resolver/recordTypes/users/users.js\";\nimport { CopyUser } from \"~/resolver/recordTypes/users/CopyUser.js\";\nimport { DeleteUser } from \"~/resolver/recordTypes/users/DeleteUser.js\";\nimport { createPutCommandHandlerPlugin } from \"~/resolver/app/commandHandler/put.js\";\nimport { createDeleteCommandHandlerPlugin } from \"~/resolver/app/commandHandler/delete.js\";\nimport type {\n ICopyFileLambdaPayload,\n IDeleteFileLambdaPayload,\n ICopyUserLambdaPayload,\n IDeleteUserLambdaPayload\n} from \"~/types.js\";\n\nasync function processResolverEvent(\n records: SQSEvent[\"Records\"],\n config: ISyncResolverConfig,\n plugins: PluginsContainer\n): Promise<void> {\n const tableName = config.tableName || process.env.DB_TABLE;\n if (!tableName) {\n throw new WebinyError({ message: \"Table name variable is not set.\" });\n }\n\n const fetcher = createFetcher({\n maxRetries: 10,\n retryDelay: 1000,\n createDocumentClient: deployment =>\n config.createDocumentClient({ region: deployment.region })\n });\n\n const deploymentsFetcher = createDeploymentsFetcher({\n client: config.createDocumentClient({ region: process.env.AWS_REGION }),\n table: tableName\n });\n\n const deployments = await deploymentsFetcher.fetch();\n\n const storerAfterEachPlugins = plugins.byType<StorerAfterEachPlugin>(\n StorerAfterEachPlugin.type\n );\n\n const storer = createStorer({\n createDocumentClient: deployment =>\n config.createDocumentClient({ region: deployment.region }),\n afterEach: async params => {\n for (const plugin of storerAfterEachPlugins) {\n if (!plugin.canHandle(params)) {\n continue;\n }\n await plugin.handle(params);\n }\n }\n });\n\n const transformHandler = new TransformHandler({ plugins });\n const recordHandler = createRecordHandler({\n plugins,\n fetcher,\n storer,\n deployments,\n transformHandler,\n commandBundler: createBundler({\n createBundles: () => createBundles({ createBundle: createCommandBundle })\n }),\n tableBundler: createBundler({\n createBundles: () => createBundles({ createBundle: createTableBundle })\n }),\n createSourceDataContainer: () => SourceDataContainer.create()\n });\n\n const app = createResolverApp({ recordHandler, deployments });\n await app.resolve({ records });\n}\n\nclass SyncResolverLambdaHandlerImpl implements SqsEventHandler.Interface {\n constructor(private config: ISyncResolverConfig) {}\n\n async execute(eventCtx: EventContext<SQSEvent>, _next: NextFunction): Promise<SqsResult> {\n const { createLambdaClient, createS3Client, createCognitoIdentityProviderClient } =\n this.config;\n\n const awsWorkerLambdaArn =\n this.config.awsWorkerLambdaArn || process.env.AWS_SYNC_WORKER_LAMBDA_ARN;\n\n const copyFileTrigger =\n createLambdaClient && awsWorkerLambdaArn\n ? new LambdaTrigger<ICopyFileLambdaPayload>({\n arn: awsWorkerLambdaArn,\n createLambdaClient\n })\n : undefined;\n\n const deleteFileTrigger =\n createLambdaClient && awsWorkerLambdaArn\n ? new LambdaTrigger<IDeleteFileLambdaPayload>({\n arn: awsWorkerLambdaArn,\n createLambdaClient\n })\n : undefined;\n\n const copyUserTrigger =\n createLambdaClient && awsWorkerLambdaArn\n ? new LambdaTrigger<ICopyUserLambdaPayload>({\n arn: awsWorkerLambdaArn,\n createLambdaClient\n })\n : undefined;\n\n const deleteUserTrigger =\n createLambdaClient && awsWorkerLambdaArn\n ? new LambdaTrigger<IDeleteUserLambdaPayload>({\n arn: awsWorkerLambdaArn,\n createLambdaClient\n })\n : undefined;\n\n const copyFile =\n createS3Client && copyFileTrigger\n ? new CopyFile({\n createS3Client,\n getLambdaTrigger: () => copyFileTrigger\n })\n : undefined;\n\n const deleteFile =\n createS3Client && deleteFileTrigger\n ? new DeleteFile({\n createS3Client,\n getLambdaTrigger: () => deleteFileTrigger\n })\n : undefined;\n\n const copyUser =\n createCognitoIdentityProviderClient && copyUserTrigger\n ? new CopyUser({\n createCognitoIdentityProviderClient,\n getLambdaTrigger: () => copyUserTrigger\n })\n : undefined;\n\n const deleteUser =\n createCognitoIdentityProviderClient && deleteUserTrigger\n ? new DeleteUser({\n createCognitoIdentityProviderClient,\n getLambdaTrigger: () => deleteUserTrigger\n })\n : undefined;\n\n const plugins = new PluginsContainer([\n ...(copyFile && deleteFile ? createFileManagerPlugins({ copyFile, deleteFile }) : []),\n ...(copyUser && deleteUser ? createUsersPlugins({ copyUser, deleteUser }) : []),\n createPutCommandHandlerPlugin(),\n createDeleteCommandHandlerPlugin(),\n ...(this.config.plugins || [])\n ]);\n\n try {\n await processResolverEvent(eventCtx.event.Records, this.config, plugins);\n return { success: true };\n } catch (ex) {\n const error = convertException(ex);\n console.error(error);\n return { success: false, message: error.message };\n }\n }\n}\n\nexport const SyncResolverLambdaHandler = SqsEventHandler.createImplementation({\n implementation: SyncResolverLambdaHandlerImpl,\n dependencies: [SyncResolverConfig]\n});\n"],"names":["processResolverEvent","records","config","plugins","tableName","process","WebinyError","fetcher","createFetcher","deployment","deploymentsFetcher","createDeploymentsFetcher","deployments","storerAfterEachPlugins","StorerAfterEachPlugin","storer","createStorer","params","plugin","transformHandler","TransformHandler","recordHandler","createRecordHandler","createBundler","createBundles","createCommandBundle","createTableBundle","SourceDataContainer","app","createResolverApp","SyncResolverLambdaHandlerImpl","eventCtx","_next","createLambdaClient","createS3Client","createCognitoIdentityProviderClient","awsWorkerLambdaArn","copyFileTrigger","LambdaTrigger","undefined","deleteFileTrigger","copyUserTrigger","deleteUserTrigger","copyFile","CopyFile","deleteFile","DeleteFile","copyUser","CopyUser","deleteUser","DeleteUser","PluginsContainer","createFileManagerPlugins","createUsersPlugins","createPutCommandHandlerPlugin","createDeleteCommandHandlerPlugin","ex","error","convertException","console","SyncResolverLambdaHandler","SqsEventHandler","SyncResolverConfig"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,eAAeA,qBACXC,OAA4B,EAC5BC,MAA2B,EAC3BC,OAAyB;IAEzB,MAAMC,YAAYF,OAAO,SAAS,IAAIG,QAAQ,GAAG,CAAC,QAAQ;IAC1D,IAAI,CAACD,WACD,MAAM,IAAIE,YAAY;QAAE,SAAS;IAAkC;IAGvE,MAAMC,UAAUC,cAAc;QAC1B,YAAY;QACZ,YAAY;QACZ,sBAAsBC,CAAAA,aAClBP,OAAO,oBAAoB,CAAC;gBAAE,QAAQO,WAAW,MAAM;YAAC;IAChE;IAEA,MAAMC,qBAAqBC,yBAAyB;QAChD,QAAQT,OAAO,oBAAoB,CAAC;YAAE,QAAQG,QAAQ,GAAG,CAAC,UAAU;QAAC;QACrE,OAAOD;IACX;IAEA,MAAMQ,cAAc,MAAMF,mBAAmB,KAAK;IAElD,MAAMG,yBAAyBV,QAAQ,MAAM,CACzCW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BAAsBG,qBAChB,IAAIE,cAAwC;YACxC,KAAKF;YACLH;QACJ,KACAM;QAEV,MAAMI,WACFT,kBAAkBG,kBACZ,IAAIO,SAAS;YACTV;YACA,kBAAkB,IAAMG;QAC5B,KACAE;QAEV,MAAMM,aACFX,kBAAkBM,oBACZ,IAAIM,WAAW;YACXZ;YACA,kBAAkB,IAAMM;QAC5B,KACAD;QAEV,MAAMQ,WACFZ,uCAAuCM,kBACjC,IAAIO,SAAS;YACTb;YACA,kBAAkB,IAAMM;QAC5B,KACAF;QAEV,MAAMU,aACFd,uCAAuCO,oBACjC,IAAIQ,WAAW;YACXf;YACA,kBAAkB,IAAMO;QAC5B,KACAH;QAEV,MAAMpC,UAAU,IAAIgD,iBAAiB;eAC7BR,YAAYE,aAAaO,yBAAyB;gBAAET;gBAAUE;YAAW,KAAK,EAAE;eAChFE,YAAYE,aAAaI,mBAAmB;gBAAEN;gBAAUE;YAAW,KAAK,EAAE;YAC9EK;YACAC;eACI,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE;SAChC;QAED,IAAI;YACA,MAAMvD,qBAAqB+B,SAAS,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE5B;YAChE,OAAO;gBAAE,SAAS;YAAK;QAC3B,EAAE,OAAOqD,IAAI;YACT,MAAMC,QAAQC,iBAAiBF;YAC/BG,QAAQ,KAAK,CAACF;YACd,OAAO;gBAAE,SAAS;gBAAO,SAASA,MAAM,OAAO;YAAC;QACpD;IACJ;AACJ;AAEO,MAAMG,4BAA4BC,gBAAgB,oBAAoB,CAAC;IAC1E,gBAAgB/B;IAChB,cAAc;QAACgC;KAAmB;AACtC"}
@@ -1,118 +1,96 @@
1
1
  import { CommandHandlerPlugin } from "../plugins/CommandHandlerPlugin.js";
2
2
  import { convertException } from "@webiny/utils";
3
- export class RecordHandler {
4
- constructor(params) {
5
- this.plugins = params.plugins;
6
- this.fetcher = params.fetcher;
7
- this.storer = params.storer;
8
- this.commandBundler = params.commandBundler;
9
- this.tableBundler = params.tableBundler;
10
- this.deployments = params.deployments;
11
- this.transformHandler = params.transformHandler;
12
- this.createSourceDataContainer = params.createSourceDataContainer;
13
- this.commandHandlerPlugins = this.plugins.byType(CommandHandlerPlugin.type);
14
- }
15
- async handle(params) {
16
- const {
17
- data
18
- } = params;
19
- const sources = this.tableBundler.bundle({
20
- items: data.getItems()
21
- });
22
- const container = this.createSourceDataContainer();
23
- for (const bundle of sources.getBundles()) {
24
- /**
25
- * Need to fetch all the records from the source deployment tables.
26
- */
27
- const {
28
- items,
29
- error
30
- } = await this.fetcher.exec({
31
- deployment: bundle.source,
32
- table: bundle.table,
33
- items: bundle.items,
34
- maxBatchSize: 25
35
- });
36
- if (error) {
37
- console.error(`Could not fetch records from the source table (${bundle.source.name} / ${bundle.table.name}). More info in next log line.`);
38
- console.log(convertException(error));
39
- continue;
40
- }
41
- container.merge(items);
3
+ class RecordHandler {
4
+ constructor(params){
5
+ this.plugins = params.plugins;
6
+ this.fetcher = params.fetcher;
7
+ this.storer = params.storer;
8
+ this.commandBundler = params.commandBundler;
9
+ this.tableBundler = params.tableBundler;
10
+ this.deployments = params.deployments;
11
+ this.transformHandler = params.transformHandler;
12
+ this.createSourceDataContainer = params.createSourceDataContainer;
13
+ this.commandHandlerPlugins = this.plugins.byType(CommandHandlerPlugin.type);
42
14
  }
43
- /**
44
- * We can now handle the records by going through all the items bundled by command, in correct order.
45
- */
46
- const bundlesByCommand = this.commandBundler.bundle({
47
- items: data.getItems()
48
- });
49
- for (const bundle of bundlesByCommand.getBundles()) {
50
- const deployments = this.deployments.without(bundle.source);
51
- for (const targetDeployment of deployments.all()) {
52
- /**
53
- * We need to map keys to actual items from the source deployment.
54
- */
55
- const items = bundle.items.map(item => {
56
- return container.get({
57
- PK: item.PK,
58
- SK: item.SK,
59
- table: bundle.table,
60
- source: bundle.source
61
- });
62
- }).filter(item => !!item);
63
- const targetTable = this.findTargetTable({
64
- bundle,
65
- targetDeployment
15
+ async handle(params) {
16
+ const { data } = params;
17
+ const sources = this.tableBundler.bundle({
18
+ items: data.getItems()
66
19
  });
67
- if (!targetTable) {
68
- console.error(`Could not find target table for source table "${bundle.table.name}" in deployment "${bundle.source.name}".`);
69
- continue;
20
+ const container = this.createSourceDataContainer();
21
+ for (const bundle of sources.getBundles()){
22
+ const { items, error } = await this.fetcher.exec({
23
+ deployment: bundle.source,
24
+ table: bundle.table,
25
+ items: bundle.items,
26
+ maxBatchSize: 25
27
+ });
28
+ if (error) {
29
+ console.error(`Could not fetch records from the source table (${bundle.source.name} / ${bundle.table.name}). More info in next log line.`);
30
+ console.log(convertException(error));
31
+ continue;
32
+ }
33
+ container.merge(items);
70
34
  }
71
- const result = await this.transformHandler.transform({
72
- items,
73
- sourceDeployment: bundle.source,
74
- sourceTable: bundle.table,
75
- targetDeployment: targetDeployment,
76
- targetTable: targetTable
35
+ const bundlesByCommand = this.commandBundler.bundle({
36
+ items: data.getItems()
77
37
  });
78
- let commandHandler;
79
- try {
80
- commandHandler = this.getCommandHandler(bundle.command);
81
- } catch (ex) {
82
- console.error(ex.message);
83
- continue;
38
+ for (const bundle of bundlesByCommand.getBundles()){
39
+ const deployments = this.deployments.without(bundle.source);
40
+ for (const targetDeployment of deployments.all()){
41
+ const items = bundle.items.map((item)=>container.get({
42
+ PK: item.PK,
43
+ SK: item.SK,
44
+ table: bundle.table,
45
+ source: bundle.source
46
+ })).filter((item)=>!!item);
47
+ const targetTable = this.findTargetTable({
48
+ bundle,
49
+ targetDeployment
50
+ });
51
+ if (!targetTable) {
52
+ console.error(`Could not find target table for source table "${bundle.table.name}" in deployment "${bundle.source.name}".`);
53
+ continue;
54
+ }
55
+ const result = await this.transformHandler.transform({
56
+ items,
57
+ sourceDeployment: bundle.source,
58
+ sourceTable: bundle.table,
59
+ targetDeployment: targetDeployment,
60
+ targetTable: targetTable
61
+ });
62
+ let commandHandler;
63
+ try {
64
+ commandHandler = this.getCommandHandler(bundle.command);
65
+ } catch (ex) {
66
+ console.error(ex.message);
67
+ continue;
68
+ }
69
+ await commandHandler.handle({
70
+ storer: this.storer,
71
+ items: result.items,
72
+ bundle,
73
+ targetDeployment: targetDeployment,
74
+ targetTable: targetTable
75
+ });
76
+ }
84
77
  }
85
- await commandHandler.handle({
86
- storer: this.storer,
87
- items: result.items,
88
- bundle,
89
- targetDeployment: targetDeployment,
90
- targetTable: targetTable
91
- });
92
- }
93
78
  }
94
- }
95
- findTargetTable(params) {
96
- const {
97
- bundle,
98
- targetDeployment
99
- } = params;
100
- try {
101
- return targetDeployment.getTable(bundle.table.type);
102
- } catch {
103
- return null;
79
+ findTargetTable(params) {
80
+ const { bundle, targetDeployment } = params;
81
+ try {
82
+ return targetDeployment.getTable(bundle.table.type);
83
+ } catch {
84
+ return null;
85
+ }
104
86
  }
105
- }
106
- getCommandHandler(command) {
107
- const handler = this.commandHandlerPlugins.find(plugin => plugin.canHandle(command));
108
- if (!handler) {
109
- throw new Error(`Could not find a command handler for command: ${command}`);
87
+ getCommandHandler(command) {
88
+ const handler = this.commandHandlerPlugins.find((plugin)=>plugin.canHandle(command));
89
+ if (!handler) throw new Error(`Could not find a command handler for command: ${command}`);
90
+ return handler;
110
91
  }
111
- return handler;
112
- }
113
92
  }
114
- export const createRecordHandler = params => {
115
- return new RecordHandler(params);
116
- };
93
+ const createRecordHandler = (params)=>new RecordHandler(params);
94
+ export { RecordHandler, createRecordHandler };
117
95
 
118
96
  //# sourceMappingURL=RecordHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["CommandHandlerPlugin","convertException","RecordHandler","constructor","params","plugins","fetcher","storer","commandBundler","tableBundler","deployments","transformHandler","createSourceDataContainer","commandHandlerPlugins","byType","type","handle","data","sources","bundle","items","getItems","container","getBundles","error","exec","deployment","source","table","maxBatchSize","console","name","log","merge","bundlesByCommand","without","targetDeployment","all","map","item","get","PK","SK","filter","targetTable","findTargetTable","result","transform","sourceDeployment","sourceTable","commandHandler","getCommandHandler","command","ex","message","getTable","handler","find","plugin","canHandle","Error","createRecordHandler"],"sources":["RecordHandler.ts"],"sourcesContent":["import type { IRecordHandler, IRecordHandlerHandleParams } from \"./abstractions/RecordHandler.js\";\nimport { CommandHandlerPlugin } from \"../plugins/CommandHandlerPlugin.js\";\nimport { convertException } from \"@webiny/utils\";\nimport type { CommandType } from \"~/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { IFetcher } from \"~/resolver/app/fetcher/types.js\";\nimport type { IStoreItem, IStorer } from \"~/resolver/app/storer/types.js\";\nimport type { IBundle, IBundler } from \"~/resolver/app/bundler/types.js\";\nimport type { IDeployment, IDeployments } from \"~/resolver/deployment/types.js\";\nimport type { ITransformHandler } from \"~/resolver/app/transform/TransformHandler.js\";\nimport type { ITable } from \"~/sync/types.js\";\nimport type { ISourceDataContainer } from \"~/resolver/app/data/types.js\";\n\nexport interface IRecordHandlerParams {\n fetcher: IFetcher;\n storer: IStorer;\n plugins: PluginsContainer;\n commandBundler: IBundler;\n tableBundler: IBundler;\n deployments: IDeployments;\n transformHandler: ITransformHandler;\n createSourceDataContainer: () => ISourceDataContainer;\n}\n\ninterface IFindTargetTableParams {\n bundle: IBundle;\n targetDeployment: IDeployment;\n}\n\nexport class RecordHandler implements IRecordHandler {\n private readonly plugins: PluginsContainer;\n private readonly commandHandlerPlugins: CommandHandlerPlugin[];\n private readonly fetcher: IFetcher;\n private readonly storer: IStorer;\n private readonly commandBundler: IBundler;\n private readonly tableBundler: IBundler;\n private readonly deployments: IDeployments;\n private readonly transformHandler: ITransformHandler;\n private readonly createSourceDataContainer: () => ISourceDataContainer;\n\n public constructor(params: IRecordHandlerParams) {\n this.plugins = params.plugins;\n this.fetcher = params.fetcher;\n this.storer = params.storer;\n this.commandBundler = params.commandBundler;\n this.tableBundler = params.tableBundler;\n this.deployments = params.deployments;\n this.transformHandler = params.transformHandler;\n this.createSourceDataContainer = params.createSourceDataContainer;\n\n this.commandHandlerPlugins = this.plugins.byType<CommandHandlerPlugin>(\n CommandHandlerPlugin.type\n );\n }\n\n public async handle(params: IRecordHandlerHandleParams): Promise<void> {\n const { data } = params;\n\n const sources = this.tableBundler.bundle({\n items: data.getItems()\n });\n\n const container = this.createSourceDataContainer();\n\n for (const bundle of sources.getBundles()) {\n /**\n * Need to fetch all the records from the source deployment tables.\n */\n const { items, error } = await this.fetcher.exec({\n deployment: bundle.source,\n table: bundle.table,\n items: bundle.items,\n maxBatchSize: 25\n });\n if (error) {\n console.error(\n `Could not fetch records from the source table (${bundle.source.name} / ${bundle.table.name}). More info in next log line.`\n );\n console.log(convertException(error));\n continue;\n }\n container.merge(items);\n }\n /**\n * We can now handle the records by going through all the items bundled by command, in correct order.\n */\n const bundlesByCommand = this.commandBundler.bundle({\n items: data.getItems()\n });\n for (const bundle of bundlesByCommand.getBundles()) {\n const deployments = this.deployments.without(bundle.source);\n for (const targetDeployment of deployments.all()) {\n /**\n * We need to map keys to actual items from the source deployment.\n */\n const items = bundle.items\n .map(item => {\n return container.get({\n PK: item.PK,\n SK: item.SK,\n table: bundle.table,\n source: bundle.source\n });\n })\n .filter((item): item is IStoreItem => !!item);\n\n const targetTable = this.findTargetTable({\n bundle,\n targetDeployment\n });\n if (!targetTable) {\n console.error(\n `Could not find target table for source table \"${bundle.table.name}\" in deployment \"${bundle.source.name}\".`\n );\n continue;\n }\n\n const result = await this.transformHandler.transform({\n items,\n sourceDeployment: bundle.source,\n sourceTable: bundle.table,\n targetDeployment: targetDeployment,\n targetTable: targetTable\n });\n\n let commandHandler: CommandHandlerPlugin;\n try {\n commandHandler = this.getCommandHandler(bundle.command);\n } catch (ex) {\n console.error(ex.message);\n continue;\n }\n\n await commandHandler.handle({\n storer: this.storer,\n items: result.items,\n bundle,\n targetDeployment: targetDeployment,\n targetTable: targetTable\n });\n }\n }\n }\n\n private findTargetTable(params: IFindTargetTableParams): ITable | null {\n const { bundle, targetDeployment } = params;\n\n try {\n return targetDeployment.getTable(bundle.table.type);\n } catch {\n return null;\n }\n }\n\n private getCommandHandler(command: CommandType): CommandHandlerPlugin {\n const handler = this.commandHandlerPlugins.find(plugin => plugin.canHandle(command));\n if (!handler) {\n throw new Error(`Could not find a command handler for command: ${command}`);\n }\n\n return handler;\n }\n}\n\nexport const createRecordHandler = (params: IRecordHandlerParams): IRecordHandler => {\n return new RecordHandler(params);\n};\n"],"mappings":"AACA,SAASA,oBAAoB;AAC7B,SAASC,gBAAgB,QAAQ,eAAe;AA2BhD,OAAO,MAAMC,aAAa,CAA2B;EAW1CC,WAAWA,CAACC,MAA4B,EAAE;IAC7C,IAAI,CAACC,OAAO,GAAGD,MAAM,CAACC,OAAO;IAC7B,IAAI,CAACC,OAAO,GAAGF,MAAM,CAACE,OAAO;IAC7B,IAAI,CAACC,MAAM,GAAGH,MAAM,CAACG,MAAM;IAC3B,IAAI,CAACC,cAAc,GAAGJ,MAAM,CAACI,cAAc;IAC3C,IAAI,CAACC,YAAY,GAAGL,MAAM,CAACK,YAAY;IACvC,IAAI,CAACC,WAAW,GAAGN,MAAM,CAACM,WAAW;IACrC,IAAI,CAACC,gBAAgB,GAAGP,MAAM,CAACO,gBAAgB;IAC/C,IAAI,CAACC,yBAAyB,GAAGR,MAAM,CAACQ,yBAAyB;IAEjE,IAAI,CAACC,qBAAqB,GAAG,IAAI,CAACR,OAAO,CAACS,MAAM,CAC5Cd,oBAAoB,CAACe,IACzB,CAAC;EACL;EAEA,MAAaC,MAAMA,CAACZ,MAAkC,EAAiB;IACnE,MAAM;MAAEa;IAAK,CAAC,GAAGb,MAAM;IAEvB,MAAMc,OAAO,GAAG,IAAI,CAACT,YAAY,CAACU,MAAM,CAAC;MACrCC,KAAK,EAAEH,IAAI,CAACI,QAAQ,CAAC;IACzB,CAAC,CAAC;IAEF,MAAMC,SAAS,GAAG,IAAI,CAACV,yBAAyB,CAAC,CAAC;IAElD,KAAK,MAAMO,MAAM,IAAID,OAAO,CAACK,UAAU,CAAC,CAAC,EAAE;MACvC;AACZ;AACA;MACY,MAAM;QAAEH,KAAK;QAAEI;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MI,OAAO,GAAG,IAAI,CAAC3C,qBAAqB,CAAC4C,IAAI,CAACC,MAAM,IAAIA,MAAM,CAACC,SAAS,CAACP,OAAO,CAAC,CAAC;IACpF,IAAI,CAACI,OAAO,EAAE;MACV,MAAM,IAAII,KAAK,CAAC,iDAAiDR,OAAO,EAAE,CAAC;IAC/E;IAEA,OAAOI,OAAO;EAClB;AACJ;AAEA,OAAO,MAAMK,mBAAmB,GAAIzD,MAA4B,IAAqB;EACjF,OAAO,IAAIF,aAAa,CAACE,MAAM,CAAC;AACpC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"resolver/app/RecordHandler.js","sources":["../../../src/resolver/app/RecordHandler.ts"],"sourcesContent":["import type { IRecordHandler, IRecordHandlerHandleParams } from \"./abstractions/RecordHandler.js\";\nimport { CommandHandlerPlugin } from \"../plugins/CommandHandlerPlugin.js\";\nimport { convertException } from \"@webiny/utils\";\nimport type { CommandType } from \"~/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { IFetcher } from \"~/resolver/app/fetcher/types.js\";\nimport type { IStoreItem, IStorer } from \"~/resolver/app/storer/types.js\";\nimport type { IBundle, IBundler } from \"~/resolver/app/bundler/types.js\";\nimport type { IDeployment, IDeployments } from \"~/resolver/deployment/types.js\";\nimport type { ITransformHandler } from \"~/resolver/app/transform/TransformHandler.js\";\nimport type { ITable } from \"~/sync/types.js\";\nimport type { ISourceDataContainer } from \"~/resolver/app/data/types.js\";\n\nexport interface IRecordHandlerParams {\n fetcher: IFetcher;\n storer: IStorer;\n plugins: PluginsContainer;\n commandBundler: IBundler;\n tableBundler: IBundler;\n deployments: IDeployments;\n transformHandler: ITransformHandler;\n createSourceDataContainer: () => ISourceDataContainer;\n}\n\ninterface IFindTargetTableParams {\n bundle: IBundle;\n targetDeployment: IDeployment;\n}\n\nexport class RecordHandler implements IRecordHandler {\n private readonly plugins: PluginsContainer;\n private readonly commandHandlerPlugins: CommandHandlerPlugin[];\n private readonly fetcher: IFetcher;\n private readonly storer: IStorer;\n private readonly commandBundler: IBundler;\n private readonly tableBundler: IBundler;\n private readonly deployments: IDeployments;\n private readonly transformHandler: ITransformHandler;\n private readonly createSourceDataContainer: () => ISourceDataContainer;\n\n public constructor(params: IRecordHandlerParams) {\n this.plugins = params.plugins;\n this.fetcher = params.fetcher;\n this.storer = params.storer;\n this.commandBundler = params.commandBundler;\n this.tableBundler = params.tableBundler;\n this.deployments = params.deployments;\n this.transformHandler = params.transformHandler;\n this.createSourceDataContainer = params.createSourceDataContainer;\n\n this.commandHandlerPlugins = this.plugins.byType<CommandHandlerPlugin>(\n CommandHandlerPlugin.type\n );\n }\n\n public async handle(params: IRecordHandlerHandleParams): Promise<void> {\n const { data } = params;\n\n const sources = this.tableBundler.bundle({\n items: data.getItems()\n });\n\n const container = this.createSourceDataContainer();\n\n for (const bundle of sources.getBundles()) {\n /**\n * Need to fetch all the records from the source deployment tables.\n */\n const { items, error } = await this.fetcher.exec({\n deployment: bundle.source,\n table: bundle.table,\n items: bundle.items,\n maxBatchSize: 25\n });\n if (error) {\n console.error(\n `Could not fetch records from the source table (${bundle.source.name} / ${bundle.table.name}). More info in next log line.`\n );\n console.log(convertException(error));\n continue;\n }\n container.merge(items);\n }\n /**\n * We can now handle the records by going through all the items bundled by command, in correct order.\n */\n const bundlesByCommand = this.commandBundler.bundle({\n items: data.getItems()\n });\n for (const bundle of bundlesByCommand.getBundles()) {\n const deployments = this.deployments.without(bundle.source);\n for (const targetDeployment of deployments.all()) {\n /**\n * We need to map keys to actual items from the source deployment.\n */\n const items = bundle.items\n .map(item => {\n return container.get({\n PK: item.PK,\n SK: item.SK,\n table: bundle.table,\n source: bundle.source\n });\n })\n .filter((item): item is IStoreItem => !!item);\n\n const targetTable = this.findTargetTable({\n bundle,\n targetDeployment\n });\n if (!targetTable) {\n console.error(\n `Could not find target table for source table \"${bundle.table.name}\" in deployment \"${bundle.source.name}\".`\n );\n continue;\n }\n\n const result = await this.transformHandler.transform({\n items,\n sourceDeployment: bundle.source,\n sourceTable: bundle.table,\n targetDeployment: targetDeployment,\n targetTable: targetTable\n });\n\n let commandHandler: CommandHandlerPlugin;\n try {\n commandHandler = this.getCommandHandler(bundle.command);\n } catch (ex) {\n console.error(ex.message);\n continue;\n }\n\n await commandHandler.handle({\n storer: this.storer,\n items: result.items,\n bundle,\n targetDeployment: targetDeployment,\n targetTable: targetTable\n });\n }\n }\n }\n\n private findTargetTable(params: IFindTargetTableParams): ITable | null {\n const { bundle, targetDeployment } = params;\n\n try {\n return targetDeployment.getTable(bundle.table.type);\n } catch {\n return null;\n }\n }\n\n private getCommandHandler(command: CommandType): CommandHandlerPlugin {\n const handler = this.commandHandlerPlugins.find(plugin => plugin.canHandle(command));\n if (!handler) {\n throw new Error(`Could not find a command handler for command: ${command}`);\n }\n\n return handler;\n }\n}\n\nexport const createRecordHandler = (params: IRecordHandlerParams): IRecordHandler => {\n return new RecordHandler(params);\n};\n"],"names":["RecordHandler","params","CommandHandlerPlugin","data","sources","container","bundle","items","error","console","convertException","bundlesByCommand","deployments","targetDeployment","item","targetTable","result","commandHandler","ex","command","handler","plugin","Error","createRecordHandler"],"mappings":";;AA6BO,MAAMA;IAWT,YAAmBC,MAA4B,CAAE;QAC7C,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO;QAC7B,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO;QAC7B,IAAI,CAAC,MAAM,GAAGA,OAAO,MAAM;QAC3B,IAAI,CAAC,cAAc,GAAGA,OAAO,cAAc;QAC3C,IAAI,CAAC,YAAY,GAAGA,OAAO,YAAY;QACvC,IAAI,CAAC,WAAW,GAAGA,OAAO,WAAW;QACrC,IAAI,CAAC,gBAAgB,GAAGA,OAAO,gBAAgB;QAC/C,IAAI,CAAC,yBAAyB,GAAGA,OAAO,yBAAyB;QAEjE,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAC5CC,qBAAqB,IAAI;IAEjC;IAEA,MAAa,OAAOD,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E,aAAa;oBACdN,QAAQ,KAAK,CACT,CAAC,8CAA8C,EAAEH,OAAO,KAAK,CAAC,IAAI,CAAC,iBAAiB,EAAEA,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;oBAEhH;gBACJ;gBAEA,MAAMU,SAAS,MAAM,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC;oBACjDT;oBACA,kBAAkBD,OAAO,MAAM;oBAC/B,aAAaA,OAAO,KAAK;oBACzB,kBAAkBO;oBAClB,aAAaE;gBACjB;gBAEA,IAAIE;gBACJ,IAAI;oBACAA,iBAAiB,IAAI,CAAC,iBAAiB,CAACX,OAAO,OAAO;gBAC1D,EAAE,OAAOY,IAAI;oBACTT,QAAQ,KAAK,CAACS,GAAG,OAAO;oBACxB;gBACJ;gBAEA,MAAMD,eAAe,MAAM,CAAC;oBACxB,QAAQ,IAAI,CAAC,MAAM;oBACnB,OAAOD,OAAO,KAAK;oBACnBV;oBACA,kBAAkBO;oBAClB,aAAaE;gBACjB;YACJ;QACJ;IACJ;IAEQ,gBAAgBd,MAA8B,EAAiB;QACnE,MAAM,EAAEK,MAAM,EAAEO,gBAAgB,EAAE,GAAGZ;QAErC,IAAI;YACA,OAAOY,iBAAiB,QAAQ,CAACP,OAAO,KAAK,CAAC,IAAI;QACtD,EAAE,OAAM;YACJ,OAAO;QACX;IACJ;IAEQ,kBAAkBa,OAAoB,EAAwB;QAClE,MAAMC,UAAU,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAACC,CAAAA,SAAUA,OAAO,SAAS,CAACF;QAC3E,IAAI,CAACC,SACD,MAAM,IAAIE,MAAM,CAAC,8CAA8C,EAAEH,SAAS;QAG9E,OAAOC;IACX;AACJ;AAEO,MAAMG,sBAAsB,CAACtB,SACzB,IAAID,cAAcC"}
@@ -1,21 +1,18 @@
1
1
  import { createZodError } from "@webiny/utils";
2
2
  import { createEventValidation } from "./validation/event.js";
3
3
  const validation = createEventValidation();
4
- export class RecordsValidation {
5
- async validate(records) {
6
- const result = await validation.safeParseAsync(records);
7
- if (result.error) {
8
- return {
9
- error: createZodError(result.error)
10
- };
4
+ class RecordsValidation {
5
+ async validate(records) {
6
+ const result = await validation.safeParseAsync(records);
7
+ if (result.error) return {
8
+ error: createZodError(result.error)
9
+ };
10
+ return {
11
+ records: result.data
12
+ };
11
13
  }
12
- return {
13
- records: result.data
14
- };
15
- }
16
14
  }
17
- export const createRecordsValidation = () => {
18
- return new RecordsValidation();
19
- };
15
+ const createRecordsValidation = ()=>new RecordsValidation();
16
+ export { RecordsValidation, createRecordsValidation };
20
17
 
21
18
  //# sourceMappingURL=RecordsValidation.js.map