@webiny/api-sync-system 6.3.0 → 6.4.0-beta.1
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/constants.js
CHANGED
package/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const SQS_EVENT_NAME = \"synchronization-input\" as const;\n"],"names":["SQS_EVENT_NAME"],"mappings":"AAAO,MAAMA,iBAAiB"}
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-sync-system",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -14,32 +14,32 @@
|
|
|
14
14
|
"author": "Webiny LTD",
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@webiny/api": "6.
|
|
18
|
-
"@webiny/aws-sdk": "6.
|
|
19
|
-
"@webiny/error": "6.
|
|
20
|
-
"@webiny/handler": "6.
|
|
21
|
-
"@webiny/handler-aws": "6.
|
|
22
|
-
"@webiny/plugins": "6.
|
|
23
|
-
"@webiny/utils": "6.
|
|
17
|
+
"@webiny/api": "6.4.0-beta.1",
|
|
18
|
+
"@webiny/aws-sdk": "6.4.0-beta.1",
|
|
19
|
+
"@webiny/error": "6.4.0-beta.1",
|
|
20
|
+
"@webiny/handler": "6.4.0-beta.1",
|
|
21
|
+
"@webiny/handler-aws": "6.4.0-beta.1",
|
|
22
|
+
"@webiny/plugins": "6.4.0-beta.1",
|
|
23
|
+
"@webiny/utils": "6.4.0-beta.1",
|
|
24
24
|
"bytes": "3.1.2",
|
|
25
25
|
"lodash": "4.18.1",
|
|
26
|
-
"semver": "7.
|
|
27
|
-
"zod": "4.3
|
|
26
|
+
"semver": "7.8.0",
|
|
27
|
+
"zod": "4.4.3"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@faker-js/faker": "10.4.0",
|
|
31
31
|
"@types/lodash": "4.17.24",
|
|
32
|
-
"@webiny/build-tools": "6.
|
|
33
|
-
"@webiny/project-utils": "6.
|
|
32
|
+
"@webiny/build-tools": "6.4.0-beta.1",
|
|
33
|
+
"@webiny/project-utils": "6.4.0-beta.1",
|
|
34
34
|
"aws-sdk-client-mock": "4.1.0",
|
|
35
35
|
"jest-dynalite": "3.6.1",
|
|
36
36
|
"rimraf": "6.1.3",
|
|
37
37
|
"typescript": "6.0.3",
|
|
38
|
-
"vitest": "4.1.
|
|
38
|
+
"vitest": "4.1.6"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public",
|
|
42
42
|
"directory": "dist"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "73237b8243693038c072bae1c0b783387448cbbe"
|
|
45
45
|
}
|
|
@@ -1,118 +1,96 @@
|
|
|
1
1
|
import { CommandHandlerPlugin } from "../plugins/CommandHandlerPlugin.js";
|
|
2
2
|
import { convertException } from "@webiny/utils";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
async handle(params) {
|
|
16
|
-
const {
|
|
17
|
-
data
|
|
18
|
-
} = params;
|
|
19
|
-
const sources = this.tableBundler.bundle({
|
|
20
|
-
items: data.getItems()
|
|
21
|
-
});
|
|
22
|
-
const container = this.createSourceDataContainer();
|
|
23
|
-
for (const bundle of sources.getBundles()) {
|
|
24
|
-
/**
|
|
25
|
-
* Need to fetch all the records from the source deployment tables.
|
|
26
|
-
*/
|
|
27
|
-
const {
|
|
28
|
-
items,
|
|
29
|
-
error
|
|
30
|
-
} = await this.fetcher.exec({
|
|
31
|
-
deployment: bundle.source,
|
|
32
|
-
table: bundle.table,
|
|
33
|
-
items: bundle.items,
|
|
34
|
-
maxBatchSize: 25
|
|
35
|
-
});
|
|
36
|
-
if (error) {
|
|
37
|
-
console.error(`Could not fetch records from the source table (${bundle.source.name} / ${bundle.table.name}). More info in next log line.`);
|
|
38
|
-
console.log(convertException(error));
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
container.merge(items);
|
|
3
|
+
class RecordHandler {
|
|
4
|
+
constructor(params){
|
|
5
|
+
this.plugins = params.plugins;
|
|
6
|
+
this.fetcher = params.fetcher;
|
|
7
|
+
this.storer = params.storer;
|
|
8
|
+
this.commandBundler = params.commandBundler;
|
|
9
|
+
this.tableBundler = params.tableBundler;
|
|
10
|
+
this.deployments = params.deployments;
|
|
11
|
+
this.transformHandler = params.transformHandler;
|
|
12
|
+
this.createSourceDataContainer = params.createSourceDataContainer;
|
|
13
|
+
this.commandHandlerPlugins = this.plugins.byType(CommandHandlerPlugin.type);
|
|
42
14
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
items: data.getItems()
|
|
48
|
-
});
|
|
49
|
-
for (const bundle of bundlesByCommand.getBundles()) {
|
|
50
|
-
const deployments = this.deployments.without(bundle.source);
|
|
51
|
-
for (const targetDeployment of deployments.all()) {
|
|
52
|
-
/**
|
|
53
|
-
* We need to map keys to actual items from the source deployment.
|
|
54
|
-
*/
|
|
55
|
-
const items = bundle.items.map(item => {
|
|
56
|
-
return container.get({
|
|
57
|
-
PK: item.PK,
|
|
58
|
-
SK: item.SK,
|
|
59
|
-
table: bundle.table,
|
|
60
|
-
source: bundle.source
|
|
61
|
-
});
|
|
62
|
-
}).filter(item => !!item);
|
|
63
|
-
const targetTable = this.findTargetTable({
|
|
64
|
-
bundle,
|
|
65
|
-
targetDeployment
|
|
15
|
+
async handle(params) {
|
|
16
|
+
const { data } = params;
|
|
17
|
+
const sources = this.tableBundler.bundle({
|
|
18
|
+
items: data.getItems()
|
|
66
19
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
20
|
+
const container = this.createSourceDataContainer();
|
|
21
|
+
for (const bundle of sources.getBundles()){
|
|
22
|
+
const { items, error } = await this.fetcher.exec({
|
|
23
|
+
deployment: bundle.source,
|
|
24
|
+
table: bundle.table,
|
|
25
|
+
items: bundle.items,
|
|
26
|
+
maxBatchSize: 25
|
|
27
|
+
});
|
|
28
|
+
if (error) {
|
|
29
|
+
console.error(`Could not fetch records from the source table (${bundle.source.name} / ${bundle.table.name}). More info in next log line.`);
|
|
30
|
+
console.log(convertException(error));
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
container.merge(items);
|
|
70
34
|
}
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
sourceDeployment: bundle.source,
|
|
74
|
-
sourceTable: bundle.table,
|
|
75
|
-
targetDeployment: targetDeployment,
|
|
76
|
-
targetTable: targetTable
|
|
35
|
+
const bundlesByCommand = this.commandBundler.bundle({
|
|
36
|
+
items: data.getItems()
|
|
77
37
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
38
|
+
for (const bundle of bundlesByCommand.getBundles()){
|
|
39
|
+
const deployments = this.deployments.without(bundle.source);
|
|
40
|
+
for (const targetDeployment of deployments.all()){
|
|
41
|
+
const items = bundle.items.map((item)=>container.get({
|
|
42
|
+
PK: item.PK,
|
|
43
|
+
SK: item.SK,
|
|
44
|
+
table: bundle.table,
|
|
45
|
+
source: bundle.source
|
|
46
|
+
})).filter((item)=>!!item);
|
|
47
|
+
const targetTable = this.findTargetTable({
|
|
48
|
+
bundle,
|
|
49
|
+
targetDeployment
|
|
50
|
+
});
|
|
51
|
+
if (!targetTable) {
|
|
52
|
+
console.error(`Could not find target table for source table "${bundle.table.name}" in deployment "${bundle.source.name}".`);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const result = await this.transformHandler.transform({
|
|
56
|
+
items,
|
|
57
|
+
sourceDeployment: bundle.source,
|
|
58
|
+
sourceTable: bundle.table,
|
|
59
|
+
targetDeployment: targetDeployment,
|
|
60
|
+
targetTable: targetTable
|
|
61
|
+
});
|
|
62
|
+
let commandHandler;
|
|
63
|
+
try {
|
|
64
|
+
commandHandler = this.getCommandHandler(bundle.command);
|
|
65
|
+
} catch (ex) {
|
|
66
|
+
console.error(ex.message);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
await commandHandler.handle({
|
|
70
|
+
storer: this.storer,
|
|
71
|
+
items: result.items,
|
|
72
|
+
bundle,
|
|
73
|
+
targetDeployment: targetDeployment,
|
|
74
|
+
targetTable: targetTable
|
|
75
|
+
});
|
|
76
|
+
}
|
|
84
77
|
}
|
|
85
|
-
await commandHandler.handle({
|
|
86
|
-
storer: this.storer,
|
|
87
|
-
items: result.items,
|
|
88
|
-
bundle,
|
|
89
|
-
targetDeployment: targetDeployment,
|
|
90
|
-
targetTable: targetTable
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
78
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return targetDeployment.getTable(bundle.table.type);
|
|
102
|
-
} catch {
|
|
103
|
-
return null;
|
|
79
|
+
findTargetTable(params) {
|
|
80
|
+
const { bundle, targetDeployment } = params;
|
|
81
|
+
try {
|
|
82
|
+
return targetDeployment.getTable(bundle.table.type);
|
|
83
|
+
} catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
104
86
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
throw new Error(`Could not find a command handler for command: ${command}`);
|
|
87
|
+
getCommandHandler(command) {
|
|
88
|
+
const handler = this.commandHandlerPlugins.find((plugin)=>plugin.canHandle(command));
|
|
89
|
+
if (!handler) throw new Error(`Could not find a command handler for command: ${command}`);
|
|
90
|
+
return handler;
|
|
110
91
|
}
|
|
111
|
-
return handler;
|
|
112
|
-
}
|
|
113
92
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
};
|
|
93
|
+
const createRecordHandler = (params)=>new RecordHandler(params);
|
|
94
|
+
export { RecordHandler, createRecordHandler };
|
|
117
95
|
|
|
118
96
|
//# sourceMappingURL=RecordHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["CommandHandlerPlugin","convertException","RecordHandler","constructor","params","plugins","fetcher","storer","commandBundler","tableBundler","deployments","transformHandler","createSourceDataContainer","commandHandlerPlugins","byType","type","handle","data","sources","bundle","items","getItems","container","getBundles","error","exec","deployment","source","table","maxBatchSize","console","name","log","merge","bundlesByCommand","without","targetDeployment","all","map","item","get","PK","SK","filter","targetTable","findTargetTable","result","transform","sourceDeployment","sourceTable","commandHandler","getCommandHandler","command","ex","message","getTable","handler","find","plugin","canHandle","Error","createRecordHandler"],"sources":["RecordHandler.ts"],"sourcesContent":["import type { IRecordHandler, IRecordHandlerHandleParams } from \"./abstractions/RecordHandler.js\";\nimport { CommandHandlerPlugin } from \"../plugins/CommandHandlerPlugin.js\";\nimport { convertException } from \"@webiny/utils\";\nimport type { CommandType } from \"~/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { IFetcher } from \"~/resolver/app/fetcher/types.js\";\nimport type { IStoreItem, IStorer } from \"~/resolver/app/storer/types.js\";\nimport type { IBundle, IBundler } from \"~/resolver/app/bundler/types.js\";\nimport type { IDeployment, IDeployments } from \"~/resolver/deployment/types.js\";\nimport type { ITransformHandler } from \"~/resolver/app/transform/TransformHandler.js\";\nimport type { ITable } from \"~/sync/types.js\";\nimport type { ISourceDataContainer } from \"~/resolver/app/data/types.js\";\n\nexport interface IRecordHandlerParams {\n fetcher: IFetcher;\n storer: IStorer;\n plugins: PluginsContainer;\n commandBundler: IBundler;\n tableBundler: IBundler;\n deployments: IDeployments;\n transformHandler: ITransformHandler;\n createSourceDataContainer: () => ISourceDataContainer;\n}\n\ninterface IFindTargetTableParams {\n bundle: IBundle;\n targetDeployment: IDeployment;\n}\n\nexport class RecordHandler implements IRecordHandler {\n private readonly plugins: PluginsContainer;\n private readonly commandHandlerPlugins: CommandHandlerPlugin[];\n private readonly fetcher: IFetcher;\n private readonly storer: IStorer;\n private readonly commandBundler: IBundler;\n private readonly tableBundler: IBundler;\n private readonly deployments: IDeployments;\n private readonly transformHandler: ITransformHandler;\n private readonly createSourceDataContainer: () => ISourceDataContainer;\n\n public constructor(params: IRecordHandlerParams) {\n this.plugins = params.plugins;\n this.fetcher = params.fetcher;\n this.storer = params.storer;\n this.commandBundler = params.commandBundler;\n this.tableBundler = params.tableBundler;\n this.deployments = params.deployments;\n this.transformHandler = params.transformHandler;\n this.createSourceDataContainer = params.createSourceDataContainer;\n\n this.commandHandlerPlugins = this.plugins.byType<CommandHandlerPlugin>(\n CommandHandlerPlugin.type\n );\n }\n\n public async handle(params: IRecordHandlerHandleParams): Promise<void> {\n const { data } = params;\n\n const sources = this.tableBundler.bundle({\n items: data.getItems()\n });\n\n const container = this.createSourceDataContainer();\n\n for (const bundle of sources.getBundles()) {\n /**\n * Need to fetch all the records from the source deployment tables.\n */\n const { items, error } = await this.fetcher.exec({\n deployment: bundle.source,\n table: bundle.table,\n items: bundle.items,\n maxBatchSize: 25\n });\n if (error) {\n console.error(\n `Could not fetch records from the source table (${bundle.source.name} / ${bundle.table.name}). More info in next log line.`\n );\n console.log(convertException(error));\n continue;\n }\n container.merge(items);\n }\n /**\n * We can now handle the records by going through all the items bundled by command, in correct order.\n */\n const bundlesByCommand = this.commandBundler.bundle({\n items: data.getItems()\n });\n for (const bundle of bundlesByCommand.getBundles()) {\n const deployments = this.deployments.without(bundle.source);\n for (const targetDeployment of deployments.all()) {\n /**\n * We need to map keys to actual items from the source deployment.\n */\n const items = bundle.items\n .map(item => {\n return container.get({\n PK: item.PK,\n SK: item.SK,\n table: bundle.table,\n source: bundle.source\n });\n })\n .filter((item): item is IStoreItem => !!item);\n\n const targetTable = this.findTargetTable({\n bundle,\n targetDeployment\n });\n if (!targetTable) {\n console.error(\n `Could not find target table for source table \"${bundle.table.name}\" in deployment \"${bundle.source.name}\".`\n );\n continue;\n }\n\n const result = await this.transformHandler.transform({\n items,\n sourceDeployment: bundle.source,\n sourceTable: bundle.table,\n targetDeployment: targetDeployment,\n targetTable: targetTable\n });\n\n let commandHandler: CommandHandlerPlugin;\n try {\n commandHandler = this.getCommandHandler(bundle.command);\n } catch (ex) {\n console.error(ex.message);\n continue;\n }\n\n await commandHandler.handle({\n storer: this.storer,\n items: result.items,\n bundle,\n targetDeployment: targetDeployment,\n targetTable: targetTable\n });\n }\n }\n }\n\n private findTargetTable(params: IFindTargetTableParams): ITable | null {\n const { bundle, targetDeployment } = params;\n\n try {\n return targetDeployment.getTable(bundle.table.type);\n } catch {\n return null;\n }\n }\n\n private getCommandHandler(command: CommandType): CommandHandlerPlugin {\n const handler = this.commandHandlerPlugins.find(plugin => plugin.canHandle(command));\n if (!handler) {\n throw new Error(`Could not find a command handler for command: ${command}`);\n }\n\n return handler;\n }\n}\n\nexport const createRecordHandler = (params: IRecordHandlerParams): IRecordHandler => {\n return new RecordHandler(params);\n};\n"],"mappings":"AACA,SAASA,oBAAoB;AAC7B,SAASC,gBAAgB,QAAQ,eAAe;AA2BhD,OAAO,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zD,MAA4B,IAAqB;EACjF,OAAO,IAAIF,aAAa,CAACE,MAAM,CAAC;AACpC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"resolver/app/RecordHandler.js","sources":["../../../src/resolver/app/RecordHandler.ts"],"sourcesContent":["import type { IRecordHandler, IRecordHandlerHandleParams } from \"./abstractions/RecordHandler.js\";\nimport { CommandHandlerPlugin } from \"../plugins/CommandHandlerPlugin.js\";\nimport { convertException } from \"@webiny/utils\";\nimport type { CommandType } from \"~/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { IFetcher } from \"~/resolver/app/fetcher/types.js\";\nimport type { IStoreItem, IStorer } from \"~/resolver/app/storer/types.js\";\nimport type { IBundle, IBundler } from \"~/resolver/app/bundler/types.js\";\nimport type { IDeployment, IDeployments } from \"~/resolver/deployment/types.js\";\nimport type { ITransformHandler } from \"~/resolver/app/transform/TransformHandler.js\";\nimport type { ITable } from \"~/sync/types.js\";\nimport type { ISourceDataContainer } from \"~/resolver/app/data/types.js\";\n\nexport interface IRecordHandlerParams {\n fetcher: IFetcher;\n storer: IStorer;\n plugins: PluginsContainer;\n commandBundler: IBundler;\n tableBundler: IBundler;\n deployments: IDeployments;\n transformHandler: ITransformHandler;\n createSourceDataContainer: () => ISourceDataContainer;\n}\n\ninterface IFindTargetTableParams {\n bundle: IBundle;\n targetDeployment: IDeployment;\n}\n\nexport class RecordHandler implements IRecordHandler {\n private readonly plugins: PluginsContainer;\n private readonly commandHandlerPlugins: CommandHandlerPlugin[];\n private readonly fetcher: IFetcher;\n private readonly storer: IStorer;\n private readonly commandBundler: IBundler;\n private readonly tableBundler: IBundler;\n private readonly deployments: IDeployments;\n private readonly transformHandler: ITransformHandler;\n private readonly createSourceDataContainer: () => ISourceDataContainer;\n\n public constructor(params: IRecordHandlerParams) {\n this.plugins = params.plugins;\n this.fetcher = params.fetcher;\n this.storer = params.storer;\n this.commandBundler = params.commandBundler;\n this.tableBundler = params.tableBundler;\n this.deployments = params.deployments;\n this.transformHandler = params.transformHandler;\n this.createSourceDataContainer = params.createSourceDataContainer;\n\n this.commandHandlerPlugins = this.plugins.byType<CommandHandlerPlugin>(\n CommandHandlerPlugin.type\n );\n }\n\n public async handle(params: IRecordHandlerHandleParams): Promise<void> {\n const { data } = params;\n\n const sources = this.tableBundler.bundle({\n items: data.getItems()\n });\n\n const container = this.createSourceDataContainer();\n\n for (const bundle of sources.getBundles()) {\n /**\n * Need to fetch all the records from the source deployment tables.\n */\n const { items, error } = await this.fetcher.exec({\n deployment: bundle.source,\n table: bundle.table,\n items: bundle.items,\n maxBatchSize: 25\n });\n if (error) {\n console.error(\n `Could not fetch records from the source table (${bundle.source.name} / ${bundle.table.name}). More info in next log line.`\n );\n console.log(convertException(error));\n continue;\n }\n container.merge(items);\n }\n /**\n * We can now handle the records by going through all the items bundled by command, in correct order.\n */\n const bundlesByCommand = this.commandBundler.bundle({\n items: data.getItems()\n });\n for (const bundle of bundlesByCommand.getBundles()) {\n const deployments = this.deployments.without(bundle.source);\n for (const targetDeployment of deployments.all()) {\n /**\n * We need to map keys to actual items from the source deployment.\n */\n const items = bundle.items\n .map(item => {\n return container.get({\n PK: item.PK,\n SK: item.SK,\n table: bundle.table,\n source: bundle.source\n });\n })\n .filter((item): item is IStoreItem => !!item);\n\n const targetTable = this.findTargetTable({\n bundle,\n targetDeployment\n });\n if (!targetTable) {\n console.error(\n `Could not find target table for source table \"${bundle.table.name}\" in deployment \"${bundle.source.name}\".`\n );\n continue;\n }\n\n const result = await this.transformHandler.transform({\n items,\n sourceDeployment: bundle.source,\n sourceTable: bundle.table,\n targetDeployment: targetDeployment,\n targetTable: targetTable\n });\n\n let commandHandler: CommandHandlerPlugin;\n try {\n commandHandler = this.getCommandHandler(bundle.command);\n } catch (ex) {\n console.error(ex.message);\n continue;\n }\n\n await commandHandler.handle({\n storer: this.storer,\n items: result.items,\n bundle,\n targetDeployment: targetDeployment,\n targetTable: targetTable\n });\n }\n }\n }\n\n private findTargetTable(params: IFindTargetTableParams): ITable | null {\n const { bundle, targetDeployment } = params;\n\n try {\n return targetDeployment.getTable(bundle.table.type);\n } catch {\n return null;\n }\n }\n\n private getCommandHandler(command: CommandType): CommandHandlerPlugin {\n const handler = this.commandHandlerPlugins.find(plugin => plugin.canHandle(command));\n if (!handler) {\n throw new Error(`Could not find a command handler for command: ${command}`);\n }\n\n return handler;\n }\n}\n\nexport const createRecordHandler = (params: IRecordHandlerParams): IRecordHandler => {\n return new RecordHandler(params);\n};\n"],"names":["RecordHandler","params","CommandHandlerPlugin","data","sources","container","bundle","items","error","console","convertException","bundlesByCommand","deployments","targetDeployment","item","targetTable","result","commandHandler","ex","command","handler","plugin","Error","createRecordHandler"],"mappings":";;AA6BO,MAAMA;IAWT,YAAmBC,MAA4B,CAAE;QAC7C,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO;QAC7B,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO;QAC7B,IAAI,CAAC,MAAM,GAAGA,OAAO,MAAM;QAC3B,IAAI,CAAC,cAAc,GAAGA,OAAO,cAAc;QAC3C,IAAI,CAAC,YAAY,GAAGA,OAAO,YAAY;QACvC,IAAI,CAAC,WAAW,GAAGA,OAAO,WAAW;QACrC,IAAI,CAAC,gBAAgB,GAAGA,OAAO,gBAAgB;QAC/C,IAAI,CAAC,yBAAyB,GAAGA,OAAO,yBAAyB;QAEjE,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAC5CC,qBAAqB,IAAI;IAEjC;IAEA,MAAa,OAAOD,MAAkC,EAAiB;QACnE,MAAM,EAAEE,IAAI,EAAE,GAAGF;QAEjB,MAAMG,UAAU,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;YACrC,OAAOD,KAAK,QAAQ;QACxB;QAEA,MAAME,YAAY,IAAI,CAAC,yBAAyB;QAEhD,KAAK,MAAMC,UAAUF,QAAQ,UAAU,GAAI;YAIvC,MAAM,EAAEG,KAAK,EAAEC,KAA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/B,aAAaA,OAAO,KAAK;oBACzB,kBAAkBO;oBAClB,aAAaE;gBACjB;gBAEA,IAAIE;gBACJ,IAAI;oBACAA,iBAAiB,IAAI,CAAC,iBAAiB,CAACX,OAAO,OAAO;gBAC1D,EAAE,OAAOY,IAAI;oBACTT,QAAQ,KAAK,CAACS,GAAG,OAAO;oBACxB;gBACJ;gBAEA,MAAMD,eAAe,MAAM,CAAC;oBACxB,QAAQ,IAAI,CAAC,MAAM;oBACnB,OAAOD,OAAO,KAAK;oBACnBV;oBACA,kBAAkBO;oBAClB,aAAaE;gBACjB;YACJ;QACJ;IACJ;IAEQ,gBAAgBd,MAA8B,EAAiB;QACnE,MAAM,EAAEK,MAAM,EAAEO,gBAAgB,EAAE,GAAGZ;QAErC,IAAI;YACA,OAAOY,iBAAiB,QAAQ,CAACP,OAAO,KAAK,CAAC,IAAI;QACtD,EAAE,OAAM;YACJ,OAAO;QACX;IACJ;IAEQ,kBAAkBa,OAAoB,EAAwB;QAClE,MAAMC,UAAU,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAACC,CAAAA,SAAUA,OAAO,SAAS,CAACF;QAC3E,IAAI,CAACC,SACD,MAAM,IAAIE,MAAM,CAAC,8CAA8C,EAAEH,SAAS;QAG9E,OAAOC;IACX;AACJ;AAEO,MAAMG,sBAAsB,CAACtB,SACzB,IAAID,cAAcC"}
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import { createZodError } from "@webiny/utils";
|
|
2
2
|
import { createEventValidation } from "./validation/event.js";
|
|
3
3
|
const validation = createEventValidation();
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
class RecordsValidation {
|
|
5
|
+
async validate(records) {
|
|
6
|
+
const result = await validation.safeParseAsync(records);
|
|
7
|
+
if (result.error) return {
|
|
8
|
+
error: createZodError(result.error)
|
|
9
|
+
};
|
|
10
|
+
return {
|
|
11
|
+
records: result.data
|
|
12
|
+
};
|
|
11
13
|
}
|
|
12
|
-
return {
|
|
13
|
-
records: result.data
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
15
|
+
const createRecordsValidation = ()=>new RecordsValidation();
|
|
16
|
+
export { RecordsValidation, createRecordsValidation };
|
|
20
17
|
|
|
21
18
|
//# sourceMappingURL=RecordsValidation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"resolver/app/RecordsValidation.js","sources":["../../../src/resolver/app/RecordsValidation.ts"],"sourcesContent":["import type { SQSRecord } from \"@webiny/aws-sdk/types/index.js\";\nimport type {\n IRecordsValidation,\n IRecordsValidationResult\n} from \"./abstractions/RecordsValidation.js\";\nimport { createZodError } from \"@webiny/utils\";\nimport { createEventValidation } from \"~/resolver/app/validation/event.js\";\n\nconst validation = createEventValidation();\n\nexport class RecordsValidation implements IRecordsValidation {\n public async validate(records: SQSRecord[]): Promise<IRecordsValidationResult> {\n const result = await validation.safeParseAsync(records);\n if (result.error) {\n return {\n error: createZodError(result.error)\n };\n }\n return {\n records: result.data\n };\n }\n}\n\nexport const createRecordsValidation = (): IRecordsValidation => {\n return new RecordsValidation();\n};\n"],"names":["validation","createEventValidation","RecordsValidation","records","result","createZodError","createRecordsValidation"],"mappings":";;AAQA,MAAMA,aAAaC;AAEZ,MAAMC;IACT,MAAa,SAASC,OAAoB,EAAqC;QAC3E,MAAMC,SAAS,MAAMJ,WAAW,cAAc,CAACG;QAC/C,IAAIC,OAAO,KAAK,EACZ,OAAO;YACH,OAAOC,eAAeD,OAAO,KAAK;QACtC;QAEJ,OAAO;YACH,SAASA,OAAO,IAAI;QACxB;IACJ;AACJ;AAEO,MAAME,0BAA0B,IAC5B,IAAIJ"}
|
|
@@ -2,39 +2,32 @@ import { createRecordsValidation } from "./RecordsValidation.js";
|
|
|
2
2
|
import { convertException } from "@webiny/utils";
|
|
3
3
|
import { createIngestor } from "./ingestor/Ingestor.js";
|
|
4
4
|
import { createIngestorResult } from "./ingestor/IngestorResult.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
async resolve(params) {
|
|
11
|
-
const validation = createRecordsValidation();
|
|
12
|
-
const result = await validation.validate(params.records);
|
|
13
|
-
if (result.error) {
|
|
14
|
-
throw result.error;
|
|
5
|
+
class ResolverApplication {
|
|
6
|
+
constructor(params){
|
|
7
|
+
this.recordHandler = params.recordHandler;
|
|
8
|
+
this.deployments = params.deployments;
|
|
15
9
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
10
|
+
async resolve(params) {
|
|
11
|
+
const validation = createRecordsValidation();
|
|
12
|
+
const result = await validation.validate(params.records);
|
|
13
|
+
if (result.error) throw result.error;
|
|
14
|
+
const ingestor = createIngestor({
|
|
15
|
+
createIngestorResult: ()=>createIngestorResult(),
|
|
16
|
+
getSource: (name)=>this.deployments.get(name)
|
|
17
|
+
});
|
|
18
|
+
const data = await ingestor.ingest({
|
|
19
|
+
records: result.records
|
|
20
|
+
});
|
|
21
|
+
try {
|
|
22
|
+
await this.recordHandler.handle({
|
|
23
|
+
data
|
|
24
|
+
});
|
|
25
|
+
} catch (ex) {
|
|
26
|
+
console.error(convertException(ex));
|
|
27
|
+
}
|
|
33
28
|
}
|
|
34
|
-
}
|
|
35
29
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
30
|
+
const createResolverApp = (params)=>new ResolverApplication(params);
|
|
31
|
+
export { ResolverApplication, createResolverApp };
|
|
39
32
|
|
|
40
33
|
//# sourceMappingURL=ResolverApplication.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"resolver/app/ResolverApplication.js","sources":["../../../src/resolver/app/ResolverApplication.ts"],"sourcesContent":["import type {\n IResolverApplication,\n IResolverApplicationResolveParams\n} from \"./abstractions/ResolverApplication.js\";\nimport { createRecordsValidation } from \"./RecordsValidation.js\";\nimport { convertException } from \"@webiny/utils\";\nimport type { IRecordHandler } from \"./abstractions/RecordHandler.js\";\nimport type { IDeployments } from \"~/resolver/deployment/types.js\";\nimport { createIngestor } from \"./ingestor/Ingestor.js\";\nimport { createIngestorResult } from \"~/resolver/app/ingestor/IngestorResult.js\";\n\nexport interface IResolverApplicationParams {\n recordHandler: IRecordHandler;\n deployments: IDeployments;\n}\n\nexport class ResolverApplication implements IResolverApplication {\n private readonly recordHandler: IRecordHandler;\n private readonly deployments: IDeployments;\n\n public constructor(params: IResolverApplicationParams) {\n this.recordHandler = params.recordHandler;\n this.deployments = params.deployments;\n }\n\n public async resolve(params: IResolverApplicationResolveParams): Promise<void> {\n const validation = createRecordsValidation();\n\n const result = await validation.validate(params.records);\n if (result.error) {\n throw result.error;\n }\n\n const ingestor = createIngestor({\n createIngestorResult: () => {\n return createIngestorResult();\n },\n getSource: name => {\n return this.deployments.get(name);\n }\n });\n\n const data = await ingestor.ingest({\n records: result.records\n });\n\n try {\n await this.recordHandler.handle({\n data\n });\n } catch (ex) {\n console.error(convertException(ex));\n }\n }\n}\n\nexport const createResolverApp = (params: IResolverApplicationParams): IResolverApplication => {\n return new ResolverApplication(params);\n};\n"],"names":["ResolverApplication","params","validation","createRecordsValidation","result","ingestor","createIngestor","createIngestorResult","name","data","ex","console","convertException","createResolverApp"],"mappings":";;;;AAgBO,MAAMA;IAIT,YAAmBC,MAAkC,CAAE;QACnD,IAAI,CAAC,aAAa,GAAGA,OAAO,aAAa;QACzC,IAAI,CAAC,WAAW,GAAGA,OAAO,WAAW;IACzC;IAEA,MAAa,QAAQA,MAAyC,EAAiB;QAC3E,MAAMC,aAAaC;QAEnB,MAAMC,SAAS,MAAMF,WAAW,QAAQ,CAACD,OAAO,OAAO;QACvD,IAAIG,OAAO,KAAK,EACZ,MAAMA,OAAO,KAAK;QAGtB,MAAMC,WAAWC,eAAe;YAC5B,sBAAsB,IACXC;YAEX,WAAWC,CAAAA,OACA,IAAI,CAAC,WAAW,CAAC,GAAG,CAACA;QAEpC;QAEA,MAAMC,OAAO,MAAMJ,SAAS,MAAM,CAAC;YAC/B,SAASD,OAAO,OAAO;QAC3B;QAEA,IAAI;YACA,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;gBAC5BK;YACJ;QACJ,EAAE,OAAOC,IAAI;YACTC,QAAQ,KAAK,CAACC,iBAAiBF;QACnC;IACJ;AACJ;AAEO,MAAMG,oBAAoB,CAACZ,SACvB,IAAID,oBAAoBC"}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
class BaseBundle {
|
|
2
|
+
constructor(params){
|
|
3
|
+
this.items = [];
|
|
4
|
+
this.command = this.getCommand(params.command);
|
|
5
|
+
this.table = params.table;
|
|
6
|
+
this.source = params.source;
|
|
7
|
+
}
|
|
8
|
+
getCommand(command) {
|
|
9
|
+
return "delete" === command ? "delete" : "put";
|
|
10
|
+
}
|
|
11
|
+
add(item) {
|
|
12
|
+
this.items.push({
|
|
13
|
+
PK: item.PK,
|
|
14
|
+
SK: item.SK
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
17
|
}
|
|
18
|
+
export { BaseBundle };
|
|
18
19
|
|
|
19
20
|
//# sourceMappingURL=BaseBundle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"resolver/app/bundler/BaseBundle.js","sources":["../../../../src/resolver/app/bundler/BaseBundle.ts"],"sourcesContent":["import type { IBundle, IBundleItem } from \"~/resolver/app/bundler/types.js\";\nimport type { IDeployment } from \"~/resolver/deployment/types.js\";\nimport type { ITable } from \"~/sync/types.js\";\nimport type { CommandType } from \"~/types.js\";\nimport { type ExtendedCommandType } from \"~/types.js\";\nimport type { IIngestorResultItem } from \"../ingestor/types.js\";\n\nexport interface IBaseBundleParams {\n command: ExtendedCommandType;\n table: ITable;\n source: IDeployment;\n}\n\nexport abstract class BaseBundle implements IBundle {\n readonly items: IBundleItem[] = [];\n readonly command: CommandType;\n readonly table: ITable;\n readonly source: IDeployment;\n\n public abstract canAdd(item: IIngestorResultItem): boolean;\n\n public constructor(params: IBaseBundleParams) {\n this.command = this.getCommand(params.command);\n this.table = params.table;\n this.source = params.source;\n }\n\n protected getCommand(command: ExtendedCommandType): CommandType {\n return command === \"delete\" ? \"delete\" : \"put\";\n }\n\n public add(item: IIngestorResultItem): void {\n this.items.push({\n PK: item.PK,\n SK: item.SK\n });\n }\n}\n"],"names":["BaseBundle","params","command","item"],"mappings":"AAaO,MAAeA;IAQlB,YAAmBC,MAAyB,CAAE;aAPrC,KAAK,GAAkB,EAAE;QAQ9B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,UAAU,CAACA,OAAO,OAAO;QAC7C,IAAI,CAAC,KAAK,GAAGA,OAAO,KAAK;QACzB,IAAI,CAAC,MAAM,GAAGA,OAAO,MAAM;IAC/B;IAEU,WAAWC,OAA4B,EAAe;QAC5D,OAAOA,AAAY,aAAZA,UAAuB,WAAW;IAC7C;IAEO,IAAIC,IAAyB,EAAQ;QACxC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACZ,IAAIA,KAAK,EAAE;YACX,IAAIA,KAAK,EAAE;QACf;IACJ;AACJ"}
|
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
item
|
|
13
|
-
});
|
|
1
|
+
class Bundler {
|
|
2
|
+
constructor(params){
|
|
3
|
+
this.createBundles = params.createBundles;
|
|
4
|
+
}
|
|
5
|
+
bundle(params) {
|
|
6
|
+
const { items } = params;
|
|
7
|
+
const bundles = this.createBundles();
|
|
8
|
+
for (const item of items)bundles.add({
|
|
9
|
+
item
|
|
10
|
+
});
|
|
11
|
+
return bundles;
|
|
14
12
|
}
|
|
15
|
-
return bundles;
|
|
16
|
-
}
|
|
17
13
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
14
|
+
const createBundler = (params)=>new Bundler(params);
|
|
15
|
+
export { Bundler, createBundler };
|
|
21
16
|
|
|
22
17
|
//# sourceMappingURL=Bundler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"resolver/app/bundler/Bundler.js","sources":["../../../../src/resolver/app/bundler/Bundler.ts"],"sourcesContent":["import type { IBundler, IBundlerBundleParams, IBundles } from \"~/resolver/app/bundler/types.js\";\n\nexport interface IBundlerParams {\n createBundles: () => IBundles;\n}\n\nexport class Bundler implements IBundler {\n private readonly createBundles: () => IBundles;\n\n public constructor(params: IBundlerParams) {\n this.createBundles = params.createBundles;\n }\n\n public bundle(params: IBundlerBundleParams): IBundles {\n const { items } = params;\n\n const bundles = this.createBundles();\n\n for (const item of items) {\n bundles.add({\n item\n });\n }\n\n return bundles;\n }\n}\n\nexport const createBundler = (params: IBundlerParams) => {\n return new Bundler(params);\n};\n"],"names":["Bundler","params","items","bundles","item","createBundler"],"mappings":"AAMO,MAAMA;IAGT,YAAmBC,MAAsB,CAAE;QACvC,IAAI,CAAC,aAAa,GAAGA,OAAO,aAAa;IAC7C;IAEO,OAAOA,MAA4B,EAAY;QAClD,MAAM,EAAEC,KAAK,EAAE,GAAGD;QAElB,MAAME,UAAU,IAAI,CAAC,aAAa;QAElC,KAAK,MAAMC,QAAQF,MACfC,QAAQ,GAAG,CAAC;YACRC;QACJ;QAGJ,OAAOD;IACX;AACJ;AAEO,MAAME,gBAAgB,CAACJ,SACnB,IAAID,QAAQC"}
|