UNPKG

@webiny/api-headless-cms-ddb-es

Version:

DynamoDB and Elasticsearch storage operations plugin for Headless CMS API.

39 lines (38 loc) 1.01 kB
import WebinyError from "@webiny/error"; import { getOpenSearchIndexPrefix, isSharedOpenSearchIndex as isSharedElasticsearchIndex } from "@webiny/api-opensearch"; export const configurations = { es({ model }) { const { tenant } = model; if (!tenant) { throw new WebinyError(`Missing "tenant" parameter when trying to create Elasticsearch index name.`, "TENANT_ERROR"); } const sharedIndex = isSharedElasticsearchIndex(); const index = [sharedIndex ? "root" : tenant, "headless-cms", model.modelId].join("-").toLowerCase(); const prefix = getOpenSearchIndexPrefix(); if (!prefix) { return { index }; } return { index: prefix + index }; }, indexSettings: ({ indexConfigs, model }) => { const usable = indexConfigs.filter(c => c.canUse({ model })); if (usable.length === 0) { return {}; } return usable[usable.length - 1].body; } }; //# sourceMappingURL=configurations.js.map