Either through patching existing entities or by generating entities that don't exist yet. Or both. Snippet:
class SomeGenerator {
public async generateEntity (output: Output, { name, field }: { name: string, field: string[] }) {
const fields = Array.isArray(field) ? field : [ field ];
const { pascalCased, camelCased } = this.generatorService.formatNames(name);
const relationRegex = /^(?:([\w]+\b)?(\*)?(-|<>|>|<)?(\*)?([\w]+)(?:\.)?(\w+)?)$/g;
const relationsMap: { [key: string]: string } = {
'-': 'oneToOne',
'>': 'manyToOne',
'<': 'oneToMany',
'<>': 'manyToMany',
};
const relations = fields.map(f => {
const matches = relationRegex.exec(f);
return {
entity: pascalCased,
relation: relationsMap[matches[3] || '-'],
property: matches[1] || this.generatorService.formatNames(matches[5]).camelCased,
owning: !!matches[2] || !matches[4],
other: {
property: matches[6] || camelCased,
entity: matches[5],
owning: !!matches[4],
},
};
});
output.addData(relations);
}
}
Example use:
stix generate:entity user user -r profile>Profile.user
Either through patching existing entities or by generating entities that don't exist yet. Or both. Snippet:
Example use:
stix generate:entity user user -r profile>Profile.user