ModelManager class from @accordproject/concerto-core manages Concerto models (CTO files) that define the data structure for your templates.
Installation
Constructor
Create a new ModelManager instance with configuration options.Configuration options for the model manager
Enable strict mode for model validation (recommended:
true)Example
Methods
addCTOModel()
Adds a Concerto model to the ModelManager.The CTO model definition as a string
Optional file name for the model (can be
undefined)Whether to disable validation when adding the model
void
updateExternalModels()
Fetches and updates any external model dependencies. Returns:Promise<void>
This method must be called after adding models to resolve external dependencies.
Complete Example
Here’s how the ModelManager is used in the Template Playground:Model Example
A typical CTO model defines the data structure:Common Options
When
true, enables strict validation of models and data. Recommended for production use.Error Handling
The ModelManager will throw errors if:- The CTO syntax is invalid
- External model dependencies cannot be resolved
- Model validation fails in strict mode
Related APIs
- TemplateMarkInterpreter - Uses ModelManager for template processing
- Transform - Works with validated data models
Source Reference
See the implementation in the Template Playground:src/store/store.ts:80-82