UNPKG

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

Version:

DynamoDB and Elasticsearch storage operations plugin for Headless CMS API.

52 lines (51 loc) 1.21 kB
import WebinyError from "@webiny/error"; import { transformValueForSearch } from "../transformValueForSearch.js"; import { hasKeyword } from "../keyword.js"; import { createFieldPathFactory } from "./path.js"; export const createApplyFiltering = ({ operatorPlugins, valueSearchRegistry }) => { const createFieldPath = createFieldPathFactory({ valueSearchRegistry }); return params => { const { key, value: initialValue, query, operator, field } = params; const plugin = operatorPlugins[operator]; if (!plugin) { throw new WebinyError(`Elasticsearch operator "${operator}" plugin missing.`, "PLUGIN_MISSING", { operator }); } const value = transformValueForSearch({ valueSearchRegistry, field: field.field, value: initialValue }); const keyword = hasKeyword(field); const { basePath, path } = createFieldPath({ field, value, originalValue: initialValue, key, keyword }); plugin.apply(query, { name: field.field.fieldId, basePath, path, value, keyword }); }; }; //# sourceMappingURL=applyFiltering.js.map