@webiny/api-sync-system 6.3.0 → 6.4.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constants.js +2 -1
- package/constants.js.map +1 -1
- package/index.js +0 -2
- package/package.json +14 -14
- 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.js +26 -31
- package/resolver/app/validation/body.js.map +1 -1
- package/resolver/app/validation/createJsonTransform.js +12 -13
- package/resolver/app/validation/createJsonTransform.js.map +1 -1
- package/resolver/app/validation/detail.js +30 -35
- package/resolver/app/validation/detail.js.map +1 -1
- package/resolver/app/validation/event.js +17 -18
- package/resolver/app/validation/event.js.map +1 -1
- package/resolver/app/validation/numericString.js +8 -11
- package/resolver/app/validation/numericString.js.map +1 -1
- package/resolver/app/validation/system.js +8 -9
- package/resolver/app/validation/system.js.map +1 -1
- package/resolver/createEventHandlerPlugin.js +70 -99
- package/resolver/createEventHandlerPlugin.js.map +1 -1
- package/resolver/createResolverHandler.js +49 -57
- package/resolver/createResolverHandler.js.map +1 -1
- package/resolver/deployment/Deployment.js +28 -31
- 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 -84
- package/resolver/deployment/DeploymentsFetcher.js.map +1 -1
- 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/FilterOutRecord.js +9 -17
- package/sync/FilterOutRecord.js.map +1 -1
- 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/createSendDataToEventBridgeOnRequestEnd.js +32 -37
- package/sync/createSendDataToEventBridgeOnRequestEnd.js.map +1 -1
- package/sync/createSyncSystem.js +24 -26
- package/sync/createSyncSystem.js.map +1 -1
- package/sync/filter/createDefaultFilterOutRecordPlugins.js +37 -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/requestPlugin.js +33 -48
- package/sync/requestPlugin.js.map +1 -1
- package/sync/types.js +0 -3
- package/sync/utils/getTableType.js +10 -9
- package/sync/utils/getTableType.js.map +1 -1
- package/sync/utils/manifest.js +28 -35
- 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.js +6 -5
- package/types.js.map +1 -1
- package/utils/createSystemName.js +5 -3
- package/utils/createSystemName.js.map +1 -1
- 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.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.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.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.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.js +13 -14
- package/worker/actions/updateUser/updateUserSchema.js.map +1 -1
- package/worker/createWorkerHandler.js +24 -30
- package/worker/createWorkerHandler.js.map +1 -1
- package/worker/handler/WorkerActionHandler.js +19 -21
- package/worker/handler/WorkerActionHandler.js.map +1 -1
- package/worker/handler/eventHandler.js +14 -16
- package/worker/handler/eventHandler.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/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/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,44 +1,39 @@
|
|
|
1
1
|
import { createOnRequestResponseSend, createOnRequestTimeout } from "@webiny/handler";
|
|
2
2
|
import { convertException } from "@webiny/utils/exception.js";
|
|
3
|
-
const execute = async handler
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* We do not want to throw an error here, because we are in the request end.
|
|
16
|
-
*/
|
|
17
|
-
}
|
|
3
|
+
const execute = async (handler)=>{
|
|
4
|
+
try {
|
|
5
|
+
return await handler.flush();
|
|
6
|
+
} catch (ex) {
|
|
7
|
+
const error = convertException(ex);
|
|
8
|
+
console.error({
|
|
9
|
+
flushError: error
|
|
10
|
+
});
|
|
11
|
+
return {
|
|
12
|
+
error
|
|
13
|
+
};
|
|
14
|
+
}
|
|
18
15
|
};
|
|
19
|
-
const isOptionsRequest = request
|
|
20
|
-
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
return request.method.toUpperCase() === "OPTIONS";
|
|
16
|
+
const isOptionsRequest = (request)=>{
|
|
17
|
+
if (!request?.method) return false;
|
|
18
|
+
return "OPTIONS" === request.method.toUpperCase();
|
|
24
19
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return [onRequestResponseSend, onRequestTimeout];
|
|
20
|
+
const createSendDataToEventBridgeOnRequestEnd = (handler)=>{
|
|
21
|
+
const onRequestResponseSend = createOnRequestResponseSend(async (request, _, payload)=>{
|
|
22
|
+
if (isOptionsRequest(request)) return payload;
|
|
23
|
+
await execute(handler);
|
|
24
|
+
return payload;
|
|
25
|
+
});
|
|
26
|
+
onRequestResponseSend.name = "sync.onRequestResponseSend";
|
|
27
|
+
const onRequestTimeout = createOnRequestTimeout(async (request)=>{
|
|
28
|
+
if (isOptionsRequest(request)) return;
|
|
29
|
+
return await execute(handler);
|
|
30
|
+
});
|
|
31
|
+
onRequestTimeout.name = "sync.onRequestTimeout";
|
|
32
|
+
return [
|
|
33
|
+
onRequestResponseSend,
|
|
34
|
+
onRequestTimeout
|
|
35
|
+
];
|
|
42
36
|
};
|
|
37
|
+
export { createSendDataToEventBridgeOnRequestEnd };
|
|
43
38
|
|
|
44
39
|
//# sourceMappingURL=createSendDataToEventBridgeOnRequestEnd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"sync/createSendDataToEventBridgeOnRequestEnd.js","sources":["../../src/sync/createSendDataToEventBridgeOnRequestEnd.ts"],"sourcesContent":["import type { IHandler } from \"./types.js\";\nimport { createOnRequestResponseSend, createOnRequestTimeout } from \"@webiny/handler\";\nimport type { Request as FastifyRequest } from \"@webiny/handler/types.js\";\nimport { convertException } from \"@webiny/utils/exception.js\";\n\nconst execute = async (handler: IHandler) => {\n try {\n return await handler.flush();\n } catch (ex) {\n const error = convertException(ex);\n console.error({\n flushError: error\n });\n return {\n error\n };\n /**\n * We do not want to throw an error here, because we are in the request end.\n */\n }\n};\n\nconst isOptionsRequest = (request: FastifyRequest): boolean => {\n if (!request?.method) {\n return false;\n }\n return request.method.toUpperCase() === \"OPTIONS\";\n};\n\nexport const createSendDataToEventBridgeOnRequestEnd = (handler: IHandler) => {\n const onRequestResponseSend = createOnRequestResponseSend(async (request, _, payload) => {\n if (isOptionsRequest(request)) {\n return payload;\n }\n await execute(handler);\n return payload;\n });\n onRequestResponseSend.name = \"sync.onRequestResponseSend\";\n\n const onRequestTimeout = createOnRequestTimeout(async request => {\n if (isOptionsRequest(request)) {\n return;\n }\n return await execute(handler);\n });\n onRequestTimeout.name = \"sync.onRequestTimeout\";\n\n return [onRequestResponseSend, onRequestTimeout];\n};\n"],"names":["execute","handler","ex","error","convertException","console","isOptionsRequest","request","createSendDataToEventBridgeOnRequestEnd","onRequestResponseSend","createOnRequestResponseSend","_","payload","onRequestTimeout","createOnRequestTimeout"],"mappings":";;AAKA,MAAMA,UAAU,OAAOC;IACnB,IAAI;QACA,OAAO,MAAMA,QAAQ,KAAK;IAC9B,EAAE,OAAOC,IAAI;QACT,MAAMC,QAAQC,iBAAiBF;QAC/BG,QAAQ,KAAK,CAAC;YACV,YAAYF;QAChB;QACA,OAAO;YACHA;QACJ;IAIJ;AACJ;AAEA,MAAMG,mBAAmB,CAACC;IACtB,IAAI,CAACA,SAAS,QACV,OAAO;IAEX,OAAOA,AAAiC,cAAjCA,QAAQ,MAAM,CAAC,WAAW;AACrC;AAEO,MAAMC,0CAA0C,CAACP;IACpD,MAAMQ,wBAAwBC,4BAA4B,OAAOH,SAASI,GAAGC;QACzE,IAAIN,iBAAiBC,UACjB,OAAOK;QAEX,MAAMZ,QAAQC;QACd,OAAOW;IACX;IACAH,sBAAsB,IAAI,GAAG;IAE7B,MAAMI,mBAAmBC,uBAAuB,OAAMP;QAClD,IAAID,iBAAiBC,UACjB;QAEJ,OAAO,MAAMP,QAAQC;IACzB;IACAY,iBAAiB,IAAI,GAAG;IAExB,OAAO;QAACJ;QAAuBI;KAAiB;AACpD"}
|
package/sync/createSyncSystem.js
CHANGED
|
@@ -2,34 +2,32 @@ import { validateSystemInput } from "./utils/validateSystemInput.js";
|
|
|
2
2
|
import { createSyncSystemHandlerOnRequestPlugin } from "./requestPlugin.js";
|
|
3
3
|
import { createDefaultFilterOutRecordPlugins } from "./filter/createDefaultFilterOutRecordPlugins.js";
|
|
4
4
|
const emptyResponse = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
plugins () {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
console.error(error);
|
|
19
|
-
return emptyResponse;
|
|
20
|
-
} else if (!system) {
|
|
21
|
-
console.error("Sync System: No system provided. Sync System will not be attached.");
|
|
22
|
-
return emptyResponse;
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
plugins: () => {
|
|
26
|
-
return [...(params.plugins || []), ...createDefaultFilterOutRecordPlugins(), createSyncSystemHandlerOnRequestPlugin({
|
|
27
|
-
getDocumentClient: params.getDocumentClient,
|
|
28
|
-
getEventBridgeClient: params.getEventBridgeClient,
|
|
29
|
-
system
|
|
30
|
-
})];
|
|
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;
|
|
31
18
|
}
|
|
32
|
-
|
|
19
|
+
return {
|
|
20
|
+
plugins: ()=>[
|
|
21
|
+
...params.plugins || [],
|
|
22
|
+
...createDefaultFilterOutRecordPlugins(),
|
|
23
|
+
createSyncSystemHandlerOnRequestPlugin({
|
|
24
|
+
getDocumentClient: params.getDocumentClient,
|
|
25
|
+
getEventBridgeClient: params.getEventBridgeClient,
|
|
26
|
+
system
|
|
27
|
+
})
|
|
28
|
+
]
|
|
29
|
+
};
|
|
33
30
|
};
|
|
31
|
+
export { createSyncSystem };
|
|
34
32
|
|
|
35
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,78 +1,39 @@
|
|
|
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
|
-
|
|
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
|
+
"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 };
|
|
77
38
|
|
|
78
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"}
|
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
|