new Container()
Stores platform elements and provides actions for loading, binding, checking, and exporting them.
A container owns namespaces, unit definitions, function definitions, scenarios, and a logger. A typical platform uses one container instance.
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 |
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 |
unitDefStorage |
Map.<string, UnitDef> | Storage for |
functionDefStorage |
Map.<string, FunctionDef> | Storage for |
scenarioStorage |
Map.<string, Scenario> | Storage for |
namespaceStorage |
Map.<string, Namespace> | Storage for |
_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 dependencies between user-defined functions and logs errors.
Returns:
This container.
- Type
- Container
checkCircRecord() → {Container}
Checks circular dependencies in record assignments across concrete namespaces.
Returns:
This container.
- Type
- Container
checkCircUnitDef() → {Container}
Checks circular dependencies between unit definitions and logs errors.
Returns:
This container.
- Type
- Container
checkTerms() → {Container}
Checks whether units use terms allowed for TimeScale, Compartment,
Species, and Reaction-like size components.
Returns:
This container.
- Type
- Container
checkUnits() → {Container}
Checks unit consistency in records and switcher expressions.
Returns:
This container.
- Type
- Container
defineFunction(q, isCore) → {FunctionDef}
Creates a FunctionDef and stores it by id.
Parameters:
| Name | Type | Description |
|---|---|---|
q |
object | The |
isCore |
boolean | Marks the function definition as read-only. |
Returns:
The created object.
- Type
- FunctionDef
defineUnit(q, isCore) → {UnitDef}
Creates a UnitDef and stores it by id.
Parameters:
| Name | Type | Description |
|---|---|---|
q |
object | The |
isCore |
boolean | Marks the unit definition as read-only. |
Returns:
The created object.
- Type
- UnitDef
delete(q) → {boolean|undefined}
Deletes an existing component from a namespace.
Parameters:
| Name | Type | Description |
|---|---|---|
q |
object | The |
Returns:
true if the component was deleted, otherwise undefined.
- Type
- boolean | undefined
deleteNS(q) → {Container}
Deletes a namespace by q.space.
Parameters:
| Name | Type | Description |
|---|---|---|
q |
object | The namespace selector. |
Returns:
This container.
- Type
- Container
export(q, isCore) → {AbstractExport|undefined}
Creates an export instance from an inline #export action.
The export class is selected by q.format, for example format: "json"
creates a JSON export instance.
Parameters:
| Name | Type | Description |
|---|---|---|
q |
object | The |
isCore |
boolean | Kept for action compatibility. |
- Deprecated:
- Use the `export` section in the platform declaration instead.
Returns:
The created export, or undefined if validation fails.
- Type
- AbstractExport | undefined
forceInsert(q, isCore) → {Component|undefined}
Creates a component of q.class and stores it in a namespace.
For example {id: "k1", class: "Const", space: "one"} creates a Const
component in namespace one.
Parameters:
| Name | Type | Description |
|---|---|---|
q |
object | The |
isCore |
boolean | Marks the component as read-only. |
Returns:
The created component, or undefined if validation fails.
- Type
- Component | undefined
hasMeta(q) → {undefined}
Accepts metadata records without changing the container.
Parameters:
| Name | Type | Description |
|---|---|---|
q |
object | Metadata object. |
Returns:
- Type
- undefined
hetaErrors() → {Array.<object>}
Returns array of errors from the default logger.
Returns:
See details in JSONTransport
- Type
- Array.<object>
import(q) → {Component|undefined}
Clones one component from another namespace and rewrites its references.
Parameters:
| Name | Type | Description |
|---|---|---|
q |
object | The |
Returns:
Cloned component, or undefined if validation fails.
- Type
- Component | undefined
Example
```
q = {
action: 'import',
id: 'k2',
space: 'two'
fromId: k1,
fromSpace: one,
prefix: '',
suffix: '',
rename: {}
};
container.import(q);
```
importNS(q) → {Array.<Component>|undefined}
Clones all components from one namespace into another namespace.
Parameters:
| Name | Type | Description |
|---|---|---|
q |
object | The |
Returns:
Array of cloned components, or undefined if validation fails.
- Type
- Array.<Component> | undefined
Example
```
let q = {
action: 'importNS'
space: 'two',
fromSpace: 'one',
prefix: '',
suffix: '',
rename: {}
};
container.importNS(q);
```
insert(q, isCore) → {Component|undefined}
Inserts a component and logs a warning when an existing component is replaced.
Parameters:
| Name | Type | Description |
|---|---|---|
q |
object | The component object in Q-object format. |
isCore |
boolean | Marks the component as read-only. |
Returns:
The inserted component, or undefined if validation fails.
- Type
- Component | undefined
knitMany() → {Container}
Creates references between platform elements.
It includes all concrete namespaces and UnitDef instances.
Returns:
This container.
- Type
- Container
load(q, isCore) → {*}
Runs a container action described by q.action.
If q.action is not set, upsert is used. This is the main entry point
for converting Q-objects 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:
Result returned by the invoked action, or undefined if the action is invalid.
- Type
- *
loadMany(qArr, isCore) → {Container}
Loads a Q-array 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 container.
- Type
- Container
select(q) → {Component|undefined}
Selects a component by id and namespace.
Parameters:
| Name | Type | Description |
|---|---|---|
q |
object | Component selector in Q-object format. |
Returns:
Selected component, or undefined if validation fails.
- Type
- Component | undefined
setNS(q) → {void}
Creates or updates a namespace.
If the namespace is new, a default t @TimeScale component is inserted.
Existing namespaces keep their components and can switch between
abstract and concrete type.
Parameters:
| Name | Type | Description |
|---|---|---|
q |
object | The |
Returns:
- Type
- void
setScenario(q, isCore) → {Scenario}
Creates a Scenario and stores it by id.
Parameters:
| Name | Type | Description |
|---|---|---|
q |
object | The |
isCore |
boolean | Marks the scenario as read-only. |
Returns:
The created object.
- Type
- Scenario
update(q) → {Component|undefined}
Updates an existing component.
Parameters:
| Name | Type | Description |
|---|---|---|
q |
object | The |
Returns:
Updated component, or undefined if validation fails.
- Type
- Component | undefined
upsert(q, isCore) → {Component|undefined}
Inserts a component when q.class is present, otherwise updates an existing component.
Parameters:
| Name | Type | Description |
|---|---|---|
q |
object | The |
isCore |
boolean | Marks inserted components as read-only. |
Returns:
Updated or inserted component.
- Type
- Component | undefined