Editing elements & metadata
Builders are for creating elements. Once an element exists, you change it in place — no builder needed. Names, cardinalities, stereotypes, and structure are all mutable through plain properties and methods on the element itself.
A builder is single-use: it assembles an element and, after .build(), is
spent. To adjust something afterwards you talk to the element directly.
That split keeps construction declarative (a fluent chain that reads top to
bottom) while leaving later edits explicit and localized.
Renaming — names are multilingual
An element's name is not a string but a
LanguageString: a set of values indexed by language
tag. add sets (or replaces) the value for one language; call it again with a
different tag to add a translation. clear() empties every language.
import { class ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project } from 'ontouml-js';
const const project: Projectproject = new new Project(): ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilderCreates a builder for a new
Package
in this project.packageBuilder().PackageBuilder.root(): PackageBuilderSets the package as the root package of its project, i.e., the package
that contains the entire model.root().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilderAdds a name to the element in the given language.name('People').PackageBuilder.build(): PackageBuilds an instance of
Package
with the parameters passed to the
builder. When no methods are evoked, the created package has the
following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `contents: []`build();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets the stereotype of the class to «kind», which decorates rigid
classes that provide an identity principle to their instances, which are
functional complexes (e.g., `Person`, `Car`). Also applies the following
defaults:
- `restrictedTo = [ "functional-complex" ]`
- `order = 1`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Person').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
// Replace the English name…
const person: Classperson.NamedElement.name: LanguageStringThe name of this element, possibly in multiple languages.name.LanguageString.add(value: string, language?: string): voidAdds a text value in the given language, replacing any existing value for
that language.add('Human');
// …and add a Portuguese one alongside it.
const person: Classperson.NamedElement.name: LanguageStringThe name of this element, possibly in multiple languages.name.LanguageString.add(value: string, language?: string): voidAdds a text value in the given language, replacing any existing value for
that language.add('Humano', 'pt');
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const person: Classperson.NamedElement.name: LanguageStringThe name of this element, possibly in multiple languages.name.LanguageString.get(language?: string): string | nullReturns the text value for the given language.
If no language is provided, returns the value of the first language in
languagePreference
for which a value exists. If no such value
exists, returns the first value it finds. If no values are defined,
returns `null`.get()); // "Human" (default language)
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const person: Classperson.NamedElement.name: LanguageStringThe name of this element, possibly in multiple languages.name.LanguageString.get(language?: string): string | nullReturns the text value for the given language.
If no language is provided, returns the value of the first language in
languagePreference
for which a value exists. If no such value
exists, returns the first value it finds. If no values are defined,
returns `null`.get('pt')); // "Humano"
// Wipe all names.
const person: Classperson.NamedElement.name: LanguageStringThe name of this element, possibly in multiple languages.name.LanguageString.clear(): voidRemoves all values of this text, in every language.clear();
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const person: Classperson.NamedElement.getNameOrId(language?: string): stringReturns the name of this element in the given language, falling back to
its
id
when no suitable name is available.getNameOrId()); // falls back to the id
The same applies to description and, on a project, to keywords and
bibliographic citations — every human-readable text field is multilingual.
Cardinalities
An attribute or a relation end carries a cardinality. The Cardinality object
has shortcut setters for the common intervals, plus setBounds for an arbitrary
one. Edit it in place; you don't reassign the field.
import { class ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project } from 'ontouml-js';
const const project: Projectproject = new new Project(): ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilderCreates a builder for a new
Package
in this project.packageBuilder().PackageBuilder.root(): PackageBuilderSets the package as the root package of its project, i.e., the package
that contains the entire model.root().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilderAdds a name to the element in the given language.name('School').PackageBuilder.build(): PackageBuilds an instance of
Package
with the parameters passed to the
builder. When no methods are evoked, the created package has the
following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `contents: []`build();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets the stereotype of the class to «kind», which decorates rigid
classes that provide an identity principle to their instances, which are
functional complexes (e.g., `Person`, `Car`). Also applies the following
defaults:
- `restrictedTo = [ "functional-complex" ]`
- `order = 1`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Person').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
const const school: Classschool = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets the stereotype of the class to «kind», which decorates rigid
classes that provide an identity principle to their instances, which are
functional complexes (e.g., `Person`, `Car`). Also applies the following
defaults:
- `restrictedTo = [ "functional-complex" ]`
- `order = 1`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('School').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
const const studiesAt: BinaryRelationstudiesAt = const model: Packagemodel
.Package.binaryRelationBuilder(): BinaryRelationBuilderCreates a builder for a
BinaryRelation
contained in this
package.binaryRelationBuilder()
.BinaryRelationBuilder.material(): BinaryRelationBuilderSets the stereotype of the relation to «material», which decorates
relations between endurants that are founded on relators, such as being
married to or being enrolled at. Also applies the following defaults:
- `isDerived = true`material()
.NamedElementBuilder<BinaryRelationBuilder>.name(value: string, language?: string): BinaryRelationBuilderAdds a name to the element in the given language.name('studies at')
.BinaryRelationBuilder.source(classifier: Classifier<any, any>): BinaryRelationBuilderSets the
Classifier
connected to the source end of the relation.source(const person: Classperson)
.BinaryRelationBuilder.target(classifier: Classifier<any, any>): BinaryRelationBuilderSets the
Classifier
connected to the target end of the relation.target(const school: Classschool)
.BinaryRelationBuilder.build(): BinaryRelationBuilds an instance of
BinaryRelation
with the parameters passed
to the builder. Both the source and the target classifiers are required
before `build()` is evoked. **WARNING:** the ordering in which methods
are evoked may affect the resulting object. When no methods are evoked,
the created relation has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`build();
// Named intervals:
const studiesAt: BinaryRelationstudiesAt.BinaryRelation.sourceEnd: PropertyThe relation end at the source (first) position.sourceEnd.Property.cardinality: CardinalityThe multiplicity of this property. Defaults to `0..*`.cardinality.Cardinality.setAsOneToMany(): voidSets the cardinality to `1..*`.setAsOneToMany(); // 1..*
const studiesAt: BinaryRelationstudiesAt.BinaryRelation.targetEnd: PropertyThe relation end at the target (second) position.targetEnd.Property.cardinality: CardinalityThe multiplicity of this property. Defaults to `0..*`.cardinality.Cardinality.setAsZeroToOne(): voidSets the cardinality to `0..1`.setAsZeroToOne(); // 0..1
// An arbitrary interval — at least two, at most five:
const studiesAt: BinaryRelationstudiesAt.BinaryRelation.sourceEnd: PropertyThe relation end at the source (first) position.sourceEnd.Property.cardinality: CardinalityThe multiplicity of this property. Defaults to `0..*`.cardinality.Cardinality.setBounds(lowerBound: number, upperBound?: number): voidSets both bounds of the cardinality at once. When the upper bound is
omitted or `Infinity`, the cardinality becomes unbounded (`"*"`).setBounds(2, 5);
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const studiesAt: BinaryRelationstudiesAt.BinaryRelation.sourceEnd: PropertyThe relation end at the source (first) position.sourceEnd.Property.cardinality: CardinalityThe multiplicity of this property. Defaults to `0..*`.cardinality.Cardinality.value: stringThe string representation of the cardinality (e.g., `"0..*"`), or `null`
when the cardinality is not set.value); // "2..5"
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const studiesAt: BinaryRelationstudiesAt.BinaryRelation.targetEnd: PropertyThe relation end at the target (second) position.targetEnd.Property.cardinality: CardinalityThe multiplicity of this property. Defaults to `0..*`.cardinality.Cardinality.isOptional(): booleanChecks whether the property is optional, i.e., whether the lower bound
of the cardinality is zero.isOptional()); // true
The same cardinality object lives on class attributes (attribute.cardinality)
— see Attributes for how it is set at build time.
Re-stereotyping
A stereotype is a plain field. Reassign it to reclassify an element — for
instance, when a modeling review decides a class you built as a kind is really
a subkind of another kind.
import { class ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project, enum ClassStereotypeThe OntoUML stereotypes applicable to a
Class
. Each stereotype
identifies the micro-theory of UFO that governs the class, constraining,
among other things, the ontological natures of its instances (see
Nature
), its rigidity, and the specializations in which it can
participate.ClassStereotype } from 'ontouml-js';
const const project: Projectproject = new new Project(): ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilderCreates a builder for a new
Package
in this project.packageBuilder().PackageBuilder.root(): PackageBuilderSets the package as the root package of its project, i.e., the package
that contains the entire model.root().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilderAdds a name to the element in the given language.name('People').PackageBuilder.build(): PackageBuilds an instance of
Package
with the parameters passed to the
builder. When no methods are evoked, the created package has the
following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `contents: []`build();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets the stereotype of the class to «kind», which decorates rigid
classes that provide an identity principle to their instances, which are
functional complexes (e.g., `Person`, `Car`). Also applies the following
defaults:
- `restrictedTo = [ "functional-complex" ]`
- `order = 1`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Person').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
const const man: Classman = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets the stereotype of the class to «kind», which decorates rigid
classes that provide an identity principle to their instances, which are
functional complexes (e.g., `Person`, `Car`). Also applies the following
defaults:
- `restrictedTo = [ "functional-complex" ]`
- `order = 1`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Man').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
// On reflection, Man isn't its own kind — it's a subkind of Person.
const man: Classman.Decoratable<ClassStereotype>.stereotype?: ClassStereotypeThe stereotype applied to this element, if any.stereotype = enum ClassStereotypeThe OntoUML stereotypes applicable to a
Class
. Each stereotype
identifies the micro-theory of UFO that governs the class, constraining,
among other things, the ontological natures of its instances (see
Nature
), its rigidity, and the specializations in which it can
participate.ClassStereotype.function (enum member) ClassStereotype.SUBKIND = "subkind"A rigid sortal that specializes a kind (or another ultimate sortal),
inheriting its identity principle, e.g., `Man` as a subkind of `Person`.SUBKIND;
const person: Classperson.Classifier<Class, ClassStereotype>.addChild(child: Class): GeneralizationCreates a
Generalization
in which this classifier is the
general and the given classifier is the specific.addChild(const man: Classman);
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const man: Classman.Class.isSubkind(): booleanChecks whether this class is stereotyped as «subkind».isSubkind()); // true
The builder shortcut .subkind() sets the stereotype and any prescribed
defaults; assigning stereotype directly changes only the label.
restrictedTo, order, and isAbstract keep their old values, so adjust them
too if the new stereotype implies different ones (e.g. a class you turn into a
category should also be made abstract).
Attributes and literals
Structure is edited by adding and removing the contained elements. Add an
attribute the same way you create any — from the class, via
propertyBuilder(). To remove one, call .delete() on it (covered next in
Deleting elements).
import { class ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project } from 'ontouml-js';
const const project: Projectproject = new new Project(): ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilderCreates a builder for a new
Package
in this project.packageBuilder().PackageBuilder.root(): PackageBuilderSets the package as the root package of its project, i.e., the package
that contains the entire model.root().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilderAdds a name to the element in the given language.name('Library').PackageBuilder.build(): PackageBuilds an instance of
Package
with the parameters passed to the
builder. When no methods are evoked, the created package has the
following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `contents: []`build();
const const string: Classstring = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.datatype(): ClassBuilderSets the stereotype of the class to «datatype», which decorates classes
whose instances are values of a (possibly structured) value space (e.g.,
`Date`, `Address`). Also applies the following defaults:
- `restrictedTo = [ "abstract" ]`
- `order = 1`datatype().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('String').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
const const book: Classbook = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets the stereotype of the class to «kind», which decorates rigid
classes that provide an identity principle to their instances, which are
functional complexes (e.g., `Person`, `Car`). Also applies the following
defaults:
- `restrictedTo = [ "functional-complex" ]`
- `order = 1`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Book').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
const const title: Propertytitle = const book: Classbook.Class.propertyBuilder(): PropertyBuilderCreates a builder for a
Property
owned by this class.propertyBuilder().NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilderAdds a name to the element in the given language.name('title').PropertyBuilder.type(c: Class): PropertyBuilderSets the
Class
that types the property, i.e., the class whose
instances are the possible values of the property.type(const string: Classstring).PropertyBuilder.one(): PropertyBuilderSets the cardinality of the property to `1`.one().PropertyBuilder.build(): PropertyBuilds an instance of
Property
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
property has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isDerived: false,`
- `isReadOnly: false,`
- `isOrdered: false,`
- `cardinality: "0..*"`build();
const book: Classbook.Class.propertyBuilder(): PropertyBuilderCreates a builder for a
Property
owned by this class.propertyBuilder().NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilderAdds a name to the element in the given language.name('subtitle').PropertyBuilder.type(c: Class): PropertyBuilderSets the
Class
that types the property, i.e., the class whose
instances are the possible values of the property.type(const string: Classstring).PropertyBuilder.optional(): PropertyBuilderSets the cardinality of the property to `0..1`.optional().PropertyBuilder.build(): PropertyBuilds an instance of
Property
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
property has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isDerived: false,`
- `isReadOnly: false,`
- `isOrdered: false,`
- `cardinality: "0..*"`build();
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const book: Classbook.Class.attributes: Property[]The attributes defined in this class, excluding inherited ones.attributes.Array<Property>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.length); // 2
// Drop one — its container releases it.
const title: Propertytitle.ModelElement.delete(): voidDeletes this element from its project, keeping the model consistent:
the deletion cascades to the elements that cannot exist without this
one (see
deleteDependents
), every reference to this element
held by other elements is cleaned up (see
removeReferences
),
and the element is detached from its container and removed from the
project's indexes.
Deleting an element that was already deleted has no effect.delete();
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const book: Classbook.Class.attributes: Property[]The attributes defined in this class, excluding inherited ones.attributes.Array<Property>.map<string>(callbackfn: (value: Property, index: number, array: Property[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.map(a: Propertya => a: Propertya.NamedElement.getNameOrId(language?: string): stringReturns the name of this element in the given language, falling back to
its
id
when no suitable name is available.getNameOrId())); // [ "subtitle" ]
Enumeration literals work the same way through literalBuilder() and
deleteLiteral().
Now you try it
Employee was built as a role but should be renamed and given a Portuguese
translation, and its salary attribute made mandatory (1). Make the three
edits, then read the console.
Show the solution
Key takeaways
- Names and descriptions are multilingual:
element.name.add(value, lang)to set or translate,element.name.clear()to empty. - Edit a cardinality in place with
setAsOneToMany(),setAsZeroToOne(),setBounds(lo, hi), … — on both relation ends and class attributes. - Re-stereotype by assigning the
stereotypefield, but remember it changes only the label — adjustrestrictedTo/isAbstractyourself. - Add structure with the same builders you used to create it; remove it with
.delete().