@webiny/api-sync-system 0.0.0-unstable.b9b64acb6d → 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.
- package/constants.js +2 -1
- package/constants.js.map +1 -1
- package/index.d.ts +11 -3
- package/index.js +8 -5
- package/package.json +29 -21
- package/resolver/SyncResolverConfig.d.ts +17 -0
- package/resolver/SyncResolverConfig.js +5 -0
- package/resolver/SyncResolverConfig.js.map +1 -0
- package/resolver/SyncResolverLambdaHandler.d.ts +14 -0
- package/resolver/SyncResolverLambdaHandler.js +159 -0
- package/resolver/SyncResolverLambdaHandler.js.map +1 -0
- package/resolver/app/RecordHandler.js +83 -105
- package/resolver/app/RecordHandler.js.map +1 -1
- package/resolver/app/RecordsValidation.js +11 -14
- package/resolver/app/RecordsValidation.js.map +1 -1
- package/resolver/app/ResolverApplication.js +24 -31
- package/resolver/app/ResolverApplication.js.map +1 -1
- package/resolver/app/abstractions/RecordHandler.js +0 -3
- package/resolver/app/abstractions/RecordsValidation.js +0 -3
- package/resolver/app/abstractions/ResolverApplication.js +0 -3
- package/resolver/app/abstractions/ResolverRecord.js +0 -3
- package/resolver/app/bundler/BaseBundle.js +17 -16
- package/resolver/app/bundler/BaseBundle.js.map +1 -1
- package/resolver/app/bundler/Bundler.js +13 -18
- package/resolver/app/bundler/Bundler.js.map +1 -1
- package/resolver/app/bundler/Bundles.js +21 -26
- package/resolver/app/bundler/Bundles.js.map +1 -1
- package/resolver/app/bundler/CommandBundle.js +7 -16
- package/resolver/app/bundler/CommandBundle.js.map +1 -1
- package/resolver/app/bundler/TableBundle.js +6 -13
- package/resolver/app/bundler/TableBundle.js.map +1 -1
- package/resolver/app/bundler/types.js +0 -3
- package/resolver/app/commandHandler/DeleteCommandHandler.js +22 -29
- package/resolver/app/commandHandler/DeleteCommandHandler.js.map +1 -1
- package/resolver/app/commandHandler/PutCommandHandler.js +16 -22
- package/resolver/app/commandHandler/PutCommandHandler.js.map +1 -1
- package/resolver/app/commandHandler/delete.js +11 -12
- package/resolver/app/commandHandler/delete.js.map +1 -1
- package/resolver/app/commandHandler/put.js +11 -12
- package/resolver/app/commandHandler/put.js.map +1 -1
- package/resolver/app/data/SourceDataContainer.js +28 -30
- package/resolver/app/data/SourceDataContainer.js.map +1 -1
- package/resolver/app/data/types.js +0 -3
- package/resolver/app/fetcher/Fetcher.js +84 -109
- package/resolver/app/fetcher/Fetcher.js.map +1 -1
- package/resolver/app/fetcher/types.js +0 -3
- package/resolver/app/ingestor/Ingestor.js +27 -32
- package/resolver/app/ingestor/Ingestor.js.map +1 -1
- package/resolver/app/ingestor/IngestorResult.js +28 -32
- package/resolver/app/ingestor/IngestorResult.js.map +1 -1
- package/resolver/app/ingestor/types.js +0 -3
- package/resolver/app/storer/Storer.js +71 -85
- package/resolver/app/storer/Storer.js.map +1 -1
- package/resolver/app/storer/types.js +0 -3
- package/resolver/app/transform/TransformHandler.js +45 -56
- package/resolver/app/transform/TransformHandler.js.map +1 -1
- package/resolver/app/transform/middleware.js +13 -20
- package/resolver/app/transform/middleware.js.map +1 -1
- package/resolver/app/utils/Retry.js +21 -24
- package/resolver/app/utils/Retry.js.map +1 -1
- package/resolver/app/utils/sleep.js +4 -5
- package/resolver/app/utils/sleep.js.map +1 -1
- package/resolver/app/validation/body.d.ts +25 -124
- package/resolver/app/validation/body.js +26 -31
- package/resolver/app/validation/body.js.map +1 -1
- package/resolver/app/validation/createJsonTransform.d.ts +1 -1
- package/resolver/app/validation/createJsonTransform.js +12 -13
- package/resolver/app/validation/createJsonTransform.js.map +1 -1
- package/resolver/app/validation/detail.d.ts +18 -71
- package/resolver/app/validation/detail.js +30 -35
- package/resolver/app/validation/detail.js.map +1 -1
- package/resolver/app/validation/event.d.ts +29 -188
- package/resolver/app/validation/event.js +17 -18
- package/resolver/app/validation/event.js.map +1 -1
- package/resolver/app/validation/numericString.d.ts +1 -1
- package/resolver/app/validation/numericString.js +8 -11
- package/resolver/app/validation/numericString.js.map +1 -1
- package/resolver/app/validation/system.d.ts +2 -14
- package/resolver/app/validation/system.js +8 -9
- package/resolver/app/validation/system.js.map +1 -1
- package/resolver/deployment/Deployment.js +28 -37
- package/resolver/deployment/Deployment.js.map +1 -1
- package/resolver/deployment/Deployments.js +20 -23
- package/resolver/deployment/Deployments.js.map +1 -1
- package/resolver/deployment/DeploymentsFetcher.js +75 -86
- package/resolver/deployment/DeploymentsFetcher.js.map +1 -1
- package/resolver/deployment/types.d.ts +0 -2
- package/resolver/deployment/types.js +0 -3
- package/resolver/lambda/LambdaTrigger.js +24 -26
- package/resolver/lambda/LambdaTrigger.js.map +1 -1
- package/resolver/plugins/CommandHandlerPlugin.js +16 -15
- package/resolver/plugins/CommandHandlerPlugin.js.map +1 -1
- package/resolver/plugins/StorerAfterEachPlugin.js +20 -19
- package/resolver/plugins/StorerAfterEachPlugin.js.map +1 -1
- package/resolver/plugins/TransformRecordPlugin.js +19 -18
- package/resolver/plugins/TransformRecordPlugin.js.map +1 -1
- package/resolver/recordTypes/fileManager/CopyFile.js +44 -67
- package/resolver/recordTypes/fileManager/CopyFile.js.map +1 -1
- package/resolver/recordTypes/fileManager/DeleteFile.js +40 -58
- package/resolver/recordTypes/fileManager/DeleteFile.js.map +1 -1
- package/resolver/recordTypes/fileManager/fileManager.js +5 -3
- package/resolver/recordTypes/fileManager/fileManager.js.map +1 -1
- package/resolver/recordTypes/fileManager/fileManagerOnDelete.js +24 -35
- package/resolver/recordTypes/fileManager/fileManagerOnDelete.js.map +1 -1
- package/resolver/recordTypes/fileManager/fileManagerOnPut.js +24 -35
- package/resolver/recordTypes/fileManager/fileManagerOnPut.js.map +1 -1
- package/resolver/recordTypes/fileManager/shouldBeHandled.js +10 -27
- package/resolver/recordTypes/fileManager/shouldBeHandled.js.map +1 -1
- package/resolver/recordTypes/fileManager/types.js +0 -3
- package/resolver/recordTypes/users/CopyUser.js +44 -54
- package/resolver/recordTypes/users/CopyUser.js.map +1 -1
- package/resolver/recordTypes/users/DeleteUser.js +40 -51
- package/resolver/recordTypes/users/DeleteUser.js.map +1 -1
- package/resolver/recordTypes/users/shouldBeHandled.js +10 -26
- package/resolver/recordTypes/users/shouldBeHandled.js.map +1 -1
- package/resolver/recordTypes/users/types.js +0 -3
- package/resolver/recordTypes/users/users.js +5 -3
- package/resolver/recordTypes/users/users.js.map +1 -1
- package/resolver/recordTypes/users/usersOnDelete.js +23 -34
- package/resolver/recordTypes/users/usersOnDelete.js.map +1 -1
- package/resolver/recordTypes/users/usersOnPut.js +24 -35
- package/resolver/recordTypes/users/usersOnPut.js.map +1 -1
- package/sync/ApiGatewaySyncDecorator.d.ts +14 -0
- package/sync/ApiGatewaySyncDecorator.js +49 -0
- package/sync/ApiGatewaySyncDecorator.js.map +1 -0
- package/sync/FilterOutRecord.js +9 -17
- package/sync/FilterOutRecord.js.map +1 -1
- package/sync/SyncSystemConfig.d.ts +11 -0
- package/sync/SyncSystemConfig.js +5 -0
- package/sync/SyncSystemConfig.js.map +1 -0
- package/sync/attachToDynamoDbDocument.js +46 -65
- package/sync/attachToDynamoDbDocument.js.map +1 -1
- package/sync/createHandler.js +31 -40
- package/sync/createHandler.js.map +1 -1
- package/sync/filter/createDefaultFilterOutRecordPlugins.js +36 -76
- package/sync/filter/createDefaultFilterOutRecordPlugins.js.map +1 -1
- package/sync/handler/Handler.js +64 -76
- package/sync/handler/Handler.js.map +1 -1
- package/sync/handler/HandlerConverter.js +21 -29
- package/sync/handler/HandlerConverter.js.map +1 -1
- package/sync/handler/converter/BatchGetCommandConverter.js +12 -11
- package/sync/handler/converter/BatchGetCommandConverter.js.map +1 -1
- package/sync/handler/converter/BatchWriteCommandConverter.js +12 -11
- package/sync/handler/converter/BatchWriteCommandConverter.js.map +1 -1
- package/sync/handler/converter/DeleteCommandConverter.js +12 -11
- package/sync/handler/converter/DeleteCommandConverter.js.map +1 -1
- package/sync/handler/converter/GetCommandConverter.js +12 -11
- package/sync/handler/converter/GetCommandConverter.js.map +1 -1
- package/sync/handler/converter/PutCommandConverter.js +12 -11
- package/sync/handler/converter/PutCommandConverter.js.map +1 -1
- package/sync/handler/converter/QueryCommandConverter.js +12 -11
- package/sync/handler/converter/QueryCommandConverter.js.map +1 -1
- package/sync/handler/converter/ScanCommandConverter.js +12 -11
- package/sync/handler/converter/ScanCommandConverter.js.map +1 -1
- package/sync/handler/converter/UpdateCommandConverter.js +12 -11
- package/sync/handler/converter/UpdateCommandConverter.js.map +1 -1
- package/sync/handler/converter/commands/BatchWriteCommandValue.js +34 -37
- package/sync/handler/converter/commands/BatchWriteCommandValue.js.map +1 -1
- package/sync/handler/converter/commands/DeleteCommandValue.js +19 -16
- package/sync/handler/converter/commands/DeleteCommandValue.js.map +1 -1
- package/sync/handler/converter/commands/NullCommandValue.js +8 -8
- package/sync/handler/converter/commands/NullCommandValue.js.map +1 -1
- package/sync/handler/converter/commands/PutCommandValue.js +19 -16
- package/sync/handler/converter/commands/PutCommandValue.js.map +1 -1
- package/sync/handler/converter/commands/UpdateCommandValue.js +19 -16
- package/sync/handler/converter/commands/UpdateCommandValue.js.map +1 -1
- package/sync/handler/types.js +0 -3
- package/sync/plugins/FilterOutRecordPlugin.js +17 -19
- package/sync/plugins/FilterOutRecordPlugin.js.map +1 -1
- package/sync/types.js +0 -3
- package/sync/utils/getTableType.js +10 -11
- package/sync/utils/getTableType.js.map +1 -1
- package/sync/utils/manifest.d.ts +3 -7
- package/sync/utils/manifest.js +27 -36
- package/sync/utils/manifest.js.map +1 -1
- package/sync/utils/validateSystemInput.js +21 -29
- package/sync/utils/validateSystemInput.js.map +1 -1
- package/types.d.ts +0 -3
- package/types.js +6 -6
- package/types.js.map +1 -1
- package/utils/createSystemName.js +5 -3
- package/utils/createSystemName.js.map +1 -1
- package/worker/SyncWorkerConfig.d.ts +9 -0
- package/worker/SyncWorkerConfig.js +5 -0
- package/worker/SyncWorkerConfig.js.map +1 -0
- package/worker/SyncWorkerEventHandler.d.ts +14 -0
- package/worker/SyncWorkerEventHandler.js +5 -0
- package/worker/SyncWorkerEventHandler.js.map +1 -0
- package/worker/SyncWorkerEventType.d.ts +10 -0
- package/worker/SyncWorkerEventType.js +24 -0
- package/worker/SyncWorkerEventType.js.map +1 -0
- package/worker/SyncWorkerLambdaHandler.d.ts +13 -0
- package/worker/SyncWorkerLambdaHandler.js +61 -0
- package/worker/SyncWorkerLambdaHandler.js.map +1 -0
- package/worker/actions/copyFile/CopyFile.js +183 -258
- package/worker/actions/copyFile/CopyFile.js.map +1 -1
- package/worker/actions/copyFile/copyFileAction.js +26 -34
- package/worker/actions/copyFile/copyFileAction.js.map +1 -1
- package/worker/actions/copyFile/copyFileSchema.d.ts +6 -38
- package/worker/actions/copyFile/copyFileSchema.js +13 -14
- package/worker/actions/copyFile/copyFileSchema.js.map +1 -1
- package/worker/actions/copyFile/types.js +0 -3
- package/worker/actions/createUser/CreateUser.js +51 -74
- package/worker/actions/createUser/CreateUser.js.map +1 -1
- package/worker/actions/createUser/createUserAction.js +24 -28
- package/worker/actions/createUser/createUserAction.js.map +1 -1
- package/worker/actions/createUser/createUserSchema.d.ts +6 -38
- package/worker/actions/createUser/createUserSchema.js +13 -14
- package/worker/actions/createUser/createUserSchema.js.map +1 -1
- package/worker/actions/createUser/types.js +0 -3
- package/worker/actions/deleteFile/DeleteFile.js +52 -67
- package/worker/actions/deleteFile/DeleteFile.js.map +1 -1
- package/worker/actions/deleteFile/deleteFileAction.js +21 -29
- package/worker/actions/deleteFile/deleteFileAction.js.map +1 -1
- package/worker/actions/deleteFile/deleteFileSchema.d.ts +6 -38
- package/worker/actions/deleteFile/deleteFileSchema.js +13 -14
- package/worker/actions/deleteFile/deleteFileSchema.js.map +1 -1
- package/worker/actions/deleteFile/types.js +0 -3
- package/worker/actions/deleteUser/DeleteUser.js +38 -52
- package/worker/actions/deleteUser/DeleteUser.js.map +1 -1
- package/worker/actions/deleteUser/deleteUserAction.js +22 -26
- package/worker/actions/deleteUser/deleteUserAction.js.map +1 -1
- package/worker/actions/deleteUser/deleteUserSchema.d.ts +5 -23
- package/worker/actions/deleteUser/deleteUserSchema.js +12 -13
- package/worker/actions/deleteUser/deleteUserSchema.js.map +1 -1
- package/worker/actions/deleteUser/types.js +0 -3
- package/worker/actions/logValidationError.js +5 -6
- package/worker/actions/logValidationError.js.map +1 -1
- package/worker/actions/removeCognitoUserAttributes.js +9 -15
- package/worker/actions/removeCognitoUserAttributes.js.map +1 -1
- package/worker/actions/updateUser/UpdateUser.js +48 -65
- package/worker/actions/updateUser/UpdateUser.js.map +1 -1
- package/worker/actions/updateUser/types.js +0 -3
- package/worker/actions/updateUser/updateUserAction.js +24 -28
- package/worker/actions/updateUser/updateUserAction.js.map +1 -1
- package/worker/actions/updateUser/updateUserSchema.d.ts +6 -38
- package/worker/actions/updateUser/updateUserSchema.js +13 -14
- package/worker/actions/updateUser/updateUserSchema.js.map +1 -1
- package/worker/handler/WorkerActionHandler.js +19 -21
- package/worker/handler/WorkerActionHandler.js.map +1 -1
- package/worker/plugins/WorkerActionPlugin.js +17 -16
- package/worker/plugins/WorkerActionPlugin.js.map +1 -1
- package/worker/types.js +0 -3
- 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/createEventHandlerPlugin.d.ts +0 -11
- package/resolver/createEventHandlerPlugin.js +0 -120
- package/resolver/createEventHandlerPlugin.js.map +0 -1
- package/resolver/createResolverHandler.d.ts +0 -21
- package/resolver/createResolverHandler.js +0 -72
- package/resolver/createResolverHandler.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/createSendDataToEventBridgeOnRequestEnd.d.ts +0 -2
- package/sync/createSendDataToEventBridgeOnRequestEnd.js +0 -44
- package/sync/createSendDataToEventBridgeOnRequestEnd.js.map +0 -1
- package/sync/createSyncSystem.d.ts +0 -16
- package/sync/createSyncSystem.js +0 -35
- package/sync/createSyncSystem.js.map +0 -1
- package/sync/handler/types.js.map +0 -1
- package/sync/requestPlugin.d.ts +0 -9
- package/sync/requestPlugin.js +0 -58
- package/sync/requestPlugin.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/createWorkerHandler.d.ts +0 -11
- package/worker/createWorkerHandler.js +0 -41
- package/worker/createWorkerHandler.js.map +0 -1
- package/worker/handler/eventHandler.d.ts +0 -1
- package/worker/handler/eventHandler.js +0 -24
- package/worker/handler/eventHandler.js.map +0 -1
- package/worker/types.js.map +0 -1
|
@@ -1,71 +1,52 @@
|
|
|
1
1
|
import { decorateDocumentClient } from "@webiny/aws-sdk/client-dynamodb/getDocumentClient.js";
|
|
2
2
|
import { BatchWriteCommand, DeleteCommand, PutCommand, UpdateCommand } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
handler
|
|
6
|
-
client
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
const decorateClientWithHandler = (params)=>{
|
|
4
|
+
const { handler, client } = params;
|
|
5
|
+
if (client.__webinyHandler?.id === handler.id) return client;
|
|
6
|
+
const originalSend = client.send;
|
|
7
|
+
const originalPut = client.put;
|
|
8
|
+
const originalDelete = client.delete;
|
|
9
|
+
const originalUpdate = client.update;
|
|
10
|
+
const originalBatchWrite = client.batchWrite;
|
|
11
|
+
client.__webinyHandler = handler;
|
|
12
|
+
client.send = async (params)=>{
|
|
13
|
+
handler.add(params);
|
|
14
|
+
return originalSend.apply(client, [
|
|
15
|
+
params
|
|
16
|
+
]);
|
|
17
|
+
};
|
|
18
|
+
client.put = async (params)=>{
|
|
19
|
+
const cmd = new PutCommand(params);
|
|
20
|
+
handler.add(cmd);
|
|
21
|
+
return originalPut.apply(client, [
|
|
22
|
+
params
|
|
23
|
+
]);
|
|
24
|
+
};
|
|
25
|
+
client.delete = async (params)=>{
|
|
26
|
+
const cmd = new DeleteCommand(params);
|
|
27
|
+
handler.add(cmd);
|
|
28
|
+
return originalDelete.apply(client, [
|
|
29
|
+
params
|
|
30
|
+
]);
|
|
31
|
+
};
|
|
32
|
+
client.batchWrite = async (params)=>{
|
|
33
|
+
const cmd = new BatchWriteCommand(params);
|
|
34
|
+
handler.add(cmd);
|
|
35
|
+
return originalBatchWrite.apply(client, [
|
|
36
|
+
params
|
|
37
|
+
]);
|
|
38
|
+
};
|
|
39
|
+
client.update = async (params)=>{
|
|
40
|
+
const cmd = new UpdateCommand(params);
|
|
41
|
+
handler.add(cmd);
|
|
42
|
+
return originalUpdate(params);
|
|
43
|
+
};
|
|
14
44
|
return client;
|
|
15
|
-
}
|
|
16
|
-
const originalSend = client.send;
|
|
17
|
-
const originalPut = client.put;
|
|
18
|
-
const originalDelete = client.delete;
|
|
19
|
-
const originalUpdate = client.update;
|
|
20
|
-
const originalBatchWrite = client.batchWrite;
|
|
21
|
-
|
|
22
|
-
// @ts-expect-error
|
|
23
|
-
client.__webinyHandler = handler;
|
|
24
|
-
client.send = async params => {
|
|
25
|
-
// @ts-expect-error
|
|
26
|
-
handler.add(params);
|
|
27
|
-
// @ts-expect-error
|
|
28
|
-
return originalSend.apply(client, [params]);
|
|
29
|
-
};
|
|
30
|
-
// @ts-expect-error
|
|
31
|
-
client.put = async params => {
|
|
32
|
-
const cmd = new PutCommand(params);
|
|
33
|
-
handler.add(cmd);
|
|
34
|
-
// @ts-expect-error
|
|
35
|
-
return originalPut.apply(client, [params]);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// @ts-expect-error
|
|
39
|
-
client.delete = async params => {
|
|
40
|
-
const cmd = new DeleteCommand(params);
|
|
41
|
-
handler.add(cmd);
|
|
42
|
-
// @ts-expect-error
|
|
43
|
-
return originalDelete.apply(client, [params]);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// @ts-expect-error
|
|
47
|
-
client.batchWrite = async params => {
|
|
48
|
-
const cmd = new BatchWriteCommand(params);
|
|
49
|
-
handler.add(cmd);
|
|
50
|
-
// @ts-expect-error
|
|
51
|
-
return originalBatchWrite.apply(client, [params]);
|
|
52
|
-
};
|
|
53
|
-
client.update = async params => {
|
|
54
|
-
const cmd = new UpdateCommand(params);
|
|
55
|
-
handler.add(cmd);
|
|
56
|
-
return originalUpdate(params);
|
|
57
|
-
};
|
|
58
|
-
return client;
|
|
59
|
-
};
|
|
60
|
-
export const attachToDynamoDbDocument = ({
|
|
61
|
-
handler
|
|
62
|
-
}) => {
|
|
63
|
-
return decorateDocumentClient(client => {
|
|
64
|
-
return decorateClientWithHandler({
|
|
65
|
-
handler,
|
|
66
|
-
client
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
45
|
};
|
|
46
|
+
const attachToDynamoDbDocument = ({ handler })=>decorateDocumentClient((client)=>decorateClientWithHandler({
|
|
47
|
+
handler,
|
|
48
|
+
client
|
|
49
|
+
}));
|
|
50
|
+
export { attachToDynamoDbDocument, decorateClientWithHandler };
|
|
70
51
|
|
|
71
52
|
//# sourceMappingURL=attachToDynamoDbDocument.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"sync/attachToDynamoDbDocument.js","sources":["../../src/sync/attachToDynamoDbDocument.ts"],"sourcesContent":["import { decorateDocumentClient } from \"@webiny/aws-sdk/client-dynamodb/getDocumentClient.js\";\nimport type { IHandler } from \"~/sync/types.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport {\n BatchWriteCommand,\n DeleteCommand,\n PutCommand,\n UpdateCommand\n} from \"@webiny/aws-sdk/client-dynamodb/index.js\";\n\nexport interface IAttachToDynamoDbDocumentParams {\n handler: IHandler;\n}\n\nexport interface IDecorateClientWithHandlerParams {\n handler: IHandler;\n client: DynamoDBDocument;\n}\n\nexport const decorateClientWithHandler = (\n params: IDecorateClientWithHandlerParams\n): DynamoDBDocument => {\n const { handler, client } = params;\n /**\n * Is there a possibility that this is already attached?\n * Let's check for the handler and then skip attaching.\n */\n // @ts-expect-error\n if (client.__webinyHandler?.id === handler.id) {\n return client;\n }\n\n const originalSend = client.send;\n const originalPut = client.put;\n const originalDelete = client.delete;\n const originalUpdate = client.update;\n const originalBatchWrite = client.batchWrite;\n\n // @ts-expect-error\n client.__webinyHandler = handler;\n\n client.send = async params => {\n // @ts-expect-error\n handler.add(params);\n // @ts-expect-error\n return originalSend.apply(client, [params]);\n };\n // @ts-expect-error\n client.put = async params => {\n const cmd = new PutCommand(params);\n handler.add(cmd);\n // @ts-expect-error\n return originalPut.apply(client, [params]);\n };\n\n // @ts-expect-error\n client.delete = async params => {\n const cmd = new DeleteCommand(params);\n handler.add(cmd);\n // @ts-expect-error\n return originalDelete.apply(client, [params]);\n };\n\n // @ts-expect-error\n client.batchWrite = async params => {\n const cmd = new BatchWriteCommand(params);\n handler.add(cmd);\n // @ts-expect-error\n return originalBatchWrite.apply(client, [params]);\n };\n\n client.update = async params => {\n const cmd = new UpdateCommand(params);\n handler.add(cmd);\n return originalUpdate(params);\n };\n\n return client;\n};\n\nexport const attachToDynamoDbDocument = ({ handler }: IAttachToDynamoDbDocumentParams): void => {\n return decorateDocumentClient(client => {\n return decorateClientWithHandler({\n handler,\n client\n });\n });\n};\n"],"names":["decorateClientWithHandler","params","handler","client","originalSend","originalPut","originalDelete","originalUpdate","originalBatchWrite","cmd","PutCommand","DeleteCommand","BatchWriteCommand","UpdateCommand","attachToDynamoDbDocument","decorateDocumentClient"],"mappings":";;AAmBO,MAAMA,4BAA4B,CACrCC;IAEA,MAAM,EAAEC,OAAO,EAAEC,MAAM,EAAE,GAAGF;IAM5B,IAAIE,OAAO,eAAe,EAAE,OAAOD,QAAQ,EAAE,EACzC,OAAOC;IAGX,MAAMC,eAAeD,OAAO,IAAI;IAChC,MAAME,cAAcF,OAAO,GAAG;IAC9B,MAAMG,iBAAiBH,OAAO,MAAM;IACpC,MAAMI,iBAAiBJ,OAAO,MAAM;IACpC,MAAMK,qBAAqBL,OAAO,UAAU;IAG5CA,OAAO,eAAe,GAAGD;IAEzBC,OAAO,IAAI,GAAG,OAAMF;QAEhBC,QAAQ,GAAG,CAACD;QAEZ,OAAOG,aAAa,KAAK,CAACD,QAAQ;YAACF;SAAO;IAC9C;IAEAE,OAAO,GAAG,GAAG,OAAMF;QACf,MAAMQ,MAAM,IAAIC,WAAWT;QAC3BC,QAAQ,GAAG,CAACO;QAEZ,OAAOJ,YAAY,KAAK,CAACF,QAAQ;YAACF;SAAO;IAC7C;IAGAE,OAAO,MAAM,GAAG,OAAMF;QAClB,MAAMQ,MAAM,IAAIE,cAAcV;QAC9BC,QAAQ,GAAG,CAACO;QAEZ,OAAOH,eAAe,KAAK,CAACH,QAAQ;YAACF;SAAO;IAChD;IAGAE,OAAO,UAAU,GAAG,OAAMF;QACtB,MAAMQ,MAAM,IAAIG,kBAAkBX;QAClCC,QAAQ,GAAG,CAACO;QAEZ,OAAOD,mBAAmB,KAAK,CAACL,QAAQ;YAACF;SAAO;IACpD;IAEAE,OAAO,MAAM,GAAG,OAAMF;QAClB,MAAMQ,MAAM,IAAII,cAAcZ;QAC9BC,QAAQ,GAAG,CAACO;QACZ,OAAOF,eAAeN;IAC1B;IAEA,OAAOE;AACX;AAEO,MAAMW,2BAA2B,CAAC,EAAEZ,OAAO,EAAmC,GAC1Ea,uBAAuBZ,CAAAA,SACnBH,0BAA0B;YAC7BE;YACAC;QACJ"}
|
package/sync/createHandler.js
CHANGED
|
@@ -11,46 +11,37 @@ import { createScanCommandConverter } from "./handler/converter/ScanCommandConve
|
|
|
11
11
|
import { createGetCommandConverter } from "./handler/converter/GetCommandConverter.js";
|
|
12
12
|
import { FilterOutRecordPlugin } from "./plugins/FilterOutRecordPlugin.js";
|
|
13
13
|
import { createFilterOutRecord } from "./FilterOutRecord.js";
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
arn: manifest.sync.eventBusArn,
|
|
45
|
-
name: manifest.sync.eventBusName
|
|
46
|
-
},
|
|
47
|
-
converter,
|
|
48
|
-
filterOutRecord
|
|
49
|
-
});
|
|
50
|
-
return {
|
|
51
|
-
handler,
|
|
52
|
-
converter
|
|
53
|
-
};
|
|
14
|
+
const createHandler = (params)=>{
|
|
15
|
+
const { manifest, commandConverters, system, getEventBridgeClient, getPlugins } = params;
|
|
16
|
+
const filterOutRecordPlugins = getPlugins().byType(FilterOutRecordPlugin.type);
|
|
17
|
+
const filterOutRecord = createFilterOutRecord(filterOutRecordPlugins);
|
|
18
|
+
const converter = createHandlerConverter({
|
|
19
|
+
defaultValue: new NullCommandValue()
|
|
20
|
+
});
|
|
21
|
+
converter.register(commandConverters || []);
|
|
22
|
+
converter.register(createBatchGetCommandConverter());
|
|
23
|
+
converter.register(createGetCommandConverter());
|
|
24
|
+
converter.register(createQueryCommandConverter());
|
|
25
|
+
converter.register(createScanCommandConverter());
|
|
26
|
+
converter.register(createBatchWriteCommandConverter());
|
|
27
|
+
converter.register(createPutCommandConverter());
|
|
28
|
+
converter.register(createDeleteCommandConverter());
|
|
29
|
+
converter.register(createUpdateCommandConverter());
|
|
30
|
+
const handler = createSyncHandler({
|
|
31
|
+
system,
|
|
32
|
+
getEventBridgeClient,
|
|
33
|
+
eventBus: {
|
|
34
|
+
arn: manifest.sync.eventBusArn,
|
|
35
|
+
name: manifest.sync.eventBusName
|
|
36
|
+
},
|
|
37
|
+
converter,
|
|
38
|
+
filterOutRecord
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
handler,
|
|
42
|
+
converter
|
|
43
|
+
};
|
|
54
44
|
};
|
|
45
|
+
export { createHandler };
|
|
55
46
|
|
|
56
47
|
//# sourceMappingURL=createHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"sync/createHandler.js","sources":["../../src/sync/createHandler.ts"],"sourcesContent":["import { createHandlerConverter } from \"~/sync/handler/HandlerConverter.js\";\nimport { NullCommandValue } from \"~/sync/handler/converter/commands/NullCommandValue.js\";\nimport { createBatchWriteCommandConverter } from \"~/sync/handler/converter/BatchWriteCommandConverter.js\";\nimport { createPutCommandConverter } from \"~/sync/handler/converter/PutCommandConverter.js\";\nimport { createDeleteCommandConverter } from \"~/sync/handler/converter/DeleteCommandConverter.js\";\nimport { createUpdateCommandConverter } from \"~/sync/handler/converter/UpdateCommandConverter.js\";\nimport { createSyncHandler } from \"~/sync/handler/Handler.js\";\nimport type { EventBridgeClient } from \"@webiny/aws-sdk/client-eventbridge/index.js\";\nimport type { ICommandConverter, IManifest, ISystem } from \"./types.js\";\nimport { createBatchGetCommandConverter } from \"./handler/converter/BatchGetCommandConverter.js\";\nimport { createQueryCommandConverter } from \"./handler/converter/QueryCommandConverter.js\";\nimport { createScanCommandConverter } from \"~/sync/handler/converter/ScanCommandConverter.js\";\nimport { createGetCommandConverter } from \"./handler/converter/GetCommandConverter.js\";\nimport type { PluginsContainer } from \"@webiny/plugins/PluginsContainer.js\";\nimport { FilterOutRecordPlugin } from \"~/sync/plugins/FilterOutRecordPlugin.js\";\nimport { createFilterOutRecord } from \"~/sync/FilterOutRecord.js\";\n\nexport interface ICreateHandlerParams {\n getEventBridgeClient(): Pick<EventBridgeClient, \"send\">;\n commandConverters?: ICommandConverter[];\n system: ISystem;\n manifest: IManifest;\n getPlugins: () => PluginsContainer;\n}\n\nexport const createHandler = (params: ICreateHandlerParams) => {\n const { manifest, commandConverters, system, getEventBridgeClient, getPlugins } = params;\n\n const filterOutRecordPlugins = getPlugins().byType<FilterOutRecordPlugin>(\n FilterOutRecordPlugin.type\n );\n\n const filterOutRecord = createFilterOutRecord(filterOutRecordPlugins);\n\n const converter = createHandlerConverter({\n defaultValue: new NullCommandValue()\n });\n /**\n * We register users command converters because those are tested out first.\n * Our converters are in some order I got from my head - the most used commands are first.\n */\n converter.register(commandConverters || []);\n converter.register(createBatchGetCommandConverter());\n converter.register(createGetCommandConverter());\n converter.register(createQueryCommandConverter());\n converter.register(createScanCommandConverter());\n converter.register(createBatchWriteCommandConverter());\n converter.register(createPutCommandConverter());\n converter.register(createDeleteCommandConverter());\n converter.register(createUpdateCommandConverter());\n\n const handler = createSyncHandler({\n system,\n getEventBridgeClient,\n eventBus: {\n arn: manifest.sync.eventBusArn,\n name: manifest.sync.eventBusName\n },\n converter,\n filterOutRecord\n });\n return {\n handler,\n converter\n };\n};\n"],"names":["createHandler","params","manifest","commandConverters","system","getEventBridgeClient","getPlugins","filterOutRecordPlugins","FilterOutRecordPlugin","filterOutRecord","createFilterOutRecord","converter","createHandlerConverter","NullCommandValue","createBatchGetCommandConverter","createGetCommandConverter","createQueryCommandConverter","createScanCommandConverter","createBatchWriteCommandConverter","createPutCommandConverter","createDeleteCommandConverter","createUpdateCommandConverter","handler","createSyncHandler"],"mappings":";;;;;;;;;;;;;AAyBO,MAAMA,gBAAgB,CAACC;IAC1B,MAAM,EAAEC,QAAQ,EAAEC,iBAAiB,EAAEC,MAAM,EAAEC,oBAAoB,EAAEC,UAAU,EAAE,GAAGL;IAElF,MAAMM,yBAAyBD,aAAa,MAAM,CAC9CE,sBAAsB,IAAI;IAG9B,MAAMC,kBAAkBC,sBAAsBH;IAE9C,MAAMI,YAAYC,uBAAuB;QACrC,cAAc,IAAIC;IACtB;IAKAF,UAAU,QAAQ,CAACR,qBAAqB,EAAE;IAC1CQ,UAAU,QAAQ,CAACG;IACnBH,UAAU,QAAQ,CAACI;IACnBJ,UAAU,QAAQ,CAACK;IACnBL,UAAU,QAAQ,CAACM;IACnBN,UAAU,QAAQ,CAACO;IACnBP,UAAU,QAAQ,CAACQ;IACnBR,UAAU,QAAQ,CAACS;IACnBT,UAAU,QAAQ,CAACU;IAEnB,MAAMC,UAAUC,kBAAkB;QAC9BnB;QACAC;QACA,UAAU;YACN,KAAKH,SAAS,IAAI,CAAC,WAAW;YAC9B,MAAMA,SAAS,IAAI,CAAC,YAAY;QACpC;QACAS;QACAF;IACJ;IACA,OAAO;QACHa;QACAX;IACJ;AACJ"}
|
|
@@ -1,78 +1,38 @@
|
|
|
1
|
-
import {
|
|
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
|
-
return key.toLowerCase();
|
|
38
|
-
});
|
|
39
|
-
/**
|
|
40
|
-
* TODO figure out a way to skip these models.
|
|
41
|
-
* When deleting a record, we do not have a modelId in the values.
|
|
42
|
-
*/
|
|
43
|
-
export const skipModels = [
|
|
44
|
-
// RECORD LOCKING
|
|
45
|
-
"wbyRecordLock",
|
|
46
|
-
// TASKS
|
|
47
|
-
"wbyTaskLog", "wbyTask"].map(key => {
|
|
48
|
-
return key.toLowerCase();
|
|
49
|
-
});
|
|
50
|
-
export const createDefaultFilterOutRecordPlugins = () => {
|
|
51
|
-
return [createFilterOutRecordPlugin({
|
|
52
|
-
name: FilterOutRecordPlugin.createName("default"),
|
|
53
|
-
filterOut: record => {
|
|
54
|
-
const pk = record.PK.toLowerCase();
|
|
55
|
-
if (equalKeys.includes(pk)) {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
for (const key of startsWithKeys) {
|
|
59
|
-
if (pk.startsWith(key)) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* TODO figure out a way to skip models without using expect-error.
|
|
65
|
-
*/
|
|
66
|
-
// @ts-expect-error
|
|
67
|
-
const modelId = record.input?.input?.Item?.modelId?.toLowerCase();
|
|
68
|
-
if (!modelId) {
|
|
69
|
-
return false;
|
|
70
|
-
} else if (skipModels.includes(modelId)) {
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
})];
|
|
76
|
-
};
|
|
1
|
+
import { FilterOutRecordPlugin, createFilterOutRecordPlugin } from "../plugins/FilterOutRecordPlugin.js";
|
|
2
|
+
const equalKeys = [
|
|
3
|
+
"LOG",
|
|
4
|
+
"PS#SETTINGS",
|
|
5
|
+
"WS#CONNECTIONS",
|
|
6
|
+
"DEPLOYMENTS",
|
|
7
|
+
"ADMIN#SETTINGS"
|
|
8
|
+
].map((key)=>key.toLowerCase());
|
|
9
|
+
const startsWithKeys = [
|
|
10
|
+
"WS#",
|
|
11
|
+
"MIGRATION_RUN#",
|
|
12
|
+
"MIGRATION#",
|
|
13
|
+
"SERVICE_MANIFEST#",
|
|
14
|
+
"DEPLOYMENT#"
|
|
15
|
+
].map((key)=>key.toLowerCase());
|
|
16
|
+
const skipModels = [
|
|
17
|
+
"wbyRecordLock",
|
|
18
|
+
"wbyTaskLog",
|
|
19
|
+
"wbyTask"
|
|
20
|
+
].map((key)=>key.toLowerCase());
|
|
21
|
+
const createDefaultFilterOutRecordPlugins = ()=>[
|
|
22
|
+
createFilterOutRecordPlugin({
|
|
23
|
+
name: FilterOutRecordPlugin.createName("default"),
|
|
24
|
+
filterOut: (record)=>{
|
|
25
|
+
const pk = record.PK.toLowerCase();
|
|
26
|
+
if (equalKeys.includes(pk)) return true;
|
|
27
|
+
for (const key of startsWithKeys)if (pk.startsWith(key)) return true;
|
|
28
|
+
const modelId = record.input?.input?.Item?.modelId?.toLowerCase();
|
|
29
|
+
if (modelId) {
|
|
30
|
+
if (skipModels.includes(modelId)) return true;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
];
|
|
36
|
+
export { createDefaultFilterOutRecordPlugins, equalKeys, skipModels, startsWithKeys };
|
|
77
37
|
|
|
78
38
|
//# 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 // 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;IAMA;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"}
|
package/sync/handler/Handler.js
CHANGED
|
@@ -1,85 +1,73 @@
|
|
|
1
1
|
import { PutEventsCommand } from "@webiny/aws-sdk/client-eventbridge/index.js";
|
|
2
2
|
import { convertException } from "@webiny/utils";
|
|
3
3
|
import { generateAlphaNumericId } from "@webiny/utils/generateId.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
add(input) {
|
|
15
|
-
const cmd = this.converter.convert(input);
|
|
16
|
-
this.commands.push(cmd);
|
|
17
|
-
}
|
|
18
|
-
async flush() {
|
|
19
|
-
const items = this.createEventBusEvent();
|
|
20
|
-
if (!items?.length) {
|
|
21
|
-
return null;
|
|
4
|
+
class Handler {
|
|
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;
|
|
22
13
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*/
|
|
27
|
-
id: generateAlphaNumericId(),
|
|
28
|
-
items,
|
|
29
|
-
source: this.system
|
|
30
|
-
};
|
|
31
|
-
const input = {
|
|
32
|
-
Entries: [{
|
|
33
|
-
DetailType: "synchronization-input",
|
|
34
|
-
Detail: JSON.stringify(detail),
|
|
35
|
-
Source: `webiny:${this.system.name}`,
|
|
36
|
-
EventBusName: this.eventBus.name
|
|
37
|
-
}]
|
|
38
|
-
};
|
|
39
|
-
const command = new PutEventsCommand(input);
|
|
40
|
-
try {
|
|
41
|
-
const eventBridgeClient = this.getEventBridgeClient();
|
|
42
|
-
return await eventBridgeClient.send(command);
|
|
43
|
-
} catch (ex) {
|
|
44
|
-
console.log("Could not send events to Sync System EventBridge.");
|
|
45
|
-
console.error(ex.message);
|
|
46
|
-
console.error(convertException(ex, ["message"]));
|
|
47
|
-
console.log(JSON.stringify({
|
|
48
|
-
event: items
|
|
49
|
-
}));
|
|
50
|
-
throw ex;
|
|
14
|
+
add(input) {
|
|
15
|
+
const cmd = this.converter.convert(input);
|
|
16
|
+
this.commands.push(cmd);
|
|
51
17
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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;
|
|
67
50
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
+
}
|
|
80
69
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
};
|
|
70
|
+
const createSyncHandler = (params)=>new Handler(params);
|
|
71
|
+
export { Handler, createSyncHandler };
|
|
84
72
|
|
|
85
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"}
|