@webiny/api-headless-cms-ddb
Version:
DynamoDB storage operations plugin for Headless CMS API.
48 lines (45 loc) • 1.56 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CmsEntryFieldFilterPathPlugin = void 0;
var _error = _interopRequireDefault(require("@webiny/error"));
var _Plugin = require("@webiny/plugins/Plugin");
class CmsEntryFieldFilterPathPlugin extends _Plugin.Plugin {
static type = "cms-field-filter-path";
get fieldType() {
return this.config.fieldType;
}
constructor(config) {
super();
this.config = config;
/**
* We expect error here because we know that `this.constructor.type` is defined, but TS does not.
*/
// @ts-expect-error
this.name = `${this.constructor.type}-${this.config.fieldType}`;
}
canUse(field, parents) {
if (field.type !== this.config.fieldType) {
return false;
} else if (this.config.canUse) {
return this.config.canUse(field, parents);
}
const fieldId = this.config.fieldId;
if (!fieldId || Array.isArray(fieldId) === false || fieldId.length === 0) {
return true;
}
return fieldId.includes(field.fieldId);
}
createPath(params) {
if (typeof this.config.path === "function") {
return this.config.path(params);
} else if (typeof this.config.path === "string") {
return this.config.path;
}
throw new _error.default(`Missing path in "${this.name}" plugin.`);
}
}
exports.CmsEntryFieldFilterPathPlugin = CmsEntryFieldFilterPathPlugin;
//# sourceMappingURL=CmsEntryFieldFilterPathPlugin.js.map
;