@tsed/schema-formio
Version:
Transform Ts.ED Schema & JsonSchema to a valid Formio schema
31 lines (30 loc) • 860 B
JavaScript
import { JsonEntityFn } from "@tsed/schema";
/**
* Declare a formio Component schema on the decorated propertyKey.
* @decorator
* @formio
* @property
* @schema
*/
export function Component(component) {
component = Object.entries(component).reduce((component, [key, value]) => {
if (key === "validate") {
component["x-formio-validate"] = {
...(component["x-formio-validate"] || {}),
...value
};
}
return {
...component,
[`x-formio-${key}`]: value
};
}, {});
return JsonEntityFn((store) => {
Object.entries(component).forEach(([key, value]) => {
store.itemSchema.customKey(key, value);
if (store.isCollection) {
store.schema.customKey(key, value);
}
});
});
}