A node owns properties that its records may contain. Use createAttribute() to give Document one required title:
import type { Attribute, Node } from '@ramen-suite/core/model';
import { DataTypes, Modeller } from '@ramen-suite/core/model';
const model: Modeller = Modeller.create('Filing');
const document: Node = model.createNode('Document').element;
const title: Attribute = model.createAttribute(document, {
name: 'title',
typeId: DataTypes.String,
bounds: { lowerBound: 1, upperBound: 1 },
}).element;
Recorded data stores the property under name and checks its value against typeId. bounds sets how many values a record may contain. Omit it for an optional single value (0..1):
model.createAttribute(document, { name: 'description', typeId: DataTypes.String });
Use -1 for an unlimited upper bound. A many-valued property is stored as an array, even when it currently has only one value:
model.createAttribute(document, {
name: 'keywords',
typeId: DataTypes.String,
bounds: { lowerBound: 0, upperBound: -1 },
});
// Recorded value: { keywords: ['history', 'letters'] }
| Bounds | Meaning |
|---|---|
0..0 |
No value allowed |
0..1 |
Optional single value and attribute default |
1..1 |
Required single value |
0..* or 1..* |
Any number or at least one with upperBound: -1 |
n..m |
From n to m values, inclusive |
Each flag describes a different rule:
| Field | Default | Effect | Example |
|---|---|---|---|
isKey |
false |
One 1..1 property identifies records across a node and its subtypes. A refinement cannot add another key. |
Document uses reference as its key. |
isUnique |
true |
Prevents repeated values in one record's multi-valued property. | With false, ['draft', 'draft'] is allowed. |
isOrdered |
true |
Array position carries meaning, although validation does not impose an order. | ['draft', 'published'] keeps this sequence. |
isReadOnly |
false |
Tells a tool to prevent changes to a recorded value after creation because validating one record cannot check its history. | A tool locks reference after creation. |
Object keys compare their JSON content, regardless of object member order. Array order within an Object value remains significant.
For example, make reference a stable key and allow repeated tags whose order does not matter:
model.createAttribute(document, {
name: 'reference',
typeId: DataTypes.String,
bounds: { lowerBound: 1, upperBound: 1 },
isKey: true,
isReadOnly: true,
});
model.createAttribute(document, {
name: 'tags',
typeId: DataTypes.String,
bounds: { lowerBound: 0, upperBound: -1 },
isUnique: false,
isOrdered: false,
});
To restrict which values a property accepts, define a data type or write a constraint.
A refined node receives its parent's properties. It may add new names but cannot redeclare title with another type or bounds. Read inherited properties with getAttributes(node), and use Request Suggestions to check a proposed name before creating it.
updateAttribute() changes a local property. Pass the owning node ID and the property ID. Here title becomes optional:
model.updateAttribute(document.id, title.id, { bounds: { lowerBound: 0, upperBound: 1 } });
Its ID stays the same. You can also change its name, typeId, flags, constraints and ext. To edit an inherited property, update it on the node that declares it.
removeAttribute() removes a local property:
model.removeAttribute(document.id, title.id);
Local subtypes then stop inheriting that property. The owner node and its other properties remain.