@webiny/api-elasticsearch-tasks 6.3.0-beta.4 → 6.4.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/abstractions/DbRegistry.js +2 -1
- package/abstractions/DbRegistry.js.map +1 -1
- package/abstractions/OpensearchTenantIndexFactory.js +2 -1
- package/abstractions/OpensearchTenantIndexFactory.js.map +1 -1
- package/abstractions/SynchronizationContext.js +2 -1
- package/abstractions/SynchronizationContext.js.map +1 -1
- package/errors/IndexSettingsGetError.js +10 -9
- package/errors/IndexSettingsGetError.js.map +1 -1
- package/errors/IndexSettingsSetError.js +10 -9
- package/errors/IndexSettingsSetError.js.map +1 -1
- package/errors/IndexingDisableError.js +3 -1
- package/errors/IndexingDisableError.js.map +1 -1
- package/errors/IndexingEnableError.js +3 -1
- package/errors/IndexingEnableError.js.map +1 -1
- package/errors/index.js +0 -2
- package/helpers/getClients.js +9 -10
- package/helpers/getClients.js.map +1 -1
- package/helpers/scan.js +12 -14
- package/helpers/scan.js.map +1 -1
- package/index.js +14 -11
- package/index.js.map +1 -1
- package/package.json +22 -22
- package/settings/DisableIndexing.js +16 -15
- package/settings/DisableIndexing.js.map +1 -1
- package/settings/EnableIndexing.js +16 -15
- package/settings/EnableIndexing.js.map +1 -1
- package/settings/IndexManager.js +67 -79
- package/settings/IndexManager.js.map +1 -1
- package/settings/IndexSettingsManager.js +31 -30
- package/settings/IndexSettingsManager.js.map +1 -1
- package/settings/index.js +0 -2
- package/settings/types.js +0 -3
- package/tasks/Manager.js +23 -24
- package/tasks/Manager.js.map +1 -1
- package/tasks/createIndexes/CreateIndexesTask.js +33 -48
- package/tasks/createIndexes/CreateIndexesTask.js.map +1 -1
- package/tasks/createIndexes/CreateIndexesTaskRunner.js +45 -61
- package/tasks/createIndexes/CreateIndexesTaskRunner.js.map +1 -1
- package/tasks/createIndexes/OnBeforeTrigger.js +28 -41
- package/tasks/createIndexes/OnBeforeTrigger.js.map +1 -1
- package/tasks/createIndexes/createIndex.js +12 -17
- package/tasks/createIndexes/createIndex.js.map +1 -1
- package/tasks/createIndexes/index.js +9 -12
- package/tasks/createIndexes/index.js.map +1 -1
- package/tasks/createIndexes/listIndexes.js +10 -16
- package/tasks/createIndexes/listIndexes.js.map +1 -1
- package/tasks/createIndexes/types.js +0 -3
- package/tasks/dataSynchronization/DataSynchronizationTask.js +52 -64
- package/tasks/dataSynchronization/DataSynchronizationTask.js.map +1 -1
- package/tasks/dataSynchronization/DataSynchronizationTaskRunner.js +31 -39
- package/tasks/dataSynchronization/DataSynchronizationTaskRunner.js.map +1 -1
- package/tasks/dataSynchronization/createFactories.js +4 -7
- package/tasks/dataSynchronization/createFactories.js.map +1 -1
- package/tasks/dataSynchronization/elasticsearch/ElasticsearchFetcher.js +65 -89
- package/tasks/dataSynchronization/elasticsearch/ElasticsearchFetcher.js.map +1 -1
- package/tasks/dataSynchronization/elasticsearch/ElasticsearchSynchronize.js +49 -62
- package/tasks/dataSynchronization/elasticsearch/ElasticsearchSynchronize.js.map +1 -1
- package/tasks/dataSynchronization/elasticsearch/ElasticsearchToDynamoDbSynchronization.js +50 -62
- package/tasks/dataSynchronization/elasticsearch/ElasticsearchToDynamoDbSynchronization.js.map +1 -1
- package/tasks/dataSynchronization/elasticsearch/abstractions/ElasticsearchFetcher.js +0 -3
- package/tasks/dataSynchronization/elasticsearch/abstractions/ElasticsearchSynchronize.js +0 -3
- package/tasks/dataSynchronization/elasticsearch/shouldIgnoreEsResponseError.js +7 -4
- package/tasks/dataSynchronization/elasticsearch/shouldIgnoreEsResponseError.js.map +1 -1
- package/tasks/dataSynchronization/entities/getElasticsearchEntity.js +14 -20
- package/tasks/dataSynchronization/entities/getElasticsearchEntity.js.map +1 -1
- package/tasks/dataSynchronization/entities/getElasticsearchEntityType.js +7 -8
- package/tasks/dataSynchronization/entities/getElasticsearchEntityType.js.map +1 -1
- package/tasks/dataSynchronization/entities/getTable.js +13 -19
- package/tasks/dataSynchronization/entities/getTable.js.map +1 -1
- package/tasks/dataSynchronization/entities/index.js +0 -2
- package/tasks/dataSynchronization/index.js +15 -18
- package/tasks/dataSynchronization/index.js.map +1 -1
- package/tasks/dataSynchronization/types.js +0 -3
- package/tasks/enableIndexing/EnableIndexingTaskRunner.js +27 -35
- package/tasks/enableIndexing/EnableIndexingTaskRunner.js.map +1 -1
- package/tasks/enableIndexing/index.js +23 -33
- package/tasks/enableIndexing/index.js.map +1 -1
- package/tasks/enableIndexing/types.js +0 -3
- package/tasks/index.js +0 -2
- package/tasks/reindexing/ReindexingTaskRunner.js +75 -119
- package/tasks/reindexing/ReindexingTaskRunner.js.map +1 -1
- package/tasks/reindexing/index.js +0 -2
- package/tasks/reindexing/reindexingTaskDefinition.js +25 -40
- package/tasks/reindexing/reindexingTaskDefinition.js.map +1 -1
- package/types.js +0 -3
- package/errors/index.js.map +0 -1
- package/settings/index.js.map +0 -1
- package/settings/types.js.map +0 -1
- package/tasks/createIndexes/types.js.map +0 -1
- package/tasks/dataSynchronization/elasticsearch/abstractions/ElasticsearchFetcher.js.map +0 -1
- package/tasks/dataSynchronization/elasticsearch/abstractions/ElasticsearchSynchronize.js.map +0 -1
- package/tasks/dataSynchronization/entities/index.js.map +0 -1
- package/tasks/dataSynchronization/types.js.map +0 -1
- package/tasks/enableIndexing/types.js.map +0 -1
- package/tasks/index.js.map +0 -1
- package/tasks/reindexing/index.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"tasks/dataSynchronization/elasticsearch/ElasticsearchFetcher.js","sources":["../../../../src/tasks/dataSynchronization/elasticsearch/ElasticsearchFetcher.ts"],"sourcesContent":["import type { Client } from \"@webiny/api-opensearch\";\nimport type {\n IElasticsearchFetcher,\n IElasticsearchFetcherFetchParams,\n IElasticsearchFetcherFetchResponse,\n IElasticsearchFetcherFetchResponseItem\n} from \"./abstractions/ElasticsearchFetcher.js\";\nimport {\n type OpenSearchSearchResponse,\n type PrimitiveValue,\n getTotalCount\n} from \"@webiny/api-opensearch/types.js\";\nimport { shouldIgnoreEsResponseError } from \"./shouldIgnoreEsResponseError.js\";\nimport { inspect } from \"node:util\";\n\nexport interface IElasticsearchFetcherParams {\n client: Client;\n}\n\nexport class ElasticsearchFetcher implements IElasticsearchFetcher {\n private readonly client: Client;\n\n public constructor(params: IElasticsearchFetcherParams) {\n this.client = params.client;\n }\n public async fetch({\n index,\n cursor,\n limit\n }: IElasticsearchFetcherFetchParams): Promise<IElasticsearchFetcherFetchResponse> {\n let response: OpenSearchSearchResponse;\n try {\n response = await this.client.search({\n index,\n body: {\n query: {\n match_all: {}\n },\n sort: {\n \"id.keyword\": {\n order: \"asc\"\n }\n },\n size: limit + 1,\n track_total_hits: true,\n search_after: cursor,\n _source: false\n }\n });\n } catch (ex) {\n /**\n * If we ignore the error, we can continue with the next index.\n */\n if (shouldIgnoreEsResponseError(ex)) {\n if (process.env.DEBUG === \"true\") {\n console.error(\n inspect(ex, {\n depth: 5,\n showHidden: true\n })\n );\n }\n return {\n done: true,\n totalCount: 0,\n items: []\n };\n }\n console.error(\"Failed to fetch data from Elasticsearch.\", ex);\n throw ex;\n }\n\n const { hits, total } = response.body.hits;\n if (hits.length === 0) {\n return {\n done: true,\n cursor: undefined,\n totalCount: getTotalCount(total),\n items: []\n };\n }\n\n /**\n * TODO expect errors over hit properties is required due to opensearch library narrowing types too much because of the _source: false. At least what Claude says, didnt go into it too much.\n * Properties are there, but types are not correct.\n */\n const hasMoreItems = hits.length > limit;\n let nextCursor: PrimitiveValue[] | undefined;\n if (hasMoreItems) {\n hits.pop();\n // @ts-expect-error\n nextCursor = hits.at(-1)?.sort;\n }\n const items = hits.reduce<IElasticsearchFetcherFetchResponseItem[]>((collection, hit) => {\n // @ts-expect-error\n const [PK, SK] = hit._id.split(\":\");\n if (!PK || !SK) {\n return collection;\n }\n collection.push({\n PK,\n SK,\n // @ts-expect-error\n _id: hit._id,\n // @ts-expect-error\n index: hit._index\n });\n\n return collection;\n }, []);\n\n return {\n totalCount: getTotalCount(total),\n cursor: nextCursor,\n done: !nextCursor,\n items\n };\n }\n}\n"],"names":["ElasticsearchFetcher","params","index","cursor","limit","response","ex","shouldIgnoreEsResponseError","process","console","inspect","hits","total","undefined","getTotalCount","hasMoreItems","nextCursor","items","collection","hit","PK","SK"],"mappings":";;;AAmBO,MAAMA;IAGT,YAAmBC,MAAmC,CAAE;QACpD,IAAI,CAAC,MAAM,GAAGA,OAAO,MAAM;IAC/B;IACA,MAAa,MAAM,EACfC,KAAK,EACLC,MAAM,EACNC,KAAK,EAC0B,EAA+C;QAC9E,IAAIC;QACJ,IAAI;YACAA,WAAW,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;gBAChCH;gBACA,MAAM;oBACF,OAAO;wBACH,WAAW,CAAC;oBAChB;oBACA,MAAM;wBACF,cAAc;4BACV,OAAO;wBACX;oBACJ;oBACA,MAAME,QAAQ;oBACd,kBAAkB;oBAClB,cAAcD;oBACd,SAAS;gBACb;YACJ;QACJ,EAAE,OAAOG,IAAI;YAIT,IAAIC,4BAA4BD,KAAK;gBACjC,IAAIE,AAAsB,WAAtBA,QAAQ,GAAG,CAAC,KAAK,EACjBC,QAAQ,KAAK,CACTC,QAAQJ,IAAI;oBACR,OAAO;oBACP,YAAY;gBAChB;gBAGR,OAAO;oBACH,MAAM;oBACN,YAAY;oBACZ,OAAO,EAAE;gBACb;YACJ;YACAG,QAAQ,KAAK,CAAC,4CAA4CH;YAC1D,MAAMA;QACV;QAEA,MAAM,EAAEK,IAAI,EAAEC,KAAK,EAAE,GAAGP,SAAS,IAAI,CAAC,IAAI;QAC1C,IAAIM,AAAgB,MAAhBA,KAAK,MAAM,EACX,OAAO;YACH,MAAM;YACN,QAAQE;YACR,YAAYC,cAAcF;YAC1B,OAAO,EAAE;QACb;QAOJ,MAAMG,eAAeJ,KAAK,MAAM,GAAGP;QACnC,IAAIY;QACJ,IAAID,cAAc;YACdJ,KAAK,GAAG;YAERK,aAAaL,KAAK,EAAE,CAAC,KAAK;QAC9B;QACA,MAAMM,QAAQN,KAAK,MAAM,CAA2C,CAACO,YAAYC;YAE7E,MAAM,CAACC,IAAIC,GAAG,GAAGF,IAAI,GAAG,CAAC,KAAK,CAAC;YAC/B,IAAI,CAACC,MAAM,CAACC,IACR,OAAOH;YAEXA,WAAW,IAAI,CAAC;gBACZE;gBACAC;gBAEA,KAAKF,IAAI,GAAG;gBAEZ,OAAOA,IAAI,MAAM;YACrB;YAEA,OAAOD;QACX,GAAG,EAAE;QAEL,OAAO;YACH,YAAYJ,cAAcF;YAC1B,QAAQI;YACR,MAAM,CAACA;YACPC;QACJ;IACJ;AACJ"}
|
|
@@ -1,70 +1,57 @@
|
|
|
1
1
|
import { batchReadAll } from "@webiny/db-dynamodb/utils/batch/batchRead.js";
|
|
2
2
|
import { createSynchronizationBuilder } from "@webiny/api-dynamodb-to-elasticsearch";
|
|
3
3
|
import { getElasticsearchEntity, getElasticsearchEntityType, getTable } from "../entities/index.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
async execute(params) {
|
|
11
|
-
const {
|
|
12
|
-
items,
|
|
13
|
-
done,
|
|
14
|
-
index
|
|
15
|
-
} = params;
|
|
16
|
-
if (items.length === 0) {
|
|
17
|
-
return {
|
|
18
|
-
done: true
|
|
19
|
-
};
|
|
4
|
+
class ElasticsearchSynchronize {
|
|
5
|
+
constructor(controller, dbRegistry, context){
|
|
6
|
+
this.controller = controller;
|
|
7
|
+
this.dbRegistry = dbRegistry;
|
|
8
|
+
this.context = context;
|
|
20
9
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
10
|
+
async execute(params) {
|
|
11
|
+
const { items, done, index } = params;
|
|
12
|
+
if (0 === items.length) return {
|
|
13
|
+
done: true
|
|
14
|
+
};
|
|
15
|
+
const table = getTable({
|
|
16
|
+
type: "es",
|
|
17
|
+
dbRegistry: this.dbRegistry
|
|
18
|
+
});
|
|
19
|
+
const readableItems = items.map((item)=>{
|
|
20
|
+
const entity = this.getEntity(item);
|
|
21
|
+
return entity.item.entity.getBatch({
|
|
22
|
+
PK: item.PK,
|
|
23
|
+
SK: item.SK
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
const tableItems = await batchReadAll({
|
|
27
|
+
items: readableItems,
|
|
28
|
+
table
|
|
29
|
+
});
|
|
30
|
+
const elasticsearchSyncBuilder = createSynchronizationBuilder({
|
|
31
|
+
context: this.context,
|
|
32
|
+
timer: this.controller.runtime
|
|
33
|
+
});
|
|
34
|
+
for (const item of items){
|
|
35
|
+
const exists = tableItems.some((ddbItem)=>ddbItem.PK === item.PK && ddbItem.SK === item.SK);
|
|
36
|
+
if (!exists) elasticsearchSyncBuilder.delete({
|
|
37
|
+
index,
|
|
38
|
+
id: item._id
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const executeWithRetry = elasticsearchSyncBuilder.build();
|
|
42
|
+
await executeWithRetry();
|
|
43
|
+
return {
|
|
44
|
+
done
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
getEntity(params) {
|
|
48
|
+
const type = getElasticsearchEntityType(params);
|
|
49
|
+
return getElasticsearchEntity({
|
|
50
|
+
type,
|
|
51
|
+
dbRegistry: this.dbRegistry
|
|
52
|
+
});
|
|
54
53
|
}
|
|
55
|
-
const executeWithRetry = elasticsearchSyncBuilder.build();
|
|
56
|
-
await executeWithRetry();
|
|
57
|
-
return {
|
|
58
|
-
done
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
getEntity(params) {
|
|
62
|
-
const type = getElasticsearchEntityType(params);
|
|
63
|
-
return getElasticsearchEntity({
|
|
64
|
-
type,
|
|
65
|
-
dbRegistry: this.dbRegistry
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
54
|
}
|
|
55
|
+
export { ElasticsearchSynchronize };
|
|
69
56
|
|
|
70
57
|
//# sourceMappingURL=ElasticsearchSynchronize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"tasks/dataSynchronization/elasticsearch/ElasticsearchSynchronize.js","sources":["../../../../src/tasks/dataSynchronization/elasticsearch/ElasticsearchSynchronize.ts"],"sourcesContent":["import { batchReadAll } from \"@webiny/db-dynamodb/utils/batch/batchRead.js\";\nimport { createSynchronizationBuilder } from \"@webiny/api-dynamodb-to-elasticsearch\";\nimport type { IGetElasticsearchEntityTypeParams } from \"~/tasks/dataSynchronization/entities/index.js\";\nimport {\n getElasticsearchEntity,\n getElasticsearchEntityType,\n getTable\n} from \"~/tasks/dataSynchronization/entities/index.js\";\nimport type { TaskController } from \"@webiny/api-core/features/task/TaskController/index.js\";\nimport type {\n IElasticsearchSynchronize,\n IElasticsearchSynchronizeExecuteParams,\n IElasticsearchSynchronizeExecuteResponse\n} from \"./abstractions/ElasticsearchSynchronize.js\";\nimport { SynchronizationContext } from \"~/abstractions/SynchronizationContext.js\";\nimport { DbRegistry } from \"~/abstractions/DbRegistry.js\";\n\ninterface IDynamoDbItem {\n PK: string;\n SK: string;\n}\n\nexport class ElasticsearchSynchronize implements IElasticsearchSynchronize {\n public constructor(\n private controller: TaskController.Interface,\n private dbRegistry: DbRegistry.Interface,\n private context: SynchronizationContext.Interface\n ) {}\n\n public async execute(\n params: IElasticsearchSynchronizeExecuteParams\n ): Promise<IElasticsearchSynchronizeExecuteResponse> {\n const { items, done, index } = params;\n if (items.length === 0) {\n return {\n done: true\n };\n }\n\n const table = getTable({\n type: \"es\",\n dbRegistry: this.dbRegistry\n });\n\n const readableItems = items.map(item => {\n const entity = this.getEntity(item);\n return entity.item.entity.getBatch({\n PK: item.PK,\n SK: item.SK\n });\n });\n\n const tableItems = await batchReadAll<IDynamoDbItem>({\n items: readableItems,\n table\n });\n\n const elasticsearchSyncBuilder = createSynchronizationBuilder({\n context: this.context,\n timer: this.controller.runtime\n });\n /**\n * We need to find the items we have in the Elasticsearch but not in the DynamoDB-Elasticsearch table.\n */\n for (const item of items) {\n const exists = tableItems.some(ddbItem => {\n return ddbItem.PK === item.PK && ddbItem.SK === item.SK;\n });\n if (exists) {\n continue;\n }\n elasticsearchSyncBuilder.delete({\n index,\n id: item._id\n });\n }\n\n const executeWithRetry = elasticsearchSyncBuilder.build();\n await executeWithRetry();\n\n return {\n done\n };\n }\n\n private getEntity(\n params: IGetElasticsearchEntityTypeParams\n ): ReturnType<typeof getElasticsearchEntity> {\n const type = getElasticsearchEntityType(params);\n return getElasticsearchEntity({\n type,\n dbRegistry: this.dbRegistry\n });\n }\n}\n"],"names":["ElasticsearchSynchronize","controller","dbRegistry","context","params","items","done","index","table","getTable","readableItems","item","entity","tableItems","batchReadAll","elasticsearchSyncBuilder","createSynchronizationBuilder","exists","ddbItem","executeWithRetry","type","getElasticsearchEntityType","getElasticsearchEntity"],"mappings":";;;AAsBO,MAAMA;IACT,YACYC,UAAoC,EACpCC,UAAgC,EAChCC,OAAyC,CACnD;aAHUF,UAAU,GAAVA;aACAC,UAAU,GAAVA;aACAC,OAAO,GAAPA;IACT;IAEH,MAAa,QACTC,MAA8C,EACG;QACjD,MAAM,EAAEC,KAAK,EAAEC,IAAI,EAAEC,KAAK,EAAE,GAAGH;QAC/B,IAAIC,AAAiB,MAAjBA,MAAM,MAAM,EACZ,OAAO;YACH,MAAM;QACV;QAGJ,MAAMG,QAAQC,SAAS;YACnB,MAAM;YACN,YAAY,IAAI,CAAC,UAAU;QAC/B;QAEA,MAAMC,gBAAgBL,MAAM,GAAG,CAACM,CAAAA;YAC5B,MAAMC,SAAS,IAAI,CAAC,SAAS,CAACD;YAC9B,OAAOC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;gBAC/B,IAAID,KAAK,EAAE;gBACX,IAAIA,KAAK,EAAE;YACf;QACJ;QAEA,MAAME,aAAa,MAAMC,aAA4B;YACjD,OAAOJ;YACPF;QACJ;QAEA,MAAMO,2BAA2BC,6BAA6B;YAC1D,SAAS,IAAI,CAAC,OAAO;YACrB,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO;QAClC;QAIA,KAAK,MAAML,QAAQN,MAAO;YACtB,MAAMY,SAASJ,WAAW,IAAI,CAACK,CAAAA,UACpBA,QAAQ,EAAE,KAAKP,KAAK,EAAE,IAAIO,QAAQ,EAAE,KAAKP,KAAK,EAAE;YAE3D,KAAIM,QAGJF,yBAAyB,MAAM,CAAC;gBAC5BR;gBACA,IAAII,KAAK,GAAG;YAChB;QACJ;QAEA,MAAMQ,mBAAmBJ,yBAAyB,KAAK;QACvD,MAAMI;QAEN,OAAO;YACHb;QACJ;IACJ;IAEQ,UACJF,MAAyC,EACA;QACzC,MAAMgB,OAAOC,2BAA2BjB;QACxC,OAAOkB,uBAAuB;YAC1BF;YACA,YAAY,IAAI,CAAC,UAAU;QAC/B;IACJ;AACJ"}
|
|
@@ -1,70 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
async run(input) {
|
|
9
|
-
const lastIndex = input.elasticsearchToDynamoDb?.index;
|
|
10
|
-
let cursor = input.elasticsearchToDynamoDb?.cursor;
|
|
11
|
-
const indexes = await this.fetchAllIndexes();
|
|
12
|
-
let next = 0;
|
|
13
|
-
if (lastIndex) {
|
|
14
|
-
next = indexes.findIndex(index => index === lastIndex);
|
|
1
|
+
class ElasticsearchToDynamoDbSynchronization {
|
|
2
|
+
constructor(params){
|
|
3
|
+
this.manager = params.manager;
|
|
4
|
+
this.indexManager = params.indexManager;
|
|
5
|
+
this.synchronize = params.synchronize;
|
|
6
|
+
this.fetcher = params.fetcher;
|
|
15
7
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
8
|
+
async run(input) {
|
|
9
|
+
const lastIndex = input.elasticsearchToDynamoDb?.index;
|
|
10
|
+
let cursor = input.elasticsearchToDynamoDb?.cursor;
|
|
11
|
+
const indexes = await this.fetchAllIndexes();
|
|
12
|
+
let next = 0;
|
|
13
|
+
if (lastIndex) next = indexes.findIndex((index)=>index === lastIndex);
|
|
14
|
+
let currentIndex = indexes[next];
|
|
15
|
+
while(currentIndex){
|
|
16
|
+
if (this.manager.controller.runtime.isAborted()) return this.manager.controller.response.aborted();
|
|
17
|
+
if (this.manager.controller.runtime.isCloseToTimeout(180)) return this.manager.controller.response.continue({
|
|
18
|
+
...input,
|
|
19
|
+
elasticsearchToDynamoDb: {
|
|
20
|
+
...input.elasticsearchToDynamoDb,
|
|
21
|
+
index: currentIndex,
|
|
22
|
+
cursor
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const result = await this.fetcher.fetch({
|
|
26
|
+
index: currentIndex,
|
|
27
|
+
cursor,
|
|
28
|
+
limit: 100
|
|
29
|
+
});
|
|
30
|
+
const syncResult = await this.synchronize.execute({
|
|
31
|
+
done: result.done,
|
|
32
|
+
index: currentIndex,
|
|
33
|
+
items: result.items
|
|
34
|
+
});
|
|
35
|
+
if (!syncResult.done && result.cursor) {
|
|
36
|
+
cursor = result.cursor;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
cursor = void 0;
|
|
40
|
+
const next = indexes.findIndex((index)=>index === currentIndex) + 1;
|
|
41
|
+
currentIndex = indexes[next];
|
|
42
|
+
}
|
|
27
43
|
return this.manager.controller.response.continue({
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
cursor
|
|
33
|
-
}
|
|
44
|
+
...input,
|
|
45
|
+
elasticsearchToDynamoDb: {
|
|
46
|
+
finished: true
|
|
47
|
+
}
|
|
34
48
|
});
|
|
35
|
-
}
|
|
36
|
-
const result = await this.fetcher.fetch({
|
|
37
|
-
index: currentIndex,
|
|
38
|
-
cursor,
|
|
39
|
-
limit: 100
|
|
40
|
-
});
|
|
41
|
-
const syncResult = await this.synchronize.execute({
|
|
42
|
-
done: result.done,
|
|
43
|
-
index: currentIndex,
|
|
44
|
-
items: result.items
|
|
45
|
-
});
|
|
46
|
-
if (!syncResult.done && result.cursor) {
|
|
47
|
-
cursor = result.cursor;
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
cursor = undefined;
|
|
51
|
-
const next = indexes.findIndex(index => index === currentIndex) + 1;
|
|
52
|
-
currentIndex = indexes[next];
|
|
53
49
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
async fetchAllIndexes() {
|
|
62
|
-
const result = await this.indexManager.list();
|
|
63
|
-
if (result.length > 0) {
|
|
64
|
-
return result;
|
|
50
|
+
async fetchAllIndexes() {
|
|
51
|
+
const result = await this.indexManager.list();
|
|
52
|
+
if (result.length > 0) return result;
|
|
53
|
+
throw new Error("No Elasticsearch / OpenSearch indexes found.");
|
|
65
54
|
}
|
|
66
|
-
throw new Error("No Elasticsearch / OpenSearch indexes found.");
|
|
67
|
-
}
|
|
68
55
|
}
|
|
56
|
+
export { ElasticsearchToDynamoDbSynchronization };
|
|
69
57
|
|
|
70
58
|
//# sourceMappingURL=ElasticsearchToDynamoDbSynchronization.js.map
|
package/tasks/dataSynchronization/elasticsearch/ElasticsearchToDynamoDbSynchronization.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"tasks/dataSynchronization/elasticsearch/ElasticsearchToDynamoDbSynchronization.js","sources":["../../../../src/tasks/dataSynchronization/elasticsearch/ElasticsearchToDynamoDbSynchronization.ts"],"sourcesContent":["import type {\n IDataSynchronizationInput,\n IDataSynchronizationManager,\n IElasticsearchSyncParams,\n ISynchronization,\n ISynchronizationRunResult\n} from \"../types.js\";\nimport type { IIndexManager } from \"~/settings/types.js\";\nimport type { NonEmptyArray } from \"@webiny/api/types.js\";\nimport type { IElasticsearchSynchronize } from \"./abstractions/ElasticsearchSynchronize.js\";\nimport type { IElasticsearchFetcher } from \"./abstractions/ElasticsearchFetcher.js\";\n\nexport class ElasticsearchToDynamoDbSynchronization implements ISynchronization {\n private readonly manager: IDataSynchronizationManager;\n private readonly indexManager: IIndexManager;\n private readonly synchronize: IElasticsearchSynchronize;\n private readonly fetcher: IElasticsearchFetcher;\n\n public constructor(params: IElasticsearchSyncParams) {\n this.manager = params.manager;\n this.indexManager = params.indexManager;\n this.synchronize = params.synchronize;\n this.fetcher = params.fetcher;\n }\n\n public async run(input: IDataSynchronizationInput): Promise<ISynchronizationRunResult> {\n const lastIndex = input.elasticsearchToDynamoDb?.index;\n let cursor = input.elasticsearchToDynamoDb?.cursor;\n const indexes = await this.fetchAllIndexes();\n\n let next = 0;\n if (lastIndex) {\n next = indexes.findIndex(index => index === lastIndex);\n }\n\n let currentIndex = indexes[next];\n\n while (currentIndex) {\n if (this.manager.controller.runtime.isAborted()) {\n return this.manager.controller.response.aborted();\n }\n /**\n * We will put 180 seconds because we are writing to the Elasticsearch/OpenSearch directly.\n * We want to leave enough time for possible retries.\n */\n //\n else if (this.manager.controller.runtime.isCloseToTimeout(180)) {\n return this.manager.controller.response.continue({\n ...input,\n elasticsearchToDynamoDb: {\n ...input.elasticsearchToDynamoDb,\n index: currentIndex,\n cursor\n }\n });\n }\n\n const result = await this.fetcher.fetch({\n index: currentIndex,\n cursor,\n limit: 100\n });\n\n const syncResult = await this.synchronize.execute({\n done: result.done,\n index: currentIndex,\n items: result.items\n });\n\n if (!syncResult.done && result.cursor) {\n cursor = result.cursor;\n continue;\n }\n cursor = undefined;\n\n const next = indexes.findIndex(index => index === currentIndex) + 1;\n currentIndex = indexes[next];\n }\n\n return this.manager.controller.response.continue({\n ...input,\n elasticsearchToDynamoDb: {\n finished: true\n }\n });\n }\n\n private async fetchAllIndexes(): Promise<NonEmptyArray<string>> {\n const result = await this.indexManager.list();\n if (result.length > 0) {\n return result as NonEmptyArray<string>;\n }\n throw new Error(\"No Elasticsearch / OpenSearch indexes found.\");\n }\n}\n"],"names":["ElasticsearchToDynamoDbSynchronization","params","input","lastIndex","cursor","indexes","next","index","currentIndex","result","syncResult","undefined","Error"],"mappings":"AAYO,MAAMA;IAMT,YAAmBC,MAAgC,CAAE;QACjD,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO;QAC7B,IAAI,CAAC,YAAY,GAAGA,OAAO,YAAY;QACvC,IAAI,CAAC,WAAW,GAAGA,OAAO,WAAW;QACrC,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO;IACjC;IAEA,MAAa,IAAIC,KAAgC,EAAsC;QACnF,MAAMC,YAAYD,MAAM,uBAAuB,EAAE;QACjD,IAAIE,SAASF,MAAM,uBAAuB,EAAE;QAC5C,MAAMG,UAAU,MAAM,IAAI,CAAC,eAAe;QAE1C,IAAIC,OAAO;QACX,IAAIH,WACAG,OAAOD,QAAQ,SAAS,CAACE,CAAAA,QAASA,UAAUJ;QAGhD,IAAIK,eAAeH,OAAO,CAACC,KAAK;QAEhC,MAAOE,aAAc;YACjB,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,SAAS,IACzC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO;YAO9C,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,gBAAgB,CAAC,MACtD,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBAC7C,GAAGN,KAAK;gBACR,yBAAyB;oBACrB,GAAGA,MAAM,uBAAuB;oBAChC,OAAOM;oBACPJ;gBACJ;YACJ;YAGJ,MAAMK,SAAS,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;gBACpC,OAAOD;gBACPJ;gBACA,OAAO;YACX;YAEA,MAAMM,aAAa,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;gBAC9C,MAAMD,OAAO,IAAI;gBACjB,OAAOD;gBACP,OAAOC,OAAO,KAAK;YACvB;YAEA,IAAI,CAACC,WAAW,IAAI,IAAID,OAAO,MAAM,EAAE;gBACnCL,SAASK,OAAO,MAAM;gBACtB;YACJ;YACAL,SAASO;YAET,MAAML,OAAOD,QAAQ,SAAS,CAACE,CAAAA,QAASA,UAAUC,gBAAgB;YAClEA,eAAeH,OAAO,CAACC,KAAK;QAChC;QAEA,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAC7C,GAAGJ,KAAK;YACR,yBAAyB;gBACrB,UAAU;YACd;QACJ;IACJ;IAEA,MAAc,kBAAkD;QAC5D,MAAMO,SAAS,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI;QAC3C,IAAIA,OAAO,MAAM,GAAG,GAChB,OAAOA;QAEX,MAAM,IAAIG,MAAM;IACpB;AACJ"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
const IGNORED_ES_SEARCH_EXCEPTIONS = [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const IGNORED_ES_SEARCH_EXCEPTIONS = [
|
|
2
|
+
"index_not_found_exception",
|
|
3
|
+
"search_phase_execution_exception",
|
|
4
|
+
"illegal_argument_exception"
|
|
5
|
+
];
|
|
6
|
+
const shouldIgnoreEsResponseError = (error)=>IGNORED_ES_SEARCH_EXCEPTIONS.includes(error.message);
|
|
7
|
+
export { shouldIgnoreEsResponseError };
|
|
5
8
|
|
|
6
9
|
//# sourceMappingURL=shouldIgnoreEsResponseError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"tasks/dataSynchronization/elasticsearch/shouldIgnoreEsResponseError.js","sources":["../../../../src/tasks/dataSynchronization/elasticsearch/shouldIgnoreEsResponseError.ts"],"sourcesContent":["import type WebinyError from \"@webiny/error\";\n\nconst IGNORED_ES_SEARCH_EXCEPTIONS = [\n \"index_not_found_exception\",\n \"search_phase_execution_exception\",\n \"illegal_argument_exception\"\n];\n\nexport const shouldIgnoreEsResponseError = (error: WebinyError) => {\n return IGNORED_ES_SEARCH_EXCEPTIONS.includes(error.message);\n};\n"],"names":["IGNORED_ES_SEARCH_EXCEPTIONS","shouldIgnoreEsResponseError","error"],"mappings":"AAEA,MAAMA,+BAA+B;IACjC;IACA;IACA;CACH;AAEM,MAAMC,8BAA8B,CAACC,QACjCF,6BAA6B,QAAQ,CAACE,MAAM,OAAO"}
|
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
import { EntityType } from "./getElasticsearchEntityType.js";
|
|
2
|
-
const createPredicate = (app, tags) =>
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
switch (type) {
|
|
17
|
-
case EntityType.CMS:
|
|
18
|
-
return getByPredicate(createPredicate("cms", ["es"]));
|
|
19
|
-
}
|
|
20
|
-
} catch {}
|
|
21
|
-
throw new Error(`Unknown entity type "${type}".`);
|
|
2
|
+
const createPredicate = (app, tags)=>(item)=>item.app === app && tags.every((tag)=>item.tags.includes(tag));
|
|
3
|
+
const getElasticsearchEntity = (params)=>{
|
|
4
|
+
const { type, dbRegistry } = params;
|
|
5
|
+
const getByPredicate = (predicate)=>dbRegistry.getOneItem(predicate);
|
|
6
|
+
try {
|
|
7
|
+
switch(type){
|
|
8
|
+
case EntityType.CMS:
|
|
9
|
+
return getByPredicate(createPredicate("cms", [
|
|
10
|
+
"es"
|
|
11
|
+
]));
|
|
12
|
+
}
|
|
13
|
+
} catch {}
|
|
14
|
+
throw new Error(`Unknown entity type "${type}".`);
|
|
22
15
|
};
|
|
16
|
+
export { getElasticsearchEntity };
|
|
23
17
|
|
|
24
18
|
//# sourceMappingURL=getElasticsearchEntity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"tasks/dataSynchronization/entities/getElasticsearchEntity.js","sources":["../../../../src/tasks/dataSynchronization/entities/getElasticsearchEntity.ts"],"sourcesContent":["import type { NonEmptyArray } from \"@webiny/api/types.js\";\nimport type { IRegistryItem } from \"@webiny/db\";\nimport { EntityType } from \"./getElasticsearchEntityType.js\";\nimport { DbRegistry } from \"~/abstractions/DbRegistry.js\";\nimport type { IEntity, IStandardEntityAttributes } from \"@webiny/db-dynamodb\";\n\nexport interface IGetElasticsearchEntityParams {\n type: EntityType | unknown;\n dbRegistry: DbRegistry.Interface;\n}\n\nconst createPredicate = (app: string, tags: NonEmptyArray<string>) => {\n return (item: IRegistryItem) => {\n return item.app === app && tags.every(tag => item.tags.includes(tag));\n };\n};\n\nexport const getElasticsearchEntity = (params: IGetElasticsearchEntityParams) => {\n const { type, dbRegistry } = params;\n\n const getByPredicate = (predicate: (item: IRegistryItem) => boolean) => {\n return dbRegistry.getOneItem<IEntity<IStandardEntityAttributes>>(predicate);\n };\n\n try {\n switch (type) {\n case EntityType.CMS:\n return getByPredicate(createPredicate(\"cms\", [\"es\"]));\n }\n } catch {}\n throw new Error(`Unknown entity type \"${type}\".`);\n};\n"],"names":["createPredicate","app","tags","item","tag","getElasticsearchEntity","params","type","dbRegistry","getByPredicate","predicate","EntityType","Error"],"mappings":";AAWA,MAAMA,kBAAkB,CAACC,KAAaC,OAC3B,CAACC,OACGA,KAAK,GAAG,KAAKF,OAAOC,KAAK,KAAK,CAACE,CAAAA,MAAOD,KAAK,IAAI,CAAC,QAAQ,CAACC;AAIjE,MAAMC,yBAAyB,CAACC;IACnC,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAE,GAAGF;IAE7B,MAAMG,iBAAiB,CAACC,YACbF,WAAW,UAAU,CAAqCE;IAGrE,IAAI;QACA,OAAQH;YACJ,KAAKI,WAAW,GAAG;gBACf,OAAOF,eAAeT,gBAAgB,OAAO;oBAAC;iBAAK;QAC3D;IACJ,EAAE,OAAM,CAAC;IACT,MAAM,IAAIY,MAAM,CAAC,qBAAqB,EAAEL,KAAK,EAAE,CAAC;AACpD"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var getElasticsearchEntityType_EntityType = /*#__PURE__*/ function(EntityType) {
|
|
2
|
+
EntityType["CMS"] = "headless-cms";
|
|
3
|
+
return EntityType;
|
|
4
4
|
}({});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
throw new Error(`Unknown entity type for item "${JSON.stringify(params)}".`);
|
|
5
|
+
const getElasticsearchEntityType = (params)=>{
|
|
6
|
+
if (params.index.includes("-headless-cms-")) return "headless-cms";
|
|
7
|
+
throw new Error(`Unknown entity type for item "${JSON.stringify(params)}".`);
|
|
10
8
|
};
|
|
9
|
+
export { getElasticsearchEntityType, getElasticsearchEntityType_EntityType as EntityType };
|
|
11
10
|
|
|
12
11
|
//# sourceMappingURL=getElasticsearchEntityType.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"tasks/dataSynchronization/entities/getElasticsearchEntityType.js","sources":["../../../../src/tasks/dataSynchronization/entities/getElasticsearchEntityType.ts"],"sourcesContent":["export enum EntityType {\n CMS = \"headless-cms\"\n}\n\nexport interface IGetElasticsearchEntityTypeParams {\n SK: string;\n index: string;\n}\n\nexport const getElasticsearchEntityType = (\n params: IGetElasticsearchEntityTypeParams\n): EntityType => {\n if (params.index.includes(\"-headless-cms-\")) {\n return EntityType.CMS;\n }\n\n throw new Error(`Unknown entity type for item \"${JSON.stringify(params)}\".`);\n};\n"],"names":["EntityType","getElasticsearchEntityType","params","Error","JSON"],"mappings":"AAAO,IAAKA,wCAAUA,WAAAA,GAAAA,SAAVA,UAAU;;WAAVA;;AASL,MAAMC,6BAA6B,CACtCC;IAEA,IAAIA,OAAO,KAAK,CAAC,QAAQ,CAAC,mBACtB,OAAO;IAGX,MAAM,IAAIC,MAAM,CAAC,8BAA8B,EAAEC,KAAK,SAAS,CAACF,QAAQ,EAAE,CAAC;AAC/E"}
|
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
const createPredicate = (app, tags) =>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return item.item;
|
|
14
|
-
};
|
|
15
|
-
const entity = getByPredicate(createPredicate("cms", [type]));
|
|
16
|
-
if (!entity) {
|
|
17
|
-
throw new Error(`Unknown entity type "${type}".`);
|
|
18
|
-
}
|
|
19
|
-
return entity.table;
|
|
1
|
+
const createPredicate = (app, tags)=>(item)=>item.app === app && tags.every((tag)=>item.tags.includes(tag));
|
|
2
|
+
const getTable = (params)=>{
|
|
3
|
+
const { dbRegistry, type } = params;
|
|
4
|
+
const getByPredicate = (predicate)=>{
|
|
5
|
+
const item = dbRegistry.getOneItem(predicate);
|
|
6
|
+
return item.item;
|
|
7
|
+
};
|
|
8
|
+
const entity = getByPredicate(createPredicate("cms", [
|
|
9
|
+
type
|
|
10
|
+
]));
|
|
11
|
+
if (!entity) throw new Error(`Unknown entity type "${type}".`);
|
|
12
|
+
return entity.table;
|
|
20
13
|
};
|
|
14
|
+
export { getTable };
|
|
21
15
|
|
|
22
16
|
//# sourceMappingURL=getTable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"tasks/dataSynchronization/entities/getTable.js","sources":["../../../../src/tasks/dataSynchronization/entities/getTable.ts"],"sourcesContent":["import type { Entity, TableDef } from \"@webiny/db-dynamodb/toolbox.js\";\nimport type { NonEmptyArray } from \"@webiny/api/types.js\";\nimport type { IRegistryItem } from \"@webiny/db\";\nimport type { DbRegistry } from \"~/abstractions/DbRegistry.js\";\n\nexport interface IGetTableParams {\n dbRegistry: DbRegistry.Interface;\n type: \"regular\" | \"es\";\n}\n\nconst createPredicate = (app: string, tags: NonEmptyArray<string>) => {\n return (item: IRegistryItem) => {\n return item.app === app && tags.every(tag => item.tags.includes(tag));\n };\n};\n\nexport const getTable = (params: IGetTableParams): TableDef => {\n const { dbRegistry, type } = params;\n\n const getByPredicate = (predicate: (item: IRegistryItem) => boolean) => {\n const item = dbRegistry.getOneItem<Entity>(predicate);\n return item.item;\n };\n\n const entity = getByPredicate(createPredicate(\"cms\", [type]));\n if (!entity) {\n throw new Error(`Unknown entity type \"${type}\".`);\n }\n return entity.table as TableDef;\n};\n"],"names":["createPredicate","app","tags","item","tag","getTable","params","dbRegistry","type","getByPredicate","predicate","entity","Error"],"mappings":"AAUA,MAAMA,kBAAkB,CAACC,KAAaC,OAC3B,CAACC,OACGA,KAAK,GAAG,KAAKF,OAAOC,KAAK,KAAK,CAACE,CAAAA,MAAOD,KAAK,IAAI,CAAC,QAAQ,CAACC;AAIjE,MAAMC,WAAW,CAACC;IACrB,MAAM,EAAEC,UAAU,EAAEC,IAAI,EAAE,GAAGF;IAE7B,MAAMG,iBAAiB,CAACC;QACpB,MAAMP,OAAOI,WAAW,UAAU,CAASG;QAC3C,OAAOP,KAAK,IAAI;IACpB;IAEA,MAAMQ,SAASF,eAAeT,gBAAgB,OAAO;QAACQ;KAAK;IAC3D,IAAI,CAACG,QACD,MAAM,IAAIC,MAAM,CAAC,qBAAqB,EAAEJ,KAAK,EAAE,CAAC;IAEpD,OAAOG,OAAO,KAAK;AACvB"}
|
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
2
2
|
import { createContextPlugin } from "@webiny/api";
|
|
3
|
-
import { DataSynchronizationTask } from "./DataSynchronizationTask.js";
|
|
3
|
+
import { DATA_SYNCHRONIZATION_TASK, DataSynchronizationTask } from "./DataSynchronizationTask.js";
|
|
4
4
|
import { getClients } from "../../helpers/getClients.js";
|
|
5
5
|
import { ElasticsearchSynchronize } from "./elasticsearch/ElasticsearchSynchronize.js";
|
|
6
6
|
import { TaskController } from "@webiny/api-core/features/task/TaskController/index.js";
|
|
7
7
|
import { DbRegistry } from "../../abstractions/DbRegistry.js";
|
|
8
8
|
import { SynchronizationContext } from "../../abstractions/SynchronizationContext.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
return new DataSynchronizationTask(elasticsearchClient, documentClient, elasticsearchSynchronize);
|
|
9
|
+
const createDataSynchronization = (params)=>createContextPlugin(async (context)=>{
|
|
10
|
+
const { documentClient, elasticsearchClient } = getClients(context, params);
|
|
11
|
+
context.container.registerFactory(TaskDefinition, ()=>{
|
|
12
|
+
const elasticsearchSynchronize = context.container.resolveWithDependencies({
|
|
13
|
+
implementation: ElasticsearchSynchronize,
|
|
14
|
+
dependencies: [
|
|
15
|
+
TaskController,
|
|
16
|
+
DbRegistry,
|
|
17
|
+
SynchronizationContext
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
return new DataSynchronizationTask(elasticsearchClient, documentClient, elasticsearchSynchronize);
|
|
21
|
+
});
|
|
24
22
|
});
|
|
25
|
-
|
|
26
|
-
};
|
|
23
|
+
export { DATA_SYNCHRONIZATION_TASK, createDataSynchronization };
|
|
27
24
|
|
|
28
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"tasks/dataSynchronization/index.js","sources":["../../../src/tasks/dataSynchronization/index.ts"],"sourcesContent":["import { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport type { Context, IElasticsearchTaskConfig } from \"~/types.js\";\nimport { createContextPlugin } from \"@webiny/api\";\nimport { DataSynchronizationTask } from \"./DataSynchronizationTask.js\";\nimport { getClients } from \"~/helpers/getClients.js\";\nimport { ElasticsearchSynchronize } from \"~/tasks/dataSynchronization/elasticsearch/ElasticsearchSynchronize.js\";\nimport { TaskController } from \"@webiny/api-core/features/task/TaskController/index.js\";\nimport { DbRegistry } from \"~/abstractions/DbRegistry.js\";\nimport { SynchronizationContext } from \"~/abstractions/SynchronizationContext.js\";\n\nexport { DATA_SYNCHRONIZATION_TASK } from \"./DataSynchronizationTask.js\";\n\nexport const createDataSynchronization = (params?: Partial<IElasticsearchTaskConfig>) => {\n return createContextPlugin<Context>(async context => {\n const { documentClient, elasticsearchClient } = getClients(context, params);\n\n // Register the task definition with DbRegistry injected\n context.container.registerFactory(TaskDefinition, () => {\n const elasticsearchSynchronize = context.container.resolveWithDependencies({\n implementation: ElasticsearchSynchronize,\n dependencies: [TaskController, DbRegistry, SynchronizationContext]\n });\n\n return new DataSynchronizationTask(\n elasticsearchClient,\n documentClient,\n elasticsearchSynchronize\n );\n });\n });\n};\n"],"names":["createDataSynchronization","params","createContextPlugin","context","documentClient","elasticsearchClient","getClients","TaskDefinition","elasticsearchSynchronize","ElasticsearchSynchronize","TaskController","DbRegistry","SynchronizationContext","DataSynchronizationTask"],"mappings":";;;;;;;;AAYO,MAAMA,4BAA4B,CAACC,SAC/BC,oBAA6B,OAAMC;QACtC,MAAM,EAAEC,cAAc,EAAEC,mBAAmB,EAAE,GAAGC,WAAWH,SAASF;QAGpEE,QAAQ,SAAS,CAAC,eAAe,CAACI,gBAAgB;YAC9C,MAAMC,2BAA2BL,QAAQ,SAAS,CAAC,uBAAuB,CAAC;gBACvE,gBAAgBM;gBAChB,cAAc;oBAACC;oBAAgBC;oBAAYC;iBAAuB;YACtE;YAEA,OAAO,IAAIC,wBACPR,qBACAD,gBACAI;QAER;IACJ"}
|