Client Extension API reference
List of all available methods on an Bark extended Prisma client.
Good to know
Bark doesn't override any of the existing Prisma model queries but it is strongly recommended to create / delete new nodes using the extensions API otherwise the tree structure might not work and require a lot of manual intervention to untangle it. For similar reasons it's best not to directly update path
, numchild
, and depth
properties.
Extend a Prisma Client
To extend a Prisma Client you only have to import Bark and call it with the Bark-compatible models passed into the modelNames
property.
Create
createRoot
createRoot
Creates a root node if one doesn't exist already or adds a sibling to an already existing one. Returns the newly create node entry.
data
Yes*
Object that will be used to create new record in database.
...args
No
createChild
createChild
Creates a new child to the defined node in either where
or node
arguments. Returns the newly create node entry.
node
Yes unless where
An existing node used as a reference where the incoming entry should be created.
where
Yes unless node
Query to find an existing node to be used as a reference.
data
Yes*
...args
No
createSibling
createSibling
Creates a new sibling to the defined node in either where
or node
arguments. The node will be created at after last sibling of the level. Returns the newly create node entry.
node
Yes unless where
An existing node used as a reference where the incoming entry should be created.
where
Yes unless node
Query to find an existing node to be used as a reference.
data
Yes*
...args
No
Find
findAncestors
findAncestors
Returns all ancestors, from the root node to the parent, of the defined node in either where
or node
arguments. If the findAncestors
called on a root node it will return null
. By default the tree is ordered by path
in ascending order.
node
Yes unless where
An existing node used as a reference where the incoming entry should be created.
where
Yes unless node
Query to find an existing node to be used as a reference.
orderBy
No
Lets you order the returned list by any property. Defaults to { path: 'asc' }
...args
No
findDescendants
findDescendants
Returns all descendants, excluding itself, of the defined node in either where
or node
arguments. If the findDescendants
called on a leaf node it will return null
. By default the tree is ordered by path
in ascending order.
node
Yes unless where
An existing node used as a reference where the incoming entry should be created.
where
Yes unless node
Query to find an existing node to be used as a reference.
orderBy
No
Lets you order the returned list by any property. Defaults to { path: 'asc' }
...args
No
findParent
findParent
Return the parent node of the defined node in either where
or node
arguments. If the findParent
called on a root node it will return null
.
node
Yes unless where
An existing node used as a reference where the incoming entry should be created.
where
Yes unless node
Query to find an existing node to be used as a reference.
...args
No
findChildren
findChildren
Returns all direct children nodes of the defined node in either where
or node
arguments. When no children were found it will return null
. By default the tree is ordered by path
in ascending order.
node
Yes unless where
An existing node used as a reference where the incoming entry should be created.
where
Yes unless node
Query to find an existing node to be used as a reference.
orderBy
No
Lets you order the returned list by any property. Defaults to { path: 'asc' }
...args
No
findSiblings
findSiblings
Returns all sibling nodes, including itself, of the defined node in either where
or node
arguments. By default the tree is ordered by path
in ascending order.
node
Yes unless where
An existing node used as a reference where the incoming entry should be created.
where
Yes unless node
Query to find an existing node to be used as a reference.
orderBy
No
Lets you order the returned list by any property. Defaults to { path: 'asc' }
...args
No
findLastRoot
findLastRoot
Returns the last root node. If no root node exist it returns null
.
...args
No
Delete
deleteNode
deleteNode
Deletes the node and all its descendants. Returns the count of deleted nodes just like deleteMany
would.
node
Yes unless where
An existing node used as a reference where the incoming entry should be created.
where
Yes unless node
Query to find an existing node to be used as a reference.
deleteManyNodes
deleteManyNodes
Deletes all matching nodes found by the where
filter and their descendants using the least number of operations. Returns the count of deleted nodes just like deleteMany
would. If no nodes were deleted it will return null
.
where
Yes
Operation
move
move
Move the node of the defined node in either where
or node
arguments relative to the reference
's node and the position
argument. Throws if the targeted node is trying to be moved to own of its descendants, if the node is already in the requested position, or if either the target or the referenced node is not found. Returns undefined
node
Yes unless where
An existing node used as a reference where the incoming entry should be move.
where
Yes unless node
Query to find an existing node to be used as a reference.
position
Yes
One of the following: first-child
, last-child
, first-sibling
, left
, right
, or last-sibling
reference.node
Yes unless reference.where
An existing node used as a reference point to move.
reference.where
Yes unless reference.node
Query to find an existing node to be used as a reference.
fixTree
[TBD]
fixTree
[TBD]Not currently implemented. See issue on GitHub to make your voice heard, or have a go at it.
Helpers [TBD]
These would serve as a syntactic sugar to help make repetitive task easier. An example function be isDescendantOf
, a function that would compare a node to another return true if it's, well, a descendant of it. Let us know what helpers function you'd find useful on the dedicated GitHub issue.
Last updated