validateInstances(data) checks recorded objects and links against a valid model. A tool first translates its stored data into a complete ModelInstanceGraph because RMF does not read databases or tool-specific file formats.
Document requires a title, but the recorded Document below has none:
import { DataTypes, Modeller } from '@ramen-suite/core/model';
import type { ModelInstanceGraph, Node, ValidationResult } from '@ramen-suite/core/model';
const model: Modeller = Modeller.create('Filing');
const document: Node = model.createNode('Document').element;
model.createAttribute(document, {
name: 'title',
typeId: DataTypes.String,
bounds: { lowerBound: 1, upperBound: 1 },
});
const data: ModelInstanceGraph = {
nodes: [{ id: 'documentRecord01', typeId: document.id, properties: {} }],
relations: [],
};
const checked: ValidationResult = model.validateInstances(data);
console.log(checked.diagnostics);
// INSTANCE_PROPERTY_REQUIRED at /nodes/0/properties/title.
documentRecord01 identifies the recorded object. Record and link IDs must contain at least 16 letters, digits, underscores or hyphens. document.id identifies its model type. The model already supplies the validation context, so the data graph has no model ID. Read Diagnostics explains the path.
A relationship can limit how many Folders one Document may have. Here the limit is one:
import type { Relation } from '@ramen-suite/core/model';
const folder: Node = model.createNode('Folder').element;
const filedIn: Relation = model.createRelation({
name: 'FILED_IN',
from: { node: document },
to: { node: folder, bounds: { lowerBound: 0, upperBound: 1 } },
}).element;
const links: ModelInstanceGraph = {
nodes: [
{ id: 'documentRecord01', typeId: document.id, properties: { title: 'Example' } },
{ id: 'folderRecord0001', typeId: folder.id, properties: {} },
{ id: 'folderRecord0002', typeId: folder.id, properties: {} },
],
relations: [
{ id: 'relationRecord01', typeId: filedIn.id, fromId: 'documentRecord01', toId: 'folderRecord0001' },
{ id: 'relationRecord02', typeId: filedIn.id, fromId: 'documentRecord01', toId: 'folderRecord0002' },
],
};
const linkResult: ValidationResult = model.validateInstances(links);
console.log(linkResult.diagnostics);
// INSTANCE_CARDINALITY_INVALID
The input is the complete proposed graph, including both links. When checking an edit, add it to a copy of the complete graph before validation. Checking only the new link would leave out existing links and could give a wrong result.
Validation checks declared properties, data types, endpoints, selected relationships, cardinalities and applicable constraints. It cannot establish whether a recorded statement is factually correct. Express project rules in the model or register a custom evaluator.