Node Operations
CRUD operations, tree traversal, and relationships.
NodeOperations
Access node operations through a workspace:
const ws = db.workspace('content');
const nodes = ws.nodes();
create()
create(options: NodeCreateOptions): Promise<Node>
interface NodeCreateOptions {
type: string;
path: string;
properties?: Record<string, any>;
content?: any;
}
get()
Get a node by ID.
get(id: string): Promise<Node | null>
getByPath()
Get a node by its path.
getByPath(path: string): Promise<Node | null>
update()
update(id: string, options: NodeUpdateOptions): Promise<Node>
delete()
delete(id: string): Promise<boolean>
query()
query(options: NodeQueryOptions): Promise<Node[]>
queryByType()
queryByType(nodeType: string, limit?: number): Promise<Node[]>
queryByProperty()
queryByProperty(name: string, value: any, limit?: number): Promise<Node[]>
Tree Operations
listChildren()
listChildren(parentPath: string): Promise<Node[]>
getChildren()
getChildren(parentId: string, limit?: number): Promise<Node[]>
getChildrenByPath()
getChildrenByPath(parentPath: string, limit?: number): Promise<Node[]>
getTree()
Returns a nested tree structure rooted at the given path.
getTree(rootPath: string, maxDepth?: number): Promise<Node>
getTreeFlat()
Returns a flat array of all nodes in the subtree.
getTreeFlat(rootPath: string, maxDepth?: number): Promise<Node[]>
move()
move(fromPath: string, toParentPath: string): Promise<Node>
rename()
rename(nodePath: string, newName: string): Promise<Node>
copy()
Shallow copy (node only, no children).
copy(fromPath: string, toParentPath: string, newName?: string): Promise<Node>
copyTree()
Deep copy (node and all descendants).
copyTree(fromPath: string, toParentPath: string, newName?: string): Promise<Node>
reorder()
Set the order key for a node.
reorder(nodePath: string, orderKey: string): Promise<Node>
moveChildBefore()
Move a child before a reference sibling.
moveChildBefore(
parentPath: string,
childPath: string,
referencePath: string
): Promise<Node>
moveChildAfter()
Move a child after a reference sibling.
moveChildAfter(
parentPath: string,
childPath: string,
referencePath: string
): Promise<Node>
Relationships
addRelation()
addRelation(
nodePath: string,
relationType: string,
targetNodePath: string,
options?: { weight?: number; targetWorkspace?: string }
): Promise<boolean>
removeRelation()
removeRelation(nodePath: string, targetPath: string): Promise<boolean>
getRelationships()
getRelationships(nodePath: string): Promise<NodeRelationships>
Returns:
interface NodeRelationships {
outgoing: Relation[];
incoming: Relation[];
}