ParaShape

NodeCollection

Source: packages/parametric/src/nodes/NodeCollection.ts

Properties

NameTypeDescription
registryRegistry | undefinedThe merged node registry, resolved through the owner chain (the root collection's owner is the ModelScope carrying it). Detached collections (a node not yet added) resolve nothing — the fromJSON path threads the registry explicitly instead.

Methods

SignatureDescription
createFromJSON(json: NodeJSON, registryParam?: Registry, lane: ModelLane): T | nullDeserialize a single NodeJSON (operation | container form) into the appropriate typed node instance, or null if unrecognized. lane = which model section the node sits in — value methods build ParameterNode/AssetNode (header), entity methods build OperationNode.
rootNodes(): NodeCollectionThe model's ROOT node collection. Keys are referenced from expressions model-wide, so key generation/rename checks must see EVERY node — not just this subtree (a container's child colliding with a root node would make the reference ambiguous). Falls back to this collection when detached.
keyExists(key: string, except?: BaseNode): booleanTrue when key is used by any node in the model other than except.
renameReferences(oldKey: string, newKey: string): voidRewrite every expression in the model that references oldKey as an identifier to newKey — called after a successful setKey() so a rename doesn't silently break every formula that referenced the old name. Each rewritten node's setInput() cascades its own dirty flag; this re-evaluates once at the end (a single batch, not one pull per rewritten expression).
addOperation(method: string, argsMap: Record<string, string>, key?: string): OperationNodeCreate and add an entity operation bound to the given registry method. Auto-assigns a model-wide-unique key from the registry's defaultKey ("array1", "fillet2", …) so the result is referenceable immediately.
addContainer(key?: string): ContainerNodeCreate and add an empty container; returns the new node.
addAsset(method: "createMaterial" | "createLayer"): AssetNodeCreate and add a material/layer resource declaration (AssetNode); returns the new node.
traverse(fn: (node: BaseNode) => void): voidWalk every node in the collection (including nested children) and call fn on each.