Support entity attributes

This commit is contained in:
Adrian Hall
2020-10-30 13:45:35 +00:00
parent 74d09b5468
commit 0c38e014d7
4 changed files with 230 additions and 29 deletions

View File

@@ -27,13 +27,26 @@ export const parseDirective = function(statement, context, type) {
const addEntity = function(name) {
if (typeof entities[name] === 'undefined') {
entities[name] = name;
logger.debug('Added new entity :', name);
entities[name] = { attributes: [] };
logger.info('Added new entity :', name);
}
return entities[name];
};
const getEntities = () => entities;
const addAttributes = function(entityName, attribs) {
let entity = addEntity(entityName); // May do nothing (if entity has already been added)
// Process attribs in reverse order due to effect of recursive construction (last attribute is first)
let i;
for (i = attribs.length - 1; i >= 0; i--) {
entity.attributes.push(attribs[i]);
logger.debug('Added attribute ', attribs[i].attributeName);
}
};
/**
* Add a relationship
* @param entA The first entity in the relationship
@@ -76,6 +89,7 @@ export default {
parseDirective,
getConfig: () => configApi.getConfig().er,
addEntity,
addAttributes,
getEntities,
addRelationship,
getRelationships,