Skip to content

codenib.types

Classes:

Name Description
NodeInfo

Node attributes for graph nodes.

QueriedNode

Node attributes representing ranked nodes that keep optional content.

Functions:

Name Description
is_symbol_node

Whether node_type is any symbol (class/function/method/generic).

node_has_definition

Whether a symbol vertex has an observed definition location.

node_is_reference_only

Whether schema v5 explicitly marks a symbol as reference-only.

lsp_symbol_kind

Return the normalized semantic label for an LSP SymbolKind.

normalize_graph_layer

Normalize and validate a graph layer name.

edge_types_for_graph_layer

Return edge types included by a graph layer.

graph_layers_for_edge_type

Return every default layer that contains edge_type.

NodeInfo

Bases: BaseModel

Node attributes for graph nodes.

QueriedNode

Bases: NodeInfo

Node attributes representing ranked nodes that keep optional content.

is_symbol_node

is_symbol_node(node_type)

Whether node_type is any symbol (class/function/method/generic).

Source code in codenib/types.py
def is_symbol_node(node_type):
    """Whether ``node_type`` is any symbol (class/function/method/generic)."""
    return node_type in SYMBOL_TYPES

node_has_definition

node_has_definition(attributes: Mapping) -> bool

Whether a symbol vertex has an observed definition location.

Schema-v5 graphs carry an explicit boolean. The range-based fallback keeps transient graphs built by older in-memory callers usable; persisted v4 graphs are rejected by the schema-version guard before reaching consumers.

Source code in codenib/types.py
def node_has_definition(attributes: Mapping) -> bool:
    """Whether a symbol vertex has an observed definition location.

    Schema-v5 graphs carry an explicit boolean. The range-based fallback keeps
    transient graphs built by older in-memory callers usable; persisted v4
    graphs are rejected by the schema-version guard before reaching consumers.
    """

    explicit = attributes.get("has_definition")
    if isinstance(explicit, bool):
        return explicit
    return (
        is_symbol_node(attributes.get("type"))
        and isinstance(attributes.get("file"), str)
        and isinstance(attributes.get("start_line"), int)
        and not isinstance(attributes.get("start_line"), bool)
        and isinstance(attributes.get("end_line"), int)
        and not isinstance(attributes.get("end_line"), bool)
    )

node_is_reference_only

node_is_reference_only(attributes: Mapping) -> bool

Whether schema v5 explicitly marks a symbol as reference-only.

Source code in codenib/types.py
def node_is_reference_only(attributes: Mapping) -> bool:
    """Whether schema v5 explicitly marks a symbol as reference-only."""

    return attributes.get("has_definition") is False

lsp_symbol_kind

lsp_symbol_kind(kind: object) -> str | None

Return the normalized semantic label for an LSP SymbolKind.

Source code in codenib/types.py
def lsp_symbol_kind(kind: object) -> Optional[str]:
    """Return the normalized semantic label for an LSP ``SymbolKind``."""

    if isinstance(kind, bool) or not isinstance(kind, int):
        return None
    return LSP_SYMBOL_KINDS.get(kind)

normalize_graph_layer

normalize_graph_layer(layer)

Normalize and validate a graph layer name.

Source code in codenib/types.py
def normalize_graph_layer(layer):
    """Normalize and validate a graph layer name."""
    normalized = (layer or "").strip().lower()
    if normalized not in GRAPH_LAYER_EDGE_TYPES:
        supported = ", ".join(sorted(GRAPH_LAYER_EDGE_TYPES))
        raise ValueError(f"Unknown graph layer {layer!r}; supported: {supported}")
    return normalized

edge_types_for_graph_layer

edge_types_for_graph_layer(layer)

Return edge types included by a graph layer.

None means "all edge types currently present in the graph".

Source code in codenib/types.py
def edge_types_for_graph_layer(layer):
    """Return edge types included by a graph layer.

    ``None`` means "all edge types currently present in the graph".
    """
    return GRAPH_LAYER_EDGE_TYPES[normalize_graph_layer(layer)]

graph_layers_for_edge_type

graph_layers_for_edge_type(edge_type)

Return every default layer that contains edge_type.

Source code in codenib/types.py
def graph_layers_for_edge_type(edge_type):
    """Return every default layer that contains ``edge_type``."""
    layers = [GRAPH_LAYER_ALL]
    for layer, edge_types in GRAPH_LAYER_EDGE_TYPES.items():
        if layer == GRAPH_LAYER_ALL:
            continue
        if edge_types is not None and edge_type in edge_types:
            layers.append(layer)
    return layers