@webiny/api-elasticsearch-tasks 5.42.1-beta.0 → 5.42.1-beta.2
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/package.json +24 -24
- package/tasks/createIndexes/CreateIndexesTaskRunner.d.ts +4 -4
- package/tasks/createIndexes/CreateIndexesTaskRunner.js +10 -23
- package/tasks/createIndexes/CreateIndexesTaskRunner.js.map +1 -1
- package/tasks/createIndexes/OnBeforeTrigger.d.ts +12 -0
- package/tasks/createIndexes/OnBeforeTrigger.js +68 -0
- package/tasks/createIndexes/OnBeforeTrigger.js.map +1 -0
- package/tasks/createIndexes/createIndex.d.ts +5 -0
- package/tasks/createIndexes/createIndex.js +27 -0
- package/tasks/createIndexes/createIndex.js.map +1 -0
- package/tasks/createIndexes/index.js +17 -0
- package/tasks/createIndexes/index.js.map +1 -1
- package/tasks/createIndexes/listCreateElasticsearchIndexTaskPlugin.d.ts +4 -0
- package/tasks/createIndexes/listCreateElasticsearchIndexTaskPlugin.js +13 -0
- package/tasks/createIndexes/listCreateElasticsearchIndexTaskPlugin.js.map +1 -0
- package/tasks/createIndexes/listIndexes.d.ts +12 -0
- package/tasks/createIndexes/listIndexes.js +53 -0
- package/tasks/createIndexes/listIndexes.js.map +1 -0
- package/types.d.ts +1 -1
- package/types.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-elasticsearch-tasks",
|
|
3
|
-
"version": "5.42.1-beta.
|
|
3
|
+
"version": "5.42.1-beta.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,31 +12,31 @@
|
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@webiny/api": "5.42.1-beta.
|
|
16
|
-
"@webiny/api-dynamodb-to-elasticsearch": "5.42.1-beta.
|
|
17
|
-
"@webiny/api-elasticsearch": "5.42.1-beta.
|
|
18
|
-
"@webiny/api-
|
|
19
|
-
"@webiny/
|
|
20
|
-
"@webiny/
|
|
21
|
-
"@webiny/
|
|
22
|
-
"@webiny/
|
|
23
|
-
"@webiny/
|
|
24
|
-
"@webiny/
|
|
15
|
+
"@webiny/api": "5.42.1-beta.2",
|
|
16
|
+
"@webiny/api-dynamodb-to-elasticsearch": "5.42.1-beta.2",
|
|
17
|
+
"@webiny/api-elasticsearch": "5.42.1-beta.2",
|
|
18
|
+
"@webiny/api-i18n": "5.42.1-beta.2",
|
|
19
|
+
"@webiny/api-log": "5.42.1-beta.2",
|
|
20
|
+
"@webiny/api-security": "5.42.1-beta.2",
|
|
21
|
+
"@webiny/api-tenancy": "5.42.1-beta.2",
|
|
22
|
+
"@webiny/aws-sdk": "5.42.1-beta.2",
|
|
23
|
+
"@webiny/db": "5.42.1-beta.2",
|
|
24
|
+
"@webiny/db-dynamodb": "5.42.1-beta.2",
|
|
25
|
+
"@webiny/error": "5.42.1-beta.2",
|
|
26
|
+
"@webiny/plugins": "5.42.1-beta.2",
|
|
27
|
+
"@webiny/tasks": "5.42.1-beta.2",
|
|
28
|
+
"@webiny/utils": "5.42.1-beta.2"
|
|
25
29
|
},
|
|
26
30
|
"devDependencies": {
|
|
27
31
|
"@webiny/api": "0.0.0",
|
|
28
|
-
"@webiny/api-headless-cms": "5.42.1-beta.
|
|
29
|
-
"@webiny/api-
|
|
30
|
-
"@webiny/
|
|
31
|
-
"@webiny/
|
|
32
|
-
"@webiny/
|
|
33
|
-
"@webiny/
|
|
34
|
-
"@webiny/handler": "5.42.1-beta.
|
|
35
|
-
"@webiny/
|
|
36
|
-
"@webiny/handler-db": "5.42.1-beta.0",
|
|
37
|
-
"@webiny/handler-graphql": "5.42.1-beta.0",
|
|
38
|
-
"@webiny/plugins": "5.42.1-beta.0",
|
|
39
|
-
"@webiny/project-utils": "5.42.1-beta.0",
|
|
32
|
+
"@webiny/api-headless-cms": "5.42.1-beta.2",
|
|
33
|
+
"@webiny/api-wcp": "5.42.1-beta.2",
|
|
34
|
+
"@webiny/cli": "5.42.1-beta.2",
|
|
35
|
+
"@webiny/handler": "5.42.1-beta.2",
|
|
36
|
+
"@webiny/handler-aws": "5.42.1-beta.2",
|
|
37
|
+
"@webiny/handler-db": "5.42.1-beta.2",
|
|
38
|
+
"@webiny/handler-graphql": "5.42.1-beta.2",
|
|
39
|
+
"@webiny/project-utils": "5.42.1-beta.2",
|
|
40
40
|
"rimraf": "6.0.1",
|
|
41
41
|
"ttypescript": "1.5.15",
|
|
42
42
|
"type-fest": "3.13.1",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"build": "yarn webiny run build",
|
|
51
51
|
"watch": "yarn webiny run watch"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "86931bade22e9407f297bb69e3a898e2b7e2450a",
|
|
54
54
|
"adio": {
|
|
55
55
|
"ignore": {
|
|
56
56
|
"src": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Manager } from "../Manager";
|
|
2
|
-
import { IndexManager } from "../../settings";
|
|
3
|
-
import { ITaskResponseResult } from "@webiny/tasks";
|
|
4
|
-
import { IElasticsearchCreateIndexesTaskInput } from "./types";
|
|
1
|
+
import type { Manager } from "../Manager";
|
|
2
|
+
import type { IndexManager } from "../../settings";
|
|
3
|
+
import type { ITaskResponseResult } from "@webiny/tasks";
|
|
4
|
+
import type { IElasticsearchCreateIndexesTaskInput } from "./types";
|
|
5
5
|
export declare class CreateIndexesTaskRunner {
|
|
6
6
|
private readonly manager;
|
|
7
7
|
private readonly indexManager;
|
|
@@ -4,37 +4,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.CreateIndexesTaskRunner = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _listIndexes = require("./listIndexes");
|
|
8
|
+
var _createIndex = require("./createIndex");
|
|
9
|
+
var _listCreateElasticsearchIndexTaskPlugin = require("./listCreateElasticsearchIndexTaskPlugin");
|
|
8
10
|
class CreateIndexesTaskRunner {
|
|
9
11
|
constructor(manager, indexManager) {
|
|
10
12
|
this.manager = manager;
|
|
11
13
|
this.indexManager = indexManager;
|
|
12
14
|
}
|
|
13
15
|
async execute(matching, done) {
|
|
14
|
-
const plugins = this.manager.context.plugins
|
|
16
|
+
const plugins = (0, _listCreateElasticsearchIndexTaskPlugin.listCreateElasticsearchIndexTaskPlugin)(this.manager.context.plugins);
|
|
15
17
|
if (plugins.length === 0) {
|
|
16
18
|
return this.manager.response.done("No index plugins found.");
|
|
17
19
|
}
|
|
18
|
-
const indexes =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
for (const locale of locales) {
|
|
23
|
-
for (const plugin of plugins) {
|
|
24
|
-
const results = await plugin.getIndexList({
|
|
25
|
-
context: this.manager.context,
|
|
26
|
-
tenant: tenant.id,
|
|
27
|
-
locale: locale.code
|
|
28
|
-
});
|
|
29
|
-
for (const result of results) {
|
|
30
|
-
if (indexes.some(i => i.index === result.index)) {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
indexes.push(result);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
20
|
+
const indexes = await (0, _listIndexes.listIndexes)({
|
|
21
|
+
context: this.manager.context,
|
|
22
|
+
plugins
|
|
23
|
+
});
|
|
38
24
|
if (indexes.length === 0) {
|
|
39
25
|
return this.manager.response.done("No indexes found.");
|
|
40
26
|
}
|
|
@@ -44,6 +30,7 @@ class CreateIndexesTaskRunner {
|
|
|
44
30
|
}
|
|
45
31
|
return index.includes(matching);
|
|
46
32
|
};
|
|
33
|
+
const createIndex = (0, _createIndex.createIndexFactory)(this.indexManager);
|
|
47
34
|
for (const {
|
|
48
35
|
index,
|
|
49
36
|
settings
|
|
@@ -66,7 +53,7 @@ class CreateIndexesTaskRunner {
|
|
|
66
53
|
continue;
|
|
67
54
|
}
|
|
68
55
|
done.push(index);
|
|
69
|
-
await
|
|
56
|
+
await createIndex.create(index, settings);
|
|
70
57
|
await this.manager.store.addInfoLog({
|
|
71
58
|
message: `Index "${index}" created.`,
|
|
72
59
|
data: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_listIndexes","require","_createIndex","_listCreateElasticsearchIndexTaskPlugin","CreateIndexesTaskRunner","constructor","manager","indexManager","execute","matching","done","plugins","listCreateElasticsearchIndexTaskPlugin","context","length","response","indexes","listIndexes","isIndexAllowed","index","includes","createIndex","createIndexFactory","settings","isAborted","aborted","isCloseToTimeout","continue","exists","indexExists","push","create","store","addInfoLog","message","data","ex","addErrorLog","error","exports"],"sources":["CreateIndexesTaskRunner.ts"],"sourcesContent":["import type { Manager } from \"~/tasks/Manager\";\nimport type { IndexManager } from \"~/settings\";\nimport type { ITaskResponseResult } from \"@webiny/tasks\";\nimport type { IElasticsearchCreateIndexesTaskInput } from \"./types\";\nimport { listIndexes } from \"./listIndexes\";\nimport { createIndexFactory } from \"./createIndex\";\nimport type { Context } from \"~/types\";\nimport { listCreateElasticsearchIndexTaskPlugin } from \"./listCreateElasticsearchIndexTaskPlugin\";\n\nexport class CreateIndexesTaskRunner {\n private readonly manager: Manager<IElasticsearchCreateIndexesTaskInput>;\n private readonly indexManager: IndexManager;\n\n public constructor(\n manager: Manager<IElasticsearchCreateIndexesTaskInput>,\n indexManager: IndexManager\n ) {\n this.manager = manager;\n\n this.indexManager = indexManager;\n }\n\n public async execute(\n matching: string | undefined,\n done: string[]\n ): Promise<ITaskResponseResult> {\n const plugins = listCreateElasticsearchIndexTaskPlugin<Context>(\n this.manager.context.plugins\n );\n if (plugins.length === 0) {\n return this.manager.response.done(\"No index plugins found.\");\n }\n\n const indexes = await listIndexes({\n context: this.manager.context,\n plugins\n });\n\n if (indexes.length === 0) {\n return this.manager.response.done(\"No indexes found.\");\n }\n\n const isIndexAllowed = (index: string): boolean => {\n if (typeof matching !== \"string\" || !matching) {\n return true;\n }\n return index.includes(matching);\n };\n\n const createIndex = createIndexFactory(this.indexManager);\n\n for (const { index, settings } of indexes) {\n if (this.manager.isAborted()) {\n return this.manager.response.aborted();\n } else if (this.manager.isCloseToTimeout()) {\n return this.manager.response.continue({\n done\n });\n }\n try {\n if (done.includes(index)) {\n continue;\n } else if (isIndexAllowed(index) === false) {\n continue;\n }\n const exists = await this.indexManager.indexExists(index);\n if (exists) {\n continue;\n }\n done.push(index);\n await createIndex.create(index, settings);\n await this.manager.store.addInfoLog({\n message: `Index \"${index}\" created.`,\n data: {\n index\n }\n });\n } catch (ex) {\n await this.manager.store.addErrorLog({\n message: `Failed to create index \"${index}\".`,\n error: ex\n });\n }\n }\n\n return this.manager.response.done(\"Indexes created.\", {\n done\n });\n }\n}\n"],"mappings":"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","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Context } from "../../types";
|
|
2
|
+
import type { IndexManager } from "../../settings";
|
|
3
|
+
export interface IOnBeforeTriggerParams {
|
|
4
|
+
indexManager: IndexManager;
|
|
5
|
+
context: Context;
|
|
6
|
+
}
|
|
7
|
+
export declare class OnBeforeTrigger {
|
|
8
|
+
private readonly context;
|
|
9
|
+
private readonly indexManager;
|
|
10
|
+
constructor(params: IOnBeforeTriggerParams);
|
|
11
|
+
run(targets: string[] | undefined): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.OnBeforeTrigger = void 0;
|
|
7
|
+
var _listIndexes = require("./listIndexes");
|
|
8
|
+
var _createIndex = require("./createIndex");
|
|
9
|
+
var _listCreateElasticsearchIndexTaskPlugin = require("./listCreateElasticsearchIndexTaskPlugin");
|
|
10
|
+
class OnBeforeTrigger {
|
|
11
|
+
constructor(params) {
|
|
12
|
+
this.context = params.context;
|
|
13
|
+
this.indexManager = params.indexManager;
|
|
14
|
+
}
|
|
15
|
+
async run(targets) {
|
|
16
|
+
const plugins = (0, _listCreateElasticsearchIndexTaskPlugin.listCreateElasticsearchIndexTaskPlugin)(this.context.plugins);
|
|
17
|
+
const tenant = this.context.tenancy.getCurrentTenant();
|
|
18
|
+
if (!tenant?.id) {
|
|
19
|
+
throw new Error("Something went wrong, tenant not found when triggering a task.");
|
|
20
|
+
}
|
|
21
|
+
const locale = this.context.i18n.getContentLocale();
|
|
22
|
+
if (!locale) {
|
|
23
|
+
throw new Error("Something went wrong, locale not found when triggering a task.");
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const allIndexes = await (0, _listIndexes.listIndexes)({
|
|
27
|
+
context: this.context,
|
|
28
|
+
plugins,
|
|
29
|
+
tenants: [tenant],
|
|
30
|
+
locales: [locale]
|
|
31
|
+
});
|
|
32
|
+
const indexes = allIndexes.filter(index => {
|
|
33
|
+
if (!targets?.length) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
for (const t of targets) {
|
|
37
|
+
if (index.index.includes(t)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
});
|
|
43
|
+
if (indexes.length === 0) {
|
|
44
|
+
console.warn("There are no indexes to create before triggering the Create indexes task.", {
|
|
45
|
+
targets
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const createIndex = (0, _createIndex.createIndexFactory)(this.indexManager);
|
|
50
|
+
for (const {
|
|
51
|
+
index,
|
|
52
|
+
settings
|
|
53
|
+
} of indexes) {
|
|
54
|
+
try {
|
|
55
|
+
console.log("Creating index", index);
|
|
56
|
+
await createIndex.createIfNotExists(index, settings);
|
|
57
|
+
} catch (ex) {
|
|
58
|
+
console.error(`Failed to create index "${index}".`, ex);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
} catch (ex) {
|
|
62
|
+
console.error(ex);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.OnBeforeTrigger = OnBeforeTrigger;
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=OnBeforeTrigger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_listIndexes","require","_createIndex","_listCreateElasticsearchIndexTaskPlugin","OnBeforeTrigger","constructor","params","context","indexManager","run","targets","plugins","listCreateElasticsearchIndexTaskPlugin","tenant","tenancy","getCurrentTenant","id","Error","locale","i18n","getContentLocale","allIndexes","listIndexes","tenants","locales","indexes","filter","index","length","t","includes","console","warn","createIndex","createIndexFactory","settings","log","createIfNotExists","ex","error","exports"],"sources":["OnBeforeTrigger.ts"],"sourcesContent":["import type { Context } from \"~/types\";\nimport type { IndexManager } from \"~/settings\";\nimport { listIndexes } from \"./listIndexes\";\nimport { createIndexFactory } from \"~/tasks/createIndexes/createIndex\";\nimport { listCreateElasticsearchIndexTaskPlugin } from \"~/tasks/createIndexes/listCreateElasticsearchIndexTaskPlugin\";\n\nexport interface IOnBeforeTriggerParams {\n indexManager: IndexManager;\n context: Context;\n}\n\nexport class OnBeforeTrigger {\n private readonly context: Context;\n private readonly indexManager: IndexManager;\n\n public constructor(params: IOnBeforeTriggerParams) {\n this.context = params.context;\n this.indexManager = params.indexManager;\n }\n\n public async run(targets: string[] | undefined): Promise<void> {\n const plugins = listCreateElasticsearchIndexTaskPlugin<Context>(this.context.plugins);\n\n const tenant = this.context.tenancy.getCurrentTenant();\n if (!tenant?.id) {\n throw new Error(\"Something went wrong, tenant not found when triggering a task.\");\n }\n const locale = this.context.i18n.getContentLocale();\n if (!locale) {\n throw new Error(\"Something went wrong, locale not found when triggering a task.\");\n }\n try {\n const allIndexes = await listIndexes({\n context: this.context,\n plugins,\n tenants: [tenant],\n locales: [locale]\n });\n const indexes = allIndexes.filter(index => {\n if (!targets?.length) {\n return true;\n }\n for (const t of targets) {\n if (index.index.includes(t)) {\n return true;\n }\n }\n return false;\n });\n if (indexes.length === 0) {\n console.warn(\n \"There are no indexes to create before triggering the Create indexes task.\",\n {\n targets\n }\n );\n return;\n }\n\n const createIndex = createIndexFactory(this.indexManager);\n\n for (const { index, settings } of indexes) {\n try {\n console.log(\"Creating index\", index);\n await createIndex.createIfNotExists(index, settings);\n } catch (ex) {\n console.error(`Failed to create index \"${index}\".`, ex);\n }\n }\n } catch (ex) {\n console.error(ex);\n }\n }\n}\n"],"mappings":";;;;;;AAEA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,uCAAA,GAAAF,OAAA;AAOO,MAAMG,eAAe,CAAC;EAIlBC,WAAWA,CAACC,MAA8B,EAAE;IAC/C,IAAI,CAACC,OAAO,GAAGD,MAAM,CAACC,OAAO;IAC7B,IAAI,CAACC,YAAY,GAAGF,MAAM,CAACE,YAAY;EAC3C;EAEA,MAAaC,GAAGA,CAACC,OAA6B,EAAiB;IAC3D,MAAMC,OAAO,GAAG,IAAAC,8EAAsC,EAAU,IAAI,CAACL,OAAO,CAACI,OAAO,CAAC;IAErF,MAAME,MAAM,GAAG,IAAI,CAACN,OAAO,CAACO,OAAO,CAACC,gBAAgB,CAAC,CAAC;IACtD,IAAI,CAACF,MAAM,EAAEG,EAAE,EAAE;MACb,MAAM,IAAIC,KAAK,CAAC,gEAAgE,CAAC;IACrF;IACA,MAAMC,MAAM,GAAG,IAAI,CAACX,OAAO,CAACY,IAAI,CAACC,gBAAgB,CAAC,CAAC;IACnD,IAAI,CAACF,MAAM,EAAE;MACT,MAAM,IAAID,KAAK,CAAC,gEAAgE,CAAC;IACrF;IACA,IAAI;MACA,MAAMI,UAAU,GAAG,MAAM,IAAAC,wBAAW,EAAC;QACjCf,OAAO,EAAE,IAAI,CAACA,OAAO;QACrBI,OAAO;QACPY,OAAO,EAAE,CAACV,MAAM,CAAC;QACjBW,OAAO,EAAE,CAACN,MAAM;MACpB,CAAC,CAAC;MACF,MAAMO,OAAO,GAAGJ,UAAU,CAACK,MAAM,CAACC,KAAK,IAAI;QACvC,IAAI,CAACjB,OAAO,EAAEkB,MAAM,EAAE;UAClB,OAAO,IAAI;QACf;QACA,KAAK,MAAMC,CAAC,IAAInB,OAAO,EAAE;UACrB,IAAIiB,KAAK,CAACA,KAAK,CAACG,QAAQ,CAACD,CAAC,CAAC,EAAE;YACzB,OAAO,IAAI;UACf;QACJ;QACA,OAAO,KAAK;MAChB,CAAC,CAAC;MACF,IAAIJ,OAAO,CAACG,MAAM,KAAK,CAAC,EAAE;QACtBG,OAAO,CAACC,IAAI,CACR,2EAA2E,EAC3E;UACItB;QACJ,CACJ,CAAC;QACD;MACJ;MAEA,MAAMuB,WAAW,GAAG,IAAAC,+BAAkB,EAAC,IAAI,CAAC1B,YAAY,CAAC;MAEzD,KAAK,MAAM;QAAEmB,KAAK;QAAEQ;MAAS,CAAC,IAAIV,OAAO,EAAE;QACvC,IAAI;UACAM,OAAO,CAACK,GAAG,CAAC,gBAAgB,EAAET,KAAK,CAAC;UACpC,MAAMM,WAAW,CAACI,iBAAiB,CAACV,KAAK,EAAEQ,QAAQ,CAAC;QACxD,CAAC,CAAC,OAAOG,EAAE,EAAE;UACTP,OAAO,CAACQ,KAAK,CAAC,2BAA2BZ,KAAK,IAAI,EAAEW,EAAE,CAAC;QAC3D;MACJ;IACJ,CAAC,CAAC,OAAOA,EAAE,EAAE;MACTP,OAAO,CAACQ,KAAK,CAACD,EAAE,CAAC;IACrB;EACJ;AACJ;AAACE,OAAA,CAAApC,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IndexManager } from "../../settings";
|
|
2
|
+
export declare const createIndexFactory: (manager: IndexManager) => {
|
|
3
|
+
create: (index: string, settings?: Record<string, any>) => Promise<void>;
|
|
4
|
+
createIfNotExists: (index: string, settings?: Record<string, any>) => Promise<void>;
|
|
5
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createIndexFactory = void 0;
|
|
7
|
+
const createIndexFactory = manager => {
|
|
8
|
+
return {
|
|
9
|
+
create: async (index, settings) => {
|
|
10
|
+
return manager.createIndex(index, settings);
|
|
11
|
+
},
|
|
12
|
+
createIfNotExists: async (index, settings) => {
|
|
13
|
+
try {
|
|
14
|
+
const exists = await manager.indexExists(index);
|
|
15
|
+
if (exists) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
} catch (ex) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
return await manager.createIndex(index, settings);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
exports.createIndexFactory = createIndexFactory;
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=createIndex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createIndexFactory","manager","create","index","settings","createIndex","createIfNotExists","exists","indexExists","ex","exports"],"sources":["createIndex.ts"],"sourcesContent":["import { IndexManager } from \"~/settings\";\n\nexport const createIndexFactory = (manager: IndexManager) => {\n return {\n create: async (index: string, settings?: Record<string, any>): Promise<void> => {\n return manager.createIndex(index, settings);\n },\n createIfNotExists: async (index: string, settings?: Record<string, any>): Promise<void> => {\n try {\n const exists = await manager.indexExists(index);\n if (exists) {\n return;\n }\n } catch (ex) {\n return;\n }\n\n return await manager.createIndex(index, settings);\n }\n };\n};\n"],"mappings":";;;;;;AAEO,MAAMA,kBAAkB,GAAIC,OAAqB,IAAK;EACzD,OAAO;IACHC,MAAM,EAAE,MAAAA,CAAOC,KAAa,EAAEC,QAA8B,KAAoB;MAC5E,OAAOH,OAAO,CAACI,WAAW,CAACF,KAAK,EAAEC,QAAQ,CAAC;IAC/C,CAAC;IACDE,iBAAiB,EAAE,MAAAA,CAAOH,KAAa,EAAEC,QAA8B,KAAoB;MACvF,IAAI;QACA,MAAMG,MAAM,GAAG,MAAMN,OAAO,CAACO,WAAW,CAACL,KAAK,CAAC;QAC/C,IAAII,MAAM,EAAE;UACR;QACJ;MACJ,CAAC,CAAC,OAAOE,EAAE,EAAE;QACT;MACJ;MAEA,OAAO,MAAMR,OAAO,CAACI,WAAW,CAACF,KAAK,EAAEC,QAAQ,CAAC;IACrD;EACJ,CAAC;AACL,CAAC;AAACM,OAAA,CAAAV,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -43,6 +43,23 @@ const createIndexesTaskDefinition = params => {
|
|
|
43
43
|
const indexManager = new IndexManager(manager.elasticsearch, {});
|
|
44
44
|
const createIndexesTaskRunner = new _CreateIndexesTaskRunner.CreateIndexesTaskRunner(manager, indexManager);
|
|
45
45
|
return createIndexesTaskRunner.execute(input.matching, Array.from(input.done || []));
|
|
46
|
+
},
|
|
47
|
+
async onBeforeTrigger({
|
|
48
|
+
context
|
|
49
|
+
}) {
|
|
50
|
+
// Let's create a new index for the tasks first.
|
|
51
|
+
const {
|
|
52
|
+
IndexManager
|
|
53
|
+
} = await import(/* webpackChunkName: "IndexManager" */"../../settings");
|
|
54
|
+
const indexManager = new IndexManager(context.elasticsearch, {});
|
|
55
|
+
const {
|
|
56
|
+
OnBeforeTrigger
|
|
57
|
+
} = await import(/* webpackChunkName: "OnBeforeTrigger" */"./OnBeforeTrigger");
|
|
58
|
+
const onBeforeTrigger = new OnBeforeTrigger({
|
|
59
|
+
indexManager,
|
|
60
|
+
context
|
|
61
|
+
});
|
|
62
|
+
await onBeforeTrigger.run(["webinytask"]);
|
|
46
63
|
}
|
|
47
64
|
});
|
|
48
65
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_tasks","require","_CreateIndexesTaskRunner","createIndexesTaskDefinition","params","createTaskDefinition","id","title","maxIterations","run","response","context","isCloseToTimeout","isAborted","store","input","timer","Manager","IndexManager","manager","elasticsearchClient","documentClient","indexManager","elasticsearch","createIndexesTaskRunner","CreateIndexesTaskRunner","execute","matching","Array","from","done","exports"],"sources":["index.ts"],"sourcesContent":["import { createTaskDefinition } from \"@webiny/tasks\";\nimport { Context, IElasticsearchTaskConfig } from \"~/types\";\nimport { IElasticsearchCreateIndexesTaskInput } from \"~/tasks/createIndexes/types\";\nimport { CreateIndexesTaskRunner } from \"./CreateIndexesTaskRunner\";\n\nexport const createIndexesTaskDefinition = (params?: IElasticsearchTaskConfig) => {\n return createTaskDefinition<Context, IElasticsearchCreateIndexesTaskInput>({\n id: \"elasticsearchCreateIndexes\",\n title: \"Create Missing Elasticsearch Indexes\",\n /**\n * Maximum number of iterations before the task goes into the error state.\n * No point in having more than 2 runs, as the create index operations should not even take 1 full run, no matter how much indeexs is there to create.\n */\n maxIterations: 2,\n run: async ({ response, context, isCloseToTimeout, isAborted, store, input, timer }) => {\n const { Manager } = await import(\n /* webpackChunkName: \"Manager\" */\n \"../Manager\"\n );\n const { IndexManager } = await import(\n /* webpackChunkName: \"IndexManager\" */ \"~/settings\"\n );\n\n const manager = new Manager<IElasticsearchCreateIndexesTaskInput>({\n elasticsearchClient: params?.elasticsearchClient,\n documentClient: params?.documentClient,\n response,\n context,\n isAborted,\n isCloseToTimeout,\n store,\n timer\n });\n\n const indexManager = new IndexManager(manager.elasticsearch, {});\n\n const createIndexesTaskRunner = new CreateIndexesTaskRunner(manager, indexManager);\n\n return createIndexesTaskRunner.execute(input.matching, Array.from(input.done || []));\n }\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,wBAAA,GAAAD,OAAA;AAEO,MAAME,2BAA2B,GAAIC,MAAiC,IAAK;EAC9E,OAAO,IAAAC,2BAAoB,EAAgD;IACvEC,EAAE,EAAE,4BAA4B;IAChCC,KAAK,EAAE,sCAAsC;IAC7C;AACR;AACA;AACA;IACQC,aAAa,EAAE,CAAC;IAChBC,GAAG,EAAE,MAAAA,CAAO;MAAEC,QAAQ;MAAEC,OAAO;MAAEC,gBAAgB;MAAEC,SAAS;MAAEC,KAAK;MAAEC,KAAK;MAAEC;IAAM,CAAC,KAAK;MACpF,MAAM;QAAEC;MAAQ,CAAC,GAAG,MAAM,MAAM,CAC5B,6CAEJ,CAAC;MACD,MAAM;QAAEC;MAAa,CAAC,GAAG,MAAM,MAAM,CACjC,sDACJ,CAAC;MAED,MAAMC,OAAO,GAAG,IAAIF,OAAO,CAAuC;QAC9DG,mBAAmB,EAAEhB,MAAM,EAAEgB,mBAAmB;QAChDC,cAAc,EAAEjB,MAAM,EAAEiB,cAAc;QACtCX,QAAQ;QACRC,OAAO;QACPE,SAAS;QACTD,gBAAgB;QAChBE,KAAK;QACLE;MACJ,CAAC,CAAC;MAEF,MAAMM,YAAY,GAAG,IAAIJ,YAAY,CAACC,OAAO,CAACI,aAAa,EAAE,CAAC,CAAC,CAAC;MAEhE,MAAMC,uBAAuB,GAAG,IAAIC,gDAAuB,CAACN,OAAO,EAAEG,YAAY,CAAC;MAElF,OAAOE,uBAAuB,CAACE,OAAO,CAACX,KAAK,CAACY,QAAQ,EAAEC,KAAK,CAACC,IAAI,CAACd,KAAK,CAACe,IAAI,IAAI,EAAE,CAAC,CAAC;IACxF;EACJ,CAAC,CAAC;AACN,CAAC;
|
|
1
|
+
{"version":3,"names":["_tasks","require","_CreateIndexesTaskRunner","createIndexesTaskDefinition","params","createTaskDefinition","id","title","maxIterations","run","response","context","isCloseToTimeout","isAborted","store","input","timer","Manager","IndexManager","manager","elasticsearchClient","documentClient","indexManager","elasticsearch","createIndexesTaskRunner","CreateIndexesTaskRunner","execute","matching","Array","from","done","onBeforeTrigger","OnBeforeTrigger","exports"],"sources":["index.ts"],"sourcesContent":["import { createTaskDefinition } from \"@webiny/tasks\";\nimport { Context, IElasticsearchTaskConfig } from \"~/types\";\nimport { IElasticsearchCreateIndexesTaskInput } from \"~/tasks/createIndexes/types\";\nimport { CreateIndexesTaskRunner } from \"./CreateIndexesTaskRunner\";\n\nexport const createIndexesTaskDefinition = (params?: IElasticsearchTaskConfig) => {\n return createTaskDefinition<Context, IElasticsearchCreateIndexesTaskInput>({\n id: \"elasticsearchCreateIndexes\",\n title: \"Create Missing Elasticsearch Indexes\",\n /**\n * Maximum number of iterations before the task goes into the error state.\n * No point in having more than 2 runs, as the create index operations should not even take 1 full run, no matter how much indeexs is there to create.\n */\n maxIterations: 2,\n run: async ({ response, context, isCloseToTimeout, isAborted, store, input, timer }) => {\n const { Manager } = await import(\n /* webpackChunkName: \"Manager\" */\n \"../Manager\"\n );\n const { IndexManager } = await import(\n /* webpackChunkName: \"IndexManager\" */ \"~/settings\"\n );\n\n const manager = new Manager<IElasticsearchCreateIndexesTaskInput>({\n elasticsearchClient: params?.elasticsearchClient,\n documentClient: params?.documentClient,\n response,\n context,\n isAborted,\n isCloseToTimeout,\n store,\n timer\n });\n\n const indexManager = new IndexManager(manager.elasticsearch, {});\n\n const createIndexesTaskRunner = new CreateIndexesTaskRunner(manager, indexManager);\n\n return createIndexesTaskRunner.execute(input.matching, Array.from(input.done || []));\n },\n async onBeforeTrigger({ context }) {\n // Let's create a new index for the tasks first.\n const { IndexManager } = await import(\n /* webpackChunkName: \"IndexManager\" */ \"~/settings\"\n );\n const indexManager = new IndexManager(context.elasticsearch, {});\n const { OnBeforeTrigger } = await import(\n /* webpackChunkName: \"OnBeforeTrigger\" */\n \"./OnBeforeTrigger\"\n );\n\n const onBeforeTrigger = new OnBeforeTrigger({\n indexManager,\n context\n });\n await onBeforeTrigger.run([\"webinytask\"]);\n }\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,wBAAA,GAAAD,OAAA;AAEO,MAAME,2BAA2B,GAAIC,MAAiC,IAAK;EAC9E,OAAO,IAAAC,2BAAoB,EAAgD;IACvEC,EAAE,EAAE,4BAA4B;IAChCC,KAAK,EAAE,sCAAsC;IAC7C;AACR;AACA;AACA;IACQC,aAAa,EAAE,CAAC;IAChBC,GAAG,EAAE,MAAAA,CAAO;MAAEC,QAAQ;MAAEC,OAAO;MAAEC,gBAAgB;MAAEC,SAAS;MAAEC,KAAK;MAAEC,KAAK;MAAEC;IAAM,CAAC,KAAK;MACpF,MAAM;QAAEC;MAAQ,CAAC,GAAG,MAAM,MAAM,CAC5B,6CAEJ,CAAC;MACD,MAAM;QAAEC;MAAa,CAAC,GAAG,MAAM,MAAM,CACjC,sDACJ,CAAC;MAED,MAAMC,OAAO,GAAG,IAAIF,OAAO,CAAuC;QAC9DG,mBAAmB,EAAEhB,MAAM,EAAEgB,mBAAmB;QAChDC,cAAc,EAAEjB,MAAM,EAAEiB,cAAc;QACtCX,QAAQ;QACRC,OAAO;QACPE,SAAS;QACTD,gBAAgB;QAChBE,KAAK;QACLE;MACJ,CAAC,CAAC;MAEF,MAAMM,YAAY,GAAG,IAAIJ,YAAY,CAACC,OAAO,CAACI,aAAa,EAAE,CAAC,CAAC,CAAC;MAEhE,MAAMC,uBAAuB,GAAG,IAAIC,gDAAuB,CAACN,OAAO,EAAEG,YAAY,CAAC;MAElF,OAAOE,uBAAuB,CAACE,OAAO,CAACX,KAAK,CAACY,QAAQ,EAAEC,KAAK,CAACC,IAAI,CAACd,KAAK,CAACe,IAAI,IAAI,EAAE,CAAC,CAAC;IACxF,CAAC;IACD,MAAMC,eAAeA,CAAC;MAAEpB;IAAQ,CAAC,EAAE;MAC/B;MACA,MAAM;QAAEO;MAAa,CAAC,GAAG,MAAM,MAAM,CACjC,sDACJ,CAAC;MACD,MAAMI,YAAY,GAAG,IAAIJ,YAAY,CAACP,OAAO,CAACY,aAAa,EAAE,CAAC,CAAC,CAAC;MAChE,MAAM;QAAES;MAAgB,CAAC,GAAG,MAAM,MAAM,CACpC,4DAEJ,CAAC;MAED,MAAMD,eAAe,GAAG,IAAIC,eAAe,CAAC;QACxCV,YAAY;QACZX;MACJ,CAAC,CAAC;MACF,MAAMoB,eAAe,CAACtB,GAAG,CAAC,CAAC,YAAY,CAAC,CAAC;IAC7C;EACJ,CAAC,CAAC;AACN,CAAC;AAACwB,OAAA,CAAA9B,2BAAA,GAAAA,2BAAA","ignoreList":[]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CreateElasticsearchIndexTaskPlugin } from "./CreateElasticsearchIndexTaskPlugin";
|
|
2
|
+
import type { Context } from "../../types";
|
|
3
|
+
import type { PluginsContainer } from "@webiny/plugins";
|
|
4
|
+
export declare const listCreateElasticsearchIndexTaskPlugin: <C extends Context = Context>(plugins: PluginsContainer) => CreateElasticsearchIndexTaskPlugin<C>[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.listCreateElasticsearchIndexTaskPlugin = void 0;
|
|
7
|
+
var _CreateElasticsearchIndexTaskPlugin = require("./CreateElasticsearchIndexTaskPlugin");
|
|
8
|
+
const listCreateElasticsearchIndexTaskPlugin = plugins => {
|
|
9
|
+
return plugins.byType(_CreateElasticsearchIndexTaskPlugin.CreateElasticsearchIndexTaskPlugin.type);
|
|
10
|
+
};
|
|
11
|
+
exports.listCreateElasticsearchIndexTaskPlugin = listCreateElasticsearchIndexTaskPlugin;
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=listCreateElasticsearchIndexTaskPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_CreateElasticsearchIndexTaskPlugin","require","listCreateElasticsearchIndexTaskPlugin","plugins","byType","CreateElasticsearchIndexTaskPlugin","type","exports"],"sources":["listCreateElasticsearchIndexTaskPlugin.ts"],"sourcesContent":["import { CreateElasticsearchIndexTaskPlugin } from \"~/tasks/createIndexes/CreateElasticsearchIndexTaskPlugin\";\nimport type { Context } from \"~/types\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\n\nexport const listCreateElasticsearchIndexTaskPlugin = <C extends Context = Context>(\n plugins: PluginsContainer\n): CreateElasticsearchIndexTaskPlugin<C>[] => {\n return plugins.byType<CreateElasticsearchIndexTaskPlugin<Context>>(\n CreateElasticsearchIndexTaskPlugin.type\n );\n};\n"],"mappings":";;;;;;AAAA,IAAAA,mCAAA,GAAAC,OAAA;AAIO,MAAMC,sCAAsC,GAC/CC,OAAyB,IACiB;EAC1C,OAAOA,OAAO,CAACC,MAAM,CACjBC,sEAAkC,CAACC,IACvC,CAAC;AACL,CAAC;AAACC,OAAA,CAAAL,sCAAA,GAAAA,sCAAA","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CreateElasticsearchIndexTaskPluginIndex } from "./CreateElasticsearchIndexTaskPlugin";
|
|
2
|
+
import { CreateElasticsearchIndexTaskPlugin } from "./CreateElasticsearchIndexTaskPlugin";
|
|
3
|
+
import type { Context } from "../../types";
|
|
4
|
+
import type { Tenant } from "@webiny/api-tenancy/types";
|
|
5
|
+
import { I18NLocale } from "@webiny/api-i18n/types";
|
|
6
|
+
export interface IListIndexesParams {
|
|
7
|
+
context: Context;
|
|
8
|
+
plugins: CreateElasticsearchIndexTaskPlugin<Context>[];
|
|
9
|
+
tenants?: Tenant[];
|
|
10
|
+
locales?: I18NLocale[];
|
|
11
|
+
}
|
|
12
|
+
export declare const listIndexes: (params: IListIndexesParams) => Promise<CreateElasticsearchIndexTaskPluginIndex[]>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.listIndexes = void 0;
|
|
7
|
+
const listIndexes = async params => {
|
|
8
|
+
const {
|
|
9
|
+
context,
|
|
10
|
+
plugins,
|
|
11
|
+
tenants: inputTenants,
|
|
12
|
+
locales: inputLocales
|
|
13
|
+
} = params;
|
|
14
|
+
if (plugins.length === 0) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
const indexes = [];
|
|
18
|
+
const tenants = inputTenants || (await context.tenancy.listTenants());
|
|
19
|
+
const initialTenant = context.tenancy.getCurrentTenant();
|
|
20
|
+
try {
|
|
21
|
+
for (const tenant of tenants) {
|
|
22
|
+
context.tenancy.setCurrentTenant(tenant);
|
|
23
|
+
let locales = inputLocales ? [...inputLocales] : [];
|
|
24
|
+
if (locales.length === 0) {
|
|
25
|
+
const [localesResult] = await context.i18n.locales.listLocales({
|
|
26
|
+
limit: 10000
|
|
27
|
+
});
|
|
28
|
+
locales = localesResult;
|
|
29
|
+
}
|
|
30
|
+
for (const locale of locales) {
|
|
31
|
+
for (const plugin of plugins) {
|
|
32
|
+
const results = await plugin.getIndexList({
|
|
33
|
+
context,
|
|
34
|
+
tenant: tenant.id,
|
|
35
|
+
locale: locale.code
|
|
36
|
+
});
|
|
37
|
+
for (const result of results) {
|
|
38
|
+
if (indexes.some(i => i.index === result.index)) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
indexes.push(result);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} finally {
|
|
47
|
+
context.tenancy.setCurrentTenant(initialTenant);
|
|
48
|
+
}
|
|
49
|
+
return indexes;
|
|
50
|
+
};
|
|
51
|
+
exports.listIndexes = listIndexes;
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=listIndexes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["listIndexes","params","context","plugins","tenants","inputTenants","locales","inputLocales","length","indexes","tenancy","listTenants","initialTenant","getCurrentTenant","tenant","setCurrentTenant","localesResult","i18n","listLocales","limit","locale","plugin","results","getIndexList","id","code","result","some","i","index","push","exports"],"sources":["listIndexes.ts"],"sourcesContent":["import type { CreateElasticsearchIndexTaskPluginIndex } from \"~/tasks/createIndexes/CreateElasticsearchIndexTaskPlugin\";\nimport { CreateElasticsearchIndexTaskPlugin } from \"~/tasks/createIndexes/CreateElasticsearchIndexTaskPlugin\";\nimport type { Context } from \"~/types\";\nimport type { Tenant } from \"@webiny/api-tenancy/types\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\n\nexport interface IListIndexesParams {\n context: Context;\n plugins: CreateElasticsearchIndexTaskPlugin<Context>[];\n tenants?: Tenant[];\n locales?: I18NLocale[];\n}\n\nexport const listIndexes = async (\n params: IListIndexesParams\n): Promise<CreateElasticsearchIndexTaskPluginIndex[]> => {\n const { context, plugins, tenants: inputTenants, locales: inputLocales } = params;\n if (plugins.length === 0) {\n return [];\n }\n\n const indexes: CreateElasticsearchIndexTaskPluginIndex[] = [];\n const tenants = inputTenants || (await context.tenancy.listTenants());\n const initialTenant = context.tenancy.getCurrentTenant();\n try {\n for (const tenant of tenants) {\n context.tenancy.setCurrentTenant(tenant);\n\n let locales = inputLocales ? [...inputLocales] : [];\n if (locales.length === 0) {\n const [localesResult] = await context.i18n.locales.listLocales({\n limit: 10000\n });\n locales = localesResult;\n }\n\n for (const locale of locales) {\n for (const plugin of plugins) {\n const results = await plugin.getIndexList({\n context,\n tenant: tenant.id,\n locale: locale.code\n });\n for (const result of results) {\n if (indexes.some(i => i.index === result.index)) {\n continue;\n }\n indexes.push(result);\n }\n }\n }\n }\n } finally {\n context.tenancy.setCurrentTenant(initialTenant);\n }\n\n return indexes;\n};\n"],"mappings":";;;;;;AAaO,MAAMA,WAAW,GAAG,MACvBC,MAA0B,IAC2B;EACrD,MAAM;IAAEC,OAAO;IAAEC,OAAO;IAAEC,OAAO,EAAEC,YAAY;IAAEC,OAAO,EAAEC;EAAa,CAAC,GAAGN,MAAM;EACjF,IAAIE,OAAO,CAACK,MAAM,KAAK,CAAC,EAAE;IACtB,OAAO,EAAE;EACb;EAEA,MAAMC,OAAkD,GAAG,EAAE;EAC7D,MAAML,OAAO,GAAGC,YAAY,KAAK,MAAMH,OAAO,CAACQ,OAAO,CAACC,WAAW,CAAC,CAAC,CAAC;EACrE,MAAMC,aAAa,GAAGV,OAAO,CAACQ,OAAO,CAACG,gBAAgB,CAAC,CAAC;EACxD,IAAI;IACA,KAAK,MAAMC,MAAM,IAAIV,OAAO,EAAE;MAC1BF,OAAO,CAACQ,OAAO,CAACK,gBAAgB,CAACD,MAAM,CAAC;MAExC,IAAIR,OAAO,GAAGC,YAAY,GAAG,CAAC,GAAGA,YAAY,CAAC,GAAG,EAAE;MACnD,IAAID,OAAO,CAACE,MAAM,KAAK,CAAC,EAAE;QACtB,MAAM,CAACQ,aAAa,CAAC,GAAG,MAAMd,OAAO,CAACe,IAAI,CAACX,OAAO,CAACY,WAAW,CAAC;UAC3DC,KAAK,EAAE;QACX,CAAC,CAAC;QACFb,OAAO,GAAGU,aAAa;MAC3B;MAEA,KAAK,MAAMI,MAAM,IAAId,OAAO,EAAE;QAC1B,KAAK,MAAMe,MAAM,IAAIlB,OAAO,EAAE;UAC1B,MAAMmB,OAAO,GAAG,MAAMD,MAAM,CAACE,YAAY,CAAC;YACtCrB,OAAO;YACPY,MAAM,EAAEA,MAAM,CAACU,EAAE;YACjBJ,MAAM,EAAEA,MAAM,CAACK;UACnB,CAAC,CAAC;UACF,KAAK,MAAMC,MAAM,IAAIJ,OAAO,EAAE;YAC1B,IAAIb,OAAO,CAACkB,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACC,KAAK,KAAKH,MAAM,CAACG,KAAK,CAAC,EAAE;cAC7C;YACJ;YACApB,OAAO,CAACqB,IAAI,CAACJ,MAAM,CAAC;UACxB;QACJ;MACJ;IACJ;EACJ,CAAC,SAAS;IACNxB,OAAO,CAACQ,OAAO,CAACK,gBAAgB,CAACH,aAAa,CAAC;EACnD;EAEA,OAAOH,OAAO;AAClB,CAAC;AAACsB,OAAA,CAAA/B,WAAA,GAAAA,WAAA","ignoreList":[]}
|
package/types.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { createTable } from "./definitions";
|
|
|
6
6
|
import type { BatchReadItem, IEntity } from "@webiny/db-dynamodb";
|
|
7
7
|
import type { ITimer } from "@webiny/handler-aws";
|
|
8
8
|
import type { GenericRecord } from "@webiny/api/types";
|
|
9
|
-
import { Context as LoggerContext } from "@webiny/api-log/types";
|
|
9
|
+
import type { Context as LoggerContext } from "@webiny/api-log/types";
|
|
10
10
|
export interface Context extends ElasticsearchContext, TasksContext, LoggerContext {
|
|
11
11
|
}
|
|
12
12
|
export interface IElasticsearchTaskConfig {
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { ElasticsearchContext } from \"@webiny/api-elasticsearch/types\";\nimport type {\n Context as TasksContext,\n IIsCloseToTimeoutCallable,\n ITaskManagerStore,\n ITaskResponse,\n ITaskResponseDoneResultOutput\n} from \"@webiny/tasks/types\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport type { Client } from \"@webiny/api-elasticsearch\";\nimport { createTable } from \"~/definitions\";\nimport type { BatchReadItem, IEntity } from \"@webiny/db-dynamodb\";\nimport type { ITimer } from \"@webiny/handler-aws\";\nimport type { GenericRecord } from \"@webiny/api/types\";\nimport { Context as LoggerContext } from \"@webiny/api-log/types\";\n\nexport interface Context extends ElasticsearchContext, TasksContext, LoggerContext {}\n\nexport interface IElasticsearchTaskConfig {\n documentClient?: DynamoDBDocument;\n elasticsearchClient?: Client;\n}\n\nexport interface IElasticsearchIndexingTaskValuesKeys {\n PK: string;\n SK: string;\n}\n\nexport interface IIndexSettingsValues {\n numberOfReplicas: number;\n refreshInterval: string;\n}\n\nexport interface IElasticsearchIndexingTaskValuesSettings {\n [key: string]: IIndexSettingsValues;\n}\n\nexport interface IElasticsearchIndexingTaskValues {\n matching?: string;\n limit?: number;\n keys?: IElasticsearchIndexingTaskValuesKeys;\n settings?: IElasticsearchIndexingTaskValuesSettings;\n}\n\nexport interface AugmentedError extends Error {\n data?: GenericRecord;\n [key: string]: any;\n}\n\nexport interface IDynamoDbElasticsearchRecord {\n PK: string;\n SK: string;\n TYPE?: string;\n index: string;\n _et?: string;\n entity: string;\n data: GenericRecord;\n modified: string;\n}\n\nexport interface IManager<\n T,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> {\n readonly documentClient: DynamoDBDocument;\n readonly elasticsearch: Client;\n readonly context: Context;\n readonly table: ReturnType<typeof createTable>;\n readonly isCloseToTimeout: IIsCloseToTimeoutCallable;\n readonly isAborted: () => boolean;\n readonly response: ITaskResponse<T, O>;\n readonly store: ITaskManagerStore<T>;\n readonly timer: ITimer;\n\n getEntity: (name: string) => IEntity;\n\n read<T>(items: BatchReadItem[]): Promise<T[]>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { ElasticsearchContext } from \"@webiny/api-elasticsearch/types\";\nimport type {\n Context as TasksContext,\n IIsCloseToTimeoutCallable,\n ITaskManagerStore,\n ITaskResponse,\n ITaskResponseDoneResultOutput\n} from \"@webiny/tasks/types\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport type { Client } from \"@webiny/api-elasticsearch\";\nimport { createTable } from \"~/definitions\";\nimport type { BatchReadItem, IEntity } from \"@webiny/db-dynamodb\";\nimport type { ITimer } from \"@webiny/handler-aws\";\nimport type { GenericRecord } from \"@webiny/api/types\";\nimport type { Context as LoggerContext } from \"@webiny/api-log/types\";\n\nexport interface Context extends ElasticsearchContext, TasksContext, LoggerContext {}\n\nexport interface IElasticsearchTaskConfig {\n documentClient?: DynamoDBDocument;\n elasticsearchClient?: Client;\n}\n\nexport interface IElasticsearchIndexingTaskValuesKeys {\n PK: string;\n SK: string;\n}\n\nexport interface IIndexSettingsValues {\n numberOfReplicas: number;\n refreshInterval: string;\n}\n\nexport interface IElasticsearchIndexingTaskValuesSettings {\n [key: string]: IIndexSettingsValues;\n}\n\nexport interface IElasticsearchIndexingTaskValues {\n matching?: string;\n limit?: number;\n keys?: IElasticsearchIndexingTaskValuesKeys;\n settings?: IElasticsearchIndexingTaskValuesSettings;\n}\n\nexport interface AugmentedError extends Error {\n data?: GenericRecord;\n [key: string]: any;\n}\n\nexport interface IDynamoDbElasticsearchRecord {\n PK: string;\n SK: string;\n TYPE?: string;\n index: string;\n _et?: string;\n entity: string;\n data: GenericRecord;\n modified: string;\n}\n\nexport interface IManager<\n T,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> {\n readonly documentClient: DynamoDBDocument;\n readonly elasticsearch: Client;\n readonly context: Context;\n readonly table: ReturnType<typeof createTable>;\n readonly isCloseToTimeout: IIsCloseToTimeoutCallable;\n readonly isAborted: () => boolean;\n readonly response: ITaskResponse<T, O>;\n readonly store: ITaskManagerStore<T>;\n readonly timer: ITimer;\n\n getEntity: (name: string) => IEntity;\n\n read<T>(items: BatchReadItem[]): Promise<T[]>;\n}\n"],"mappings":"","ignoreList":[]}
|