Class: Container

Container()

new Container()

The main class storing a modeling platform and it's methods.

It is highly recommended to use only one container instance in developed code.

Properties:
Name Type Description
classes object

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.classes.UnitDef().merge({id: 'new', units: 'g/litre'}) The new_unit element will be automatically bound to the container and pushed to unitDefStorage.

logger Logger

object providing transport of errors, warnings and info messages on Heta platform level.

defaultLogs Array.<object>

Default storage of errors which will be used for diagnostics. The JSONTransport is used here.

unitDefStorage Map.<string, UnitDef>

Storage for UnitDef instances. Key is a string identifier.

functionDefStorage Map.<string, FunctionDef>

Storage for FunctionDef instances. Key is a string identifier.

scenarioStorage Map.<string, Scenario>

Storage for Scenario instances. Key is a string identifier.

namespaceStorage Map.<string, Namespace>

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.

_builder object

reference to the parent builder object (if exists).

Members

length

Get number of total elements of a platform.

Methods

checkCircFunctionDef() → {Container}

Checks circular ref in FunctionDef

Returns:

This function returns the container.

Type
Container

checkCircRecord() → {Container}

Checks circular dependencies in all instances of Record.

Returns:

This function returns the container.

Type
Container

checkCircUnitDef() → {Container}

Checks circular ref in UnitDef

Returns:

This function returns the container.

Type
Container

checkTerms() → {Container}

check TimeScale, Compartment, Species, Reaction for correct terms.

Returns:

This function returns the container.

Type
Container

checkUnits() → {Container}

Compare left and right side of Record, DSwitcher, CSwitcher, StopSwitcher.

Returns:

This function returns the container.

Type
Container

defineFunction(q, isCore) → {FunctionDef}

Creates FunctionDef instance and puts it in container.functionDefStorage.

Parameters:
Name Type Description
q object

The #defineFunction statement in JS object format.

isCore Boolean

Set element as a "core" which means you cannot rewrite or delete it.

Returns:

The created object.

Type
FunctionDef

defineUnit(q, isCore) → {UnitDef}

Creates UnitDef instance and puts it in container.unitDefStorage.

Parameters:
Name Type Description
q object

The #defineUnit statement in JS object format.

isCore Boolean

Set element as a "core" which means you cannot rewrite or delete it.

Returns:

The created object.

Type
UnitDef

delete(q) → {Component}

Deletes the Component with the index. If it is not exist it throws an error.

Parameters:
Name Type Description
q *

The #delete action in JS object format.

Returns:

Deleted component.

Type
Component

export(q, isCore) → {AbstractExport}

Creates one of inheritors of AbstractExport and put it in container.exportArray. The inheritor depends on q.format property. For example {id: 'output', format: 'JSON', ...} creates the object of JSONExport type.

Parameters:
Name Type Description
q object

The export object in JS object format.

isCore Boolean

Set element as a "core" which means you cannot rewrite or delete it.

Returns:

The created object.

Type
AbstractExport

forceInsert(q, isCore) → {Component}

Creates one of inheritors of Component and put it in a namespace. The inheritor depends on q.class property. For example {id: 'k1', class: 'Const', namespace: 'one'} creates the object of Const type and puts it into namespace one.

Parameters:
Name Type Description
q object

The #forceInsert statement in JS object format.

isCore Boolean

Set element as a "core" which means you cannot rewrite or delete it.

Returns:

The created object.

Type
Component

hetaErrors() → {Array.<object>}

Returns array of errors from the default logger.

Returns:

See details in JSONTransport

Type
Array.<object>

import(q) → {Component}

Clone a component to another space. It also renames id and references stored in a component.

Parameters:
Name Type Description
q object

The #import action in JS object format.

Returns:

Cloned component.

Type
Component
Example
```
q = {
   action: 'import',
   id: 'k2',
   space: 'two'
   fromId: k1,
   fromSpace: one,
   prefix: '',
   suffix: '',
   rename: {}
};

container.import(q);
```

importNS(q) → {Array.<Component>}

Clones and rename all components to another space.

Parameters:
Name Type Description
q object

The #importNS action in JS object format.

Returns:

Array of cloned components.

Type
Array.<Component>
Example
```
let q = {
  action: 'importNS'
  space: 'two',
  fromSpace: 'one',
  prefix: '',
  suffix: '',
  rename: {}
};
container.importNS(q);
```

knitMany() → {Container}

Creates references between elements in a platform. It includes all concrete namespaces and UnitDef instances.

Returns:

This function returns the container.

Type
Container

load(q, isCore) → {Container}

Runs an action (like creating a component) based on q.action property. 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 Q-object into platform elements.

Parameters:
Name Type Default Description
q object

Simple object with the same structure as Heta plain format.

isCore boolean false

Set element as a "core" which means you cannot rewrite or delete it.

Returns:

This function returns the container.

Type
Container

loadMany(qArr, isCore) → {Container}

Runs Container#load method many times for each element of qArr vector sequentially.

Parameters:
Name Type Default Description
qArr Array.<object>

Q-array.

isCore boolean false

Set element as a "core" which means you cannot rewrite or delete it.

Returns:

This function returns the container.

Type
Container

setNS(The)

Creates namespace with id from q.space and push it to container.namespaceStorage. If the namespace already exists it does not create anything but updates namespace properties. It can also change type of a namespace.

Parameters:
Name Type Description
The object

#setNS action in JS object format.

setScenario(q, isCore) → {Scenario}

Creates Scenario instance and puts it in container.scenarioStorage.

Parameters:
Name Type Description
q object

The #setScenario statement in JS object format.

isCore Boolean

Set element as a "core" which means you cannot rewrite or delete it.

Returns:

The created object.

Type
Scenario

update(q) → {Component}

Searches a component with the index and updates its properties.

Parameters:
Name Type Description
q object

The #update action in JS object format.

Returns:

Updated component.

Type
Component

upsert(q, isCore) → {Component}

If q.class property is set it acts as #insert action. If not it works as #update.

Parameters:
Name Type Description
q object

The #update or #insert action in JS object format.

isCore Boolean

Set element as a "core" which means you cannot rewrite or delete it.

Returns:

Updated or inserted component.

Type
Component