feat(8.0): related({ node }) — one-call both-direction incident edges
related({ from }) / related({ to }) each return one direction; related({ node })
unions both (every edge where the node is source OR target), deduped, in a single
O(degree) call — the indexed equivalent of merging two related() calls by hand.
The 'all edges on a noun' query the graph-viz path needs.
- RelatedParams.node: mutually exclusive with from/to (throws if combined);
composes with type/subtype/visibility filters; natural-key ids resolved.
- Implemented as a parallel out-edge (sourceId) + in-edge (targetId) fetch through
the O(degree) graph-index fast paths, merged + deduped by id (a self-loop appears
once), sorted for a stable page. Full incidence is the intended O(degree) cost;
deep offset paging of a very-high-degree node is best-effort (use the native
edgesForNode / a graph cursor for exhaustive paging).
- db.related() parity: node resolved + honored in relationMatchesParams (matches an
edge incident in either direction) for the historical/overlay paths.
Test: related-node-bidirectional.test.ts — both directions, equals from∪to, self-loop
dedupe, type-filter composition, default-hides-internal, node+from/to throws.
This commit is contained in:
parent
a3d6fdb8b3
commit
d4de48d004
4 changed files with 161 additions and 19 deletions
|
|
@ -684,6 +684,21 @@ export interface RelatedParams {
|
|||
*/
|
||||
to?: string
|
||||
|
||||
/**
|
||||
* Filter by INCIDENT entity ID — every relationship touching this entity in
|
||||
* EITHER direction (where it is the source OR the target), deduped. The
|
||||
* one-call "all edges on a noun" query: equivalent to merging
|
||||
* `related({ from: id })` and `related({ to: id })` but in a single
|
||||
* O(degree) call. Mutually exclusive with `from` / `to` (pass `node` for
|
||||
* both directions, or `from` / `to` for one). Composes with `type` /
|
||||
* `subtype` / visibility filters.
|
||||
*
|
||||
* @example
|
||||
* // Everything connected to this person, in or out.
|
||||
* const edges = await brain.related({ node: personId })
|
||||
*/
|
||||
node?: string
|
||||
|
||||
/**
|
||||
* Filter by relationship type(s)
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue