Skip to content

Commit

Permalink
minor docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Metelkin committed Sep 16, 2021
1 parent 4aca352 commit c86adb5
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 81 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ Heta compiler has been written in NodeJS environment and can be used as a packag
```javascript
const { Container } = require('heta-compiler');
// platform code in Queue format
let queue = [
// platform code in Q-array format
let qArr = [
{ class: 'Compartment', id: 'comp1', assignments: {start_: '1'} },
{ class: 'Species', id: 's1', compartment: 'comp1', assignments: {start_: '10'} },
{ class: 'Reaction', id: 'r1', actors: 's1 =>', assignments: {ode_: 'k1*s1*comp1'} },
Expand All @@ -134,7 +134,7 @@ let queue = [
// compilation
let c = (new Container)
.loadMany(queue)
.loadMany(qArr)
.knitMany();
// get export element
let output = c.exportStorage[0]
Expand Down
77 changes: 77 additions & 0 deletions classes.uxf
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<diagram program="umletino" version="14.4.0-SNAPSHOT"><zoom_level>10</zoom_level><help_text>Space for diagram notes
</help_text><element><id>UMLClass</id><coordinates><x>10</x><y>370</y><w>280</w><h>350</h></coordinates><panel_attributes>Container
{}
--
- classes: Object.&lt;String,Constructor&gt;
- logger: Logger
- defaultLogs: Array.&lt;object&gt;
- exportStorage: Map.&lt;string, _Export&gt;
- unitDefStorage: Map.&lt;string, UnitDef&gt;
- namespaceStorage: Map.&lt;string, Namespace&gt;
- _componentClasses: &lt;String,Constructor&gt;
- _exportClasses: &lt;String,Constructor&gt;

--

#export()
#defineUnit()
#insert()
#update()
#upsert()
#delete()
#import()
#setNS()
#importNS()
</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLClass</id><coordinates><x>360</x><y>520</y><w>210</w><h>110</h></coordinates><panel_attributes>Namespace extends Map
{}
--
- _spaceName: String
- container: Container
- isAbstract: Boolean = false
</panel_attributes><additional_attributes></additional_attributes></element><element><id>Relation</id><coordinates><x>280</x><y>480</y><w>210</w><h>60</h></coordinates><panel_attributes>lt=&lt;&lt;&lt;&lt;-</panel_attributes><additional_attributes>10;10;190;10;190;40</additional_attributes></element><element><id>UMLClass</id><coordinates><x>580</x><y>0</y><w>210</w><h>220</h></coordinates><panel_attributes>Top (Element)
{}
--
- isCore: Boolean
- _id: String
- isRandomId: Boolean = false
- _container: Container

--

#id
#index
#className
#toQ()
#toFlat()
</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLClass</id><coordinates><x>610</x><y>570</y><w>210</w><h>360</h></coordinates><panel_attributes>Component
{}
--
- _id: String
- namespace: Namespace
- _isCore: Boolean = false
- tags: Array.&lt;String&gt;
- aux: Object
- title: String
- notes: String

--

#id
#space
#index
#className
#indexObj
#notesHTML
#clone()
#updateReferences()
#bind()
#toQ()
#toFlat()

</panel_attributes><additional_attributes></additional_attributes></element><element><id>Relation</id><coordinates><x>560</x><y>530</y><w>110</w><h>60</h></coordinates><panel_attributes>lt=&lt;&lt;&lt;&lt;-</panel_attributes><additional_attributes>10;10;90;10;90;40</additional_attributes></element><element><id>UMLClass</id><coordinates><x>340</x><y>280</y><w>160</w><h>70</h></coordinates><panel_attributes>_Export
{}
--
</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLClass</id><coordinates><x>450</x><y>360</y><w>160</w><h>70</h></coordinates><panel_attributes>UnitDef
{}
--
</panel_attributes><additional_attributes></additional_attributes></element><element><id>Relation</id><coordinates><x>280</x><y>340</y><w>150</w><h>130</h></coordinates><panel_attributes>lt=&lt;&lt;&lt;&lt;-</panel_attributes><additional_attributes>10;110;130;110;130;10</additional_attributes></element><element><id>Relation</id><coordinates><x>280</x><y>420</y><w>270</w><h>70</h></coordinates><panel_attributes>lt=&lt;&lt;&lt;&lt;-</panel_attributes><additional_attributes>10;50;250;50;250;10</additional_attributes></element><element><id>Relation</id><coordinates><x>410</x><y>210</y><w>280</w><h>90</h></coordinates><panel_attributes>lt=&lt;&lt;&lt;-</panel_attributes><additional_attributes>260;10;260;40;10;40;10;70</additional_attributes></element><element><id>Relation</id><coordinates><x>520</x><y>210</y><w>210</w><h>170</h></coordinates><panel_attributes>lt=&lt;&lt;&lt;-</panel_attributes><additional_attributes>190;10;190;50;10;50;10;150</additional_attributes></element></diagram>
4 changes: 2 additions & 2 deletions src/builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ class Builder {
this.logger.info(`Meta file was saved to ${absPath}`);
});
}
let queue = ms.integrate();
let qArr = ms.integrate();

// 3. Translation
this.container.loadMany(queue, false);
this.container.loadMany(qArr, false);
//console.log([...this.container.unitDefStorage]); // XXX: debugging

// 4. Binding
Expand Down
2 changes: 1 addition & 1 deletion src/container/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ Container.prototype.select = function(q = {}){
* Calculates string formatted index.
* Exampel: `{id: 'k1', space: 'one'}` => `'one::k1'`
*
* @param {object} q Heta's element in queue format.
* @param {object} q Heta's element in Q-object format.
* @returns {string} Get index of a component.
*/
function getIndexFromQ(q = {}){
Expand Down
9 changes: 5 additions & 4 deletions src/container/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const TopoSort = require('@insysbio/topo-sort');
*
* @property {object} classes Map-like storage for all element constructors that can be created inside platform.
* For example the element of the type `UnitsDef` can be created as follows:
* ```let new_unit = new c.UnitDef({id: 'new', units: 'g/litre'})```
* ```let new_unit = new c.classes.UnitDef({id: 'new', units: 'g/litre'})```
* The `new_unit` element will be automatically bound to the container and pushed to `unitDefStorage`.
* @property {Logger} logger object providing transport of errors, warnings and info messages on Heta platform level.
* @property {object[]} defaultLogs Default storage of errors which will be used for diagnostics.
Expand All @@ -42,7 +42,8 @@ const TopoSort = require('@insysbio/topo-sort');
* @property {Map<string,Namespace>} namespaceStorage Storage for `Namespace` instances. Key is a string identifier.
* There is a default namespace with identifier `nameless` which will be used as a default namespace
* for all components where namespace name is not set.
* @property {object} _componentClasses map-like structure for storing all available classes describing `Component`s.
* @property {object} _componentClasses map-like structure for storing all available constructors for `Component`s.
* @property {object} _exportClasses map-like structure for storing all available constructors describing `_Export`s.
*/
class Container {
/* constructor can be run many times */
Expand Down Expand Up @@ -105,7 +106,7 @@ class Container {
* If `q.action` is not set than apply "upsert".
* An "action" name should be set as a name of the `Container` method.
*
* This is the main method to convert from elements of "queue" into platform elements.
* This is the main method to convert from Q-object into platform elements.
*
* @param {object} q Simple object with the same structure as Heta plain format.
* @param {boolean} isCore Set element as a "core" which means you cannot rewrite or delete it.
Expand All @@ -129,7 +130,7 @@ class Container {
/**
* Runs {@link Container#load} method many times for each element of `qArr` vector sequentially.
*
* @param {object[]} qArr Array of "queue" formatted elements.
* @param {object[]} qArr Q-array.
* @param {boolean} isCore Set element as a "core" which means you cannot rewrite or delete it.
*
* @returns {Container} This function returns the container.
Expand Down
118 changes: 59 additions & 59 deletions src/core/top.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,73 +39,73 @@ const schema = {
*/
class Top { // or const Top = class {...}
/*
new Top({id: 'ttt1'});
*/
constructor(q = {}, isCore = false){
let logger = this._container.logger;
let valid = Top.isValid(q, logger);
if (!valid) { this.errored = true; return; }
/*
new Top({id: 'ttt1'});
*/
constructor(q = {}, isCore = false){
let logger = this._container.logger;
let valid = Top.isValid(q, logger);
if (!valid) { this.errored = true; return; }

if (isCore) this.isCore = true;
if (typeof q.id !== 'undefined') {
this._id = q.id;
this.isRandomId = false;
} else {
this._id = 'rand_' + randomId(lengthRandom, patternRandom);
this.isRandomId = true;
}
if (isCore) this.isCore = true;
if (typeof q.id !== 'undefined') {
this._id = q.id;
this.isRandomId = false;
} else {
this._id = 'rand_' + randomId(lengthRandom, patternRandom);
this.isRandomId = true;
}
get id(){
return this._id;
}
get index(){
return this._id;
}
get className(){
return 'Top';
}
static get validate(){
return ajv.compile(schema);
}
static isValid(q, logger){
let valid = this.validate(q);
if (!valid) {
let msg = `${q.id} Some of properties do not satisfy requirements for class "${this.name}"\n`
+ this.validate.errors.map((x, i) => ` ${i+1}. ${x.dataPath} ${x.message}`)
.join('\n');
logger.error(msg, {type: 'ValidationError', space: q.space});
}

return valid;
}
get id(){
return this._id;
}
get index(){
return this._id;
}
get className(){
return 'Top';
}
static get validate(){
return ajv.compile(schema);
}
static isValid(q, logger){
let valid = this.validate(q);
if (!valid) {
let msg = `${q.id} Some of properties do not satisfy requirements for class "${this.name}"\n`
+ this.validate.errors.map((x, i) => ` ${i+1}. ${x.dataPath} ${x.message}`)
.join('\n');
logger.error(msg, {type: 'ValidationError', space: q.space});
}
_toQ(options = {}){
let q = {};
if (!this.isRandomId) q.id = this.id;

return valid;
}
_toQ(options = {}){
let q = {};
if (!this.isRandomId) q.id = this.id;

return q;
}
toQ(options = {}){
let q = this._toQ(options);
q.action = 'defineTop';
return q;
}
toQ(options = {}){
let q = this._toQ(options);
q.action = 'defineTop';

return q;
}
toFlat(options = {}){
// set defaults
_.defaults(options, {
simplifyModifiers: true,
simplifyActors: true,
simplifyExpressions: true
});
return q;
}
toFlat(options = {}){
// set defaults
_.defaults(options, {
simplifyModifiers: true,
simplifyActors: true,
simplifyExpressions: true
});

let q = this.toQ(options);
let res = flatten(q);
let q = this.toQ(options);
let res = flatten(q);

return res;
}
return res;
}
}

module.exports = {
Top
Top
};
2 changes: 1 addition & 1 deletion src/module-system/heta-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ _Module.prototype.setHetaModule = function(){
*
* @param {string} filename File to parse. It is used only for log messages.
* @param {...any} params Additional parameters passed to `parse()` method.
* @returns {array} Queue array format.
* @returns {array} Module content in Q-array format.
*/
function _hetaParse(filename, ...params){
try {
Expand Down
4 changes: 2 additions & 2 deletions src/module-system/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class ModuleSystem {
/**
* Composes parsed modules into single platform.
*
* @returns {object[]} integrated queue array.
* @returns {object[]} integrated Q-array.
*/
integrate(){
this
Expand Down Expand Up @@ -141,7 +141,7 @@ class ModuleSystem {
* @param {object} obj This should be merged.
* @param {object[]} arr Array to merge.
*
* @returns {object} merged queue array.
* @returns {object} merged Q-array.
*/
function compose(obj, arr){
let cleanedObj = _.omit(obj, ['action', 'id', 'class', 'source', 'type', 'sheet']);
Expand Down
4 changes: 2 additions & 2 deletions src/module-system/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const fs = require('fs');
*
* @class _Module
*
* @property {object[]} parsed Array of queue objects.
* @property {object[]} parsed Q-array.
* @property {string} filename File name (absolute) associated with the module.
* @property {Logger} logger Object to analyze log events.
* @property {string} type One of module types: heta, json, yaml, xlsx, sbml
Expand Down Expand Up @@ -71,7 +71,7 @@ class _Module {
}

/**
* Select only `#include` actions from the queue array.
* Select only `#include` actions from the Q-array.
*
* @returns {object[]} Array of `#include actions`.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/module-system/sbml-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { SBMLParse } = require('./sbml-parse');

