@webiny/migrations 0.0.0-unstable.06b2ede40f
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/LICENSE +26 -0
- package/README.md +1 -0
- package/ddb-es.d.ts +2 -0
- package/ddb-es.js +17 -0
- package/ddb-es.js.map +1 -0
- package/ddb.d.ts +2 -0
- package/ddb.js +17 -0
- package/ddb.js.map +1 -0
- package/migrations/5.43.0/001/constants.d.ts +2 -0
- package/migrations/5.43.0/001/constants.js +10 -0
- package/migrations/5.43.0/001/constants.js.map +1 -0
- package/migrations/5.43.0/001/ddb/index.d.ts +13 -0
- package/migrations/5.43.0/001/ddb/index.js +215 -0
- package/migrations/5.43.0/001/ddb/index.js.map +1 -0
- package/migrations/5.43.0/001/ddb-es/index.d.ts +16 -0
- package/migrations/5.43.0/001/ddb-es/index.js +257 -0
- package/migrations/5.43.0/001/ddb-es/index.js.map +1 -0
- package/migrations/5.43.0/001/entities/createEntryEntity.d.ts +91 -0
- package/migrations/5.43.0/001/entities/createEntryEntity.js +188 -0
- package/migrations/5.43.0/001/entities/createEntryEntity.js.map +1 -0
- package/migrations/5.43.0/001/types.d.ts +47 -0
- package/migrations/5.43.0/001/types.js +7 -0
- package/migrations/5.43.0/001/types.js.map +1 -0
- package/package.json +36 -0
- package/utils/createEntity.d.ts +90 -0
- package/utils/createEntity.js +67 -0
- package/utils/createEntity.js.map +1 -0
- package/utils/createLocaleEntity.d.ts +42 -0
- package/utils/createLocaleEntity.js +32 -0
- package/utils/createLocaleEntity.js.map +1 -0
- package/utils/createTenantEntity.d.ts +48 -0
- package/utils/createTenantEntity.js +13 -0
- package/utils/createTenantEntity.js.map +1 -0
- package/utils/dynamoDb.d.ts +4 -0
- package/utils/dynamoDb.js +62 -0
- package/utils/dynamoDb.js.map +1 -0
- package/utils/elasticsearch/disableEsIndexing.d.ts +9 -0
- package/utils/elasticsearch/disableEsIndexing.js +33 -0
- package/utils/elasticsearch/disableEsIndexing.js.map +1 -0
- package/utils/elasticsearch/esCreateIndex.d.ts +9 -0
- package/utils/elasticsearch/esCreateIndex.js +62 -0
- package/utils/elasticsearch/esCreateIndex.js.map +1 -0
- package/utils/elasticsearch/esFindOne.d.ts +8 -0
- package/utils/elasticsearch/esFindOne.js +27 -0
- package/utils/elasticsearch/esFindOne.js.map +1 -0
- package/utils/elasticsearch/esGetIndexExist.d.ts +9 -0
- package/utils/elasticsearch/esGetIndexExist.js +37 -0
- package/utils/elasticsearch/esGetIndexExist.js.map +1 -0
- package/utils/elasticsearch/esGetIndexName.d.ts +7 -0
- package/utils/elasticsearch/esGetIndexName.js +41 -0
- package/utils/elasticsearch/esGetIndexName.js.map +1 -0
- package/utils/elasticsearch/esGetIndexSettings.d.ts +7 -0
- package/utils/elasticsearch/esGetIndexSettings.js +32 -0
- package/utils/elasticsearch/esGetIndexSettings.js.map +1 -0
- package/utils/elasticsearch/esListIndexes.d.ts +6 -0
- package/utils/elasticsearch/esListIndexes.js +23 -0
- package/utils/elasticsearch/esListIndexes.js.map +1 -0
- package/utils/elasticsearch/esPutIndexSettings.d.ts +7 -0
- package/utils/elasticsearch/esPutIndexSettings.js +30 -0
- package/utils/elasticsearch/esPutIndexSettings.js.map +1 -0
- package/utils/elasticsearch/esQueryAll.d.ts +8 -0
- package/utils/elasticsearch/esQueryAll.js +26 -0
- package/utils/elasticsearch/esQueryAll.js.map +1 -0
- package/utils/elasticsearch/esQueryAllWithCallback.d.ts +10 -0
- package/utils/elasticsearch/esQueryAllWithCallback.js +45 -0
- package/utils/elasticsearch/esQueryAllWithCallback.js.map +1 -0
- package/utils/elasticsearch/fetchOriginalEsSettings.d.ts +12 -0
- package/utils/elasticsearch/fetchOriginalEsSettings.js +35 -0
- package/utils/elasticsearch/fetchOriginalEsSettings.js.map +1 -0
- package/utils/elasticsearch/index.d.ts +12 -0
- package/utils/elasticsearch/index.js +139 -0
- package/utils/elasticsearch/index.js.map +1 -0
- package/utils/elasticsearch/plugins/base.d.ts +3 -0
- package/utils/elasticsearch/plugins/base.js +12 -0
- package/utils/elasticsearch/plugins/base.js.map +1 -0
- package/utils/elasticsearch/plugins/index.d.ts +6 -0
- package/utils/elasticsearch/plugins/index.js +14 -0
- package/utils/elasticsearch/plugins/index.js.map +1 -0
- package/utils/elasticsearch/plugins/japanese.d.ts +4 -0
- package/utils/elasticsearch/plugins/japanese.js +13 -0
- package/utils/elasticsearch/plugins/japanese.js.map +1 -0
- package/utils/elasticsearch/restoreOriginalEsSettings.d.ts +14 -0
- package/utils/elasticsearch/restoreOriginalEsSettings.js +52 -0
- package/utils/elasticsearch/restoreOriginalEsSettings.js.map +1 -0
- package/utils/forEachTenantLocale.d.ts +22 -0
- package/utils/forEachTenantLocale.js +55 -0
- package/utils/forEachTenantLocale.js.map +1 -0
- package/utils/getCompressedData.d.ts +4 -0
- package/utils/getCompressedData.js +19 -0
- package/utils/getCompressedData.js.map +1 -0
- package/utils/index.d.ts +7 -0
- package/utils/index.js +84 -0
- package/utils/index.js.map +1 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createLocaleEntity = void 0;
|
|
7
|
+
var _ = require("./");
|
|
8
|
+
const createLocaleEntity = table => {
|
|
9
|
+
return (0, _.createLegacyEntity)(table, "I18NLocale", {
|
|
10
|
+
createdOn: {
|
|
11
|
+
type: "string"
|
|
12
|
+
},
|
|
13
|
+
createdBy: {
|
|
14
|
+
type: "map"
|
|
15
|
+
},
|
|
16
|
+
code: {
|
|
17
|
+
type: "string"
|
|
18
|
+
},
|
|
19
|
+
default: {
|
|
20
|
+
type: "boolean"
|
|
21
|
+
},
|
|
22
|
+
webinyVersion: {
|
|
23
|
+
type: "string"
|
|
24
|
+
},
|
|
25
|
+
tenant: {
|
|
26
|
+
type: "string"
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
exports.createLocaleEntity = createLocaleEntity;
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=createLocaleEntity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_","require","createLocaleEntity","table","createLegacyEntity","createdOn","type","createdBy","code","default","webinyVersion","tenant","exports"],"sources":["createLocaleEntity.ts"],"sourcesContent":["import type { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { createLegacyEntity } from \"~/utils\";\n\nexport const createLocaleEntity = (table: Table<string, string, string>) => {\n return createLegacyEntity(table, \"I18NLocale\", {\n createdOn: {\n type: \"string\"\n },\n createdBy: {\n type: \"map\"\n },\n code: {\n type: \"string\"\n },\n default: {\n type: \"boolean\"\n },\n webinyVersion: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n }\n });\n};\n"],"mappings":";;;;;;AACA,IAAAA,CAAA,GAAAC,OAAA;AAEO,MAAMC,kBAAkB,GAAIC,KAAoC,IAAK;EACxE,OAAO,IAAAC,oBAAkB,EAACD,KAAK,EAAE,YAAY,EAAE;IAC3CE,SAAS,EAAE;MACPC,IAAI,EAAE;IACV,CAAC;IACDC,SAAS,EAAE;MACPD,IAAI,EAAE;IACV,CAAC;IACDE,IAAI,EAAE;MACFF,IAAI,EAAE;IACV,CAAC;IACDG,OAAO,EAAE;MACLH,IAAI,EAAE;IACV,CAAC;IACDI,aAAa,EAAE;MACXJ,IAAI,EAAE;IACV,CAAC;IACDK,MAAM,EAAE;MACJL,IAAI,EAAE;IACV;EACJ,CAAC,CAAC;AACN,CAAC;AAACM,OAAA,CAAAV,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Table } from "@webiny/db-dynamodb/toolbox";
|
|
2
|
+
export declare const createTenantEntity: (table: Table<string, string, string>) => import("dynamodb-toolbox/dist/cjs/classes/Entity/Entity").default<string, import("dynamodb-toolbox/dist/cjs/classes/Entity").Overlay, import("dynamodb-toolbox/dist/cjs/classes/Entity").Overlay, Table<string, string, string>, true, true, boolean, string, string, string, boolean, {
|
|
3
|
+
PK: {
|
|
4
|
+
partitionKey: true;
|
|
5
|
+
};
|
|
6
|
+
SK: {
|
|
7
|
+
sortKey: true;
|
|
8
|
+
};
|
|
9
|
+
GSI1_PK: {
|
|
10
|
+
type: "string";
|
|
11
|
+
};
|
|
12
|
+
GSI1_SK: {
|
|
13
|
+
type: "string";
|
|
14
|
+
};
|
|
15
|
+
TYPE: {
|
|
16
|
+
type: "string";
|
|
17
|
+
};
|
|
18
|
+
data: {
|
|
19
|
+
type: "map";
|
|
20
|
+
};
|
|
21
|
+
}, {
|
|
22
|
+
PK: {
|
|
23
|
+
partitionKey: true;
|
|
24
|
+
};
|
|
25
|
+
SK: {
|
|
26
|
+
sortKey: true;
|
|
27
|
+
};
|
|
28
|
+
GSI1_PK: {
|
|
29
|
+
type: "string";
|
|
30
|
+
};
|
|
31
|
+
GSI1_SK: {
|
|
32
|
+
type: "string";
|
|
33
|
+
};
|
|
34
|
+
TYPE: {
|
|
35
|
+
type: "string";
|
|
36
|
+
};
|
|
37
|
+
data: {
|
|
38
|
+
type: "map";
|
|
39
|
+
};
|
|
40
|
+
}, import("dynamodb-toolbox/dist/cjs/classes/Entity").ParsedAttributes<import("ts-toolbelt/out/Any/Key").Key>, any, {
|
|
41
|
+
[x: string]: any;
|
|
42
|
+
[x: number]: any;
|
|
43
|
+
[x: symbol]: any;
|
|
44
|
+
}, {
|
|
45
|
+
[x: string]: any;
|
|
46
|
+
[x: number]: any;
|
|
47
|
+
[x: symbol]: any;
|
|
48
|
+
}>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createTenantEntity = void 0;
|
|
7
|
+
var _ = require("./");
|
|
8
|
+
const createTenantEntity = table => {
|
|
9
|
+
return (0, _.createStandardEntity)(table, "TenancyTenant");
|
|
10
|
+
};
|
|
11
|
+
exports.createTenantEntity = createTenantEntity;
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=createTenantEntity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_","require","createTenantEntity","table","createStandardEntity","exports"],"sources":["createTenantEntity.ts"],"sourcesContent":["import type { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { createStandardEntity } from \"~/utils\";\n\nexport const createTenantEntity = (table: Table<string, string, string>) => {\n return createStandardEntity(table, \"TenancyTenant\");\n};\n"],"mappings":";;;;;;AACA,IAAAA,CAAA,GAAAC,OAAA;AAEO,MAAMC,kBAAkB,GAAIC,KAAoC,IAAK;EACxE,OAAO,IAAAC,sBAAoB,EAACD,KAAK,EAAE,eAAe,CAAC;AACvD,CAAC;AAACE,OAAA,CAAAH,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BatchReadItem, BatchReadParams, BatchWriteItem, BatchWriteParams, GetRecordParams, ScanParams, ScanResponse } from "@webiny/db-dynamodb/utils";
|
|
2
|
+
import { batchReadAll, batchWriteAll, get, count, queryAll, queryAllWithCallback as ddbQueryAllWithCallback, queryOne, scan, scanWithCallback as ddbScanWithCallback } from "@webiny/db-dynamodb/utils";
|
|
3
|
+
export { count, get, queryAll, ddbQueryAllWithCallback, queryOne, batchReadAll, batchWriteAll, scan, ddbScanWithCallback };
|
|
4
|
+
export type { GetRecordParams, BatchWriteItem, BatchWriteParams, BatchReadItem, BatchReadParams, ScanParams, ScanResponse };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "batchReadAll", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _utils.batchReadAll;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "batchWriteAll", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _utils.batchWriteAll;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "count", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _utils.count;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "ddbQueryAllWithCallback", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _utils.queryAllWithCallback;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "ddbScanWithCallback", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _utils.scanWithCallback;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "get", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _utils.get;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "queryAll", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _utils.queryAll;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "queryOne", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _utils.queryOne;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "scan", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _utils.scan;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
var _utils = require("@webiny/db-dynamodb/utils");
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=dynamoDb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_utils","require"],"sources":["dynamoDb.ts"],"sourcesContent":["import type {\n BatchReadItem,\n BatchReadParams,\n BatchWriteItem,\n BatchWriteParams,\n GetRecordParams,\n ScanParams,\n ScanResponse\n} from \"@webiny/db-dynamodb/utils\";\nimport {\n batchReadAll,\n batchWriteAll,\n get,\n count,\n queryAll,\n queryAllWithCallback as ddbQueryAllWithCallback,\n queryOne,\n scan,\n scanWithCallback as ddbScanWithCallback\n} from \"@webiny/db-dynamodb/utils\";\n\nexport {\n count,\n get,\n queryAll,\n ddbQueryAllWithCallback,\n queryOne,\n batchReadAll,\n batchWriteAll,\n scan,\n ddbScanWithCallback\n};\nexport type {\n GetRecordParams,\n BatchWriteItem,\n BatchWriteParams,\n BatchReadItem,\n BatchReadParams,\n ScanParams,\n ScanResponse\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,IAAAA,MAAA,GAAAC,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Logger } from "@webiny/data-migration";
|
|
2
|
+
import type { Client } from "@elastic/elasticsearch";
|
|
3
|
+
interface DisableElasticsearchIndexingParams {
|
|
4
|
+
index: string;
|
|
5
|
+
logger: Logger;
|
|
6
|
+
elasticsearchClient: Client;
|
|
7
|
+
}
|
|
8
|
+
export declare const disableElasticsearchIndexing: (params: DisableElasticsearchIndexingParams) => Promise<void>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.disableElasticsearchIndexing = void 0;
|
|
7
|
+
var _ = require("./..");
|
|
8
|
+
const disableElasticsearchIndexing = async params => {
|
|
9
|
+
const {
|
|
10
|
+
index,
|
|
11
|
+
logger
|
|
12
|
+
} = params;
|
|
13
|
+
try {
|
|
14
|
+
await (0, _.esPutIndexSettings)({
|
|
15
|
+
elasticsearchClient: params.elasticsearchClient,
|
|
16
|
+
index,
|
|
17
|
+
settings: {
|
|
18
|
+
refresh_interval: -1
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
} catch (ex) {
|
|
22
|
+
logger.error(`Failed to disable indexing for index "${index}".`);
|
|
23
|
+
logger.error({
|
|
24
|
+
...ex,
|
|
25
|
+
message: ex.message,
|
|
26
|
+
code: ex.code,
|
|
27
|
+
data: ex.data
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.disableElasticsearchIndexing = disableElasticsearchIndexing;
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=disableEsIndexing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_","require","disableElasticsearchIndexing","params","index","logger","esPutIndexSettings","elasticsearchClient","settings","refresh_interval","ex","error","message","code","data","exports"],"sources":["disableEsIndexing.ts"],"sourcesContent":["import { esPutIndexSettings } from \"~/utils\";\nimport type { Logger } from \"@webiny/data-migration\";\nimport type { Client } from \"@elastic/elasticsearch\";\n\ninterface DisableElasticsearchIndexingParams {\n index: string;\n logger: Logger;\n elasticsearchClient: Client;\n}\n\nexport const disableElasticsearchIndexing = async (\n params: DisableElasticsearchIndexingParams\n): Promise<void> => {\n const { index, logger } = params;\n\n try {\n await esPutIndexSettings({\n elasticsearchClient: params.elasticsearchClient,\n index,\n settings: {\n refresh_interval: -1\n }\n });\n } catch (ex) {\n logger.error(`Failed to disable indexing for index \"${index}\".`);\n logger.error({\n ...ex,\n message: ex.message,\n code: ex.code,\n data: ex.data\n });\n }\n};\n"],"mappings":";;;;;;AAAA,IAAAA,CAAA,GAAAC,OAAA;AAUO,MAAMC,4BAA4B,GAAG,MACxCC,MAA0C,IAC1B;EAChB,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGF,MAAM;EAEhC,IAAI;IACA,MAAM,IAAAG,oBAAkB,EAAC;MACrBC,mBAAmB,EAAEJ,MAAM,CAACI,mBAAmB;MAC/CH,KAAK;MACLI,QAAQ,EAAE;QACNC,gBAAgB,EAAE,CAAC;MACvB;IACJ,CAAC,CAAC;EACN,CAAC,CAAC,OAAOC,EAAE,EAAE;IACTL,MAAM,CAACM,KAAK,CAAC,yCAAyCP,KAAK,IAAI,CAAC;IAChEC,MAAM,CAACM,KAAK,CAAC;MACT,GAAGD,EAAE;MACLE,OAAO,EAAEF,EAAE,CAACE,OAAO;MACnBC,IAAI,EAAEH,EAAE,CAACG,IAAI;MACbC,IAAI,EAAEJ,EAAE,CAACI;IACb,CAAC,CAAC;EACN;AACJ,CAAC;AAACC,OAAA,CAAAb,4BAAA,GAAAA,4BAAA","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Client } from "@elastic/elasticsearch";
|
|
2
|
+
export interface EsCreateIndexParams {
|
|
3
|
+
elasticsearchClient: Client;
|
|
4
|
+
tenant: string;
|
|
5
|
+
locale: string;
|
|
6
|
+
type: string;
|
|
7
|
+
isHeadlessCmsModel: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const esCreateIndex: (params: EsCreateIndexParams) => Promise<string>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.esCreateIndex = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _ = require("./..");
|
|
10
|
+
var _plugins = require("./plugins");
|
|
11
|
+
const esCreateIndex = async params => {
|
|
12
|
+
const {
|
|
13
|
+
elasticsearchClient,
|
|
14
|
+
tenant,
|
|
15
|
+
locale,
|
|
16
|
+
type,
|
|
17
|
+
isHeadlessCmsModel
|
|
18
|
+
} = params;
|
|
19
|
+
const indexName = (0, _.esGetIndexName)({
|
|
20
|
+
tenant,
|
|
21
|
+
locale,
|
|
22
|
+
type,
|
|
23
|
+
isHeadlessCmsModel
|
|
24
|
+
});
|
|
25
|
+
try {
|
|
26
|
+
const exist = await (0, _.esGetIndexExist)(params);
|
|
27
|
+
if (exist) {
|
|
28
|
+
return indexName;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Get registered plugins
|
|
32
|
+
const plugin = (0, _plugins.elasticsearchIndexPlugins)().filter(plugin => {
|
|
33
|
+
if (!plugin.locales) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return plugin.locales.includes(locale.toLowerCase());
|
|
37
|
+
}).pop();
|
|
38
|
+
await elasticsearchClient.indices.create({
|
|
39
|
+
index: indexName,
|
|
40
|
+
...(plugin && {
|
|
41
|
+
body: plugin.body
|
|
42
|
+
})
|
|
43
|
+
});
|
|
44
|
+
return indexName;
|
|
45
|
+
} catch (ex) {
|
|
46
|
+
// Despite the fact the above `esGetIndexExist` check told us the index does not exist,
|
|
47
|
+
// we've seen cases where the `resource_already_exists_exception` would still be thrown
|
|
48
|
+
// upon index creation. That's why we're doing an additional check of the error message.
|
|
49
|
+
if (ex.message === "resource_already_exists_exception") {
|
|
50
|
+
return indexName;
|
|
51
|
+
}
|
|
52
|
+
throw new _error.default(ex.message || "Could not create Elasticsearch index.", ex.code || "CREATE_ELASTICSEARCH_INDEX_ERROR", {
|
|
53
|
+
error: ex,
|
|
54
|
+
locale,
|
|
55
|
+
tenant,
|
|
56
|
+
type
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.esCreateIndex = esCreateIndex;
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=esCreateIndex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_","_plugins","esCreateIndex","params","elasticsearchClient","tenant","locale","type","isHeadlessCmsModel","indexName","esGetIndexName","exist","esGetIndexExist","plugin","elasticsearchIndexPlugins","filter","locales","includes","toLowerCase","pop","indices","create","index","body","ex","message","WebinyError","code","error","exports"],"sources":["esCreateIndex.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { Client } from \"@elastic/elasticsearch\";\nimport { esGetIndexName, esGetIndexExist } from \"~/utils\";\nimport { elasticsearchIndexPlugins } from \"~/utils/elasticsearch/plugins\";\n\nexport interface EsCreateIndexParams {\n elasticsearchClient: Client;\n tenant: string;\n locale: string;\n type: string;\n isHeadlessCmsModel: boolean;\n}\n\nexport const esCreateIndex = async (params: EsCreateIndexParams): Promise<string> => {\n const { elasticsearchClient, tenant, locale, type, isHeadlessCmsModel } = params;\n\n const indexName = esGetIndexName({ tenant, locale, type, isHeadlessCmsModel });\n\n try {\n const exist = await esGetIndexExist(params);\n\n if (exist) {\n return indexName;\n }\n\n // Get registered plugins\n const plugin = elasticsearchIndexPlugins()\n .filter(plugin => {\n if (!plugin.locales) {\n return true;\n }\n\n return plugin.locales.includes(locale.toLowerCase());\n })\n .pop();\n\n await elasticsearchClient.indices.create({\n index: indexName,\n ...(plugin && { body: plugin.body })\n });\n return indexName;\n } catch (ex) {\n // Despite the fact the above `esGetIndexExist` check told us the index does not exist,\n // we've seen cases where the `resource_already_exists_exception` would still be thrown\n // upon index creation. That's why we're doing an additional check of the error message.\n if (ex.message === \"resource_already_exists_exception\") {\n return indexName;\n }\n\n throw new WebinyError(\n ex.message || \"Could not create Elasticsearch index.\",\n ex.code || \"CREATE_ELASTICSEARCH_INDEX_ERROR\",\n {\n error: ex,\n locale,\n tenant,\n type\n }\n );\n }\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,CAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAUO,MAAMG,aAAa,GAAG,MAAOC,MAA2B,IAAsB;EACjF,MAAM;IAAEC,mBAAmB;IAAEC,MAAM;IAAEC,MAAM;IAAEC,IAAI;IAAEC;EAAmB,CAAC,GAAGL,MAAM;EAEhF,MAAMM,SAAS,GAAG,IAAAC,gBAAc,EAAC;IAAEL,MAAM;IAAEC,MAAM;IAAEC,IAAI;IAAEC;EAAmB,CAAC,CAAC;EAE9E,IAAI;IACA,MAAMG,KAAK,GAAG,MAAM,IAAAC,iBAAe,EAACT,MAAM,CAAC;IAE3C,IAAIQ,KAAK,EAAE;MACP,OAAOF,SAAS;IACpB;;IAEA;IACA,MAAMI,MAAM,GAAG,IAAAC,kCAAyB,EAAC,CAAC,CACrCC,MAAM,CAACF,MAAM,IAAI;MACd,IAAI,CAACA,MAAM,CAACG,OAAO,EAAE;QACjB,OAAO,IAAI;MACf;MAEA,OAAOH,MAAM,CAACG,OAAO,CAACC,QAAQ,CAACX,MAAM,CAACY,WAAW,CAAC,CAAC,CAAC;IACxD,CAAC,CAAC,CACDC,GAAG,CAAC,CAAC;IAEV,MAAMf,mBAAmB,CAACgB,OAAO,CAACC,MAAM,CAAC;MACrCC,KAAK,EAAEb,SAAS;MAChB,IAAII,MAAM,IAAI;QAAEU,IAAI,EAAEV,MAAM,CAACU;MAAK,CAAC;IACvC,CAAC,CAAC;IACF,OAAOd,SAAS;EACpB,CAAC,CAAC,OAAOe,EAAE,EAAE;IACT;IACA;IACA;IACA,IAAIA,EAAE,CAACC,OAAO,KAAK,mCAAmC,EAAE;MACpD,OAAOhB,SAAS;IACpB;IAEA,MAAM,IAAIiB,cAAW,CACjBF,EAAE,CAACC,OAAO,IAAI,uCAAuC,EACrDD,EAAE,CAACG,IAAI,IAAI,kCAAkC,EAC7C;MACIC,KAAK,EAAEJ,EAAE;MACTlB,MAAM;MACND,MAAM;MACNE;IACJ,CACJ,CAAC;EACL;AACJ,CAAC;AAACsB,OAAA,CAAA3B,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Client } from "@elastic/elasticsearch";
|
|
2
|
+
import type { SearchBody } from "@webiny/api-elasticsearch/types";
|
|
3
|
+
export interface EsFindOneParams {
|
|
4
|
+
elasticsearchClient: Client;
|
|
5
|
+
index: string;
|
|
6
|
+
body: Omit<SearchBody, "size">;
|
|
7
|
+
}
|
|
8
|
+
export declare const esFindOne: <TItem>({ elasticsearchClient, body, index }: EsFindOneParams) => Promise<TItem | null>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.esFindOne = void 0;
|
|
7
|
+
const esFindOne = async ({
|
|
8
|
+
elasticsearchClient,
|
|
9
|
+
body,
|
|
10
|
+
index
|
|
11
|
+
}) => {
|
|
12
|
+
const response = await elasticsearchClient.search({
|
|
13
|
+
index,
|
|
14
|
+
body: {
|
|
15
|
+
...body,
|
|
16
|
+
size: 1
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const hits = response.body.hits;
|
|
20
|
+
if (hits.hits.length <= 0) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return hits.hits[0]._source;
|
|
24
|
+
};
|
|
25
|
+
exports.esFindOne = esFindOne;
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=esFindOne.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["esFindOne","elasticsearchClient","body","index","response","search","size","hits","length","_source","exports"],"sources":["esFindOne.ts"],"sourcesContent":["import type { Client } from \"@elastic/elasticsearch\";\nimport type { SearchBody, ElasticsearchSearchResponse } from \"@webiny/api-elasticsearch/types\";\n\nexport interface EsFindOneParams {\n elasticsearchClient: Client;\n index: string;\n body: Omit<SearchBody, \"size\">;\n}\n\nexport const esFindOne = async <TItem>({ elasticsearchClient, body, index }: EsFindOneParams) => {\n const response: ElasticsearchSearchResponse<TItem> = await elasticsearchClient.search({\n index,\n body: {\n ...body,\n size: 1\n }\n });\n\n const hits = response.body.hits;\n\n if (hits.hits.length <= 0) {\n return null;\n }\n\n return hits.hits[0]._source;\n};\n"],"mappings":";;;;;;AASO,MAAMA,SAAS,GAAG,MAAAA,CAAc;EAAEC,mBAAmB;EAAEC,IAAI;EAAEC;AAAuB,CAAC,KAAK;EAC7F,MAAMC,QAA4C,GAAG,MAAMH,mBAAmB,CAACI,MAAM,CAAC;IAClFF,KAAK;IACLD,IAAI,EAAE;MACF,GAAGA,IAAI;MACPI,IAAI,EAAE;IACV;EACJ,CAAC,CAAC;EAEF,MAAMC,IAAI,GAAGH,QAAQ,CAACF,IAAI,CAACK,IAAI;EAE/B,IAAIA,IAAI,CAACA,IAAI,CAACC,MAAM,IAAI,CAAC,EAAE;IACvB,OAAO,IAAI;EACf;EAEA,OAAOD,IAAI,CAACA,IAAI,CAAC,CAAC,CAAC,CAACE,OAAO;AAC/B,CAAC;AAACC,OAAA,CAAAV,SAAA,GAAAA,SAAA","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Client } from "@elastic/elasticsearch";
|
|
2
|
+
export interface GetIndexExistParams {
|
|
3
|
+
elasticsearchClient: Client;
|
|
4
|
+
tenant: string;
|
|
5
|
+
locale: string;
|
|
6
|
+
type: string;
|
|
7
|
+
isHeadlessCmsModel?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const esGetIndexExist: (params: GetIndexExistParams) => Promise<boolean>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.esGetIndexExist = void 0;
|
|
7
|
+
var _ = require("./..");
|
|
8
|
+
const esGetIndexExist = async params => {
|
|
9
|
+
const {
|
|
10
|
+
elasticsearchClient,
|
|
11
|
+
tenant,
|
|
12
|
+
locale,
|
|
13
|
+
type,
|
|
14
|
+
isHeadlessCmsModel
|
|
15
|
+
} = params;
|
|
16
|
+
try {
|
|
17
|
+
const index = (0, _.esGetIndexName)({
|
|
18
|
+
tenant,
|
|
19
|
+
locale,
|
|
20
|
+
type,
|
|
21
|
+
isHeadlessCmsModel
|
|
22
|
+
});
|
|
23
|
+
const response = await elasticsearchClient.indices.exists({
|
|
24
|
+
index
|
|
25
|
+
});
|
|
26
|
+
if (response.body) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
} catch (ex) {
|
|
31
|
+
console.warn(`Could not find Elasticsearch index:`, ex.message);
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.esGetIndexExist = esGetIndexExist;
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=esGetIndexExist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_","require","esGetIndexExist","params","elasticsearchClient","tenant","locale","type","isHeadlessCmsModel","index","esGetIndexName","response","indices","exists","body","ex","console","warn","message","exports"],"sources":["esGetIndexExist.ts"],"sourcesContent":["import type { Client } from \"@elastic/elasticsearch\";\nimport { esGetIndexName } from \"~/utils\";\n\nexport interface GetIndexExistParams {\n elasticsearchClient: Client;\n tenant: string;\n locale: string;\n type: string;\n isHeadlessCmsModel?: boolean;\n}\n\nexport const esGetIndexExist = async (params: GetIndexExistParams) => {\n const { elasticsearchClient, tenant, locale, type, isHeadlessCmsModel } = params;\n\n try {\n const index = esGetIndexName({ tenant, locale, type, isHeadlessCmsModel });\n\n const response = await elasticsearchClient.indices.exists({\n index\n });\n\n if (response.body) {\n return true;\n }\n\n return false;\n } catch (ex) {\n console.warn(`Could not find Elasticsearch index:`, ex.message);\n return false;\n }\n};\n"],"mappings":";;;;;;AACA,IAAAA,CAAA,GAAAC,OAAA;AAUO,MAAMC,eAAe,GAAG,MAAOC,MAA2B,IAAK;EAClE,MAAM;IAAEC,mBAAmB;IAAEC,MAAM;IAAEC,MAAM;IAAEC,IAAI;IAAEC;EAAmB,CAAC,GAAGL,MAAM;EAEhF,IAAI;IACA,MAAMM,KAAK,GAAG,IAAAC,gBAAc,EAAC;MAAEL,MAAM;MAAEC,MAAM;MAAEC,IAAI;MAAEC;IAAmB,CAAC,CAAC;IAE1E,MAAMG,QAAQ,GAAG,MAAMP,mBAAmB,CAACQ,OAAO,CAACC,MAAM,CAAC;MACtDJ;IACJ,CAAC,CAAC;IAEF,IAAIE,QAAQ,CAACG,IAAI,EAAE;MACf,OAAO,IAAI;IACf;IAEA,OAAO,KAAK;EAChB,CAAC,CAAC,OAAOC,EAAE,EAAE;IACTC,OAAO,CAACC,IAAI,CAAC,qCAAqC,EAAEF,EAAE,CAACG,OAAO,CAAC;IAC/D,OAAO,KAAK;EAChB;AACJ,CAAC;AAACC,OAAA,CAAAjB,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.esGetIndexName = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
10
|
+
const esGetIndexName = params => {
|
|
11
|
+
const {
|
|
12
|
+
tenant,
|
|
13
|
+
locale,
|
|
14
|
+
type,
|
|
15
|
+
isHeadlessCmsModel
|
|
16
|
+
} = params;
|
|
17
|
+
if (!type) {
|
|
18
|
+
throw new _error.default(`Missing "type" parameter when trying to create Elasticsearch index name.`, "INDEX_TYPE_ERROR");
|
|
19
|
+
}
|
|
20
|
+
if (!tenant) {
|
|
21
|
+
throw new _error.default(`Missing "tenant" parameter when trying to create Elasticsearch index name.`, "TENANT_ERROR");
|
|
22
|
+
}
|
|
23
|
+
const sharedIndex = (0, _apiElasticsearch.isSharedElasticsearchIndex)();
|
|
24
|
+
const tenantId = sharedIndex ? "root" : tenant;
|
|
25
|
+
let localeCode = null;
|
|
26
|
+
if (isHeadlessCmsModel || process.env.WEBINY_ELASTICSEARCH_INDEX_LOCALE === "true") {
|
|
27
|
+
if (!locale) {
|
|
28
|
+
throw new _error.default(`Missing "locale" parameter when trying to create Elasticsearch index name.`, "LOCALE_ERROR");
|
|
29
|
+
}
|
|
30
|
+
localeCode = locale;
|
|
31
|
+
}
|
|
32
|
+
const index = [tenantId, isHeadlessCmsModel && "headless-cms", localeCode, type].filter(Boolean).join("-").toLowerCase();
|
|
33
|
+
const prefix = (0, _apiElasticsearch.getElasticsearchIndexPrefix)();
|
|
34
|
+
if (!prefix) {
|
|
35
|
+
return index;
|
|
36
|
+
}
|
|
37
|
+
return prefix + index;
|
|
38
|
+
};
|
|
39
|
+
exports.esGetIndexName = esGetIndexName;
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=esGetIndexName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_apiElasticsearch","esGetIndexName","params","tenant","locale","type","isHeadlessCmsModel","WebinyError","sharedIndex","isSharedElasticsearchIndex","tenantId","localeCode","process","env","WEBINY_ELASTICSEARCH_INDEX_LOCALE","index","filter","Boolean","join","toLowerCase","prefix","getElasticsearchIndexPrefix","exports"],"sources":["esGetIndexName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { getElasticsearchIndexPrefix, isSharedElasticsearchIndex } from \"@webiny/api-elasticsearch\";\n\nexport interface EsGetIndexNameParams {\n tenant: string;\n locale: string;\n type: string;\n isHeadlessCmsModel?: boolean;\n}\n\nexport const esGetIndexName = (params: EsGetIndexNameParams) => {\n const { tenant, locale, type, isHeadlessCmsModel } = params;\n\n if (!type) {\n throw new WebinyError(\n `Missing \"type\" parameter when trying to create Elasticsearch index name.`,\n \"INDEX_TYPE_ERROR\"\n );\n }\n\n if (!tenant) {\n throw new WebinyError(\n `Missing \"tenant\" parameter when trying to create Elasticsearch index name.`,\n \"TENANT_ERROR\"\n );\n }\n\n const sharedIndex = isSharedElasticsearchIndex();\n\n const tenantId = sharedIndex ? \"root\" : tenant;\n let localeCode: string | null = null;\n if (isHeadlessCmsModel || process.env.WEBINY_ELASTICSEARCH_INDEX_LOCALE === \"true\") {\n if (!locale) {\n throw new WebinyError(\n `Missing \"locale\" parameter when trying to create Elasticsearch index name.`,\n \"LOCALE_ERROR\"\n );\n }\n localeCode = locale;\n }\n\n const index = [tenantId, isHeadlessCmsModel && \"headless-cms\", localeCode, type]\n .filter(Boolean)\n .join(\"-\")\n .toLowerCase();\n\n const prefix = getElasticsearchIndexPrefix();\n if (!prefix) {\n return index;\n }\n return prefix + index;\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AASO,MAAME,cAAc,GAAIC,MAA4B,IAAK;EAC5D,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC,IAAI;IAAEC;EAAmB,CAAC,GAAGJ,MAAM;EAE3D,IAAI,CAACG,IAAI,EAAE;IACP,MAAM,IAAIE,cAAW,CACjB,0EAA0E,EAC1E,kBACJ,CAAC;EACL;EAEA,IAAI,CAACJ,MAAM,EAAE;IACT,MAAM,IAAII,cAAW,CACjB,4EAA4E,EAC5E,cACJ,CAAC;EACL;EAEA,MAAMC,WAAW,GAAG,IAAAC,4CAA0B,EAAC,CAAC;EAEhD,MAAMC,QAAQ,GAAGF,WAAW,GAAG,MAAM,GAAGL,MAAM;EAC9C,IAAIQ,UAAyB,GAAG,IAAI;EACpC,IAAIL,kBAAkB,IAAIM,OAAO,CAACC,GAAG,CAACC,iCAAiC,KAAK,MAAM,EAAE;IAChF,IAAI,CAACV,MAAM,EAAE;MACT,MAAM,IAAIG,cAAW,CACjB,4EAA4E,EAC5E,cACJ,CAAC;IACL;IACAI,UAAU,GAAGP,MAAM;EACvB;EAEA,MAAMW,KAAK,GAAG,CAACL,QAAQ,EAAEJ,kBAAkB,IAAI,cAAc,EAAEK,UAAU,EAAEN,IAAI,CAAC,CAC3EW,MAAM,CAACC,OAAO,CAAC,CACfC,IAAI,CAAC,GAAG,CAAC,CACTC,WAAW,CAAC,CAAC;EAElB,MAAMC,MAAM,GAAG,IAAAC,6CAA2B,EAAC,CAAC;EAC5C,IAAI,CAACD,MAAM,EAAE;IACT,OAAOL,KAAK;EAChB;EACA,OAAOK,MAAM,GAAGL,KAAK;AACzB,CAAC;AAACO,OAAA,CAAArB,cAAA,GAAAA,cAAA","ignoreList":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Client } from "@elastic/elasticsearch";
|
|
2
|
+
export interface GetIndexSettingsParams {
|
|
3
|
+
elasticsearchClient: Client;
|
|
4
|
+
index: string;
|
|
5
|
+
fields: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare const esGetIndexSettings: (params: GetIndexSettingsParams) => Promise<Pick<any, string>>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.esGetIndexSettings = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _pick = _interopRequireDefault(require("lodash/pick"));
|
|
10
|
+
const esGetIndexSettings = async params => {
|
|
11
|
+
const {
|
|
12
|
+
elasticsearchClient,
|
|
13
|
+
index,
|
|
14
|
+
fields
|
|
15
|
+
} = params;
|
|
16
|
+
try {
|
|
17
|
+
const response = await elasticsearchClient.indices.getSettings({
|
|
18
|
+
index
|
|
19
|
+
});
|
|
20
|
+
const settings = response.body[index].settings.index;
|
|
21
|
+
return (0, _pick.default)(settings, fields);
|
|
22
|
+
} catch (ex) {
|
|
23
|
+
throw new _error.default(ex.message || "Could not get Elasticsearch index settings.", ex.code || "GET_ELASTICSEARCH_INDEX_SETTINGS_ERROR", {
|
|
24
|
+
error: ex,
|
|
25
|
+
index,
|
|
26
|
+
fields
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.esGetIndexSettings = esGetIndexSettings;
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=esGetIndexSettings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_pick","esGetIndexSettings","params","elasticsearchClient","index","fields","response","indices","getSettings","settings","body","pick","ex","WebinyError","message","code","error","exports"],"sources":["esGetIndexSettings.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { Client } from \"@elastic/elasticsearch\";\nimport pick from \"lodash/pick\";\n\nexport interface GetIndexSettingsParams {\n elasticsearchClient: Client;\n index: string;\n fields: string[];\n}\n\nexport const esGetIndexSettings = async (params: GetIndexSettingsParams) => {\n const { elasticsearchClient, index, fields } = params;\n\n try {\n const response = await elasticsearchClient.indices.getSettings({\n index\n });\n\n const settings = response.body[index].settings.index;\n\n return pick(settings, fields);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get Elasticsearch index settings.\",\n ex.code || \"GET_ELASTICSEARCH_INDEX_SETTINGS_ERROR\",\n {\n error: ex,\n index,\n fields\n }\n );\n }\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AAQO,MAAME,kBAAkB,GAAG,MAAOC,MAA8B,IAAK;EACxE,MAAM;IAAEC,mBAAmB;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGH,MAAM;EAErD,IAAI;IACA,MAAMI,QAAQ,GAAG,MAAMH,mBAAmB,CAACI,OAAO,CAACC,WAAW,CAAC;MAC3DJ;IACJ,CAAC,CAAC;IAEF,MAAMK,QAAQ,GAAGH,QAAQ,CAACI,IAAI,CAACN,KAAK,CAAC,CAACK,QAAQ,CAACL,KAAK;IAEpD,OAAO,IAAAO,aAAI,EAACF,QAAQ,EAAEJ,MAAM,CAAC;EACjC,CAAC,CAAC,OAAOO,EAAE,EAAE;IACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,6CAA6C,EAC3DF,EAAE,CAACG,IAAI,IAAI,wCAAwC,EACnD;MACIC,KAAK,EAAEJ,EAAE;MACTR,KAAK;MACLC;IACJ,CACJ,CAAC;EACL;AACJ,CAAC;AAACY,OAAA,CAAAhB,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.esListIndexes = void 0;
|
|
7
|
+
const esListIndexes = async params => {
|
|
8
|
+
const {
|
|
9
|
+
elasticsearchClient
|
|
10
|
+
} = params;
|
|
11
|
+
const response = await elasticsearchClient.cat.indices({
|
|
12
|
+
format: "json"
|
|
13
|
+
});
|
|
14
|
+
const listOfIndexes = response.body.map(item => item.index);
|
|
15
|
+
const match = params.match;
|
|
16
|
+
if (match) {
|
|
17
|
+
return listOfIndexes.filter(index => index.includes(match));
|
|
18
|
+
}
|
|
19
|
+
return listOfIndexes;
|
|
20
|
+
};
|
|
21
|
+
exports.esListIndexes = esListIndexes;
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=esListIndexes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["esListIndexes","params","elasticsearchClient","response","cat","indices","format","listOfIndexes","body","map","item","index","match","filter","includes","exports"],"sources":["esListIndexes.ts"],"sourcesContent":["import type { Client } from \"@elastic/elasticsearch\";\n\nexport interface ListIndexesParams {\n elasticsearchClient: Client;\n match?: string;\n}\n\ntype IndicesApiResponse = Array<Record<string, string>>;\n\nexport const esListIndexes = async (params: ListIndexesParams): Promise<string[]> => {\n const { elasticsearchClient } = params;\n\n const response = await elasticsearchClient.cat.indices<IndicesApiResponse>({\n format: \"json\"\n });\n\n const listOfIndexes = response.body.map(item => item.index);\n\n const match = params.match;\n if (match) {\n return listOfIndexes.filter(index => index.includes(match));\n }\n\n return listOfIndexes;\n};\n"],"mappings":";;;;;;AASO,MAAMA,aAAa,GAAG,MAAOC,MAAyB,IAAwB;EACjF,MAAM;IAAEC;EAAoB,CAAC,GAAGD,MAAM;EAEtC,MAAME,QAAQ,GAAG,MAAMD,mBAAmB,CAACE,GAAG,CAACC,OAAO,CAAqB;IACvEC,MAAM,EAAE;EACZ,CAAC,CAAC;EAEF,MAAMC,aAAa,GAAGJ,QAAQ,CAACK,IAAI,CAACC,GAAG,CAACC,IAAI,IAAIA,IAAI,CAACC,KAAK,CAAC;EAE3D,MAAMC,KAAK,GAAGX,MAAM,CAACW,KAAK;EAC1B,IAAIA,KAAK,EAAE;IACP,OAAOL,aAAa,CAACM,MAAM,CAACF,KAAK,IAAIA,KAAK,CAACG,QAAQ,CAACF,KAAK,CAAC,CAAC;EAC/D;EAEA,OAAOL,aAAa;AACxB,CAAC;AAACQ,OAAA,CAAAf,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Client } from "@elastic/elasticsearch";
|
|
2
|
+
export interface PutIndexSettingsParams {
|
|
3
|
+
elasticsearchClient: Client;
|
|
4
|
+
index: string;
|
|
5
|
+
settings: Record<string, any>;
|
|
6
|
+
}
|
|
7
|
+
export declare const esPutIndexSettings: (params: PutIndexSettingsParams) => Promise<void>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.esPutIndexSettings = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
const esPutIndexSettings = async params => {
|
|
10
|
+
const {
|
|
11
|
+
elasticsearchClient,
|
|
12
|
+
index,
|
|
13
|
+
settings
|
|
14
|
+
} = params;
|
|
15
|
+
try {
|
|
16
|
+
await elasticsearchClient.indices.putSettings({
|
|
17
|
+
index,
|
|
18
|
+
body: settings
|
|
19
|
+
});
|
|
20
|
+
} catch (ex) {
|
|
21
|
+
throw new _error.default(ex.message || "Could not put Elasticsearch index settings.", ex.code || "PUT_ELASTICSEARCH_INDEX_SETTINGS_ERROR", {
|
|
22
|
+
error: ex,
|
|
23
|
+
index,
|
|
24
|
+
settings
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.esPutIndexSettings = esPutIndexSettings;
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=esPutIndexSettings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","esPutIndexSettings","params","elasticsearchClient","index","settings","indices","putSettings","body","ex","WebinyError","message","code","error","exports"],"sources":["esPutIndexSettings.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { Client } from \"@elastic/elasticsearch\";\n\nexport interface PutIndexSettingsParams {\n elasticsearchClient: Client;\n index: string;\n settings: Record<string, any>;\n}\n\nexport const esPutIndexSettings = async (params: PutIndexSettingsParams) => {\n const { elasticsearchClient, index, settings } = params;\n\n try {\n await elasticsearchClient.indices.putSettings({\n index,\n body: settings\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not put Elasticsearch index settings.\",\n ex.code || \"PUT_ELASTICSEARCH_INDEX_SETTINGS_ERROR\",\n {\n error: ex,\n index,\n settings\n }\n );\n }\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AASO,MAAMC,kBAAkB,GAAG,MAAOC,MAA8B,IAAK;EACxE,MAAM;IAAEC,mBAAmB;IAAEC,KAAK;IAAEC;EAAS,CAAC,GAAGH,MAAM;EAEvD,IAAI;IACA,MAAMC,mBAAmB,CAACG,OAAO,CAACC,WAAW,CAAC;MAC1CH,KAAK;MACLI,IAAI,EAAEH;IACV,CAAC,CAAC;EACN,CAAC,CAAC,OAAOI,EAAE,EAAE;IACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,6CAA6C,EAC3DF,EAAE,CAACG,IAAI,IAAI,wCAAwC,EACnD;MACIC,KAAK,EAAEJ,EAAE;MACTL,KAAK;MACLC;IACJ,CACJ,CAAC;EACL;AACJ,CAAC;AAACS,OAAA,CAAAb,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Client } from "@elastic/elasticsearch";
|
|
2
|
+
import type { SearchBody } from "@webiny/api-elasticsearch/types";
|
|
3
|
+
export interface EsQueryAllParams {
|
|
4
|
+
elasticsearchClient: Client;
|
|
5
|
+
index: string;
|
|
6
|
+
body: SearchBody;
|
|
7
|
+
}
|
|
8
|
+
export declare const esQueryAll: <TItem>({ elasticsearchClient, body, index }: EsQueryAllParams) => Promise<TItem[]>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.esQueryAll = void 0;
|
|
7
|
+
var _utils = require("@webiny/utils");
|
|
8
|
+
const esQueryAll = async ({
|
|
9
|
+
elasticsearchClient,
|
|
10
|
+
body,
|
|
11
|
+
index
|
|
12
|
+
}) => {
|
|
13
|
+
const search = async () => {
|
|
14
|
+
return elasticsearchClient.search({
|
|
15
|
+
index,
|
|
16
|
+
body
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
const response = await (0, _utils.executeWithRetry)(search);
|
|
20
|
+
return response.body.hits.hits.map(item => {
|
|
21
|
+
return item._source;
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
exports.esQueryAll = esQueryAll;
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=esQueryAll.js.map
|