@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.
- package/README.md +6 -108
- package/constants.js +2 -7
- package/constants.js.map +1 -1
- package/index.js +3 -40
- package/package.json +29 -26
- package/resolver/app/RecordHandler.d.ts +6 -6
- package/resolver/app/RecordHandler.js +84 -114
- package/resolver/app/RecordHandler.js.map +1 -1
- package/resolver/app/RecordsValidation.js +13 -24
- package/resolver/app/RecordsValidation.js.map +1 -1
- package/resolver/app/ResolverApplication.d.ts +1 -1
- package/resolver/app/ResolverApplication.js +27 -42
- package/resolver/app/ResolverApplication.js.map +1 -1
- package/resolver/app/abstractions/RecordHandler.d.ts +1 -1
- package/resolver/app/abstractions/RecordHandler.js +0 -7
- package/resolver/app/abstractions/RecordsValidation.d.ts +2 -2
- package/resolver/app/abstractions/RecordsValidation.js +0 -7
- package/resolver/app/abstractions/ResolverApplication.js +0 -7
- package/resolver/app/abstractions/ResolverRecord.d.ts +1 -1
- package/resolver/app/abstractions/ResolverRecord.js +0 -7
- package/resolver/app/bundler/BaseBundle.d.ts +6 -6
- package/resolver/app/bundler/BaseBundle.js +16 -22
- package/resolver/app/bundler/BaseBundle.js.map +1 -1
- package/resolver/app/bundler/Bundler.d.ts +1 -1
- package/resolver/app/bundler/Bundler.js +12 -25
- package/resolver/app/bundler/Bundler.js.map +1 -1
- package/resolver/app/bundler/Bundles.d.ts +2 -2
- package/resolver/app/bundler/Bundles.js +20 -33
- package/resolver/app/bundler/Bundles.js.map +1 -1
- package/resolver/app/bundler/CommandBundle.d.ts +1 -1
- package/resolver/app/bundler/CommandBundle.js +8 -25
- package/resolver/app/bundler/CommandBundle.js.map +1 -1
- package/resolver/app/bundler/TableBundle.d.ts +1 -1
- package/resolver/app/bundler/TableBundle.js +7 -22
- package/resolver/app/bundler/TableBundle.js.map +1 -1
- package/resolver/app/bundler/types.d.ts +2 -2
- package/resolver/app/bundler/types.js +0 -7
- package/resolver/app/commandHandler/DeleteCommandHandler.d.ts +3 -3
- package/resolver/app/commandHandler/DeleteCommandHandler.js +21 -35
- package/resolver/app/commandHandler/DeleteCommandHandler.js.map +1 -1
- package/resolver/app/commandHandler/PutCommandHandler.d.ts +4 -4
- package/resolver/app/commandHandler/PutCommandHandler.js +15 -28
- package/resolver/app/commandHandler/PutCommandHandler.js.map +1 -1
- package/resolver/app/commandHandler/delete.d.ts +1 -1
- package/resolver/app/commandHandler/delete.js +13 -21
- package/resolver/app/commandHandler/delete.js.map +1 -1
- package/resolver/app/commandHandler/put.d.ts +1 -1
- package/resolver/app/commandHandler/put.js +13 -21
- package/resolver/app/commandHandler/put.js.map +1 -1
- package/resolver/app/data/SourceDataContainer.d.ts +3 -3
- package/resolver/app/data/SourceDataContainer.js +27 -36
- package/resolver/app/data/SourceDataContainer.js.map +1 -1
- package/resolver/app/data/types.d.ts +2 -2
- package/resolver/app/data/types.js +0 -7
- package/resolver/app/fetcher/Fetcher.d.ts +3 -3
- package/resolver/app/fetcher/Fetcher.js +87 -121
- package/resolver/app/fetcher/Fetcher.js.map +1 -1
- package/resolver/app/fetcher/types.d.ts +2 -2
- package/resolver/app/fetcher/types.js +0 -7
- package/resolver/app/ingestor/Ingestor.d.ts +1 -1
- package/resolver/app/ingestor/Ingestor.js +26 -39
- package/resolver/app/ingestor/Ingestor.js.map +1 -1
- package/resolver/app/ingestor/IngestorResult.js +27 -39
- package/resolver/app/ingestor/IngestorResult.js.map +1 -1
- package/resolver/app/ingestor/types.d.ts +2 -2
- package/resolver/app/ingestor/types.js +0 -7
- package/resolver/app/storer/Storer.d.ts +3 -3
- package/resolver/app/storer/Storer.js +73 -95
- package/resolver/app/storer/Storer.js.map +1 -1
- package/resolver/app/storer/types.d.ts +2 -2
- package/resolver/app/storer/types.js +0 -7
- package/resolver/app/transform/TransformHandler.d.ts +4 -4
- package/resolver/app/transform/TransformHandler.js +46 -64
- package/resolver/app/transform/TransformHandler.js.map +1 -1
- package/resolver/app/transform/middleware.d.ts +1 -1
- package/resolver/app/transform/middleware.js +12 -25
- package/resolver/app/transform/middleware.js.map +1 -1
- package/resolver/app/utils/Retry.js +21 -32
- package/resolver/app/utils/Retry.js.map +1 -1
- package/resolver/app/utils/sleep.js +4 -12
- package/resolver/app/utils/sleep.js.map +1 -1
- package/resolver/app/validation/body.d.ts +25 -124
- package/resolver/app/validation/body.js +31 -44
- package/resolver/app/validation/body.js.map +1 -1
- package/resolver/app/validation/createJsonTransform.d.ts +1 -1
- package/resolver/app/validation/createJsonTransform.js +13 -22
- package/resolver/app/validation/createJsonTransform.js.map +1 -1
- package/resolver/app/validation/detail.d.ts +19 -72
- package/resolver/app/validation/detail.js +33 -46
- package/resolver/app/validation/detail.js.map +1 -1
- package/resolver/app/validation/event.d.ts +29 -188
- package/resolver/app/validation/event.js +21 -30
- package/resolver/app/validation/event.js.map +1 -1
- package/resolver/app/validation/numericString.d.ts +1 -1
- package/resolver/app/validation/numericString.js +9 -20
- package/resolver/app/validation/numericString.js.map +1 -1
- package/resolver/app/validation/system.d.ts +2 -14
- package/resolver/app/validation/system.js +9 -18
- package/resolver/app/validation/system.js.map +1 -1
- package/resolver/createEventHandlerPlugin.d.ts +2 -1
- package/resolver/createEventHandlerPlugin.js +85 -121
- package/resolver/createEventHandlerPlugin.js.map +1 -1
- package/resolver/createResolverHandler.d.ts +1 -1
- package/resolver/createResolverHandler.js +60 -75
- package/resolver/createResolverHandler.js.map +1 -1
- package/resolver/deployment/Deployment.d.ts +2 -3
- package/resolver/deployment/Deployment.js +27 -44
- package/resolver/deployment/Deployment.js.map +1 -1
- package/resolver/deployment/Deployments.js +19 -30
- package/resolver/deployment/Deployments.js.map +1 -1
- package/resolver/deployment/DeploymentsFetcher.js +82 -102
- package/resolver/deployment/DeploymentsFetcher.js.map +1 -1
- package/resolver/deployment/types.d.ts +4 -6
- package/resolver/deployment/types.js +0 -7
- package/resolver/lambda/LambdaTrigger.js +25 -34
- package/resolver/lambda/LambdaTrigger.js.map +1 -1
- package/resolver/plugins/CommandHandlerPlugin.d.ts +3 -3
- package/resolver/plugins/CommandHandlerPlugin.js +17 -24
- package/resolver/plugins/CommandHandlerPlugin.js.map +1 -1
- package/resolver/plugins/StorerAfterEachPlugin.d.ts +2 -2
- package/resolver/plugins/StorerAfterEachPlugin.js +21 -29
- package/resolver/plugins/StorerAfterEachPlugin.js.map +1 -1
- package/resolver/plugins/TransformRecordPlugin.d.ts +3 -3
- package/resolver/plugins/TransformRecordPlugin.js +20 -27
- package/resolver/plugins/TransformRecordPlugin.js.map +1 -1
- package/resolver/recordTypes/fileManager/CopyFile.js +44 -74
- package/resolver/recordTypes/fileManager/CopyFile.js.map +1 -1
- package/resolver/recordTypes/fileManager/DeleteFile.d.ts +1 -1
- package/resolver/recordTypes/fileManager/DeleteFile.js +40 -65
- package/resolver/recordTypes/fileManager/DeleteFile.js.map +1 -1
- package/resolver/recordTypes/fileManager/fileManager.d.ts +1 -1
- package/resolver/recordTypes/fileManager/fileManager.js +7 -12
- package/resolver/recordTypes/fileManager/fileManager.js.map +1 -1
- package/resolver/recordTypes/fileManager/fileManagerOnDelete.d.ts +1 -1
- package/resolver/recordTypes/fileManager/fileManagerOnDelete.js +27 -45
- package/resolver/recordTypes/fileManager/fileManagerOnDelete.js.map +1 -1
- package/resolver/recordTypes/fileManager/fileManagerOnPut.d.ts +1 -1
- package/resolver/recordTypes/fileManager/fileManagerOnPut.js +27 -45
- package/resolver/recordTypes/fileManager/fileManagerOnPut.js.map +1 -1
- package/resolver/recordTypes/fileManager/shouldBeHandled.d.ts +1 -1
- package/resolver/recordTypes/fileManager/shouldBeHandled.js +10 -34
- package/resolver/recordTypes/fileManager/shouldBeHandled.js.map +1 -1
- package/resolver/recordTypes/fileManager/types.d.ts +2 -2
- package/resolver/recordTypes/fileManager/types.js +0 -7
- package/resolver/recordTypes/users/CopyUser.d.ts +2 -2
- package/resolver/recordTypes/users/CopyUser.js +44 -61
- package/resolver/recordTypes/users/CopyUser.js.map +1 -1
- package/resolver/recordTypes/users/DeleteUser.d.ts +2 -2
- package/resolver/recordTypes/users/DeleteUser.js +40 -58
- package/resolver/recordTypes/users/DeleteUser.js.map +1 -1
- package/resolver/recordTypes/users/shouldBeHandled.d.ts +1 -1
- package/resolver/recordTypes/users/shouldBeHandled.js +10 -33
- package/resolver/recordTypes/users/shouldBeHandled.js.map +1 -1
- package/resolver/recordTypes/users/types.d.ts +1 -1
- package/resolver/recordTypes/users/types.js +0 -7
- package/resolver/recordTypes/users/users.js +7 -12
- package/resolver/recordTypes/users/users.js.map +1 -1
- package/resolver/recordTypes/users/usersOnDelete.d.ts +2 -2
- package/resolver/recordTypes/users/usersOnDelete.js +26 -44
- package/resolver/recordTypes/users/usersOnDelete.js.map +1 -1
- package/resolver/recordTypes/users/usersOnPut.d.ts +2 -2
- package/resolver/recordTypes/users/usersOnPut.js +27 -45
- package/resolver/recordTypes/users/usersOnPut.js.map +1 -1
- package/sync/FilterOutRecord.d.ts +2 -2
- package/sync/FilterOutRecord.js +8 -24
- package/sync/FilterOutRecord.js.map +1 -1
- package/sync/attachToDynamoDbDocument.d.ts +1 -1
- package/sync/attachToDynamoDbDocument.js +48 -75
- package/sync/attachToDynamoDbDocument.js.map +1 -1
- package/sync/createHandler.js +44 -60
- package/sync/createHandler.js.map +1 -1
- package/sync/createSendDataToEventBridgeOnRequestEnd.js +34 -46
- package/sync/createSendDataToEventBridgeOnRequestEnd.js.map +1 -1
- package/sync/createSyncSystem.d.ts +1 -1
- package/sync/createSyncSystem.js +27 -36
- package/sync/createSyncSystem.js.map +1 -1
- package/sync/filter/createDefaultFilterOutRecordPlugins.d.ts +1 -1
- package/sync/filter/createDefaultFilterOutRecordPlugins.js +37 -86
- package/sync/filter/createDefaultFilterOutRecordPlugins.js.map +1 -1
- package/sync/handler/Handler.d.ts +2 -2
- package/sync/handler/Handler.js +66 -86
- package/sync/handler/Handler.js.map +1 -1
- package/sync/handler/HandlerConverter.js +20 -36
- package/sync/handler/HandlerConverter.js.map +1 -1
- package/sync/handler/converter/BatchGetCommandConverter.js +13 -20
- package/sync/handler/converter/BatchGetCommandConverter.js.map +1 -1
- package/sync/handler/converter/BatchWriteCommandConverter.js +13 -20
- package/sync/handler/converter/BatchWriteCommandConverter.js.map +1 -1
- package/sync/handler/converter/DeleteCommandConverter.js +13 -20
- package/sync/handler/converter/DeleteCommandConverter.js.map +1 -1
- package/sync/handler/converter/GetCommandConverter.js +13 -20
- package/sync/handler/converter/GetCommandConverter.js.map +1 -1
- package/sync/handler/converter/PutCommandConverter.js +13 -20
- package/sync/handler/converter/PutCommandConverter.js.map +1 -1
- package/sync/handler/converter/QueryCommandConverter.js +13 -20
- package/sync/handler/converter/QueryCommandConverter.js.map +1 -1
- package/sync/handler/converter/ScanCommandConverter.js +13 -20
- package/sync/handler/converter/ScanCommandConverter.js.map +1 -1
- package/sync/handler/converter/UpdateCommandConverter.js +13 -20
- package/sync/handler/converter/UpdateCommandConverter.js.map +1 -1
- package/sync/handler/converter/commands/BatchWriteCommandValue.d.ts +2 -2
- package/sync/handler/converter/commands/BatchWriteCommandValue.js +34 -44
- package/sync/handler/converter/commands/BatchWriteCommandValue.js.map +1 -1
- package/sync/handler/converter/commands/DeleteCommandValue.d.ts +2 -2
- package/sync/handler/converter/commands/DeleteCommandValue.js +19 -23
- package/sync/handler/converter/commands/DeleteCommandValue.js.map +1 -1
- package/sync/handler/converter/commands/NullCommandValue.d.ts +1 -1
- package/sync/handler/converter/commands/NullCommandValue.js +7 -14
- package/sync/handler/converter/commands/NullCommandValue.js.map +1 -1
- package/sync/handler/converter/commands/PutCommandValue.d.ts +2 -2
- package/sync/handler/converter/commands/PutCommandValue.js +19 -23
- package/sync/handler/converter/commands/PutCommandValue.js.map +1 -1
- package/sync/handler/converter/commands/UpdateCommandValue.d.ts +2 -2
- package/sync/handler/converter/commands/UpdateCommandValue.js +19 -23
- package/sync/handler/converter/commands/UpdateCommandValue.js.map +1 -1
- package/sync/handler/types.d.ts +3 -3
- package/sync/handler/types.js +0 -7
- package/sync/plugins/FilterOutRecordPlugin.d.ts +1 -1
- package/sync/plugins/FilterOutRecordPlugin.js +18 -28
- package/sync/plugins/FilterOutRecordPlugin.js.map +1 -1
- package/sync/requestPlugin.d.ts +1 -1
- package/sync/requestPlugin.js +39 -55
- package/sync/requestPlugin.js.map +1 -1
- package/sync/types.js +0 -7
- package/sync/utils/getTableType.js +11 -19
- package/sync/utils/getTableType.js.map +1 -1
- package/sync/utils/manifest.d.ts +3 -7
- package/sync/utils/manifest.js +30 -47
- package/sync/utils/manifest.js.map +1 -1
- package/sync/utils/validateSystemInput.d.ts +1 -1
- package/sync/utils/validateSystemInput.js +22 -37
- package/sync/utils/validateSystemInput.js.map +1 -1
- package/types.d.ts +3 -5
- package/types.js +6 -12
- package/types.js.map +1 -1
- package/utils/createSystemName.js +5 -10
- package/utils/createSystemName.js.map +1 -1
- package/worker/actions/copyFile/CopyFile.js +185 -268
- package/worker/actions/copyFile/CopyFile.js.map +1 -1
- package/worker/actions/copyFile/copyFileAction.d.ts +1 -1
- package/worker/actions/copyFile/copyFileAction.js +30 -45
- package/worker/actions/copyFile/copyFileAction.js.map +1 -1
- package/worker/actions/copyFile/copyFileSchema.d.ts +6 -38
- package/worker/actions/copyFile/copyFileSchema.js +14 -23
- package/worker/actions/copyFile/copyFileSchema.js.map +1 -1
- package/worker/actions/copyFile/types.js +0 -7
- package/worker/actions/createUser/CreateUser.d.ts +1 -1
- package/worker/actions/createUser/CreateUser.js +53 -83
- package/worker/actions/createUser/CreateUser.js.map +1 -1
- package/worker/actions/createUser/createUserAction.d.ts +2 -2
- package/worker/actions/createUser/createUserAction.js +28 -39
- package/worker/actions/createUser/createUserAction.js.map +1 -1
- package/worker/actions/createUser/createUserSchema.d.ts +6 -38
- package/worker/actions/createUser/createUserSchema.js +14 -23
- package/worker/actions/createUser/createUserSchema.js.map +1 -1
- package/worker/actions/createUser/types.js +0 -7
- package/worker/actions/deleteFile/DeleteFile.js +52 -74
- package/worker/actions/deleteFile/DeleteFile.js.map +1 -1
- package/worker/actions/deleteFile/deleteFileAction.d.ts +1 -1
- package/worker/actions/deleteFile/deleteFileAction.js +25 -40
- package/worker/actions/deleteFile/deleteFileAction.js.map +1 -1
- package/worker/actions/deleteFile/deleteFileSchema.d.ts +6 -38
- package/worker/actions/deleteFile/deleteFileSchema.js +14 -23
- package/worker/actions/deleteFile/deleteFileSchema.js.map +1 -1
- package/worker/actions/deleteFile/types.js +0 -7
- package/worker/actions/deleteUser/DeleteUser.d.ts +2 -2
- package/worker/actions/deleteUser/DeleteUser.js +39 -60
- package/worker/actions/deleteUser/DeleteUser.js.map +1 -1
- package/worker/actions/deleteUser/deleteUserAction.d.ts +1 -1
- package/worker/actions/deleteUser/deleteUserAction.js +26 -37
- package/worker/actions/deleteUser/deleteUserAction.js.map +1 -1
- package/worker/actions/deleteUser/deleteUserSchema.d.ts +5 -23
- package/worker/actions/deleteUser/deleteUserSchema.js +13 -22
- package/worker/actions/deleteUser/deleteUserSchema.js.map +1 -1
- package/worker/actions/deleteUser/types.js +0 -7
- package/worker/actions/logValidationError.js +6 -14
- package/worker/actions/logValidationError.js.map +1 -1
- package/worker/actions/removeCognitoUserAttributes.js +9 -22
- package/worker/actions/removeCognitoUserAttributes.js.map +1 -1
- package/worker/actions/updateUser/UpdateUser.d.ts +1 -1
- package/worker/actions/updateUser/UpdateUser.js +50 -74
- package/worker/actions/updateUser/UpdateUser.js.map +1 -1
- package/worker/actions/updateUser/types.js +0 -7
- package/worker/actions/updateUser/updateUserAction.d.ts +2 -2
- package/worker/actions/updateUser/updateUserAction.js +28 -39
- package/worker/actions/updateUser/updateUserAction.js.map +1 -1
- package/worker/actions/updateUser/updateUserSchema.d.ts +6 -38
- package/worker/actions/updateUser/updateUserSchema.js +14 -23
- package/worker/actions/updateUser/updateUserSchema.js.map +1 -1
- package/worker/createWorkerHandler.js +32 -45
- package/worker/createWorkerHandler.js.map +1 -1
- package/worker/handler/WorkerActionHandler.d.ts +2 -2
- package/worker/handler/WorkerActionHandler.js +19 -28
- package/worker/handler/WorkerActionHandler.js.map +1 -1
- package/worker/handler/eventHandler.js +18 -27
- package/worker/handler/eventHandler.js.map +1 -1
- package/worker/plugins/WorkerActionPlugin.d.ts +1 -1
- package/worker/plugins/WorkerActionPlugin.js +18 -25
- package/worker/plugins/WorkerActionPlugin.js.map +1 -1
- package/worker/types.js +0 -7
- package/index.js.map +0 -1
- package/resolver/app/abstractions/RecordHandler.js.map +0 -1
- package/resolver/app/abstractions/RecordsValidation.js.map +0 -1
- package/resolver/app/abstractions/ResolverApplication.js.map +0 -1
- package/resolver/app/abstractions/ResolverRecord.js.map +0 -1
- package/resolver/app/bundler/types.js.map +0 -1
- package/resolver/app/data/types.js.map +0 -1
- package/resolver/app/fetcher/types.js.map +0 -1
- package/resolver/app/ingestor/types.js.map +0 -1
- package/resolver/app/storer/types.js.map +0 -1
- package/resolver/deployment/types.js.map +0 -1
- package/resolver/recordTypes/fileManager/types.js.map +0 -1
- package/resolver/recordTypes/users/types.js.map +0 -1
- package/sync/handler/types.js.map +0 -1
- package/sync/types.js.map +0 -1
- package/worker/actions/copyFile/types.js.map +0 -1
- package/worker/actions/createUser/types.js.map +0 -1
- package/worker/actions/deleteFile/types.js.map +0 -1
- package/worker/actions/deleteUser/types.js.map +0 -1
- package/worker/actions/updateUser/types.js.map +0 -1
- package/worker/types.js.map +0 -1
package/sync/createSyncSystem.js
CHANGED
|
@@ -1,42 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createSyncSystem = void 0;
|
|
7
|
-
var _validateSystemInput = require("./utils/validateSystemInput.js");
|
|
8
|
-
var _requestPlugin = require("./requestPlugin.js");
|
|
9
|
-
var _createDefaultFilterOutRecordPlugins = require("./filter/createDefaultFilterOutRecordPlugins.js");
|
|
1
|
+
import { validateSystemInput } from "./utils/validateSystemInput.js";
|
|
2
|
+
import { createSyncSystemHandlerOnRequestPlugin } from "./requestPlugin.js";
|
|
3
|
+
import { createDefaultFilterOutRecordPlugins } from "./filter/createDefaultFilterOutRecordPlugins.js";
|
|
10
4
|
const emptyResponse = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
plugins () {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
14
8
|
};
|
|
15
|
-
const createSyncSystem = params
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
console.error(error);
|
|
25
|
-
return emptyResponse;
|
|
26
|
-
} else if (!system) {
|
|
27
|
-
console.error("Sync System: No system provided. Sync System will not be attached.");
|
|
28
|
-
return emptyResponse;
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
plugins: () => {
|
|
32
|
-
return [...(params.plugins || []), ...(0, _createDefaultFilterOutRecordPlugins.createDefaultFilterOutRecordPlugins)(), (0, _requestPlugin.createSyncSystemHandlerOnRequestPlugin)({
|
|
33
|
-
getDocumentClient: params.getDocumentClient,
|
|
34
|
-
getEventBridgeClient: params.getEventBridgeClient,
|
|
35
|
-
system
|
|
36
|
-
})];
|
|
9
|
+
const createSyncSystem = (params)=>{
|
|
10
|
+
const { system, error } = validateSystemInput(params.system);
|
|
11
|
+
if (error) {
|
|
12
|
+
console.error(error);
|
|
13
|
+
return emptyResponse;
|
|
14
|
+
}
|
|
15
|
+
if (!system) {
|
|
16
|
+
console.error("Sync System: No system provided. Sync System will not be attached.");
|
|
17
|
+
return emptyResponse;
|
|
37
18
|
}
|
|
38
|
-
|
|
19
|
+
return {
|
|
20
|
+
plugins: ()=>[
|
|
21
|
+
...params.plugins || [],
|
|
22
|
+
...createDefaultFilterOutRecordPlugins(),
|
|
23
|
+
createSyncSystemHandlerOnRequestPlugin({
|
|
24
|
+
getDocumentClient: params.getDocumentClient,
|
|
25
|
+
getEventBridgeClient: params.getEventBridgeClient,
|
|
26
|
+
system
|
|
27
|
+
})
|
|
28
|
+
]
|
|
29
|
+
};
|
|
39
30
|
};
|
|
40
|
-
|
|
31
|
+
export { createSyncSystem };
|
|
41
32
|
|
|
42
33
|
//# sourceMappingURL=createSyncSystem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"sync/createSyncSystem.js","sources":["../../src/sync/createSyncSystem.ts"],"sourcesContent":["import type { Plugin } from \"@webiny/plugins/types.js\";\nimport type { IGetEventBridgeCallable, ISystem } from \"./types.js\";\nimport { validateSystemInput } from \"./utils/validateSystemInput.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { PossiblyUndefinedProperties } from \"@webiny/api/types.js\";\nimport { createSyncSystemHandlerOnRequestPlugin } from \"./requestPlugin.js\";\nimport type { FilterOutRecordPlugin } from \"./plugins/FilterOutRecordPlugin.js\";\nimport { createDefaultFilterOutRecordPlugins } from \"./filter/createDefaultFilterOutRecordPlugins.js\";\n\nexport type IAllowedPlugins = FilterOutRecordPlugin;\n\nexport interface ICreateSyncSystemParams {\n getDocumentClient(): Pick<DynamoDBDocument, \"send\">;\n getEventBridgeClient: IGetEventBridgeCallable;\n system: PossiblyUndefinedProperties<Omit<ISystem, \"name\">>;\n plugins?: IAllowedPlugins[];\n}\n\nexport interface ICreateSyncSystemResponse {\n plugins(): Plugin[];\n}\n\nconst emptyResponse: ICreateSyncSystemResponse = {\n plugins(): Plugin[] {\n return [];\n }\n};\n\nexport const createSyncSystem = (params: ICreateSyncSystemParams): ICreateSyncSystemResponse => {\n const { system, error } = validateSystemInput(params.system);\n /**\n * We do not want to throw any errors. We will log them and just return a function which returns empty array as plugins.\n */\n if (error) {\n console.error(error);\n return emptyResponse;\n } else if (!system) {\n console.error(\"Sync System: No system provided. Sync System will not be attached.\");\n return emptyResponse;\n }\n\n return {\n plugins: () => {\n return [\n ...(params.plugins || []),\n ...createDefaultFilterOutRecordPlugins(),\n createSyncSystemHandlerOnRequestPlugin({\n getDocumentClient: params.getDocumentClient,\n getEventBridgeClient: params.getEventBridgeClient,\n system\n })\n ];\n }\n };\n};\n"],"names":["emptyResponse","createSyncSystem","params","system","error","validateSystemInput","console","createDefaultFilterOutRecordPlugins","createSyncSystemHandlerOnRequestPlugin"],"mappings":";;;AAsBA,MAAMA,gBAA2C;IAC7C;QACI,OAAO,EAAE;IACb;AACJ;AAEO,MAAMC,mBAAmB,CAACC;IAC7B,MAAM,EAAEC,MAAM,EAAEC,KAAK,EAAE,GAAGC,oBAAoBH,OAAO,MAAM;IAI3D,IAAIE,OAAO;QACPE,QAAQ,KAAK,CAACF;QACd,OAAOJ;IACX;IAAO,IAAI,CAACG,QAAQ;QAChBG,QAAQ,KAAK,CAAC;QACd,OAAON;IACX;IAEA,OAAO;QACH,SAAS,IACE;mBACCE,OAAO,OAAO,IAAI,EAAE;mBACrBK;gBACHC,uCAAuC;oBACnC,mBAAmBN,OAAO,iBAAiB;oBAC3C,sBAAsBA,OAAO,oBAAoB;oBACjDC;gBACJ;aACH;IAET;AACJ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FilterOutRecordPlugin } from "
|
|
1
|
+
import { FilterOutRecordPlugin } from "../../sync/plugins/FilterOutRecordPlugin.js";
|
|
2
2
|
/**
|
|
3
3
|
* Order keys by what is most like to be filtered out - most inserts/updates/deletes.
|
|
4
4
|
* This is out of my head, so it might not be the best order.
|
|
@@ -1,88 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// Service Manifest - on deployment if something was changed in the service manifest
|
|
39
|
-
"SERVICE_MANIFEST#",
|
|
40
|
-
// Deployments - on every deployment
|
|
41
|
-
"DEPLOYMENT#"].map(key => {
|
|
42
|
-
return key.toLowerCase();
|
|
43
|
-
});
|
|
44
|
-
/**
|
|
45
|
-
* TODO figure out a way to skip these models.
|
|
46
|
-
* When deleting a record, we do not have a modelId in the values.
|
|
47
|
-
*/
|
|
48
|
-
const skipModels = exports.skipModels = [
|
|
49
|
-
// APW
|
|
50
|
-
"apwChangeRequestModelDefinition", "apwCommentModelDefinition", "apwContentReviewModelDefinition", "apwReviewerModelDefinition", "apwWorkflowModelDefnition", "apwWorkflowModelDefinition",
|
|
51
|
-
// AUDIT LOGS
|
|
52
|
-
"acoSearchRecord-auditlogs",
|
|
53
|
-
// RECORD LOCKING
|
|
54
|
-
"wby_recordLocking",
|
|
55
|
-
// TASKS
|
|
56
|
-
"webinyTaskLog", "webinyTask"].map(key => {
|
|
57
|
-
return key.toLowerCase();
|
|
58
|
-
});
|
|
59
|
-
const createDefaultFilterOutRecordPlugins = () => {
|
|
60
|
-
return [(0, _FilterOutRecordPlugin.createFilterOutRecordPlugin)({
|
|
61
|
-
name: _FilterOutRecordPlugin.FilterOutRecordPlugin.createName("default"),
|
|
62
|
-
filterOut: record => {
|
|
63
|
-
const pk = record.PK.toLowerCase();
|
|
64
|
-
if (equalKeys.includes(pk)) {
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
for (const key of startsWithKeys) {
|
|
68
|
-
if (pk.startsWith(key)) {
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* TODO figure out a way to skip models without using expect-error.
|
|
74
|
-
*/
|
|
75
|
-
// @ts-expect-error
|
|
76
|
-
const modelId = record.input?.input?.Item?.modelId?.toLowerCase();
|
|
77
|
-
if (!modelId) {
|
|
78
|
-
return false;
|
|
79
|
-
} else if (skipModels.includes(modelId)) {
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
})];
|
|
85
|
-
};
|
|
86
|
-
exports.createDefaultFilterOutRecordPlugins = createDefaultFilterOutRecordPlugins;
|
|
1
|
+
import { FilterOutRecordPlugin, createFilterOutRecordPlugin } from "../plugins/FilterOutRecordPlugin.js";
|
|
2
|
+
const equalKeys = [
|
|
3
|
+
"LOG",
|
|
4
|
+
"PS#SETTINGS",
|
|
5
|
+
"WS#CONNECTIONS",
|
|
6
|
+
"APW#SETTINGS",
|
|
7
|
+
"DEPLOYMENTS",
|
|
8
|
+
"ADMIN#SETTINGS"
|
|
9
|
+
].map((key)=>key.toLowerCase());
|
|
10
|
+
const startsWithKeys = [
|
|
11
|
+
"WS#",
|
|
12
|
+
"MIGRATION_RUN#",
|
|
13
|
+
"MIGRATION#",
|
|
14
|
+
"SERVICE_MANIFEST#",
|
|
15
|
+
"DEPLOYMENT#"
|
|
16
|
+
].map((key)=>key.toLowerCase());
|
|
17
|
+
const skipModels = [
|
|
18
|
+
"wbyRecordLock",
|
|
19
|
+
"wbyTaskLog",
|
|
20
|
+
"wbyTask"
|
|
21
|
+
].map((key)=>key.toLowerCase());
|
|
22
|
+
const createDefaultFilterOutRecordPlugins = ()=>[
|
|
23
|
+
createFilterOutRecordPlugin({
|
|
24
|
+
name: FilterOutRecordPlugin.createName("default"),
|
|
25
|
+
filterOut: (record)=>{
|
|
26
|
+
const pk = record.PK.toLowerCase();
|
|
27
|
+
if (equalKeys.includes(pk)) return true;
|
|
28
|
+
for (const key of startsWithKeys)if (pk.startsWith(key)) return true;
|
|
29
|
+
const modelId = record.input?.input?.Item?.modelId?.toLowerCase();
|
|
30
|
+
if (modelId) {
|
|
31
|
+
if (skipModels.includes(modelId)) return true;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
];
|
|
37
|
+
export { createDefaultFilterOutRecordPlugins, equalKeys, skipModels, startsWithKeys };
|
|
87
38
|
|
|
88
39
|
//# sourceMappingURL=createDefaultFilterOutRecordPlugins.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"sync/filter/createDefaultFilterOutRecordPlugins.js","sources":["../../../src/sync/filter/createDefaultFilterOutRecordPlugins.ts"],"sourcesContent":["import {\n createFilterOutRecordPlugin,\n FilterOutRecordPlugin\n} from \"~/sync/plugins/FilterOutRecordPlugin.js\";\n\n/**\n * Order keys by what is most like to be filtered out - most inserts/updates/deletes.\n * This is out of my head, so it might not be the best order.\n */\nexport const equalKeys: string[] = [\n // Logging - every request\n \"LOG\",\n // P\n \"PS#SETTINGS\",\n // Websockets - on every user login\n \"WS#CONNECTIONS\",\n /**\n * packages/db-dynamodb/src/DynamoDbDriver.ts\n */\n //`W#INTERNAL`,\n /**\n * APW settings\n */\n \"APW#SETTINGS\",\n // Deployments - on every deployment\n \"DEPLOYMENTS\",\n // Admin\n \"ADMIN#SETTINGS\"\n].map(key => {\n return key.toLowerCase();\n});\n\nexport const startsWithKeys: string[] = [\n // Websockets - on every user login\n \"WS#\",\n // Migrations - on every deployment\n \"MIGRATION_RUN#\",\n \"MIGRATION#\",\n // Service Manifest - on deployment if something was changed in the service manifest\n \"SERVICE_MANIFEST#\",\n // Deployments - on every deployment\n \"DEPLOYMENT#\"\n].map(key => {\n return key.toLowerCase();\n});\n/**\n * TODO figure out a way to skip these models.\n * When deleting a record, we do not have a modelId in the values.\n */\nexport const skipModels: string[] = [\n // RECORD LOCKING\n \"wbyRecordLock\",\n // TASKS\n \"wbyTaskLog\",\n \"wbyTask\"\n].map(key => {\n return key.toLowerCase();\n});\n\nexport const createDefaultFilterOutRecordPlugins = (): FilterOutRecordPlugin[] => {\n return [\n createFilterOutRecordPlugin({\n name: FilterOutRecordPlugin.createName(\"default\"),\n filterOut: record => {\n const pk = record.PK.toLowerCase();\n if (equalKeys.includes(pk)) {\n return true;\n }\n for (const key of startsWithKeys) {\n if (pk.startsWith(key)) {\n return true;\n }\n }\n /**\n * TODO figure out a way to skip models without using expect-error.\n */\n // @ts-expect-error\n const modelId = record.input?.input?.Item?.modelId?.toLowerCase();\n if (!modelId) {\n return false;\n } else if (skipModels.includes(modelId)) {\n return true;\n }\n return false;\n }\n })\n ];\n};\n"],"names":["equalKeys","key","startsWithKeys","skipModels","createDefaultFilterOutRecordPlugins","createFilterOutRecordPlugin","FilterOutRecordPlugin","record","pk","modelId"],"mappings":";AASO,MAAMA,YAAsB;IAE/B;IAEA;IAEA;IAQA;IAEA;IAEA;CACH,CAAC,GAAG,CAACC,CAAAA,MACKA,IAAI,WAAW;AAGnB,MAAMC,iBAA2B;IAEpC;IAEA;IACA;IAEA;IAEA;CACH,CAAC,GAAG,CAACD,CAAAA,MACKA,IAAI,WAAW;AAMnB,MAAME,aAAuB;IAEhC;IAEA;IACA;CACH,CAAC,GAAG,CAACF,CAAAA,MACKA,IAAI,WAAW;AAGnB,MAAMG,sCAAsC,IACxC;QACHC,4BAA4B;YACxB,MAAMC,sBAAsB,UAAU,CAAC;YACvC,WAAWC,CAAAA;gBACP,MAAMC,KAAKD,OAAO,EAAE,CAAC,WAAW;gBAChC,IAAIP,UAAU,QAAQ,CAACQ,KACnB,OAAO;gBAEX,KAAK,MAAMP,OAAOC,eACd,IAAIM,GAAG,UAAU,CAACP,MACd,OAAO;gBAOf,MAAMQ,UAAUF,OAAO,KAAK,EAAE,OAAO,MAAM,SAAS;gBACpD,IAAKE,SAEE;oBAAA,IAAIN,WAAW,QAAQ,CAACM,UAC3B,OAAO;gBACX;gBACA,OAAO;YACX;QACJ;KACH"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IDynamoDbCommand, IHandler, IHandlerConverter, ISystem } from "../types.js";
|
|
2
|
-
import type { EventBridgeClient, PutEventsCommandOutput } from "@webiny/aws-sdk/client-eventbridge";
|
|
3
|
-
import type { FilterOutRecord } from "
|
|
2
|
+
import type { EventBridgeClient, PutEventsCommandOutput } from "@webiny/aws-sdk/client-eventbridge/index.js";
|
|
3
|
+
import type { FilterOutRecord } from "../../sync/FilterOutRecord.js";
|
|
4
4
|
export interface IHandlerEventBus {
|
|
5
5
|
name: string;
|
|
6
6
|
arn: string;
|
package/sync/handler/Handler.js
CHANGED
|
@@ -1,93 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createSyncHandler = exports.Handler = void 0;
|
|
7
|
-
var _clientEventbridge = require("@webiny/aws-sdk/client-eventbridge");
|
|
8
|
-
var _utils = require("@webiny/utils");
|
|
9
|
-
var _generateId = require("@webiny/utils/generateId.js");
|
|
1
|
+
import { PutEventsCommand } from "@webiny/aws-sdk/client-eventbridge/index.js";
|
|
2
|
+
import { convertException } from "@webiny/utils";
|
|
3
|
+
import { generateAlphaNumericId } from "@webiny/utils/generateId.js";
|
|
10
4
|
class Handler {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
add(input) {
|
|
21
|
-
const cmd = this.converter.convert(input);
|
|
22
|
-
this.commands.push(cmd);
|
|
23
|
-
}
|
|
24
|
-
async flush() {
|
|
25
|
-
const items = this.createEventBusEvent();
|
|
26
|
-
if (!items?.length) {
|
|
27
|
-
return null;
|
|
5
|
+
constructor(params){
|
|
6
|
+
this.id = generateAlphaNumericId();
|
|
7
|
+
this.commands = [];
|
|
8
|
+
this.getEventBridgeClient = params.getEventBridgeClient;
|
|
9
|
+
this.system = params.system;
|
|
10
|
+
this.converter = params.converter;
|
|
11
|
+
this.eventBus = params.eventBus;
|
|
12
|
+
this.filterOutRecord = params.filterOutRecord;
|
|
28
13
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*/
|
|
33
|
-
id: (0, _generateId.generateAlphaNumericId)(),
|
|
34
|
-
items,
|
|
35
|
-
source: this.system
|
|
36
|
-
};
|
|
37
|
-
const input = {
|
|
38
|
-
Entries: [{
|
|
39
|
-
DetailType: "synchronization-input",
|
|
40
|
-
Detail: JSON.stringify(detail),
|
|
41
|
-
Source: `webiny:${this.system.name}`,
|
|
42
|
-
EventBusName: this.eventBus.name
|
|
43
|
-
}]
|
|
44
|
-
};
|
|
45
|
-
const command = new _clientEventbridge.PutEventsCommand(input);
|
|
46
|
-
try {
|
|
47
|
-
const eventBridgeClient = this.getEventBridgeClient();
|
|
48
|
-
return await eventBridgeClient.send(command);
|
|
49
|
-
} catch (ex) {
|
|
50
|
-
console.log("Could not send events to Sync System EventBridge.");
|
|
51
|
-
console.error(ex.message);
|
|
52
|
-
console.error((0, _utils.convertException)(ex, ["message"]));
|
|
53
|
-
console.log(JSON.stringify({
|
|
54
|
-
event: items
|
|
55
|
-
}));
|
|
56
|
-
throw ex;
|
|
14
|
+
add(input) {
|
|
15
|
+
const cmd = this.converter.convert(input);
|
|
16
|
+
this.commands.push(cmd);
|
|
57
17
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
18
|
+
async flush() {
|
|
19
|
+
const items = this.createEventBusEvent();
|
|
20
|
+
if (!items?.length) return null;
|
|
21
|
+
const detail = {
|
|
22
|
+
id: generateAlphaNumericId(),
|
|
23
|
+
items,
|
|
24
|
+
source: this.system
|
|
25
|
+
};
|
|
26
|
+
const input = {
|
|
27
|
+
Entries: [
|
|
28
|
+
{
|
|
29
|
+
DetailType: "synchronization-input",
|
|
30
|
+
Detail: JSON.stringify(detail),
|
|
31
|
+
Source: `webiny:${this.system.name}`,
|
|
32
|
+
EventBusName: this.eventBus.name
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
};
|
|
36
|
+
const command = new PutEventsCommand(input);
|
|
37
|
+
try {
|
|
38
|
+
const eventBridgeClient = this.getEventBridgeClient();
|
|
39
|
+
return await eventBridgeClient.send(command);
|
|
40
|
+
} catch (ex) {
|
|
41
|
+
console.log("Could not send events to Sync System EventBridge.");
|
|
42
|
+
console.error(ex.message);
|
|
43
|
+
console.error(convertException(ex, [
|
|
44
|
+
"message"
|
|
45
|
+
]));
|
|
46
|
+
console.log(JSON.stringify({
|
|
47
|
+
event: items
|
|
48
|
+
}));
|
|
49
|
+
throw ex;
|
|
73
50
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
51
|
+
}
|
|
52
|
+
createEventBusEvent() {
|
|
53
|
+
const commands = Array.from(this.commands);
|
|
54
|
+
this.commands = [];
|
|
55
|
+
const everything = commands.reduce((items, cmd)=>{
|
|
56
|
+
const commandItems = cmd.getItems();
|
|
57
|
+
if (!commandItems?.length) return items;
|
|
58
|
+
for (const item of commandItems)if (!this.filterOutRecord.filterOut(item)) items.push({
|
|
59
|
+
tableName: item.tableName,
|
|
60
|
+
command: item.command,
|
|
61
|
+
tableType: item.tableType,
|
|
62
|
+
PK: item.PK,
|
|
63
|
+
SK: item.SK
|
|
64
|
+
});
|
|
65
|
+
return items;
|
|
66
|
+
}, []);
|
|
67
|
+
return 0 === everything.length ? null : everything;
|
|
68
|
+
}
|
|
86
69
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return new Handler(params);
|
|
90
|
-
};
|
|
91
|
-
exports.createSyncHandler = createSyncHandler;
|
|
70
|
+
const createSyncHandler = (params)=>new Handler(params);
|
|
71
|
+
export { Handler, createSyncHandler };
|
|
92
72
|
|
|
93
73
|
//# sourceMappingURL=Handler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"sync/handler/Handler.js","sources":["../../../src/sync/handler/Handler.ts"],"sourcesContent":["import type {\n ICommandValue,\n ICommandValueItem,\n ICommandValueItemExtended,\n IDynamoDbCommand,\n IHandler,\n IHandlerConverter,\n ISystem\n} from \"../types.js\";\nimport type {\n EventBridgeClient,\n PutEventsCommandInput,\n PutEventsCommandOutput\n} from \"@webiny/aws-sdk/client-eventbridge/index.js\";\nimport { PutEventsCommand } from \"@webiny/aws-sdk/client-eventbridge/index.js\";\nimport { convertException } from \"@webiny/utils\";\nimport { generateAlphaNumericId } from \"@webiny/utils/generateId.js\";\nimport type { IDetail } from \"~/sync/handler/types.js\";\nimport type { NonEmptyArray } from \"@webiny/api/types.js\";\nimport type { FilterOutRecord } from \"~/sync/FilterOutRecord.js\";\n\nexport interface IHandlerEventBus {\n name: string;\n arn: string;\n}\n\nexport interface IHandlerParams {\n getEventBridgeClient(): Pick<EventBridgeClient, \"send\">;\n converter: IHandlerConverter;\n eventBus: IHandlerEventBus;\n system: ISystem;\n filterOutRecord: FilterOutRecord;\n}\n\nexport class Handler implements IHandler {\n public readonly id = generateAlphaNumericId();\n private readonly system: ISystem;\n private readonly getEventBridgeClient: () => Pick<EventBridgeClient, \"send\">;\n private commands: ICommandValue[] = [];\n private readonly converter: IHandlerConverter;\n private readonly eventBus: IHandlerEventBus;\n private readonly filterOutRecord: FilterOutRecord;\n\n public constructor(params: IHandlerParams) {\n this.getEventBridgeClient = params.getEventBridgeClient;\n this.system = params.system;\n this.converter = params.converter;\n this.eventBus = params.eventBus;\n this.filterOutRecord = params.filterOutRecord;\n }\n\n public add(input: IDynamoDbCommand): void {\n const cmd = this.converter.convert(input);\n this.commands.push(cmd);\n }\n\n public async flush(): Promise<PutEventsCommandOutput | null> {\n const items = this.createEventBusEvent();\n\n if (!items?.length) {\n return null;\n }\n\n const detail: IDetail = {\n /**\n * We need a random ID because there can be multiple commands with same items sent - but that does not mean they are duplicates.\n */\n id: generateAlphaNumericId(),\n items,\n source: this.system\n };\n\n const input: PutEventsCommandInput = {\n Entries: [\n {\n DetailType: \"synchronization-input\",\n Detail: JSON.stringify(detail),\n Source: `webiny:${this.system.name}`,\n EventBusName: this.eventBus.name\n }\n ]\n };\n const command = new PutEventsCommand(input);\n\n try {\n const eventBridgeClient = this.getEventBridgeClient();\n return await eventBridgeClient.send(command);\n } catch (ex) {\n console.log(\"Could not send events to Sync System EventBridge.\");\n console.error(ex.message);\n console.error(convertException(ex, [\"message\"]));\n console.log(\n JSON.stringify({\n event: items\n })\n );\n throw ex;\n }\n }\n\n private createEventBusEvent(): NonEmptyArray<ICommandValueItem> | null {\n const commands = Array.from(this.commands);\n /**\n * Remove all existing commands so we can start fresh.\n */\n this.commands = [];\n const everything = commands.reduce<ICommandValueItem[]>((items, cmd) => {\n const commandItems = cmd.getItems();\n if (!commandItems?.length) {\n return items;\n }\n\n for (const item of commandItems) {\n if (this.filterOutRecord.filterOut(item)) {\n continue;\n }\n items.push({\n tableName: item.tableName,\n command: item.command,\n tableType: item.tableType,\n PK: item.PK,\n SK: item.SK\n });\n }\n\n return items;\n }, []);\n\n return everything.length === 0\n ? null\n : (everything as NonEmptyArray<ICommandValueItemExtended>);\n }\n}\n\nexport const createSyncHandler = (params: IHandlerParams): IHandler => {\n return new Handler(params);\n};\n"],"names":["Handler","params","generateAlphaNumericId","input","cmd","items","detail","JSON","command","PutEventsCommand","eventBridgeClient","ex","console","convertException","commands","Array","everything","commandItems","item","createSyncHandler"],"mappings":";;;AAkCO,MAAMA;IAST,YAAmBC,MAAsB,CAAE;aAR3B,EAAE,GAAGC;aAGb,QAAQ,GAAoB,EAAE;QAMlC,IAAI,CAAC,oBAAoB,GAAGD,OAAO,oBAAoB;QACvD,IAAI,CAAC,MAAM,GAAGA,OAAO,MAAM;QAC3B,IAAI,CAAC,SAAS,GAAGA,OAAO,SAAS;QACjC,IAAI,CAAC,QAAQ,GAAGA,OAAO,QAAQ;QAC/B,IAAI,CAAC,eAAe,GAAGA,OAAO,eAAe;IACjD;IAEO,IAAIE,KAAuB,EAAQ;QACtC,MAAMC,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACD;QACnC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAACC;IACvB;IAEA,MAAa,QAAgD;QACzD,MAAMC,QAAQ,IAAI,CAAC,mBAAmB;QAEtC,IAAI,CAACA,OAAO,QACR,OAAO;QAGX,MAAMC,SAAkB;YAIpB,IAAIJ;YACJG;YACA,QAAQ,IAAI,CAAC,MAAM;QACvB;QAEA,MAAMF,QAA+B;YACjC,SAAS;gBACL;oBACI,YAAY;oBACZ,QAAQI,KAAK,SAAS,CAACD;oBACvB,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;oBACpC,cAAc,IAAI,CAAC,QAAQ,CAAC,IAAI;gBACpC;aACH;QACL;QACA,MAAME,UAAU,IAAIC,iBAAiBN;QAErC,IAAI;YACA,MAAMO,oBAAoB,IAAI,CAAC,oBAAoB;YACnD,OAAO,MAAMA,kBAAkB,IAAI,CAACF;QACxC,EAAE,OAAOG,IAAI;YACTC,QAAQ,GAAG,CAAC;YACZA,QAAQ,KAAK,CAACD,GAAG,OAAO;YACxBC,QAAQ,KAAK,CAACC,iBAAiBF,IAAI;gBAAC;aAAU;YAC9CC,QAAQ,GAAG,CACPL,KAAK,SAAS,CAAC;gBACX,OAAOF;YACX;YAEJ,MAAMM;QACV;IACJ;IAEQ,sBAA+D;QACnE,MAAMG,WAAWC,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ;QAIzC,IAAI,CAAC,QAAQ,GAAG,EAAE;QAClB,MAAMC,aAAaF,SAAS,MAAM,CAAsB,CAACT,OAAOD;YAC5D,MAAMa,eAAeb,IAAI,QAAQ;YACjC,IAAI,CAACa,cAAc,QACf,OAAOZ;YAGX,KAAK,MAAMa,QAAQD,aACf,KAAI,IAAI,CAAC,eAAe,CAAC,SAAS,CAACC,OAGnCb,MAAM,IAAI,CAAC;gBACP,WAAWa,KAAK,SAAS;gBACzB,SAASA,KAAK,OAAO;gBACrB,WAAWA,KAAK,SAAS;gBACzB,IAAIA,KAAK,EAAE;gBACX,IAAIA,KAAK,EAAE;YACf;YAGJ,OAAOb;QACX,GAAG,EAAE;QAEL,OAAOW,AAAsB,MAAtBA,WAAW,MAAM,GAClB,OACCA;IACX;AACJ;AAEO,MAAMG,oBAAoB,CAAClB,SACvB,IAAID,QAAQC"}
|
|
@@ -1,43 +1,27 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createHandlerConverter = exports.HandlerConverter = void 0;
|
|
7
1
|
class HandlerConverter {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
register(input) {
|
|
13
|
-
if (Array.isArray(input)) {
|
|
14
|
-
this.converters.push(...input);
|
|
15
|
-
return;
|
|
2
|
+
constructor(params){
|
|
3
|
+
this.converters = [];
|
|
4
|
+
this.defaultValue = params.defaultValue;
|
|
16
5
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
for (const converter of this.converters) {
|
|
21
|
-
if (converter.can(command)) {
|
|
22
|
-
return converter.convert(command);
|
|
23
|
-
}
|
|
6
|
+
register(input) {
|
|
7
|
+
if (Array.isArray(input)) return void this.converters.push(...input);
|
|
8
|
+
this.converters.push(input);
|
|
24
9
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
10
|
+
convert(command) {
|
|
11
|
+
for (const converter of this.converters)if (converter.can(command)) return converter.convert(command);
|
|
12
|
+
if ("true" === process.env.DEBUG) {
|
|
13
|
+
console.error(`Unknown command: ${command.constructor?.name || "unknown"}`);
|
|
14
|
+
if (!command.constructor?.name) {
|
|
15
|
+
console.error("Command is not an instance of a class, it might be a plain object. Stringified command is in next line.");
|
|
16
|
+
console.log(JSON.stringify({
|
|
17
|
+
command
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return this.defaultValue;
|
|
33
22
|
}
|
|
34
|
-
return this.defaultValue;
|
|
35
|
-
}
|
|
36
23
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return new HandlerConverter(params);
|
|
40
|
-
};
|
|
41
|
-
exports.createHandlerConverter = createHandlerConverter;
|
|
24
|
+
const createHandlerConverter = (params)=>new HandlerConverter(params);
|
|
25
|
+
export { HandlerConverter, createHandlerConverter };
|
|
42
26
|
|
|
43
27
|
//# sourceMappingURL=HandlerConverter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"sync/handler/HandlerConverter.js","sources":["../../../src/sync/handler/HandlerConverter.ts"],"sourcesContent":["import type {\n ICommandConverter,\n ICommandValue,\n IDynamoDbCommand,\n IHandlerConverter\n} from \"../types.js\";\n\nexport interface IHandlerConverterParams {\n defaultValue: ICommandValue;\n}\n\nexport class HandlerConverter implements IHandlerConverter {\n private readonly defaultValue: ICommandValue;\n private readonly converters: ICommandConverter[] = [];\n\n public constructor(params: IHandlerConverterParams) {\n this.defaultValue = params.defaultValue;\n }\n\n public register(input: ICommandConverter | ICommandConverter[]): void {\n if (Array.isArray(input)) {\n this.converters.push(...input);\n return;\n }\n\n this.converters.push(input);\n }\n\n public convert(command: IDynamoDbCommand): ICommandValue {\n for (const converter of this.converters) {\n if (converter.can(command)) {\n return converter.convert(command);\n }\n }\n if (process.env.DEBUG === \"true\") {\n console.error(`Unknown command: ${command.constructor?.name || \"unknown\"}`);\n if (!command.constructor?.name) {\n console.error(\n \"Command is not an instance of a class, it might be a plain object. Stringified command is in next line.\"\n );\n console.log(\n JSON.stringify({\n command\n })\n );\n }\n }\n\n return this.defaultValue;\n }\n}\n\nexport const createHandlerConverter = (params: IHandlerConverterParams): IHandlerConverter => {\n return new HandlerConverter(params);\n};\n"],"names":["HandlerConverter","params","input","Array","command","converter","process","console","JSON","createHandlerConverter"],"mappings":"AAWO,MAAMA;IAIT,YAAmBC,MAA+B,CAAE;aAFnC,UAAU,GAAwB,EAAE;QAGjD,IAAI,CAAC,YAAY,GAAGA,OAAO,YAAY;IAC3C;IAEO,SAASC,KAA8C,EAAQ;QAClE,IAAIC,MAAM,OAAO,CAACD,QAAQ,YACtB,IAAI,CAAC,UAAU,CAAC,IAAI,IAAIA;QAI5B,IAAI,CAAC,UAAU,CAAC,IAAI,CAACA;IACzB;IAEO,QAAQE,OAAyB,EAAiB;QACrD,KAAK,MAAMC,aAAa,IAAI,CAAC,UAAU,CACnC,IAAIA,UAAU,GAAG,CAACD,UACd,OAAOC,UAAU,OAAO,CAACD;QAGjC,IAAIE,AAAsB,WAAtBA,QAAQ,GAAG,CAAC,KAAK,EAAa;YAC9BC,QAAQ,KAAK,CAAC,CAAC,iBAAiB,EAAEH,QAAQ,WAAW,EAAE,QAAQ,WAAW;YAC1E,IAAI,CAACA,QAAQ,WAAW,EAAE,MAAM;gBAC5BG,QAAQ,KAAK,CACT;gBAEJA,QAAQ,GAAG,CACPC,KAAK,SAAS,CAAC;oBACXJ;gBACJ;YAER;QACJ;QAEA,OAAO,IAAI,CAAC,YAAY;IAC5B;AACJ;AAEO,MAAMK,yBAAyB,CAACR,SAC5B,IAAID,iBAAiBC"}
|
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createBatchGetCommandConverter = exports.BatchGetCommandConverter = void 0;
|
|
7
|
-
var _index = require("@webiny/aws-sdk/client-dynamodb/index.js");
|
|
8
|
-
var _NullCommandValue = require("./commands/NullCommandValue.js");
|
|
1
|
+
import { BatchGetCommand } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
import { NullCommandValue } from "./commands/NullCommandValue.js";
|
|
9
3
|
class BatchGetCommandConverter {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
can(input) {
|
|
5
|
+
return input instanceof BatchGetCommand;
|
|
6
|
+
}
|
|
7
|
+
convert() {
|
|
8
|
+
return new NullCommandValue();
|
|
9
|
+
}
|
|
10
|
+
constructor(){
|
|
11
|
+
this.name = "batchGet";
|
|
12
|
+
}
|
|
17
13
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return new BatchGetCommandConverter();
|
|
21
|
-
};
|
|
22
|
-
exports.createBatchGetCommandConverter = createBatchGetCommandConverter;
|
|
14
|
+
const createBatchGetCommandConverter = ()=>new BatchGetCommandConverter();
|
|
15
|
+
export { BatchGetCommandConverter, createBatchGetCommandConverter };
|
|
23
16
|
|
|
24
17
|
//# sourceMappingURL=BatchGetCommandConverter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"sync/handler/converter/BatchGetCommandConverter.js","sources":["../../../../src/sync/handler/converter/BatchGetCommandConverter.ts"],"sourcesContent":["import { BatchGetCommand } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { ICommandConverter, IDynamoDbCommand } from \"../../types.js\";\nimport { NullCommandValue } from \"./commands/NullCommandValue.js\";\n\nexport class BatchGetCommandConverter implements ICommandConverter {\n public readonly name: string = \"batchGet\";\n\n public can(input: IDynamoDbCommand): boolean {\n return input instanceof BatchGetCommand;\n }\n\n public convert() {\n return new NullCommandValue();\n }\n}\n\nexport const createBatchGetCommandConverter = (): ICommandConverter => {\n return new BatchGetCommandConverter();\n};\n"],"names":["BatchGetCommandConverter","input","BatchGetCommand","NullCommandValue","createBatchGetCommandConverter"],"mappings":";;AAIO,MAAMA;IAGF,IAAIC,KAAuB,EAAW;QACzC,OAAOA,iBAAiBC;IAC5B;IAEO,UAAU;QACb,OAAO,IAAIC;IACf;;aARgB,IAAI,GAAW;;AASnC;AAEO,MAAMC,iCAAiC,IACnC,IAAIJ"}
|