@webiny/api-headless-cms-ddb-es 0.0.0-mt-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +35 -0
- package/configurations.d.ts +12 -0
- package/configurations.js +32 -0
- package/definitions/entry.d.ts +8 -0
- package/definitions/entry.js +91 -0
- package/definitions/entryElasticsearch.d.ts +8 -0
- package/definitions/entryElasticsearch.js +46 -0
- package/definitions/group.d.ts +8 -0
- package/definitions/group.js +74 -0
- package/definitions/model.d.ts +8 -0
- package/definitions/model.js +96 -0
- package/definitions/settings.d.ts +8 -0
- package/definitions/settings.js +62 -0
- package/definitions/system.d.ts +8 -0
- package/definitions/system.js +50 -0
- package/definitions/table.d.ts +8 -0
- package/definitions/table.js +24 -0
- package/definitions/tableElasticsearch.d.ts +8 -0
- package/definitions/tableElasticsearch.js +24 -0
- package/dynamoDb/index.d.ts +2 -0
- package/dynamoDb/index.js +18 -0
- package/dynamoDb/storage/date.d.ts +3 -0
- package/dynamoDb/storage/date.js +65 -0
- package/dynamoDb/storage/longText.d.ts +7 -0
- package/dynamoDb/storage/longText.js +83 -0
- package/dynamoDb/storage/richText.d.ts +8 -0
- package/dynamoDb/storage/richText.js +110 -0
- package/elasticsearch/index.d.ts +2 -0
- package/elasticsearch/index.js +16 -0
- package/elasticsearch/indexing/dateTimeIndexing.d.ts +3 -0
- package/elasticsearch/indexing/dateTimeIndexing.js +89 -0
- package/elasticsearch/indexing/defaultFieldIndexing.d.ts +3 -0
- package/elasticsearch/indexing/defaultFieldIndexing.js +47 -0
- package/elasticsearch/indexing/index.d.ts +2 -0
- package/elasticsearch/indexing/index.js +24 -0
- package/elasticsearch/indexing/longTextIndexing.d.ts +3 -0
- package/elasticsearch/indexing/longTextIndexing.js +36 -0
- package/elasticsearch/indexing/numberIndexing.d.ts +3 -0
- package/elasticsearch/indexing/numberIndexing.js +48 -0
- package/elasticsearch/indexing/objectIndexing.d.ts +3 -0
- package/elasticsearch/indexing/objectIndexing.js +200 -0
- package/elasticsearch/indexing/richTextIndexing.d.ts +3 -0
- package/elasticsearch/indexing/richTextIndexing.js +34 -0
- package/elasticsearch/search/index.d.ts +3 -0
- package/elasticsearch/search/index.js +16 -0
- package/elasticsearch/search/refSearch.d.ts +3 -0
- package/elasticsearch/search/refSearch.js +24 -0
- package/elasticsearch/search/timeSearch.d.ts +3 -0
- package/elasticsearch/search/timeSearch.js +25 -0
- package/helpers/createElasticsearchQueryBody.d.ts +11 -0
- package/helpers/createElasticsearchQueryBody.js +375 -0
- package/helpers/entryIndexHelpers.d.ts +18 -0
- package/helpers/entryIndexHelpers.js +189 -0
- package/helpers/fields.d.ts +77 -0
- package/helpers/fields.js +174 -0
- package/helpers/index.d.ts +2 -0
- package/helpers/index.js +31 -0
- package/helpers/operatorPluginsList.d.ts +7 -0
- package/helpers/operatorPluginsList.js +30 -0
- package/helpers/searchPluginsList.d.ts +6 -0
- package/helpers/searchPluginsList.js +26 -0
- package/helpers/transformValueForSearch.d.ts +9 -0
- package/helpers/transformValueForSearch.js +26 -0
- package/index.d.ts +2 -0
- package/index.js +171 -0
- package/operations/entry/dataLoaders.d.ts +47 -0
- package/operations/entry/dataLoaders.js +347 -0
- package/operations/entry/elasticsearchFields.d.ts +2 -0
- package/operations/entry/elasticsearchFields.js +32 -0
- package/operations/entry/fields.d.ts +3 -0
- package/operations/entry/fields.js +60 -0
- package/operations/entry/index.d.ts +13 -0
- package/operations/entry/index.js +1152 -0
- package/operations/entry/keys.d.ts +12 -0
- package/operations/entry/keys.js +40 -0
- package/operations/group/index.d.ts +8 -0
- package/operations/group/index.js +202 -0
- package/operations/model/index.d.ts +8 -0
- package/operations/model/index.js +205 -0
- package/operations/settings/index.d.ts +6 -0
- package/operations/settings/index.js +141 -0
- package/operations/system/createElasticsearchTemplate.d.ts +5 -0
- package/operations/system/createElasticsearchTemplate.js +62 -0
- package/operations/system/index.d.ts +6 -0
- package/operations/system/index.js +105 -0
- package/package.json +73 -0
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +17 -0
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +24 -0
- package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +12 -0
- package/plugins/CmsEntryElasticsearchFieldPlugin.js +24 -0
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +17 -0
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +24 -0
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +17 -0
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +24 -0
- package/types.d.ts +191 -0
- package/types.js +60 -0
- package/upgrades/index.d.ts +2 -0
- package/upgrades/index.js +16 -0
- package/upgrades/utils.d.ts +1 -0
- package/upgrades/utils.js +16 -0
- package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +6 -0
- package/upgrades/v5.0.0/cleanDatabaseRecord.js +16 -0
- package/upgrades/v5.0.0/createOldVersionIndiceName.d.ts +2 -0
- package/upgrades/v5.0.0/createOldVersionIndiceName.js +12 -0
- package/upgrades/v5.0.0/entryValueFixer.d.ts +4 -0
- package/upgrades/v5.0.0/entryValueFixer.js +124 -0
- package/upgrades/v5.0.0/fieldFinder.d.ts +6 -0
- package/upgrades/v5.0.0/fieldFinder.js +42 -0
- package/upgrades/v5.0.0/helpers.d.ts +4 -0
- package/upgrades/v5.0.0/helpers.js +57 -0
- package/upgrades/v5.0.0/index.d.ts +4 -0
- package/upgrades/v5.0.0/index.js +232 -0
- package/upgrades/v5.8.0/index.d.ts +4 -0
- package/upgrades/v5.8.0/index.js +426 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createOldVersionIndiceName = void 0;
|
|
7
|
+
|
|
8
|
+
const createOldVersionIndiceName = context => {
|
|
9
|
+
return `${context.tenancy.getCurrentTenant().id}-headless-cms`;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
exports.createOldVersionIndiceName = createOldVersionIndiceName;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ModelFieldFinder } from "./fieldFinder";
|
|
2
|
+
import { CmsIndexEntry } from "../../types";
|
|
3
|
+
import { CmsEntry, CmsModel } from "@webiny/api-headless-cms/types";
|
|
4
|
+
export declare const entryValueFixer: (_: CmsModel, finder: ModelFieldFinder, target: CmsIndexEntry) => CmsEntry;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.entryValueFixer = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _cleanDatabaseRecord = require("./cleanDatabaseRecord");
|
|
13
|
+
|
|
14
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
+
|
|
16
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
17
|
+
|
|
18
|
+
const convertTimeToNumber = time => {
|
|
19
|
+
if (!time) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const [hours, minutes, seconds = 0] = time.split(":").map(Number);
|
|
24
|
+
return hours * 60 * 60 + minutes * 60 + seconds;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const fixRawValues = (target, finder) => {
|
|
28
|
+
const entry = _objectSpread({}, target);
|
|
29
|
+
|
|
30
|
+
for (const fieldId in entry.rawValues) {
|
|
31
|
+
// if field is ref field then continue, otherwise break
|
|
32
|
+
const field = finder.findById(target.modelId, fieldId);
|
|
33
|
+
|
|
34
|
+
if (field.type !== "ref") {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const existingValue = entry.values[fieldId];
|
|
39
|
+
const rawValue = entry.rawValues[fieldId]; // always remove from rawValue
|
|
40
|
+
|
|
41
|
+
delete entry.rawValues[fieldId]; // if there is something in values - do not switch it
|
|
42
|
+
|
|
43
|
+
if (typeof existingValue !== "undefined" || rawValue === undefined || rawValue === null) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
entry.values[fieldId] = rawValue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return entry;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const fixTime = (field, time) => {
|
|
54
|
+
if (isNaN(time) === false) {
|
|
55
|
+
return parseInt(time);
|
|
56
|
+
} // lets not reinvent the wheel
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
return convertTimeToNumber(time);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
console.log(`fixTime on field "${field.fieldId}" failed`, err);
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const fixDateTime = (field, dateTime) => {
|
|
68
|
+
switch (field.settings.type) {
|
|
69
|
+
case "time":
|
|
70
|
+
return fixTime(field, dateTime);
|
|
71
|
+
|
|
72
|
+
case "date":
|
|
73
|
+
return new Date(dateTime).toISOString();
|
|
74
|
+
|
|
75
|
+
case "dateTimeWithoutTimezone":
|
|
76
|
+
return new Date(dateTime).toISOString();
|
|
77
|
+
|
|
78
|
+
default:
|
|
79
|
+
return dateTime;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const fixNumber = (_, value) => {
|
|
84
|
+
if (value === undefined || value === null) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return parseFloat(value);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const fieldFixMethods = {
|
|
92
|
+
datetime: fixDateTime,
|
|
93
|
+
number: fixNumber
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const fixFieldValues = (target, finder) => {
|
|
97
|
+
const entry = _objectSpread({}, target);
|
|
98
|
+
|
|
99
|
+
for (const fieldId in target.values) {
|
|
100
|
+
const field = finder.findById(target.modelId, fieldId);
|
|
101
|
+
|
|
102
|
+
if (!field) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const fixMethod = fieldFixMethods[field.type];
|
|
107
|
+
|
|
108
|
+
if (!fixMethod) {
|
|
109
|
+
continue;
|
|
110
|
+
} else if (target.values[fieldId] === null || target.values[fieldId] === undefined) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
target.values[fieldId] = fixMethod(field, target.values[fieldId]);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return entry;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const entryValueFixer = (_, finder, target) => {
|
|
121
|
+
return (0, _cleanDatabaseRecord.cleanDatabaseRecord)(fixFieldValues(fixRawValues(target, finder), finder));
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
exports.entryValueFixer = entryValueFixer;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CmsModel, CmsModelField } from "@webiny/api-headless-cms/types";
|
|
2
|
+
export interface ModelFieldFinder {
|
|
3
|
+
findById: (model: CmsModel | string, fieldId: string) => CmsModelField;
|
|
4
|
+
findByType: (model: CmsModel | string, type: string) => CmsModelField[];
|
|
5
|
+
}
|
|
6
|
+
export declare const createFieldFinder: (models: CmsModel[]) => ModelFieldFinder;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createFieldFinder = void 0;
|
|
7
|
+
|
|
8
|
+
const createFieldFinder = models => {
|
|
9
|
+
const modelsList = {};
|
|
10
|
+
|
|
11
|
+
for (const model of models) {
|
|
12
|
+
const values = {
|
|
13
|
+
id: {},
|
|
14
|
+
type: {}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
for (const field of model.fields) {
|
|
18
|
+
values.id[field.fieldId] = field;
|
|
19
|
+
|
|
20
|
+
if (!values.type[field.type]) {
|
|
21
|
+
values.type[field.type] = [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
values.type[field.type].push(field);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
modelsList[model.modelId] = values;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
findById: (model, fieldId) => {
|
|
32
|
+
const modelId = typeof model === "string" ? model : model.modelId;
|
|
33
|
+
return modelsList[modelId].id[fieldId];
|
|
34
|
+
},
|
|
35
|
+
findByType: (model, type) => {
|
|
36
|
+
const modelId = typeof model === "string" ? model : model.modelId;
|
|
37
|
+
return modelsList[modelId].type[type];
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
exports.createFieldFinder = createFieldFinder;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _cleanDatabaseRecord = require("./cleanDatabaseRecord");
|
|
8
|
+
|
|
9
|
+
Object.keys(_cleanDatabaseRecord).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _cleanDatabaseRecord[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _cleanDatabaseRecord[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
var _entryValueFixer = require("./entryValueFixer");
|
|
21
|
+
|
|
22
|
+
Object.keys(_entryValueFixer).forEach(function (key) {
|
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
|
24
|
+
if (key in exports && exports[key] === _entryValueFixer[key]) return;
|
|
25
|
+
Object.defineProperty(exports, key, {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _entryValueFixer[key];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
var _fieldFinder = require("./fieldFinder");
|
|
34
|
+
|
|
35
|
+
Object.keys(_fieldFinder).forEach(function (key) {
|
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (key in exports && exports[key] === _fieldFinder[key]) return;
|
|
38
|
+
Object.defineProperty(exports, key, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return _fieldFinder[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
var _createOldVersionIndiceName = require("./createOldVersionIndiceName");
|
|
47
|
+
|
|
48
|
+
Object.keys(_createOldVersionIndiceName).forEach(function (key) {
|
|
49
|
+
if (key === "default" || key === "__esModule") return;
|
|
50
|
+
if (key in exports && exports[key] === _createOldVersionIndiceName[key]) return;
|
|
51
|
+
Object.defineProperty(exports, key, {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return _createOldVersionIndiceName[key];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _helpers = require("./helpers");
|
|
15
|
+
|
|
16
|
+
var _utils = require("../utils");
|
|
17
|
+
|
|
18
|
+
var _configurations = _interopRequireDefault(require("../../configurations"));
|
|
19
|
+
|
|
20
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
+
|
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
23
|
+
|
|
24
|
+
const plugin = () => ({
|
|
25
|
+
name: "api-upgrade-cms-5.0.0",
|
|
26
|
+
type: "api-upgrade",
|
|
27
|
+
app: "headless-cms",
|
|
28
|
+
version: "5.0.0",
|
|
29
|
+
|
|
30
|
+
async apply(context) {
|
|
31
|
+
const {
|
|
32
|
+
db,
|
|
33
|
+
fileManager
|
|
34
|
+
} = context;
|
|
35
|
+
const elasticsearch = context.elasticsearch;
|
|
36
|
+
|
|
37
|
+
if (!elasticsearch) {
|
|
38
|
+
throw new _error.default("Missing Elasticsearch client on the context.");
|
|
39
|
+
} // Check if we still have the old elasticsearch index
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
const esIndex = (0, _helpers.createOldVersionIndiceName)(context);
|
|
43
|
+
const {
|
|
44
|
+
body: exists
|
|
45
|
+
} = await elasticsearch.indices.exists({
|
|
46
|
+
index: esIndex
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (!exists) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
await elasticsearch.indices.putTemplate({
|
|
55
|
+
name: "headless-cms-entries-index",
|
|
56
|
+
body: {
|
|
57
|
+
index_patterns: ["*headless-cms*"],
|
|
58
|
+
settings: {
|
|
59
|
+
analysis: {
|
|
60
|
+
analyzer: {
|
|
61
|
+
lowercase_analyzer: {
|
|
62
|
+
type: "custom",
|
|
63
|
+
filter: ["lowercase", "trim"],
|
|
64
|
+
tokenizer: "keyword"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
mappings: {
|
|
70
|
+
properties: {
|
|
71
|
+
property: {
|
|
72
|
+
type: "text",
|
|
73
|
+
fields: {
|
|
74
|
+
keyword: {
|
|
75
|
+
type: "keyword",
|
|
76
|
+
ignore_above: 256
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
analyzer: "lowercase_analyzer"
|
|
80
|
+
},
|
|
81
|
+
rawValues: {
|
|
82
|
+
type: "object",
|
|
83
|
+
enabled: false
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
} catch (err) {
|
|
90
|
+
console.log(err);
|
|
91
|
+
throw new _error.default("Put index template failed!");
|
|
92
|
+
} // Load existing ES items
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
let hasMoreItems = true;
|
|
96
|
+
let after = undefined;
|
|
97
|
+
const limit = 1000;
|
|
98
|
+
let esItems = []; // go through old index and load data in bulks of 1000
|
|
99
|
+
|
|
100
|
+
while (hasMoreItems) {
|
|
101
|
+
const response = await elasticsearch.search({
|
|
102
|
+
index: esIndex,
|
|
103
|
+
body: {
|
|
104
|
+
sort: {
|
|
105
|
+
createdOn: {
|
|
106
|
+
order: "asc",
|
|
107
|
+
// eslint-disable-next-line
|
|
108
|
+
unmapped_type: "date"
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
size: limit + 1,
|
|
112
|
+
after
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
const {
|
|
116
|
+
hits
|
|
117
|
+
} = response.body.hits;
|
|
118
|
+
hasMoreItems = hits.length > limit;
|
|
119
|
+
after = hasMoreItems ? hits[limit - 1].sort : undefined;
|
|
120
|
+
esItems = [...esItems, ...hits.filter(item => !item._id.includes("T#root#"))];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
console.log(`Fetched ${esItems.length} items from Elasticsearch`);
|
|
124
|
+
|
|
125
|
+
if (esItems.length === 0) {
|
|
126
|
+
return;
|
|
127
|
+
} // Store a backup of old items
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
const esJSON = JSON.stringify(esItems);
|
|
131
|
+
const {
|
|
132
|
+
file
|
|
133
|
+
} = await fileManager.storage.storagePlugin.upload({
|
|
134
|
+
name: "upgrade-headless-cms-es-5.0.0.json",
|
|
135
|
+
type: "application/json",
|
|
136
|
+
size: esJSON.length,
|
|
137
|
+
buffer: Buffer.from(esJSON)
|
|
138
|
+
});
|
|
139
|
+
console.log(`Stored backup of Elasticsearch items to ${file.key}`); // Load models for each locale and distribute ES items to new per-model indexes
|
|
140
|
+
|
|
141
|
+
const locales = context.i18n.getLocales();
|
|
142
|
+
const esOperations = [];
|
|
143
|
+
|
|
144
|
+
for (const locale of locales) {
|
|
145
|
+
const [models] = await db.read(_objectSpread(_objectSpread({}, _configurations.default.db()), {}, {
|
|
146
|
+
query: {
|
|
147
|
+
PK: `T#root#L#${locale.code}#CMS#CM`,
|
|
148
|
+
SK: {
|
|
149
|
+
$gt: " "
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
})); // Sleep for 2 seconds
|
|
153
|
+
|
|
154
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
155
|
+
const modelsById = models.reduce((acc, model) => {
|
|
156
|
+
acc[model.modelId] = model;
|
|
157
|
+
return acc;
|
|
158
|
+
}, {});
|
|
159
|
+
/**
|
|
160
|
+
* Build a list of items for ES DDB table
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
const ddbItems = esItems.filter(hit => {
|
|
164
|
+
return hit._source.locale === locale.code;
|
|
165
|
+
}).map(hit => {
|
|
166
|
+
const entry = hit._source;
|
|
167
|
+
const model = modelsById[entry.modelId];
|
|
168
|
+
|
|
169
|
+
if (!model) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const modelFieldFinder = (0, _helpers.createFieldFinder)(models);
|
|
174
|
+
const indexName = `root-headless-cms-${locale.code}-${model.modelId}`.toLowerCase();
|
|
175
|
+
const PK = `T#root#L#${locale.code}#CMS#CME#${entry.id.split("#")[0]}`;
|
|
176
|
+
const SK = entry.__type === "cms.entry.l" ? "L" : "P";
|
|
177
|
+
|
|
178
|
+
const esData = _objectSpread(_objectSpread({}, (0, _helpers.entryValueFixer)(model, modelFieldFinder, (0, _helpers.cleanDatabaseRecord)(entry))), {}, {
|
|
179
|
+
webinyVersion: "5.0.0"
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
esOperations.push({
|
|
183
|
+
index: {
|
|
184
|
+
_index: indexName,
|
|
185
|
+
_id: `${PK}:${SK}`
|
|
186
|
+
}
|
|
187
|
+
}, esData);
|
|
188
|
+
return {
|
|
189
|
+
PK,
|
|
190
|
+
SK,
|
|
191
|
+
index: indexName,
|
|
192
|
+
data: esData,
|
|
193
|
+
savedOn: new Date().toISOString(),
|
|
194
|
+
version: "5.0.0",
|
|
195
|
+
ignore: true
|
|
196
|
+
};
|
|
197
|
+
}).filter(Boolean);
|
|
198
|
+
console.log(`[${locale.code}] Prepared ${ddbItems.length} ES DDB items.`);
|
|
199
|
+
await (0, _utils.paginateBatch)(ddbItems, 25, async items => {
|
|
200
|
+
const batch = db.batch();
|
|
201
|
+
await batch.create(...items.map(item => {
|
|
202
|
+
return _objectSpread(_objectSpread({}, _configurations.default.esDb()), {}, {
|
|
203
|
+
data: item
|
|
204
|
+
});
|
|
205
|
+
})).execute();
|
|
206
|
+
});
|
|
207
|
+
console.log(`[${locale.code}] Inserted ES DDB items.`); // update all models to latest version
|
|
208
|
+
|
|
209
|
+
await (0, _utils.paginateBatch)(models, 25, async items => {
|
|
210
|
+
await db.batch().create(...items.map(model => {
|
|
211
|
+
return _objectSpread(_objectSpread({}, _configurations.default.db()), {}, {
|
|
212
|
+
data: _objectSpread(_objectSpread({}, model), {}, {
|
|
213
|
+
locale: locale.code,
|
|
214
|
+
webinyVersion: "5.0.0"
|
|
215
|
+
})
|
|
216
|
+
});
|
|
217
|
+
})).execute();
|
|
218
|
+
});
|
|
219
|
+
console.log(`[${locale.code}] Updated DDB model records with version number and locale code.`);
|
|
220
|
+
} // ES BULK INSERT
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
const bulkInsert = await elasticsearch.bulk({
|
|
224
|
+
body: esOperations
|
|
225
|
+
});
|
|
226
|
+
console.log("ES bulk index", bulkInsert);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
var _default = plugin;
|
|
232
|
+
exports.default = _default;
|