Skip to main content
Version: Next

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.

Builders create; elements mutate

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 Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
} from 'ontouml-js';
const const project: Projectproject = new new Project(): Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilder
Creates a builder for a new Package in this project.
packageBuilder
().PackageBuilder.root(): PackageBuilder
Sets the package as the root package of its project, i.e., the package that contains the entire model.
@returnsthis builder, for method chaining.
root
().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('People').PackageBuilder.build(): Package
Builds 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: []`
@throwsan error if the builder has already been used.
build
();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Person').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
// Replace the English name… const person: Classperson.NamedElement.name: LanguageString
The name of this element, possibly in multiple languages.
name
.LanguageString.add(value: string, language?: string): void
Adds a text value in the given language, replacing any existing value for that language.
@paramvalue - the text to add.@paramlanguage - language tag of `value`; defaults to defaultLanguage.@throwsan error if `language` is not a valid language tag.
add
('Human');
// …and add a Portuguese one alongside it. const person: Classperson.NamedElement.name: LanguageString
The name of this element, possibly in multiple languages.
name
.LanguageString.add(value: string, language?: string): void
Adds a text value in the given language, replacing any existing value for that language.
@paramvalue - the text to add.@paramlanguage - language tag of `value`; defaults to defaultLanguage.@throwsan error if `language` is not a valid language tag.
add
('Humano', 'pt');
var console: Consoleconsole.Console.log(...data: any[]): void
The **`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: LanguageString
The name of this element, possibly in multiple languages.
name
.LanguageString.get(language?: string): string | null
Returns 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`.
@paramlanguage - language tag of the desired value (e.g., `"en"`).@throwsan error if `language` is provided but invalid or has no value.
get
()); // "Human" (default language)
var console: Consoleconsole.Console.log(...data: any[]): void
The **`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: LanguageString
The name of this element, possibly in multiple languages.
name
.LanguageString.get(language?: string): string | null
Returns 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`.
@paramlanguage - language tag of the desired value (e.g., `"en"`).@throwsan error if `language` is provided but invalid or has no value.
get
('pt')); // "Humano"
// Wipe all names. const person: Classperson.NamedElement.name: LanguageString
The name of this element, possibly in multiple languages.
name
.LanguageString.clear(): void
Removes all values of this text, in every language.
clear
();
var console: Consoleconsole.Console.log(...data: any[]): void
The **`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): string
Returns the name of this element in the given language, falling back to its id when no suitable name is available.
@paramlanguage - language tag of the desired name (e.g., `"en"`); when omitted, the name is selected according to LanguageString.languagePreference.
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 Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
} from 'ontouml-js';
const const project: Projectproject = new new Project(): Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilder
Creates a builder for a new Package in this project.
packageBuilder
().PackageBuilder.root(): PackageBuilder
Sets the package as the root package of its project, i.e., the package that contains the entire model.
@returnsthis builder, for method chaining.
root
().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('School').PackageBuilder.build(): Package
Builds 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: []`
@throwsan error if the builder has already been used.
build
();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Person').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const const school: Classschool = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('School').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const const studiesAt: BinaryRelationstudiesAt = const model: Packagemodel .Package.binaryRelationBuilder(): BinaryRelationBuilder
Creates a builder for a BinaryRelation contained in this package.
binaryRelationBuilder
()
.BinaryRelationBuilder.material(): BinaryRelationBuilder
Sets 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`
@returnsthis builder, for method chaining.
material
()
.NamedElementBuilder<BinaryRelationBuilder>.name(value: string, language?: string): BinaryRelationBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('studies at')
.BinaryRelationBuilder.source(classifier: Classifier<any, any>): BinaryRelationBuilder
Sets the Classifier connected to the source end of the relation.
@returnsthis builder, for method chaining.
source
(const person: Classperson)
.BinaryRelationBuilder.target(classifier: Classifier<any, any>): BinaryRelationBuilder
Sets the Classifier connected to the target end of the relation.
@returnsthis builder, for method chaining.
target
(const school: Classschool)
.BinaryRelationBuilder.build(): BinaryRelation
Builds 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,`
@throwsan error if the builder has already been used.
build
();
// Named intervals: const studiesAt: BinaryRelationstudiesAt.BinaryRelation.sourceEnd: Property
The relation end at the source (first) position.
sourceEnd
.Property.cardinality: Cardinality
The multiplicity of this property. Defaults to `0..*`.
cardinality
.Cardinality.setAsOneToMany(): void
Sets the cardinality to `1..*`.
setAsOneToMany
(); // 1..*
const studiesAt: BinaryRelationstudiesAt.BinaryRelation.targetEnd: Property
The relation end at the target (second) position.
targetEnd
.Property.cardinality: Cardinality
The multiplicity of this property. Defaults to `0..*`.
cardinality
.Cardinality.setAsZeroToOne(): void
Sets the cardinality to `0..1`.
setAsZeroToOne
(); // 0..1
// An arbitrary interval — at least two, at most five: const studiesAt: BinaryRelationstudiesAt.BinaryRelation.sourceEnd: Property
The relation end at the source (first) position.
sourceEnd
.Property.cardinality: Cardinality
The multiplicity of this property. Defaults to `0..*`.
cardinality
.Cardinality.setBounds(lowerBound: number, upperBound?: number): void
Sets both bounds of the cardinality at once. When the upper bound is omitted or `Infinity`, the cardinality becomes unbounded (`"*"`).
@throwsan error if the bounds are out of range or the lower bound exceeds the upper bound.
setBounds
(2, 5);
var console: Consoleconsole.Console.log(...data: any[]): void
The **`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: Property
The relation end at the source (first) position.
sourceEnd
.Property.cardinality: Cardinality
The multiplicity of this property. Defaults to `0..*`.
cardinality
.Cardinality.value: string
The 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[]): void
The **`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: Property
The relation end at the target (second) position.
targetEnd
.Property.cardinality: Cardinality
The multiplicity of this property. Defaults to `0..*`.
cardinality
.Cardinality.isOptional(): boolean
Checks 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 Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
, enum ClassStereotype
The 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(): Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilder
Creates a builder for a new Package in this project.
packageBuilder
().PackageBuilder.root(): PackageBuilder
Sets the package as the root package of its project, i.e., the package that contains the entire model.
@returnsthis builder, for method chaining.
root
().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('People').PackageBuilder.build(): Package
Builds 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: []`
@throwsan error if the builder has already been used.
build
();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Person').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const const man: Classman = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Man').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
// On reflection, Man isn't its own kind — it's a subkind of Person. const man: Classman.Decoratable<ClassStereotype>.stereotype?: ClassStereotype
The stereotype applied to this element, if any.
stereotype
= enum ClassStereotype
The 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): Generalization
Creates a Generalization in which this classifier is the general and the given classifier is the specific.
@paramchild - the classifier to be set as the specific.@returnsthe newly created generalization.
addChild
(const man: Classman);
var console: Consoleconsole.Console.log(...data: any[]): void
The **`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(): boolean
Checks whether this class is stereotyped as «subkind».
isSubkind
()); // true
Assigning the field skips the defaults

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 Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
} from 'ontouml-js';
const const project: Projectproject = new new Project(): Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilder
Creates a builder for a new Package in this project.
packageBuilder
().PackageBuilder.root(): PackageBuilder
Sets the package as the root package of its project, i.e., the package that contains the entire model.
@returnsthis builder, for method chaining.
root
().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Library').PackageBuilder.build(): Package
Builds 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: []`
@throwsan error if the builder has already been used.
build
();
const const string: Classstring = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.datatype(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
datatype
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('String').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const const book: Classbook = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Book').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const const title: Propertytitle = const book: Classbook.Class.propertyBuilder(): PropertyBuilder
Creates a builder for a Property owned by this class.
propertyBuilder
().NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('title').PropertyBuilder.type(c: Class): PropertyBuilder
Sets the Class that types the property, i.e., the class whose instances are the possible values of the property.
@returnsthis builder, for method chaining.
type
(const string: Classstring).PropertyBuilder.one(): PropertyBuilder
Sets the cardinality of the property to `1`.
@returnsthis builder, for method chaining.
one
().PropertyBuilder.build(): Property
Builds 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..*"`
@throwsan error if the builder has already been used.
build
();
const book: Classbook.Class.propertyBuilder(): PropertyBuilder
Creates a builder for a Property owned by this class.
propertyBuilder
().NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('subtitle').PropertyBuilder.type(c: Class): PropertyBuilder
Sets the Class that types the property, i.e., the class whose instances are the possible values of the property.
@returnsthis builder, for method chaining.
type
(const string: Classstring).PropertyBuilder.optional(): PropertyBuilder
Sets the cardinality of the property to `0..1`.
@returnsthis builder, for method chaining.
optional
().PropertyBuilder.build(): Property
Builds 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..*"`
@throwsan error if the builder has already been used.
build
();
var console: Consoleconsole.Console.log(...data: any[]): void
The **`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: number
Gets 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(): void
Deletes 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[]): void
The **`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.
@paramcallbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
map
(a: Propertya => a: Propertya.NamedElement.getNameOrId(language?: string): string
Returns the name of this element in the given language, falling back to its id when no suitable name is available.
@paramlanguage - language tag of the desired name (e.g., `"en"`); when omitted, the name is selected according to LanguageString.languagePreference.
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.

Loading playground…
Show the solution
Loading playground…

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 stereotype field, but remember it changes only the label — adjust restrictedTo/isAbstract yourself.
  • Add structure with the same builders you used to create it; remove it with .delete().

Next: moving elements between packages →.