Deleting elements
Removing an element is more than dropping it from a list. A model is a web of
references — relations point at classes, generalizations connect classifiers,
anchors tie notes to elements — and a delete has to leave that web consistent.
element.delete() does the whole job.
Some elements cannot exist without the one you remove. A «mediation» relation
is meaningless once one of the classes it connects is gone; a generalization
needs both its general and its specific; a view has nothing to depict once its
element is deleted. So delete() cascades to those dependents, then
clears every remaining reference held by survivors (a generalization set's
categorizer, a diagram's owner), and finally detaches the element from its
container.
Deleting a single element
Call .delete() on the element. It is removed from the project's indexes and
from its container in one call.
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('Model').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 note: Classnote = 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('Note').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();
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 project: Projectproject.Project.classes: Class[]The classes contained in this project.classes.Array<Class>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.length); // 2
const note: Classnote.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 project: Projectproject.Project.classes: Class[]The classes contained in this project.classes.Array<Class>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.length); // 1
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 model: Packagemodel.Package.contents: PackageableElement[]The model elements directly contained in this package.
Sets the model elements directly contained in this package, detaching
any previous contents.contents.Array<PackageableElement>.includes(searchElement: PackageableElement, fromIndex?: number): booleanDetermines whether an array includes a certain element, returning true or false as appropriate.includes(const note: Classnote)); // false
Deleting an element that is already deleted is a no-op — safe to call twice, so you never have to guard against double removal.
What a class delete cascades to
Deleting a classifier (a class or relation) is the far-reaching case. It removes everything that existentially depends on it:
- the relations in which it types an end,
- the generalizations it participates in,
- its own attributes (or relation ends),
- the anchors and views that reference it.
Attributes elsewhere that were typed by the class aren't deleted — instead
their propertyType is cleared, since an attribute can outlive the loss of its
type.
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('Model').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 student: Classstudent = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.role(): ClassBuilderSets the stereotype of the class to «role», which decorates anti-rigid
classes whose instances are contingently classified by virtue of a
relational condition (e.g., `Student`, `Employee`).role().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Student').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 enrollment: Classenrollment = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.relator(): ClassBuilderSets the stereotype of the class to «relator», which decorates rigid
classes whose instances are relators, i.e., entities that mediate other
entities and are the truthmakers of material relations (e.g.,
`Marriage`, `Enrollment`). Also applies the following defaults:
- `restrictedTo = [ "relator" ]`
- `order = 1`relator().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Enrollment').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 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 student: Classstudent); // a generalization
const const mediates: BinaryRelationmediates = const model: Packagemodel
.Package.binaryRelationBuilder(): BinaryRelationBuilderCreates a builder for a
BinaryRelation
contained in this
package.binaryRelationBuilder()
.BinaryRelationBuilder.mediation(): BinaryRelationBuilderSets the stereotype of the relation to «mediation», which decorates
relations between a relator and an endurant it mediates, such as a
marriage and one of its spouses. Also applies the following defaults:
- `sourceCardinality = "1..*"`
- `targetCardinality = "1"`
- `targetEnd.isReadOnly = true`mediation()
.BinaryRelationBuilder.source(classifier: Classifier<any, any>): BinaryRelationBuilderSets the
Classifier
connected to the source end of the relation.source(const enrollment: Classenrollment)
.BinaryRelationBuilder.target(classifier: Classifier<any, any>): BinaryRelationBuilderSets the
Classifier
connected to the target end of the relation.target(const student: Classstudent)
.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();
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 project: Projectproject.Project.generalizations: Generalization[]The generalizations contained in this project.generalizations.Array<Generalization>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.length); // 1
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 project: Projectproject.Project.binaryRelations: BinaryRelation[]The binary relations contained in this project.binaryRelations.Array<T>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.length); // 1
// Removing Student takes its generalization and its mediation with it.
const student: Classstudent.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 project: Projectproject.Project.generalizations: Generalization[]The generalizations contained in this project.generalizations.Array<Generalization>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.length); // 0 — cascaded
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 project: Projectproject.Project.binaryRelations: BinaryRelation[]The binary relations contained in this project.binaryRelations.Array<T>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.length); // 0 — cascaded
Deleting a package
Deleting a package deletes everything it contains, recursively — the natural way to drop an entire sub-domain. Delete a leaf element to remove just that one; delete its package to remove the whole subtree.
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('Model').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 payments: Packagepayments = const model: Packagemodel.Package.packageBuilder(): PackageBuilderCreates a builder for a
Package
contained in this package.packageBuilder().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilderAdds a name to the element in the given language.name('Payments').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 payments: Packagepayments.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('Invoice').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 payments: Packagepayments.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.relator(): ClassBuilderSets the stereotype of the class to «relator», which decorates rigid
classes whose instances are relators, i.e., entities that mediate other
entities and are the truthmakers of material relations (e.g.,
`Marriage`, `Enrollment`). Also applies the following defaults:
- `restrictedTo = [ "relator" ]`
- `order = 1`relator().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Payment').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();
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 project: Projectproject.Project.classes: Class[]The classes contained in this project.classes.Array<Class>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.length); // 2
const payments: Packagepayments.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(); // takes Invoice and Payment with it
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 project: Projectproject.Project.classes: Class[]The classes contained in this project.classes.Array<Class>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.length); // 0
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 model: Packagemodel.Package.contents: PackageableElement[]The model elements directly contained in this package.
Sets the model elements directly contained in this package, detaching
any previous contents.contents.Array<PackageableElement>.includes(searchElement: PackageableElement, fromIndex?: number): booleanDetermines whether an array includes a certain element, returning true or false as appropriate.includes(const payments: Packagepayments)); // false
Bulk cleanup with a query
Because delete() is safe to call on any element, pairing it with a
query prunes a model in a single pass — a common step in a
model-to-model transformation. Snapshot the query result into an array first,
so you iterate over a stable list rather than one shifting under you.
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('Model').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 model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.role(): ClassBuilderSets the stereotype of the class to «role», which decorates anti-rigid
classes whose instances are contingently classified by virtue of a
relational condition (e.g., `Student`, `Employee`).role().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Student').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 model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.role(): ClassBuilderSets the stereotype of the class to «role», which decorates anti-rigid
classes whose instances are contingently classified by virtue of a
relational condition (e.g., `Student`, `Employee`).role().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Teacher').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();
// Drop every role — e.g. to derive a "rigid-only" projection of the model.
const const roles: Class[]roles = [...const project: Projectproject.Queries.getRoles(): Class[]Retrieves all classes in scope stereotyped as «role».getRoles()];
const roles: Class[]roles.Array<Class>.forEach(callbackfn: (value: Class, index: number, array: Class[]) => void, thisArg?: any): voidPerforms the specified action for each element in an array.forEach(role: Classrole => role: Classrole.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 project: Projectproject.Project.classes: Class[]The classes contained in this project.classes.Array<Class>.map<string>(callbackfn: (value: Class, index: number, array: Class[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.map(c: Classc => c: Classc.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())); // [ "Person" ]
Now you try it
LegacyData is a package holding two classes you no longer want. Delete the
whole package, then confirm the model is empty.
Show the solution
Key takeaways
element.delete()removes an element, cascades to its dependents, clears references to it, and detaches it from its container.- Deleting a classifier also removes its relations, generalizations, and own properties; attributes typed by it keep existing with a cleared type.
- Deleting a package deletes its whole subtree recursively.
delete()on an already-deleted element is a no-op, so it composes cleanly with a query for bulk pruning — snapshot the results into an array first.
That completes editing a model. Next, learn to read one back in depth under Querying, or round-trip it to disk under Serialization.