@webiny/api-headless-cms-ddb-es
Version:
DynamoDB and Elasticsearch storage operations plugin for Headless CMS API.
49 lines (47 loc) • 1.52 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.configurations = void 0;
var _error = _interopRequireDefault(require("@webiny/error"));
var _apiElasticsearch = require("@webiny/api-elasticsearch");
var _plugins = require("./plugins");
const configurations = exports.configurations = {
es({
model
}) {
const {
tenant,
locale
} = model;
if (!tenant) {
throw new _error.default(`Missing "tenant" parameter when trying to create Elasticsearch index name.`, "TENANT_ERROR");
} else if (!locale) {
throw new _error.default(`Missing "locale" parameter when trying to create Elasticsearch index name.`, "LOCALE_ERROR");
}
const sharedIndex = (0, _apiElasticsearch.isSharedElasticsearchIndex)();
const index = [sharedIndex ? "root" : tenant, "headless-cms", locale, model.modelId].join("-").toLowerCase();
const prefix = (0, _apiElasticsearch.getElasticsearchIndexPrefix)();
if (!prefix) {
return {
index
};
}
return {
index: prefix + index
};
},
indexSettings: ({
context,
model
}) => {
const plugin = (0, _apiElasticsearch.getLastAddedIndexPlugin)({
container: context.plugins,
type: _plugins.CmsEntryElasticsearchIndexPlugin.type,
locale: model.locale
});
return plugin ? plugin.body : {};
}
};
//# sourceMappingURL=configurations.js.map
;