@webiny/api-headless-cms-ddb-es
Version:
DynamoDB and Elasticsearch storage operations plugin for Headless CMS API.
36 lines (35 loc) • 1.44 kB
JavaScript
import { CmsEntryOpenSearchFieldIndexRegistry as Abstraction } from "./abstractions/CmsEntryOpenSearchFieldIndexRegistry.js";
import { CmsEntryOpenSearchFieldIndex } from "./abstractions/CmsEntryOpenSearchFieldIndex.js";
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
import { FIELD_INDEXING_DEFAULT } from "./constants.js";
class CmsEntryOpenSearchFieldIndexRegistryImpl {
constructor(fieldIndexing) {
this.fieldIndexing = fieldIndexing;
}
get(type) {
const fieldType = getBaseFieldType({
type
});
return this.fieldIndexing.find(field => field.fieldType === fieldType);
}
getDefault() {
const fieldIndex = this.fieldIndexing.find(field => field.fieldType === FIELD_INDEXING_DEFAULT);
if (fieldIndex) {
return fieldIndex;
}
/**
* This should never happen, as the default field index plugin exists in our code. This can fail during testing.
*/
throw new Error(`Missing default field index plugin. Please make sure to register a plugin with "${FIELD_INDEXING_DEFAULT}" field type.`);
}
getAll() {
return this.fieldIndexing;
}
}
export const CmsEntryOpenSearchFieldIndexRegistry = Abstraction.createImplementation({
implementation: CmsEntryOpenSearchFieldIndexRegistryImpl,
dependencies: [[CmsEntryOpenSearchFieldIndex, {
multiple: true
}]]
});
//# sourceMappingURL=CmsEntryOpenSearchFieldIndexRegistry.js.map