Skip to content

Commit

Permalink
Merge 7542e46 into f2ee5de
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSPb89 committed Mar 27, 2018
2 parents f2ee5de + 7542e46 commit 5084e1c
Show file tree
Hide file tree
Showing 18 changed files with 2,938 additions and 143 deletions.
38 changes: 38 additions & 0 deletions src/model/Declaration.js
@@ -0,0 +1,38 @@
import Port from './Port';
import { extractExpression, extractType } from '../parser/WDL/utils/utils';

/**
* Class representing binding points of workflow steps.
*/
export default class Declaration extends Port {
/**
* Create a Declaration.
*
* @param {string} name - Declaration name
* @param {ast} declaration - Declaration ast tree node
* @param {Step} step - Parent step this Declaration belongs to.
*/
constructor(name, declaration, step) {
if (!name) {
throw new Error('Declaration must have a name');
}
if (!declaration.expression || !declaration.type) {
throw new Error('Declaration could be created only using declaration object');
}
super(name, step, {});

delete this.desc;

/**
* Declaration expression extracted object.
* @type {string}
*/
this.expression = extractExpression(declaration.expression);
/**
* Declaration type.
* @type {string}
*/
this.type = extractType(declaration.type);
}

}
59 changes: 59 additions & 0 deletions src/model/Group.js
Expand Up @@ -34,6 +34,65 @@ class Group extends Step {
super(name, new Action(name, config), config);

this.type = type || 'default';
/**
* Dictionary of Group's own declarations.
* @type {Object.<string, Declaration>}
*/
this.ownDeclarations = {};
}

/**
* Add a child step.
*
* @param {Declaration} declaration - Declaration to add.
* @returns {Declaration} Added declaration. May be used for easy declaration creation.
* @throws {Error} Generic exception if a declaration with the same name already exists.
* @example
* const declaration = parent.addDeclaration(new Declaration('declaration', ...));
*/
addDeclaration(declaration) {
const root = this.workflow();
const existingInRoot = root && root.declarations[declaration.name];
const ownExisting = this.ownDeclarations[declaration.name];
if (!existingInRoot && !ownExisting) {
if (declaration.step !== null) {
declaration.step.removeDeclaration(declaration.name, root);
}

declaration.step = this;

if (root) {
root.declarations[declaration.name] = declaration;
}
this.ownDeclarations[declaration.name] = declaration;
} else if (existingInRoot !== declaration && ownExisting !== declaration) {
throw new Error(`Cannot add a declaration with the same name ${declaration.name}.`);
}
return declaration;
}

/**
* Remove a declaration.
*
* @param {string} name - Declaration to remove.
* @param {Workflow} root - Declaration's workflow
* @example
* parent.removeDeclaration('declaration');
*/
removeDeclaration(name, root = null) {
const workflow = root || this.workflow();
const declarationInRoot = workflow && workflow.declarations[name];
const declaration = this.ownDeclarations[name];
if (declarationInRoot) {
declarationInRoot.step = null;
delete workflow.declarations[name];
}
if (declaration) {
declaration.step = null;
delete this.ownDeclarations[name];
}

return declaration;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/model/Step.js
Expand Up @@ -95,9 +95,9 @@ export default class Step {
* Create a workflow step. You should {@link Workflow#add add} it to a workflow or a compound step.
*
* @param {string} name - Step name. Must be unique in a parent step (e.g. {@link Workflow}).
* @param {Action=} [action={}] action - Action to execute during the step. If no action is specified it will
* @param {Action|{}} action - Action to execute during the step. If no action is specified it will
* automatically be created based on the configuration. Multiple steps may share a single action.
* @param {object} [config={}] - Action configuration containing input bindings.
* @param {object} config - Action configuration containing input bindings.
* It should include action description in case the action is missing.
*
*/
Expand Down
6 changes: 6 additions & 0 deletions src/model/Workflow.js
Expand Up @@ -35,6 +35,12 @@ class Workflow extends Group {
* @type {Object.<string, Action>}
*/
this.actions = {};
/**
* Dictionary of all declarations accessible within workflow.
* @type {Object.<string, Declaration>}
*/
this.declarations = {};

if (config.ast) {
this.ast = config.ast;
}
Expand Down

0 comments on commit 5084e1c

Please sign in to comment.