Skip to content

ChainGraph API Documentation / @badaitech/chaingraph-types / ITreeStore

Interface: ITreeStore<TNode, TCreate, TUpdate>

Defined in: packages/chaingraph-types/src/hierarchy/types.ts:82

Generic tree store interface that all hierarchical stores must implement Provides consistent CRUD + tree operations

Type Parameters

TNode

TNode extends ITreeNode

TCreate

TCreate extends ICreateTreeNodeInput

TUpdate

TUpdate extends IUpdateTreeNodeInput

Properties

create()

create: (input) => Promise<TNode>

Defined in: packages/chaingraph-types/src/hierarchy/types.ts:92

Create a new node in the tree

Parameters

input

TCreate

Returns

Promise<TNode>


delete()

delete: (id) => Promise<boolean>

Defined in: packages/chaingraph-types/src/hierarchy/types.ts:109

Delete a node from the tree Implementation should handle cascade strategy

Parameters

id

string

Returns

Promise<boolean>


get()

get: (id) => Promise<TNode | null>

Defined in: packages/chaingraph-types/src/hierarchy/types.ts:97

Get a single node by ID

Parameters

id

string

Returns

Promise<TNode | null>


getAncestors()

getAncestors: (nodeId) => Promise<TNode[]>

Defined in: packages/chaingraph-types/src/hierarchy/types.ts:148

Get all ancestor nodes of a node (path to root)

Parameters

nodeId

string

Starting node ID

Returns

Promise<TNode[]>


getDescendants()

getDescendants: (rootId, ownerId) => Promise<TNode[]>

Defined in: packages/chaingraph-types/src/hierarchy/types.ts:142

Get all descendant nodes of a root node (recursive)

Parameters

rootId

string

Root node ID

ownerId

string

Owner to verify access

Returns

Promise<TNode[]>


getMaxOrder()

getMaxOrder: (parentId, ownerId) => Promise<number>

Defined in: packages/chaingraph-types/src/hierarchy/types.ts:155

Get maximum order value in a parent for appending

Parameters

parentId

Parent node ID (null = root level)

string | null

ownerId

string

Owner ID to filter by

Returns

Promise<number>


hasAccess()

hasAccess: (nodeId, userId) => Promise<boolean>

Defined in: packages/chaingraph-types/src/hierarchy/types.ts:162

Check if user has access to a node

Parameters

nodeId

string

Node ID to check

userId

string

User ID to verify

Returns

Promise<boolean>


list()

list: (ownerId, rootId?, limit?) => Promise<TNode[]>

Defined in: packages/chaingraph-types/src/hierarchy/types.ts:119

List all nodes for a user

Parameters

ownerId

string

User ID to filter by

rootId?

Optional root node to filter descendants

string | null

limit?

number

Maximum number of results

Returns

Promise<TNode[]>


listChildren()

listChildren: (parentId) => Promise<TNode[]>

Defined in: packages/chaingraph-types/src/hierarchy/types.ts:125

List direct children of a parent node

Parameters

parentId

Parent node ID (null = root level)

string | null

Returns

Promise<TNode[]>


move()

move: (input) => Promise<TNode>

Defined in: packages/chaingraph-types/src/hierarchy/types.ts:133

Move a node to a new parent and/or order Must prevent circular references

Parameters

input

IMoveTreeNodeInput

Returns

Promise<TNode>


update()

update: (input) => Promise<TNode>

Defined in: packages/chaingraph-types/src/hierarchy/types.ts:103

Update node metadata (name, description, color, etc.) Does NOT move the node in the tree

Parameters

input

TUpdate

Returns

Promise<TNode>


wouldCreateCircularRef()

wouldCreateCircularRef: (sourceId, targetParentId) => Promise<boolean>

Defined in: packages/chaingraph-types/src/hierarchy/types.ts:169

Check if moving a node would create a circular reference

Parameters

sourceId

string

Node being moved

targetParentId

string

Proposed new parent

Returns

Promise<boolean>

Licensed under BUSL-1.1