@webiny/api-sync-system 6.0.0-alpha.4 → 6.0.0-rc.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/README.md +6 -108
- package/constants.js +1 -7
- package/constants.js.map +1 -1
- package/index.js +3 -38
- package/index.js.map +1 -1
- package/package.json +20 -23
- package/resolver/app/RecordHandler.d.ts +6 -6
- package/resolver/app/RecordHandler.js +7 -15
- package/resolver/app/RecordHandler.js.map +1 -1
- package/resolver/app/RecordsValidation.js +6 -14
- package/resolver/app/RecordsValidation.js.map +1 -1
- package/resolver/app/ResolverApplication.d.ts +1 -1
- package/resolver/app/ResolverApplication.js +10 -18
- package/resolver/app/ResolverApplication.js.map +1 -1
- package/resolver/app/abstractions/RecordHandler.d.ts +1 -1
- package/resolver/app/abstractions/RecordHandler.js +1 -5
- package/resolver/app/abstractions/RecordsValidation.d.ts +2 -2
- package/resolver/app/abstractions/RecordsValidation.js +1 -5
- package/resolver/app/abstractions/RecordsValidation.js.map +1 -1
- package/resolver/app/abstractions/ResolverApplication.js +1 -5
- package/resolver/app/abstractions/ResolverRecord.d.ts +1 -1
- package/resolver/app/abstractions/ResolverRecord.js +1 -5
- package/resolver/app/abstractions/ResolverRecord.js.map +1 -1
- package/resolver/app/bundler/BaseBundle.d.ts +6 -6
- package/resolver/app/bundler/BaseBundle.js +1 -8
- package/resolver/app/bundler/BaseBundle.js.map +1 -1
- package/resolver/app/bundler/Bundler.d.ts +1 -1
- package/resolver/app/bundler/Bundler.js +2 -10
- package/resolver/app/bundler/Bundler.js.map +1 -1
- package/resolver/app/bundler/Bundles.d.ts +2 -2
- package/resolver/app/bundler/Bundles.js +2 -10
- package/resolver/app/bundler/Bundles.js.map +1 -1
- package/resolver/app/bundler/CommandBundle.d.ts +1 -1
- package/resolver/app/bundler/CommandBundle.js +3 -11
- package/resolver/app/bundler/CommandBundle.js.map +1 -1
- package/resolver/app/bundler/TableBundle.d.ts +1 -1
- package/resolver/app/bundler/TableBundle.js +3 -11
- package/resolver/app/bundler/TableBundle.js.map +1 -1
- package/resolver/app/bundler/types.d.ts +2 -2
- package/resolver/app/bundler/types.js +1 -5
- package/resolver/app/commandHandler/DeleteCommandHandler.d.ts +3 -3
- package/resolver/app/commandHandler/DeleteCommandHandler.js +1 -8
- package/resolver/app/commandHandler/DeleteCommandHandler.js.map +1 -1
- package/resolver/app/commandHandler/PutCommandHandler.d.ts +4 -4
- package/resolver/app/commandHandler/PutCommandHandler.js +1 -8
- package/resolver/app/commandHandler/PutCommandHandler.js.map +1 -1
- package/resolver/app/commandHandler/delete.d.ts +1 -1
- package/resolver/app/commandHandler/delete.js +6 -13
- package/resolver/app/commandHandler/delete.js.map +1 -1
- package/resolver/app/commandHandler/put.d.ts +1 -1
- package/resolver/app/commandHandler/put.js +6 -13
- package/resolver/app/commandHandler/put.js.map +1 -1
- package/resolver/app/data/SourceDataContainer.d.ts +3 -3
- package/resolver/app/data/SourceDataContainer.js +1 -8
- package/resolver/app/data/SourceDataContainer.js.map +1 -1
- package/resolver/app/data/types.d.ts +2 -2
- package/resolver/app/data/types.js +1 -5
- package/resolver/app/fetcher/Fetcher.d.ts +3 -3
- package/resolver/app/fetcher/Fetcher.js +13 -22
- package/resolver/app/fetcher/Fetcher.js.map +1 -1
- package/resolver/app/fetcher/types.d.ts +2 -2
- package/resolver/app/fetcher/types.js +1 -5
- package/resolver/app/ingestor/Ingestor.d.ts +1 -1
- package/resolver/app/ingestor/Ingestor.js +2 -10
- package/resolver/app/ingestor/Ingestor.js.map +1 -1
- package/resolver/app/ingestor/IngestorResult.js +3 -11
- package/resolver/app/ingestor/IngestorResult.js.map +1 -1
- package/resolver/app/ingestor/types.d.ts +2 -2
- package/resolver/app/ingestor/types.js +1 -5
- package/resolver/app/storer/Storer.d.ts +3 -3
- package/resolver/app/storer/Storer.js +12 -20
- package/resolver/app/storer/Storer.js.map +1 -1
- package/resolver/app/storer/types.d.ts +2 -2
- package/resolver/app/storer/types.js +1 -5
- package/resolver/app/storer/types.js.map +1 -1
- package/resolver/app/transform/TransformHandler.d.ts +4 -4
- package/resolver/app/transform/TransformHandler.js +5 -12
- package/resolver/app/transform/TransformHandler.js.map +1 -1
- package/resolver/app/transform/middleware.d.ts +1 -1
- package/resolver/app/transform/middleware.js +1 -7
- package/resolver/app/transform/middleware.js.map +1 -1
- package/resolver/app/utils/Retry.js +4 -12
- package/resolver/app/utils/Retry.js.map +1 -1
- package/resolver/app/utils/sleep.js +1 -8
- package/resolver/app/utils/sleep.js.map +1 -1
- package/resolver/app/validation/body.d.ts +6 -6
- package/resolver/app/validation/body.js +22 -30
- package/resolver/app/validation/body.js.map +1 -1
- package/resolver/app/validation/createJsonTransform.js +6 -14
- package/resolver/app/validation/createJsonTransform.js.map +1 -1
- package/resolver/app/validation/detail.d.ts +6 -6
- package/resolver/app/validation/detail.js +16 -24
- package/resolver/app/validation/detail.js.map +1 -1
- package/resolver/app/validation/event.d.ts +6 -6
- package/resolver/app/validation/event.js +19 -27
- package/resolver/app/validation/event.js.map +1 -1
- package/resolver/app/validation/numericString.js +5 -13
- package/resolver/app/validation/numericString.js.map +1 -1
- package/resolver/app/validation/system.js +8 -16
- package/resolver/app/validation/system.js.map +1 -1
- package/resolver/createEventHandlerPlugin.d.ts +2 -1
- package/resolver/createEventHandlerPlugin.js +35 -42
- package/resolver/createEventHandlerPlugin.js.map +1 -1
- package/resolver/createResolverHandler.d.ts +1 -1
- package/resolver/createResolverHandler.js +24 -31
- package/resolver/createResolverHandler.js.map +1 -1
- package/resolver/deployment/Deployment.d.ts +2 -3
- package/resolver/deployment/Deployment.js +6 -14
- package/resolver/deployment/Deployment.js.map +1 -1
- package/resolver/deployment/Deployments.js +2 -10
- package/resolver/deployment/Deployments.js.map +1 -1
- package/resolver/deployment/DeploymentsFetcher.js +33 -42
- package/resolver/deployment/DeploymentsFetcher.js.map +1 -1
- package/resolver/deployment/types.d.ts +4 -4
- package/resolver/deployment/types.js +1 -5
- package/resolver/deployment/types.js.map +1 -1
- package/resolver/lambda/LambdaTrigger.js +5 -12
- package/resolver/lambda/LambdaTrigger.js.map +1 -1
- package/resolver/plugins/CommandHandlerPlugin.d.ts +3 -3
- package/resolver/plugins/CommandHandlerPlugin.js +3 -11
- package/resolver/plugins/CommandHandlerPlugin.js.map +1 -1
- package/resolver/plugins/StorerAfterEachPlugin.d.ts +2 -2
- package/resolver/plugins/StorerAfterEachPlugin.js +4 -13
- package/resolver/plugins/StorerAfterEachPlugin.js.map +1 -1
- package/resolver/plugins/TransformRecordPlugin.d.ts +3 -3
- package/resolver/plugins/TransformRecordPlugin.js +3 -11
- package/resolver/plugins/TransformRecordPlugin.js.map +1 -1
- package/resolver/recordTypes/fileManager/CopyFile.js +4 -11
- package/resolver/recordTypes/fileManager/CopyFile.js.map +1 -1
- package/resolver/recordTypes/fileManager/DeleteFile.d.ts +1 -1
- package/resolver/recordTypes/fileManager/DeleteFile.js +3 -10
- package/resolver/recordTypes/fileManager/DeleteFile.js.map +1 -1
- package/resolver/recordTypes/fileManager/fileManager.d.ts +1 -1
- package/resolver/recordTypes/fileManager/fileManager.js +4 -11
- package/resolver/recordTypes/fileManager/fileManager.js.map +1 -1
- package/resolver/recordTypes/fileManager/fileManagerOnDelete.d.ts +1 -1
- package/resolver/recordTypes/fileManager/fileManagerOnDelete.js +7 -14
- package/resolver/recordTypes/fileManager/fileManagerOnDelete.js.map +1 -1
- package/resolver/recordTypes/fileManager/fileManagerOnPut.d.ts +1 -1
- package/resolver/recordTypes/fileManager/fileManagerOnPut.js +7 -14
- package/resolver/recordTypes/fileManager/fileManagerOnPut.js.map +1 -1
- package/resolver/recordTypes/fileManager/shouldBeHandled.d.ts +1 -1
- package/resolver/recordTypes/fileManager/shouldBeHandled.js +1 -8
- package/resolver/recordTypes/fileManager/shouldBeHandled.js.map +1 -1
- package/resolver/recordTypes/fileManager/types.d.ts +2 -2
- package/resolver/recordTypes/fileManager/types.js +1 -5
- package/resolver/recordTypes/users/CopyUser.d.ts +2 -2
- package/resolver/recordTypes/users/CopyUser.js +3 -10
- package/resolver/recordTypes/users/CopyUser.js.map +1 -1
- package/resolver/recordTypes/users/DeleteUser.d.ts +2 -2
- package/resolver/recordTypes/users/DeleteUser.js +3 -10
- package/resolver/recordTypes/users/DeleteUser.js.map +1 -1
- package/resolver/recordTypes/users/shouldBeHandled.d.ts +1 -1
- package/resolver/recordTypes/users/shouldBeHandled.js +1 -8
- package/resolver/recordTypes/users/shouldBeHandled.js.map +1 -1
- package/resolver/recordTypes/users/types.d.ts +1 -1
- package/resolver/recordTypes/users/types.js +1 -5
- package/resolver/recordTypes/users/types.js.map +1 -1
- package/resolver/recordTypes/users/users.js +4 -11
- package/resolver/recordTypes/users/users.js.map +1 -1
- package/resolver/recordTypes/users/usersOnDelete.d.ts +2 -2
- package/resolver/recordTypes/users/usersOnDelete.js +7 -14
- package/resolver/recordTypes/users/usersOnDelete.js.map +1 -1
- package/resolver/recordTypes/users/usersOnPut.d.ts +2 -2
- package/resolver/recordTypes/users/usersOnPut.js +7 -14
- package/resolver/recordTypes/users/usersOnPut.js.map +1 -1
- package/sync/FilterOutRecord.d.ts +2 -2
- package/sync/FilterOutRecord.js +2 -10
- package/sync/FilterOutRecord.js.map +1 -1
- package/sync/attachToDynamoDbDocument.d.ts +1 -1
- package/sync/attachToDynamoDbDocument.js +9 -17
- package/sync/attachToDynamoDbDocument.js.map +1 -1
- package/sync/createHandler.js +27 -34
- package/sync/createHandler.js.map +1 -1
- package/sync/createSendDataToEventBridgeOnRequestEnd.js +6 -13
- package/sync/createSendDataToEventBridgeOnRequestEnd.js.map +1 -1
- package/sync/createSyncSystem.d.ts +1 -1
- package/sync/createSyncSystem.js +6 -13
- package/sync/createSyncSystem.js.map +1 -1
- package/sync/filter/createDefaultFilterOutRecordPlugins.d.ts +1 -1
- package/sync/filter/createDefaultFilterOutRecordPlugins.js +9 -19
- package/sync/filter/createDefaultFilterOutRecordPlugins.js.map +1 -1
- package/sync/handler/Handler.d.ts +2 -2
- package/sync/handler/Handler.js +9 -17
- package/sync/handler/Handler.js.map +1 -1
- package/sync/handler/HandlerConverter.js +2 -10
- package/sync/handler/HandlerConverter.js.map +1 -1
- package/sync/handler/converter/BatchGetCommandConverter.js +6 -14
- package/sync/handler/converter/BatchGetCommandConverter.js.map +1 -1
- package/sync/handler/converter/BatchWriteCommandConverter.js +6 -14
- package/sync/handler/converter/BatchWriteCommandConverter.js.map +1 -1
- package/sync/handler/converter/DeleteCommandConverter.js +6 -14
- package/sync/handler/converter/DeleteCommandConverter.js.map +1 -1
- package/sync/handler/converter/GetCommandConverter.js +6 -14
- package/sync/handler/converter/GetCommandConverter.js.map +1 -1
- package/sync/handler/converter/PutCommandConverter.js +6 -14
- package/sync/handler/converter/PutCommandConverter.js.map +1 -1
- package/sync/handler/converter/QueryCommandConverter.js +6 -14
- package/sync/handler/converter/QueryCommandConverter.js.map +1 -1
- package/sync/handler/converter/ScanCommandConverter.js +6 -14
- package/sync/handler/converter/ScanCommandConverter.js.map +1 -1
- package/sync/handler/converter/UpdateCommandConverter.js +6 -14
- package/sync/handler/converter/UpdateCommandConverter.js.map +1 -1
- package/sync/handler/converter/commands/BatchWriteCommandValue.d.ts +2 -2
- package/sync/handler/converter/commands/BatchWriteCommandValue.js +4 -11
- package/sync/handler/converter/commands/BatchWriteCommandValue.js.map +1 -1
- package/sync/handler/converter/commands/DeleteCommandValue.d.ts +2 -2
- package/sync/handler/converter/commands/DeleteCommandValue.js +3 -10
- package/sync/handler/converter/commands/DeleteCommandValue.js.map +1 -1
- package/sync/handler/converter/commands/NullCommandValue.d.ts +1 -1
- package/sync/handler/converter/commands/NullCommandValue.js +1 -8
- package/sync/handler/converter/commands/NullCommandValue.js.map +1 -1
- package/sync/handler/converter/commands/PutCommandValue.d.ts +2 -2
- package/sync/handler/converter/commands/PutCommandValue.js +3 -10
- package/sync/handler/converter/commands/PutCommandValue.js.map +1 -1
- package/sync/handler/converter/commands/UpdateCommandValue.d.ts +2 -2
- package/sync/handler/converter/commands/UpdateCommandValue.js +3 -10
- package/sync/handler/converter/commands/UpdateCommandValue.js.map +1 -1
- package/sync/handler/types.d.ts +3 -3
- package/sync/handler/types.js +1 -5
- package/sync/handler/types.js.map +1 -1
- package/sync/plugins/FilterOutRecordPlugin.d.ts +1 -1
- package/sync/plugins/FilterOutRecordPlugin.js +3 -11
- package/sync/plugins/FilterOutRecordPlugin.js.map +1 -1
- package/sync/requestPlugin.d.ts +1 -1
- package/sync/requestPlugin.js +19 -20
- package/sync/requestPlugin.js.map +1 -1
- package/sync/types.js +1 -5
- package/sync/utils/getTableType.js +7 -14
- package/sync/utils/getTableType.js.map +1 -1
- package/sync/utils/manifest.d.ts +1 -1
- package/sync/utils/manifest.js +12 -20
- package/sync/utils/manifest.js.map +1 -1
- package/sync/utils/validateSystemInput.d.ts +1 -1
- package/sync/utils/validateSystemInput.js +3 -10
- package/sync/utils/validateSystemInput.js.map +1 -1
- package/types.d.ts +3 -4
- package/types.js +2 -8
- package/types.js.map +1 -1
- package/utils/createSystemName.js +1 -8
- package/utils/createSystemName.js.map +1 -1
- package/worker/actions/copyFile/CopyFile.js +13 -21
- package/worker/actions/copyFile/CopyFile.js.map +1 -1
- package/worker/actions/copyFile/copyFileAction.d.ts +1 -1
- package/worker/actions/copyFile/copyFileAction.js +9 -16
- package/worker/actions/copyFile/copyFileAction.js.map +1 -1
- package/worker/actions/copyFile/copyFileSchema.js +8 -16
- package/worker/actions/copyFile/copyFileSchema.js.map +1 -1
- package/worker/actions/copyFile/types.js +1 -5
- package/worker/actions/createUser/CreateUser.d.ts +1 -1
- package/worker/actions/createUser/CreateUser.js +9 -16
- package/worker/actions/createUser/CreateUser.js.map +1 -1
- package/worker/actions/createUser/createUserAction.d.ts +2 -2
- package/worker/actions/createUser/createUserAction.js +9 -16
- package/worker/actions/createUser/createUserAction.js.map +1 -1
- package/worker/actions/createUser/createUserSchema.js +8 -16
- package/worker/actions/createUser/createUserSchema.js.map +1 -1
- package/worker/actions/createUser/types.js +1 -5
- package/worker/actions/deleteFile/DeleteFile.js +4 -11
- package/worker/actions/deleteFile/DeleteFile.js.map +1 -1
- package/worker/actions/deleteFile/deleteFileAction.d.ts +1 -1
- package/worker/actions/deleteFile/deleteFileAction.js +9 -16
- package/worker/actions/deleteFile/deleteFileAction.js.map +1 -1
- package/worker/actions/deleteFile/deleteFileSchema.js +8 -16
- package/worker/actions/deleteFile/deleteFileSchema.js.map +1 -1
- package/worker/actions/deleteFile/types.js +1 -5
- package/worker/actions/deleteUser/DeleteUser.d.ts +2 -2
- package/worker/actions/deleteUser/DeleteUser.js +7 -14
- package/worker/actions/deleteUser/DeleteUser.js.map +1 -1
- package/worker/actions/deleteUser/deleteUserAction.d.ts +1 -1
- package/worker/actions/deleteUser/deleteUserAction.js +9 -16
- package/worker/actions/deleteUser/deleteUserAction.js.map +1 -1
- package/worker/actions/deleteUser/deleteUserSchema.js +8 -16
- package/worker/actions/deleteUser/deleteUserSchema.js.map +1 -1
- package/worker/actions/deleteUser/types.js +1 -5
- package/worker/actions/logValidationError.js +4 -11
- package/worker/actions/logValidationError.js.map +1 -1
- package/worker/actions/removeCognitoUserAttributes.js +1 -8
- package/worker/actions/removeCognitoUserAttributes.js.map +1 -1
- package/worker/actions/updateUser/UpdateUser.d.ts +1 -1
- package/worker/actions/updateUser/UpdateUser.js +9 -16
- package/worker/actions/updateUser/UpdateUser.js.map +1 -1
- package/worker/actions/updateUser/types.js +1 -5
- package/worker/actions/updateUser/updateUserAction.d.ts +2 -2
- package/worker/actions/updateUser/updateUserAction.js +9 -16
- package/worker/actions/updateUser/updateUserAction.js.map +1 -1
- package/worker/actions/updateUser/updateUserSchema.js +8 -16
- package/worker/actions/updateUser/updateUserSchema.js.map +1 -1
- package/worker/createWorkerHandler.js +17 -24
- package/worker/createWorkerHandler.js.map +1 -1
- package/worker/handler/WorkerActionHandler.d.ts +2 -2
- package/worker/handler/WorkerActionHandler.js +3 -10
- package/worker/handler/WorkerActionHandler.js.map +1 -1
- package/worker/handler/eventHandler.js +9 -16
- package/worker/handler/eventHandler.js.map +1 -1
- package/worker/plugins/WorkerActionPlugin.d.ts +1 -1
- package/worker/plugins/WorkerActionPlugin.js +3 -11
- package/worker/plugins/WorkerActionPlugin.js.map +1 -1
- package/worker/types.js +1 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["BatchGetCommand","lodashChunk","SourceDataContainer","convertException","createRetry","Fetcher","constructor","params","createDocumentClient","maxRetries","retryDelay","exec","deployment","items","input","table","maxBatchSize","length","create","client","results","execute","records","item","data","find","result","PK","SK","add","source","batches","batch","keys","getKeys","command","RequestItems","name","Keys","unprocessedKeys","runCommand","push","retry","send","Responses","UnprocessedKeys","onFail","ex","console","error","log","JSON","stringify","Map","key","has","set","Array","from","values","createFetcher"],"sources":["Fetcher.ts"],"sourcesContent":["import type { IFetcher, IFetcherExecParams, IFetcherExecResult } from \"./types.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { BatchGetCommand } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport lodashChunk from \"lodash/chunk.js\";\nimport type { IDeployment } from \"~/resolver/deployment/types.js\";\nimport { SourceDataContainer } from \"~/resolver/app/data/SourceDataContainer.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { convertException } from \"@webiny/utils\";\nimport type { IStoreItem } from \"~/resolver/app/storer/types.js\";\nimport type { ITable } from \"~/sync/types.js\";\nimport { createRetry } from \"~/resolver/app/utils/Retry.js\";\n\nexport interface IFetcherParamsCreateDocumentClientCallable {\n (deployment: Pick<IDeployment, \"region\">): Pick<DynamoDBDocument, \"send\">;\n}\n\nexport interface IFetcherParams {\n maxRetries?: number;\n retryDelay?: number;\n createDocumentClient: IFetcherParamsCreateDocumentClientCallable;\n}\n\ninterface IKeys {\n PK: string;\n SK: string;\n}\n\ninterface IFetcherExecuteRunCommandParams {\n command: BatchGetCommand;\n table: string;\n client: Pick<DynamoDBDocument, \"send\">;\n}\n\ninterface IFetcherExecuteRunCommandResult<T = GenericRecord> {\n items: T[];\n unprocessedKeys: IKeys[];\n}\n\ninterface IFetchExecuteExecuteParamsItem {\n PK: string;\n SK: string;\n}\n\ninterface IFetchExecuteExecuteParams {\n maxBatchSize: number;\n client: Pick<DynamoDBDocument, \"send\">;\n table: ITable;\n records: IFetchExecuteExecuteParamsItem[];\n}\n\nexport class Fetcher implements IFetcher {\n private readonly createDocumentClient: IFetcherParamsCreateDocumentClientCallable;\n private readonly maxRetries: number;\n private readonly retryDelay: number;\n\n public constructor(params: IFetcherParams) {\n this.createDocumentClient = params.createDocumentClient;\n this.maxRetries = params.maxRetries || 10;\n this.retryDelay = params.retryDelay || 1000;\n }\n\n public async exec(params: IFetcherExecParams): Promise<IFetcherExecResult> {\n const { deployment, items: input, table, maxBatchSize = 25 } = params;\n if (input.length === 0) {\n return {\n items: SourceDataContainer.create()\n };\n }\n\n const client = this.createDocumentClient(deployment);\n\n const results = await this.execute({\n client,\n table,\n maxBatchSize,\n records: input\n });\n\n const items = SourceDataContainer.create();\n\n for (const item of input) {\n const data = results.find(result => {\n return item.PK === result.PK && item.SK === result.SK;\n });\n items.add(\n {\n PK: item.PK,\n SK: item.SK,\n table,\n source: deployment\n },\n data || null\n );\n }\n\n return {\n items\n };\n }\n\n private async execute<T = IStoreItem>(params: IFetchExecuteExecuteParams) {\n const { client, table, records: items, maxBatchSize } = params;\n const batches = lodashChunk(items, maxBatchSize);\n\n const results: T[] = [];\n for (const batch of batches) {\n let keys = this.getKeys(batch);\n\n while (keys.length > 0) {\n const command = new BatchGetCommand({\n RequestItems: {\n [table.name]: {\n Keys: keys\n }\n }\n });\n const { items, unprocessedKeys } = await this.runCommand<T>({\n command,\n client,\n table: table.name\n });\n\n results.push(...items);\n\n keys = unprocessedKeys;\n }\n }\n return results;\n }\n\n private async runCommand<T = GenericRecord>(\n params: IFetcherExecuteRunCommandParams\n ): Promise<IFetcherExecuteRunCommandResult<T>> {\n const { command, table, client } = params;\n\n const retry = createRetry({\n maxRetries: this.maxRetries,\n retryDelay: this.retryDelay\n });\n\n return await retry.retry(\n async () => {\n const result = await client.send(command);\n\n return {\n items: (result.Responses?.[table] || []) as T[],\n unprocessedKeys: (result.UnprocessedKeys?.[table]?.Keys || []) as IKeys[]\n };\n },\n {\n onFail: ex => {\n console.error(\n `Max retries reached. Could not fetch items from table: ${table}`\n );\n console.log(convertException(ex));\n console.log(JSON.stringify(command));\n }\n }\n );\n }\n\n private getKeys(items: IFetchExecuteExecuteParamsItem[]): IKeys[] {\n const keys = new Map<string, IKeys>();\n\n for (const item of items) {\n const key = `PK:${item.PK}#SK:${item.SK}`;\n if (keys.has(key)) {\n continue;\n }\n keys.set(key, {\n PK: item.PK,\n SK: item.SK\n });\n }\n\n return Array.from(keys.values());\n }\n}\n\nexport const createFetcher = (params: IFetcherParams): IFetcher => {\n return new Fetcher(params);\n};\n"],"mappings":"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","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { IDeployment } from "
|
|
1
|
+
import type { IDeployment } from "../../../resolver/deployment/types.js";
|
|
2
2
|
import type { ITable } from "../../../sync/types.js";
|
|
3
|
-
import type { ISourceDataContainer } from "
|
|
3
|
+
import type { ISourceDataContainer } from "../../../resolver/app/data/types.js";
|
|
4
4
|
export interface IFetcherExecParamsItem {
|
|
5
5
|
PK: string;
|
|
6
6
|
SK: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IIngestor, IIngestorIngestParams, IIngestorResult } from "./types.js";
|
|
2
|
-
import type { IDeployment } from "
|
|
2
|
+
import type { IDeployment } from "../../../resolver/deployment/types.js";
|
|
3
3
|
export interface IIngestorParams {
|
|
4
4
|
createIngestorResult: () => IIngestorResult;
|
|
5
5
|
getSource: (name: string) => IDeployment | null;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createIngestor = exports.Ingestor = void 0;
|
|
7
|
-
class Ingestor {
|
|
1
|
+
export class Ingestor {
|
|
8
2
|
constructor(params) {
|
|
9
3
|
this.createIngestorResult = params.createIngestorResult;
|
|
10
4
|
this.getSource = params.getSource;
|
|
@@ -35,10 +29,8 @@ class Ingestor {
|
|
|
35
29
|
return result;
|
|
36
30
|
}
|
|
37
31
|
}
|
|
38
|
-
|
|
39
|
-
const createIngestor = params => {
|
|
32
|
+
export const createIngestor = params => {
|
|
40
33
|
return new Ingestor(params);
|
|
41
34
|
};
|
|
42
|
-
exports.createIngestor = createIngestor;
|
|
43
35
|
|
|
44
36
|
//# sourceMappingURL=Ingestor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Ingestor","constructor","params","createIngestorResult","getSource","ingest","records","result","record","detail","body","source","name","console","error","log","JSON","stringify","items","item","add","
|
|
1
|
+
{"version":3,"names":["Ingestor","constructor","params","createIngestorResult","getSource","ingest","records","result","record","detail","body","source","name","console","error","log","JSON","stringify","items","item","add","createIngestor"],"sources":["Ingestor.ts"],"sourcesContent":["import type { IIngestor, IIngestorIngestParams, IIngestorResult } from \"./types.js\";\nimport type { IDeployment } from \"~/resolver/deployment/types.js\";\n\nexport interface IIngestorParams {\n createIngestorResult: () => IIngestorResult;\n getSource: (name: string) => IDeployment | null;\n}\n\nexport class Ingestor implements IIngestor {\n private readonly createIngestorResult: () => IIngestorResult;\n private readonly getSource: (name: string) => IDeployment | null;\n\n public constructor(params: IIngestorParams) {\n this.createIngestorResult = params.createIngestorResult;\n this.getSource = params.getSource;\n }\n\n public async ingest(params: IIngestorIngestParams): Promise<IIngestorResult> {\n const { records } = params;\n\n const result = this.createIngestorResult();\n\n for (const record of records) {\n const detail = record.body.detail;\n const source = this.getSource(detail.source.name);\n if (!source) {\n console.error(\n `Could not find deployment for SQS Record source: ${detail.source.name}. More info in next log line.`\n );\n console.log(\n JSON.stringify({\n source: detail.source,\n items: detail.items\n })\n );\n continue;\n }\n\n for (const item of detail.items) {\n result.add({\n item,\n source\n });\n }\n }\n\n return result;\n }\n}\n\nexport const createIngestor = (params: IIngestorParams): IIngestor => {\n return new Ingestor(params);\n};\n"],"mappings":"AAQA,OAAO,MAAMA,QAAQ,CAAsB;EAIhCC,WAAWA,CAACC,MAAuB,EAAE;IACxC,IAAI,CAACC,oBAAoB,GAAGD,MAAM,CAACC,oBAAoB;IACvD,IAAI,CAACC,SAAS,GAAGF,MAAM,CAACE,SAAS;EACrC;EAEA,MAAaC,MAAMA,CAACH,MAA6B,EAA4B;IACzE,MAAM;MAAEI;IAAQ,CAAC,GAAGJ,MAAM;IAE1B,MAAMK,MAAM,GAAG,IAAI,CAACJ,oBAAoB,CAAC,CAAC;IAE1C,KAAK,MAAMK,MAAM,IAAIF,OAAO,EAAE;MAC1B,MAAMG,MAAM,GAAGD,MAAM,CAACE,IAAI,CAACD,MAAM;MACjC,MAAME,MAAM,GAAG,IAAI,CAACP,SAAS,CAACK,MAAM,CAACE,MAAM,CAACC,IAAI,CAAC;MACjD,IAAI,CAACD,MAAM,EAAE;QACTE,OAAO,CAACC,KAAK,CACT,oDAAoDL,MAAM,CAACE,MAAM,CAACC,IAAI,+BAC1E,CAAC;QACDC,OAAO,CAACE,GAAG,CACPC,IAAI,CAACC,SAAS,CAAC;UACXN,MAAM,EAAEF,MAAM,CAACE,MAAM;UACrBO,KAAK,EAAET,MAAM,CAACS;QAClB,CAAC,CACL,CAAC;QACD;MACJ;MAEA,KAAK,MAAMC,IAAI,IAAIV,MAAM,CAACS,KAAK,EAAE;QAC7BX,MAAM,CAACa,GAAG,CAAC;UACPD,IAAI;UACJR;QACJ,CAAC,CAAC;MACN;IACJ;IAEA,OAAOJ,MAAM;EACjB;AACJ;AAEA,OAAO,MAAMc,cAAc,GAAInB,MAAuB,IAAgB;EAClE,OAAO,IAAIF,QAAQ,CAACE,MAAM,CAAC;AAC/B,CAAC","ignoreList":[]}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createIngestorResult = exports.IngestorResult = void 0;
|
|
7
|
-
class IngestorResult {
|
|
1
|
+
export class IngestorResult {
|
|
8
2
|
items = new Map();
|
|
9
3
|
add(params) {
|
|
10
4
|
const {
|
|
@@ -14,7 +8,7 @@ class IngestorResult {
|
|
|
14
8
|
let table;
|
|
15
9
|
try {
|
|
16
10
|
table = source.getTable(item.tableType);
|
|
17
|
-
} catch
|
|
11
|
+
} catch {
|
|
18
12
|
console.error(`Could not find table for SQS Record source: ${item.tableName} / ${item.tableType}. More info in next log line.`);
|
|
19
13
|
console.log(JSON.stringify(item));
|
|
20
14
|
return;
|
|
@@ -36,10 +30,8 @@ class IngestorResult {
|
|
|
36
30
|
return Array.from(this.items.values());
|
|
37
31
|
}
|
|
38
32
|
}
|
|
39
|
-
|
|
40
|
-
const createIngestorResult = () => {
|
|
33
|
+
export const createIngestorResult = () => {
|
|
41
34
|
return new IngestorResult();
|
|
42
35
|
};
|
|
43
|
-
exports.createIngestorResult = createIngestorResult;
|
|
44
36
|
|
|
45
37
|
//# sourceMappingURL=IngestorResult.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["IngestorResult","items","Map","add","params","item","source","table","getTable","tableType","
|
|
1
|
+
{"version":3,"names":["IngestorResult","items","Map","add","params","item","source","table","getTable","tableType","console","error","tableName","log","JSON","stringify","command","key","PK","SK","name","has","set","getItems","Array","from","values","createIngestorResult"],"sources":["IngestorResult.ts"],"sourcesContent":["import type { IIngestorResult, IIngestorResultAddParams, IIngestorResultItem } from \"./types.js\";\nimport type { ITable } from \"~/sync/types.js\";\n\nexport class IngestorResult implements IIngestorResult {\n private readonly items: Map<string, IIngestorResultItem> = new Map();\n\n public add(params: IIngestorResultAddParams): void {\n const { item, source } = params;\n let table: ITable;\n try {\n table = source.getTable(item.tableType);\n } catch {\n console.error(\n `Could not find table for SQS Record source: ${item.tableName} / ${item.tableType}. More info in next log line.`\n );\n console.log(JSON.stringify(item));\n return;\n }\n\n const command = item.command === \"delete\" ? \"delete\" : \"put\";\n\n const key = `PK:${item.PK}#SK:${item.SK}#cmd:${command}#source:${source.name}`;\n\n if (this.items.has(key)) {\n return;\n }\n\n this.items.set(key, {\n PK: item.PK,\n SK: item.SK,\n source,\n command,\n table\n });\n }\n\n public getItems(): IIngestorResultItem[] {\n return Array.from(this.items.values());\n }\n}\n\nexport const createIngestorResult = (): IIngestorResult => {\n return new IngestorResult();\n};\n"],"mappings":"AAGA,OAAO,MAAMA,cAAc,CAA4B;EAClCC,KAAK,GAAqC,IAAIC,GAAG,CAAC,CAAC;EAE7DC,GAAGA,CAACC,MAAgC,EAAQ;IAC/C,MAAM;MAAEC,IAAI;MAAEC;IAAO,CAAC,GAAGF,MAAM;IAC/B,IAAIG,KAAa;IACjB,IAAI;MACAA,KAAK,GAAGD,MAAM,CAACE,QAAQ,CAACH,IAAI,CAACI,SAAS,CAAC;IAC3C,CAAC,CAAC,MAAM;MACJC,OAAO,CAACC,KAAK,CACT,+CAA+CN,IAAI,CAACO,SAAS,MAAMP,IAAI,CAACI,SAAS,+BACrF,CAAC;MACDC,OAAO,CAACG,GAAG,CAACC,IAAI,CAACC,SAAS,CAACV,IAAI,CAAC,CAAC;MACjC;IACJ;IAEA,MAAMW,OAAO,GAAGX,IAAI,CAACW,OAAO,KAAK,QAAQ,GAAG,QAAQ,GAAG,KAAK;IAE5D,MAAMC,GAAG,GAAG,MAAMZ,IAAI,CAACa,EAAE,OAAOb,IAAI,CAACc,EAAE,QAAQH,OAAO,WAAWV,MAAM,CAACc,IAAI,EAAE;IAE9E,IAAI,IAAI,CAACnB,KAAK,CAACoB,GAAG,CAACJ,GAAG,CAAC,EAAE;MACrB;IACJ;IAEA,IAAI,CAAChB,KAAK,CAACqB,GAAG,CAACL,GAAG,EAAE;MAChBC,EAAE,EAAEb,IAAI,CAACa,EAAE;MACXC,EAAE,EAAEd,IAAI,CAACc,EAAE;MACXb,MAAM;MACNU,OAAO;MACPT;IACJ,CAAC,CAAC;EACN;EAEOgB,QAAQA,CAAA,EAA0B;IACrC,OAAOC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACxB,KAAK,CAACyB,MAAM,CAAC,CAAC,CAAC;EAC1C;AACJ;AAEA,OAAO,MAAMC,oBAAoB,GAAGA,CAAA,KAAuB;EACvD,OAAO,IAAI3B,cAAc,CAAC,CAAC;AAC/B,CAAC","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { CommandType } from "../../../types.js";
|
|
2
|
-
import type { IResolverSQSRecord } from "
|
|
2
|
+
import type { IResolverSQSRecord } from "../../../resolver/app/abstractions/ResolverRecord.js";
|
|
3
3
|
import type { IDetailItem } from "../../../sync/handler/types.js";
|
|
4
4
|
import type { ITable } from "../../../sync/types.js";
|
|
5
|
-
import type { IDeployment } from "
|
|
5
|
+
import type { IDeployment } from "../../../resolver/deployment/types.js";
|
|
6
6
|
export interface IIngestorIngestParams {
|
|
7
7
|
records: IResolverSQSRecord[];
|
|
8
8
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { IStoreItem, IStorer, IStorerExecParams } from "./types";
|
|
2
|
-
import type { IDeployment } from "
|
|
1
|
+
import type { IStoreItem, IStorer, IStorerExecParams } from "./types.js";
|
|
2
|
+
import type { IDeployment } from "../../../resolver/deployment/types.js";
|
|
3
3
|
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
4
|
-
import type { CommandType } from "../../../types";
|
|
4
|
+
import type { CommandType } from "../../../types.js";
|
|
5
5
|
import type { ITable } from "../../../sync/types.js";
|
|
6
6
|
export interface IStorerParamsCreateDocumentClientCallable {
|
|
7
7
|
(deployment: Pick<IDeployment, "region">): Pick<DynamoDBDocument, "send">;
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.createStorer = exports.Storer = void 0;
|
|
7
|
-
var _index = require("@webiny/aws-sdk/client-dynamodb/index.js");
|
|
8
|
-
var _Retry = require("../utils/Retry");
|
|
9
|
-
var _utils = require("@webiny/utils");
|
|
10
|
-
class Storer {
|
|
1
|
+
import { DeleteCommand, PutCommand } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
import { createRetry } from "../utils/Retry.js";
|
|
3
|
+
import { convertException } from "@webiny/utils";
|
|
4
|
+
export class Storer {
|
|
11
5
|
constructor(params) {
|
|
12
6
|
this.maxRetries = params.maxRetries || 10;
|
|
13
7
|
this.retryDelay = params.retryDelay || 1000;
|
|
@@ -29,7 +23,7 @@ class Storer {
|
|
|
29
23
|
const client = this.createDocumentClient({
|
|
30
24
|
region: deployment.region
|
|
31
25
|
});
|
|
32
|
-
const retry =
|
|
26
|
+
const retry = createRetry({
|
|
33
27
|
maxRetries: this.maxRetries,
|
|
34
28
|
retryDelay: this.retryDelay
|
|
35
29
|
});
|
|
@@ -37,7 +31,7 @@ class Storer {
|
|
|
37
31
|
const result = await retry.retry(async () => {
|
|
38
32
|
switch (command) {
|
|
39
33
|
case "delete":
|
|
40
|
-
return await client.send(new
|
|
34
|
+
return await client.send(new DeleteCommand({
|
|
41
35
|
TableName: table.name,
|
|
42
36
|
Key: {
|
|
43
37
|
PK: item.PK,
|
|
@@ -45,7 +39,7 @@ class Storer {
|
|
|
45
39
|
}
|
|
46
40
|
}));
|
|
47
41
|
case "put":
|
|
48
|
-
return await client.send(new
|
|
42
|
+
return await client.send(new PutCommand({
|
|
49
43
|
TableName: table.name,
|
|
50
44
|
Item: item
|
|
51
45
|
}));
|
|
@@ -56,7 +50,7 @@ class Storer {
|
|
|
56
50
|
}, {
|
|
57
51
|
onFail: async error => {
|
|
58
52
|
console.error("Error executing batch write command.");
|
|
59
|
-
console.log(
|
|
53
|
+
console.log(convertException(error));
|
|
60
54
|
if (!this.onError) {
|
|
61
55
|
return;
|
|
62
56
|
}
|
|
@@ -70,8 +64,8 @@ class Storer {
|
|
|
70
64
|
} catch (ex) {
|
|
71
65
|
console.error(`Error in onError callback for command: ${command}`);
|
|
72
66
|
console.log({
|
|
73
|
-
original:
|
|
74
|
-
error:
|
|
67
|
+
original: convertException(error),
|
|
68
|
+
error: convertException(ex)
|
|
75
69
|
});
|
|
76
70
|
}
|
|
77
71
|
}
|
|
@@ -89,15 +83,13 @@ class Storer {
|
|
|
89
83
|
});
|
|
90
84
|
} catch (ex) {
|
|
91
85
|
console.error(`Error in afterEach callback for command: ${command}`);
|
|
92
|
-
console.log(
|
|
86
|
+
console.log(convertException(ex));
|
|
93
87
|
}
|
|
94
88
|
}
|
|
95
89
|
}
|
|
96
90
|
}
|
|
97
|
-
|
|
98
|
-
const createStorer = params => {
|
|
91
|
+
export const createStorer = params => {
|
|
99
92
|
return new Storer(params);
|
|
100
93
|
};
|
|
101
|
-
exports.createStorer = createStorer;
|
|
102
94
|
|
|
103
95
|
//# sourceMappingURL=Storer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["DeleteCommand","PutCommand","createRetry","convertException","Storer","constructor","params","maxRetries","retryDelay","createDocumentClient","afterEach","onError","store","deployment","bundle","table","command","items","length","client","region","retry","item","result","send","TableName","name","Key","PK","SK","Item","console","error","onFail","log","ex","original","source","target","createStorer"],"sources":["Storer.ts"],"sourcesContent":["import type { IStoreItem, IStorer, IStorerExecParams } from \"./types.js\";\nimport type { IDeployment } from \"~/resolver/deployment/types.js\";\nimport type {\n DeleteCommandOutput,\n DynamoDBDocument,\n PutCommandOutput\n} from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { DeleteCommand, PutCommand } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { CommandType } from \"~/types.js\";\nimport type { ITable } from \"~/sync/types.js\";\nimport { createRetry } from \"../utils/Retry.js\";\nimport { convertException } from \"@webiny/utils\";\n\nexport interface IStorerParamsCreateDocumentClientCallable {\n (deployment: Pick<IDeployment, \"region\">): Pick<DynamoDBDocument, \"send\">;\n}\n\nexport interface IStorerOnErrorParams {\n command: CommandType;\n item: IStoreItem;\n table: ITable;\n error: Error;\n}\n\nexport interface IStorerOnErrorCb {\n (params: IStorerOnErrorParams): Promise<void>;\n}\n\nexport interface ISingleStorerAfterEachParams {\n command: CommandType;\n target: IDeployment;\n source: IDeployment;\n table: ITable;\n item: IStoreItem;\n}\n\nexport interface IStorerAfterEachCb {\n (params: ISingleStorerAfterEachParams): Promise<void>;\n}\n\nexport interface IStorerParams {\n maxRetries?: number;\n retryDelay?: number;\n createDocumentClient: IStorerParamsCreateDocumentClientCallable;\n onError?: IStorerOnErrorCb;\n afterEach?: IStorerAfterEachCb;\n}\n\nexport class Storer implements IStorer {\n private readonly maxRetries: number;\n private readonly retryDelay: number;\n private readonly createDocumentClient: IStorerParamsCreateDocumentClientCallable;\n private readonly afterEach?: IStorerAfterEachCb;\n private readonly onError?: IStorerOnErrorCb;\n\n public constructor(params: IStorerParams) {\n this.maxRetries = params.maxRetries || 10;\n this.retryDelay = params.retryDelay || 1000;\n this.createDocumentClient = params.createDocumentClient;\n this.afterEach = params.afterEach;\n this.onError = params.onError;\n }\n\n public async store(params: IStorerExecParams): Promise<void> {\n const { deployment, bundle, table, command, items } = params;\n if (items.length === 0) {\n return;\n }\n const client = this.createDocumentClient({\n region: deployment.region\n });\n\n const retry = createRetry({\n maxRetries: this.maxRetries,\n retryDelay: this.retryDelay\n });\n\n for (const item of items) {\n const result = await retry.retry(\n async (): Promise<DeleteCommandOutput | PutCommandOutput | null> => {\n switch (command) {\n case \"delete\":\n return await client.send(\n new DeleteCommand({\n TableName: table.name,\n Key: {\n PK: item.PK,\n SK: item.SK\n }\n })\n );\n case \"put\":\n return await client.send(\n new PutCommand({\n TableName: table.name,\n Item: item\n })\n );\n\n default:\n console.error(`Unsupported command type: ${command}`);\n return null;\n }\n },\n {\n onFail: async error => {\n console.error(\"Error executing batch write command.\");\n console.log(convertException(error));\n if (!this.onError) {\n return;\n }\n try {\n await this.onError({\n item,\n command,\n table,\n error\n });\n } catch (ex) {\n console.error(`Error in onError callback for command: ${command}`);\n console.log({\n original: convertException(error),\n error: convertException(ex)\n });\n }\n }\n }\n );\n if (!result || !this.afterEach) {\n continue;\n }\n try {\n await this.afterEach({\n table,\n command,\n item,\n source: bundle.source,\n target: deployment\n });\n } catch (ex) {\n console.error(`Error in afterEach callback for command: ${command}`);\n console.log(convertException(ex));\n }\n }\n }\n}\n\nexport const createStorer = (params: IStorerParams): IStorer => {\n return new Storer(params);\n};\n"],"mappings":"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","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { IDeployment } from "
|
|
1
|
+
import type { IDeployment } from "../../../resolver/deployment/types.js";
|
|
2
2
|
import type { ITable } from "../../../sync/types.js";
|
|
3
3
|
import type { CommandType } from "../../../types.js";
|
|
4
4
|
import type { GenericRecord } from "@webiny/api/types.js";
|
|
5
|
-
import type { IBundle } from "../bundler/types";
|
|
5
|
+
import type { IBundle } from "../bundler/types.js";
|
|
6
6
|
export type StoreItemPossibleValues = string | number | boolean | undefined | null | GenericRecord | StoreItemPossibleValues[];
|
|
7
7
|
export interface IStoreItem {
|
|
8
8
|
PK: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { IDeployment } from \"~/resolver/deployment/types.js\";\nimport type { ITable } from \"~/sync/types.js\";\nimport type { CommandType } from \"~/types.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { IBundle } from \"../bundler/types\";\n\nexport type StoreItemPossibleValues =\n | string\n | number\n | boolean\n | undefined\n | null\n | GenericRecord\n | StoreItemPossibleValues[];\n\nexport interface IStoreItem {\n PK: string;\n SK: string;\n [key: string]: StoreItemPossibleValues;\n}\n\nexport interface IStorerExecParams {\n deployment: IDeployment;\n bundle: IBundle;\n command: CommandType;\n table: ITable;\n items: IStoreItem[];\n}\n\nexport interface IStorer {\n store(params: IStorerExecParams): Promise<void>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { IDeployment } from \"~/resolver/deployment/types.js\";\nimport type { ITable } from \"~/sync/types.js\";\nimport type { CommandType } from \"~/types.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { IBundle } from \"../bundler/types.js\";\n\nexport type StoreItemPossibleValues =\n | string\n | number\n | boolean\n | undefined\n | null\n | GenericRecord\n | StoreItemPossibleValues[];\n\nexport interface IStoreItem {\n PK: string;\n SK: string;\n [key: string]: StoreItemPossibleValues;\n}\n\nexport interface IStorerExecParams {\n deployment: IDeployment;\n bundle: IBundle;\n command: CommandType;\n table: ITable;\n items: IStoreItem[];\n}\n\nexport interface IStorer {\n store(params: IStorerExecParams): Promise<void>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ITable } from "../../../sync/types";
|
|
2
|
-
import type { IDeployment } from "
|
|
3
|
-
import type { PluginsContainer } from "@webiny/plugins/types";
|
|
4
|
-
import type { IStoreItem } from "../storer/types";
|
|
1
|
+
import type { ITable } from "../../../sync/types.js";
|
|
2
|
+
import type { IDeployment } from "../../../resolver/deployment/types.js";
|
|
3
|
+
import type { PluginsContainer } from "@webiny/plugins/types.js";
|
|
4
|
+
import type { IStoreItem } from "../storer/types.js";
|
|
5
5
|
export interface IMiddlewareParams {
|
|
6
6
|
readonly plugins: PluginsContainer;
|
|
7
7
|
readonly record: IStoreItem;
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.TransformHandler = void 0;
|
|
7
|
-
var _TransformRecordPlugin = require("../../plugins/TransformRecordPlugin.js");
|
|
8
|
-
var _middleware = require("./middleware.js");
|
|
9
|
-
class TransformHandler {
|
|
1
|
+
import { TransformRecordPlugin } from "../../plugins/TransformRecordPlugin.js";
|
|
2
|
+
import { middleware } from "./middleware.js";
|
|
3
|
+
export class TransformHandler {
|
|
10
4
|
constructor(params) {
|
|
11
5
|
this.pluginsContainer = params.plugins;
|
|
12
|
-
this.plugins = params.plugins.byType(
|
|
6
|
+
this.plugins = params.plugins.byType(TransformRecordPlugin.type);
|
|
13
7
|
}
|
|
14
8
|
async transform(params) {
|
|
15
9
|
const {
|
|
@@ -44,7 +38,7 @@ class TransformHandler {
|
|
|
44
38
|
items
|
|
45
39
|
};
|
|
46
40
|
}
|
|
47
|
-
const runner =
|
|
41
|
+
const runner = middleware(plugins.map(plugin => {
|
|
48
42
|
return async (params, next) => {
|
|
49
43
|
return await plugin.transform(params, next);
|
|
50
44
|
};
|
|
@@ -65,6 +59,5 @@ class TransformHandler {
|
|
|
65
59
|
};
|
|
66
60
|
}
|
|
67
61
|
}
|
|
68
|
-
exports.TransformHandler = TransformHandler;
|
|
69
62
|
|
|
70
63
|
//# sourceMappingURL=TransformHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["TransformRecordPlugin","middleware","TransformHandler","constructor","params","pluginsContainer","plugins","byType","type","transform","sourceTable","sourceDeployment","targetDeployment","targetTable","items","length","process","env","DEBUG","console","log","filter","plugin","isForTableType","canTransform","from","to","sourceVersion","version","format","targetVersion","runner","map","next","results","Promise","all","input","record","Object","freeze","item"],"sources":["TransformHandler.ts"],"sourcesContent":["import type { ITable } from \"~/sync/types.js\";\nimport type { IDeployment } from \"~/resolver/deployment/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins/types.js\";\nimport { TransformRecordPlugin } from \"~/resolver/plugins/TransformRecordPlugin.js\";\nimport { middleware } from \"./middleware.js\";\nimport type { IStoreItem } from \"../storer/types.js\";\n\nexport interface IMiddlewareParams {\n readonly plugins: PluginsContainer;\n readonly record: IStoreItem;\n readonly sourceDeployment: IDeployment;\n readonly targetDeployment: IDeployment;\n readonly sourceTable: ITable;\n readonly targetTable: ITable;\n}\n\nexport interface ITransformHandlerTransformParams {\n readonly sourceTable: ITable;\n readonly sourceDeployment: IDeployment;\n readonly targetTable: ITable;\n readonly targetDeployment: IDeployment;\n readonly items: IStoreItem[];\n}\n\nexport interface ITransformHandlerTransformResult {\n items: IStoreItem[];\n}\n\nexport interface ITransformHandler {\n transform(params: ITransformHandlerTransformParams): Promise<ITransformHandlerTransformResult>;\n}\n\nexport interface ITransformHandlerParams {\n readonly plugins: PluginsContainer;\n}\n\nexport class TransformHandler implements ITransformHandler {\n private readonly pluginsContainer: PluginsContainer;\n private readonly plugins: TransformRecordPlugin[];\n\n public constructor(params: ITransformHandlerParams) {\n this.pluginsContainer = params.plugins;\n this.plugins = params.plugins.byType<TransformRecordPlugin>(TransformRecordPlugin.type);\n }\n\n public async transform(\n params: ITransformHandlerTransformParams\n ): Promise<ITransformHandlerTransformResult> {\n const { sourceTable, sourceDeployment, targetDeployment, targetTable, items } = params;\n\n if (this.plugins.length === 0) {\n process.env.DEBUG === \"true\" &&\n console.log(\"There are no transform plugins registered in the system.\");\n return {\n items\n };\n }\n\n const plugins = this.plugins.filter(plugin => {\n if (plugin.isForTableType(sourceTable.type) === false) {\n return false;\n }\n return plugin.canTransform({\n from: sourceDeployment,\n to: targetDeployment\n });\n });\n\n if (plugins.length === 0) {\n process.env.DEBUG === \"true\" &&\n console.log(\n \"There are no transform plugins registered for the given deployment versions or sourceTable type.\",\n {\n sourceVersion: sourceDeployment.version.format(),\n targetVersion: targetDeployment.version.format(),\n sourceTable\n }\n );\n return {\n items\n };\n }\n\n const runner = middleware<IMiddlewareParams, IStoreItem>(\n plugins.map(plugin => {\n return async (params, next) => {\n return await plugin.transform(params, next);\n };\n })\n );\n\n const results = await Promise.all(\n items.map(async input => {\n const record = Object.freeze(input);\n return await runner(\n {\n plugins: this.pluginsContainer,\n sourceTable,\n sourceDeployment,\n targetDeployment,\n targetTable,\n record\n },\n record\n );\n })\n );\n return {\n items: results.filter((item): item is IStoreItem => !!item)\n };\n }\n}\n"],"mappings":"AAGA,SAASA,qBAAqB;AAC9B,SAASC,UAAU;AAgCnB,OAAO,MAAMC,gBAAgB,CAA8B;EAIhDC,WAAWA,CAACC,MAA+B,EAAE;IAChD,IAAI,CAACC,gBAAgB,GAAGD,MAAM,CAACE,OAAO;IACtC,IAAI,CAACA,OAAO,GAAGF,MAAM,CAACE,OAAO,CAACC,MAAM,CAAwBP,qBAAqB,CAACQ,IAAI,CAAC;EAC3F;EAEA,MAAaC,SAASA,CAClBL,MAAwC,EACC;IACzC,MAAM;MAAEM,WAAW;MAAEC,gBAAgB;MAAEC,gBAAgB;MAAEC,WAAW;MAAEC;IAAM,CAAC,GAAGV,MAAM;IAEtF,IAAI,IAAI,CAACE,OAAO,CAACS,MAAM,KAAK,CAAC,EAAE;MAC3BC,OAAO,CAACC,GAAG,CAACC,KAAK,KAAK,MAAM,IACxBC,OAAO,CAACC,GAAG,CAAC,0DAA0D,CAAC;MAC3E,OAAO;QACHN;MACJ,CAAC;IACL;IAEA,MAAMR,OAAO,GAAG,IAAI,CAACA,OAAO,CAACe,MAAM,CAACC,MAAM,IAAI;MAC1C,IAAIA,MAAM,CAACC,cAAc,CAACb,WAAW,CAACF,IAAI,CAAC,KAAK,KAAK,EAAE;QACnD,OAAO,KAAK;MAChB;MACA,OAAOc,MAAM,CAACE,YAAY,CAAC;QACvBC,IAAI,EAAEd,gBAAgB;QACtBe,EAAE,EAAEd;MACR,CAAC,CAAC;IACN,CAAC,CAAC;IAEF,IAAIN,OAAO,CAACS,MAAM,KAAK,CAAC,EAAE;MACtBC,OAAO,CAACC,GAAG,CAACC,KAAK,KAAK,MAAM,IACxBC,OAAO,CAACC,GAAG,CACP,kGAAkG,EAClG;QACIO,aAAa,EAAEhB,gBAAgB,CAACiB,OAAO,CAACC,MAAM,CAAC,CAAC;QAChDC,aAAa,EAAElB,gBAAgB,CAACgB,OAAO,CAACC,MAAM,CAAC,CAAC;QAChDnB;MACJ,CACJ,CAAC;MACL,OAAO;QACHI;MACJ,CAAC;IACL;IAEA,MAAMiB,MAAM,GAAG9B,UAAU,CACrBK,OAAO,CAAC0B,GAAG,CAACV,MAAM,IAAI;MAClB,OAAO,OAAOlB,MAAM,EAAE6B,IAAI,KAAK;QAC3B,OAAO,MAAMX,MAAM,CAACb,SAAS,CAACL,MAAM,EAAE6B,IAAI,CAAC;MAC/C,CAAC;IACL,CAAC,CACL,CAAC;IAED,MAAMC,OAAO,GAAG,MAAMC,OAAO,CAACC,GAAG,CAC7BtB,KAAK,CAACkB,GAAG,CAAC,MAAMK,KAAK,IAAI;MACrB,MAAMC,MAAM,GAAGC,MAAM,CAACC,MAAM,CAACH,KAAK,CAAC;MACnC,OAAO,MAAMN,MAAM,CACf;QACIzB,OAAO,EAAE,IAAI,CAACD,gBAAgB;QAC9BK,WAAW;QACXC,gBAAgB;QAChBC,gBAAgB;QAChBC,WAAW;QACXyB;MACJ,CAAC,EACDA,MACJ,CAAC;IACL,CAAC,CACL,CAAC;IACD,OAAO;MACHxB,KAAK,EAAEoB,OAAO,CAACb,MAAM,CAAEoB,IAAI,IAAyB,CAAC,CAACA,IAAI;IAC9D,CAAC;EACL;AACJ","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { GenericRecord } from "@webiny/api/types";
|
|
1
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
2
2
|
export type Middleware<Input, Output> = (input: Input, next: () => Promise<Output>) => Promise<Output>;
|
|
3
3
|
export declare function middleware<Input = GenericRecord, Output = GenericRecord>(middlewares: Middleware<Input, Output>[]): (input: Input, defaultValue: Output) => Promise<Output>;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.middleware = middleware;
|
|
7
|
-
function middleware(middlewares) {
|
|
1
|
+
export function middleware(middlewares) {
|
|
8
2
|
return async function runner(input, defaultValue) {
|
|
9
3
|
let current = -1;
|
|
10
4
|
async function dispatch(index) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["middleware","middlewares","runner","input","defaultValue","current","dispatch","index","Error","fn"],"sources":["middleware.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types\";\n\nexport type Middleware<Input, Output> = (\n input: Input,\n next: () => Promise<Output>\n) => Promise<Output>;\n\nexport function middleware<Input = GenericRecord, Output = GenericRecord>(\n middlewares: Middleware<Input, Output>[]\n) {\n return async function runner(input: Input, defaultValue: Output): Promise<Output> {\n let current = -1;\n\n async function dispatch(index: number): Promise<Output> {\n /**\n * Should not be possible to run next multiple times.\n * Or do we want to allow it? What are possible downsides except something being done multiple times?\n */\n if (index <= current) {\n throw new Error(\"next() called multiple times\");\n }\n current = index;\n\n const fn = middlewares[index];\n if (!fn) {\n return defaultValue;\n }\n\n return fn(input, () => dispatch(index + 1));\n }\n\n return dispatch(0);\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["middleware","middlewares","runner","input","defaultValue","current","dispatch","index","Error","fn"],"sources":["middleware.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport type Middleware<Input, Output> = (\n input: Input,\n next: () => Promise<Output>\n) => Promise<Output>;\n\nexport function middleware<Input = GenericRecord, Output = GenericRecord>(\n middlewares: Middleware<Input, Output>[]\n) {\n return async function runner(input: Input, defaultValue: Output): Promise<Output> {\n let current = -1;\n\n async function dispatch(index: number): Promise<Output> {\n /**\n * Should not be possible to run next multiple times.\n * Or do we want to allow it? What are possible downsides except something being done multiple times?\n */\n if (index <= current) {\n throw new Error(\"next() called multiple times\");\n }\n current = index;\n\n const fn = middlewares[index];\n if (!fn) {\n return defaultValue;\n }\n\n return fn(input, () => dispatch(index + 1));\n }\n\n return dispatch(0);\n };\n}\n"],"mappings":"AAOA,OAAO,SAASA,UAAUA,CACtBC,WAAwC,EAC1C;EACE,OAAO,eAAeC,MAAMA,CAACC,KAAY,EAAEC,YAAoB,EAAmB;IAC9E,IAAIC,OAAO,GAAG,CAAC,CAAC;IAEhB,eAAeC,QAAQA,CAACC,KAAa,EAAmB;MACpD;AACZ;AACA;AACA;MACY,IAAIA,KAAK,IAAIF,OAAO,EAAE;QAClB,MAAM,IAAIG,KAAK,CAAC,8BAA8B,CAAC;MACnD;MACAH,OAAO,GAAGE,KAAK;MAEf,MAAME,EAAE,GAAGR,WAAW,CAACM,KAAK,CAAC;MAC7B,IAAI,CAACE,EAAE,EAAE;QACL,OAAOL,YAAY;MACvB;MAEA,OAAOK,EAAE,CAACN,KAAK,EAAE,MAAMG,QAAQ,CAACC,KAAK,GAAG,CAAC,CAAC,CAAC;IAC/C;IAEA,OAAOD,QAAQ,CAAC,CAAC,CAAC;EACtB,CAAC;AACL","ignoreList":[]}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createRetry = exports.Retry = void 0;
|
|
7
|
-
var _sleep = require("./sleep");
|
|
8
|
-
class Retry {
|
|
1
|
+
import { sleep } from "./sleep.js";
|
|
2
|
+
export class Retry {
|
|
9
3
|
retryCount = 0;
|
|
10
4
|
constructor(params) {
|
|
11
5
|
this.maxRetries = params.maxRetries;
|
|
@@ -23,16 +17,14 @@ class Retry {
|
|
|
23
17
|
}
|
|
24
18
|
}
|
|
25
19
|
this.retryCount++;
|
|
26
|
-
await
|
|
20
|
+
await sleep(this.retryDelay);
|
|
27
21
|
const result = await this.retry(fn, options);
|
|
28
22
|
this.retryCount = 0;
|
|
29
23
|
return result;
|
|
30
24
|
}
|
|
31
25
|
}
|
|
32
|
-
|
|
33
|
-
const createRetry = params => {
|
|
26
|
+
export const createRetry = params => {
|
|
34
27
|
return new Retry(params);
|
|
35
28
|
};
|
|
36
|
-
exports.createRetry = createRetry;
|
|
37
29
|
|
|
38
30
|
//# sourceMappingURL=Retry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["sleep","Retry","retryCount","constructor","params","maxRetries","retryDelay","retry","fn","options","ex","onFail","result","createRetry"],"sources":["Retry.ts"],"sourcesContent":["import { sleep } from \"./sleep.js\";\n\nexport interface IRetryableRetryOptions {\n onFail?: (error: Error) => Promise<void> | void;\n}\n\nexport interface IRetryable {\n retry<T>(fn: () => Promise<T>, options: IRetryableRetryOptions): Promise<T>;\n}\n\nexport interface IRetryParams {\n maxRetries: number;\n retryDelay: number;\n}\n\nexport class Retry implements IRetryable {\n private readonly maxRetries: number;\n private readonly retryDelay: number;\n private retryCount: number = 0;\n\n public constructor(params: IRetryParams) {\n this.maxRetries = params.maxRetries;\n this.retryDelay = params.retryDelay;\n }\n\n public async retry<T>(fn: () => Promise<T>, options?: IRetryableRetryOptions): Promise<T> {\n try {\n return await fn();\n } catch (ex) {\n if (this.retryCount >= this.maxRetries) {\n if (options?.onFail) {\n await options.onFail(ex as Error);\n }\n throw ex;\n }\n }\n this.retryCount++;\n await sleep(this.retryDelay);\n const result = await this.retry<T>(fn, options);\n this.retryCount = 0;\n return result;\n }\n}\n\nexport const createRetry = (params: IRetryParams): IRetryable => {\n return new Retry(params);\n};\n"],"mappings":"AAAA,SAASA,KAAK;AAed,OAAO,MAAMC,KAAK,CAAuB;EAG7BC,UAAU,GAAW,CAAC;EAEvBC,WAAWA,CAACC,MAAoB,EAAE;IACrC,IAAI,CAACC,UAAU,GAAGD,MAAM,CAACC,UAAU;IACnC,IAAI,CAACC,UAAU,GAAGF,MAAM,CAACE,UAAU;EACvC;EAEA,MAAaC,KAAKA,CAAIC,EAAoB,EAAEC,OAAgC,EAAc;IACtF,IAAI;MACA,OAAO,MAAMD,EAAE,CAAC,CAAC;IACrB,CAAC,CAAC,OAAOE,EAAE,EAAE;MACT,IAAI,IAAI,CAACR,UAAU,IAAI,IAAI,CAACG,UAAU,EAAE;QACpC,IAAII,OAAO,EAAEE,MAAM,EAAE;UACjB,MAAMF,OAAO,CAACE,MAAM,CAACD,EAAW,CAAC;QACrC;QACA,MAAMA,EAAE;MACZ;IACJ;IACA,IAAI,CAACR,UAAU,EAAE;IACjB,MAAMF,KAAK,CAAC,IAAI,CAACM,UAAU,CAAC;IAC5B,MAAMM,MAAM,GAAG,MAAM,IAAI,CAACL,KAAK,CAAIC,EAAE,EAAEC,OAAO,CAAC;IAC/C,IAAI,CAACP,UAAU,GAAG,CAAC;IACnB,OAAOU,MAAM;EACjB;AACJ;AAEA,OAAO,MAAMC,WAAW,GAAIT,MAAoB,IAAiB;EAC7D,OAAO,IAAIH,KAAK,CAACG,MAAM,CAAC;AAC5B,CAAC","ignoreList":[]}
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.sleep = void 0;
|
|
7
|
-
const sleep = ms => {
|
|
1
|
+
export const sleep = ms => {
|
|
8
2
|
return new Promise(resolve => {
|
|
9
3
|
setTimeout(resolve, ms);
|
|
10
4
|
});
|
|
11
5
|
};
|
|
12
|
-
exports.sleep = sleep;
|
|
13
6
|
|
|
14
7
|
//# sourceMappingURL=sleep.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["sleep","ms","Promise","resolve","setTimeout"
|
|
1
|
+
{"version":3,"names":["sleep","ms","Promise","resolve","setTimeout"],"sources":["sleep.ts"],"sourcesContent":["export const sleep = (ms: number) => {\n return new Promise<void>(resolve => {\n setTimeout(resolve, ms);\n });\n};\n"],"mappings":"AAAA,OAAO,MAAMA,KAAK,GAAIC,EAAU,IAAK;EACjC,OAAO,IAAIC,OAAO,CAAOC,OAAO,IAAI;IAChCC,UAAU,CAACD,OAAO,EAAEF,EAAE,CAAC;EAC3B,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|