/**
* To initialize a Heta module of the "sbml" type.
* It includes reading and parsing SBML file and representing it into Heta queue,
* It includes reading and parsing SBML file and representing it into Q-object,
* see [Heta specifications](https://hetalang.github.io/#/specifications/modules?id=sbml-module)
*
* @returns {_Module} Self.
Expand Down
12 changes: 6 additions & 6 deletions src/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ class Namespace extends Map {
return [...this].map((x) => x[1]);
}
/**
* Converts namespace into queue array.
* Converts namespace into Q-array.
*
* @param {boolean} removeCoreComponents=true
* @param {object} options Options passed to {@link Top#toQ} method
*
* @returns {object[]} Array of JS objects in queue format.
* @returns {object[]} Q-array format.
*/
toQArr(removeCoreComponents = false, options = {}){
let qArr = this.toArray()
Expand All @@ -59,10 +59,10 @@ class Namespace extends Map {
return qArr;
}
/**
* Representation of namespace in queue format.
* Representation of namespace into Q-object format.
*
* @param {object} options reserved for future versions.
* @returns {object} JS object in queue format.
* @returns {object} JS object in Q-object format.
*/
toQ(options = {}){
let res = {
Expand All @@ -75,11 +75,11 @@ class Namespace extends Map {
}

/**
* Representation of namespace in flat queue format.
* Representation of namespace in flat Q-object format.
*
* @param {object} options reserved for future versions.
*
* @returns {object} JS object in flat queue format.
* @returns {object} flat Q-object format.
*/
toFlat(options = {}){
let q = this.toQ(options);
Expand Down

0 comments on commit c86adb5

Please sign in to comment.