Removing a model definition can affect later levels. previewNodeRemoval() and previewRelationRemoval() show the effects without changing the model.
RMF previews list affected nodes and relationships. The RAMEN API extends these previews with annotation declarations that would be removed or changed.
Page refines Document. Removing Document would also remove Page:
import { Modeller } from '@ramen-suite/core/model';
import type { Node, NodeRemovalPreview } from '@ramen-suite/core/model';
const filing: Modeller = Modeller.create('Filing');
const document: Node = filing.createNode('Document').element;
const website: Modeller = filing.createNextLevel('Website');
const page: Node = website.createNode({ name: 'Page', refines: document }).element;
const preview: NodeRemovalPreview = filing.previewNodeRemoval(document.id);
console.log(preview.nodes);
// Document in Filing; Page in Website.
Each preview item has a modelId and elementId, so a tool can identify the affected definition and level. preview.relations lists relationships that would also be removed. Domain extensions may fill annotations and updatedAnnotations with other affected definitions.
removeNode(document.id) throws while Page depends on Document and leaves the draft unchanged. After showing the preview, a tool may request the full removal explicitly:
filing.removeNode(document.id, { cascade: true });
// Document and Page are removed together.
The same rule applies to a relationship selected on a later level. In a fresh model, Website applies Filing's FILED_IN relationship:
import type { Relation, RelationRemovalPreview } from '@ramen-suite/core/model';
const base: Modeller = Modeller.create('Filing');
const record: Node = base.createNode('Record').element;
const folder: Node = base.createNode('Folder').element;
const filedIn: Relation = base.createRelation({
name: 'FILED_IN',
from: { node: record },
to: { node: folder },
}).element;
const next: Modeller = base.createNextLevel('Website');
const pageType: Node = next.createNode({ name: 'Page', refines: record }).element;
next.createRelation({ refines: filedIn, from: { node: pageType }, to: { node: folder } });
const links: RelationRemovalPreview = base.previewRelationRemoval(filedIn.id);
console.log(links.relations);
// FILED_IN and its Website refinement.
removeRelation(filedIn.id) throws while the later relationship depends on it. { cascade: true } removes both. A preview lists the effects of one proposed removal, while snapshot() saves an independent copy of the whole editable workspace.