Add custom fields to TS generators

This commit is contained in:
Rémi de Juvigny 2022-09-21 12:29:06 +02:00
parent baad89e678
commit cb10c9a81a
3 changed files with 21 additions and 0 deletions

View File

@ -29,6 +29,9 @@ export type NonUniqueAttribute = { unique: false };
export type ConfigurableAttribute = { configurable: true };
export type NonConfigurableAttribute = { configurable: false };
// custom field
export type CustomField<T extends string, P extends object = undefined> = { customField: T, options?: P };
// min/max
export type SetMinMax<T extends MinMaxOption<U>, U = number> = T;

View File

@ -438,6 +438,8 @@ describe('Attributes', () => {
});
});
// TODO custom field
describe('Plugin Options', () => {
test('No plugin options', () => {
const attribute = {};

View File

@ -70,6 +70,22 @@ const getAttributeModifiers = (attribute) => {
);
}
// Custom field
if (attribute.customField) {
addImport('CustomField');
const customFieldUid = factory.createStringLiteral(attribute.customField);
const typeParams = [customFieldUid];
if (attribute.options) {
typeParams.push(toTypeLiteral(attribute.options));
}
modifiers.push(
factory.createTypeReferenceNode(factory.createIdentifier('CustomField'), typeParams)
);
}
// Plugin Options
if (!_.isEmpty(attribute.pluginOptions)) {
addImport('SetPluginOptions');