UNPKG

@loopback/context-explorer

Version:

Visualize context hierarchy, bindings, configurations, and dependencies

100 lines (99 loc) 2.75 kB
import { JSONObject } from '@loopback/core'; import { ICluster, IEdge, INode } from 'ts-graphviz'; /** * A wrapper class for context, binding, and its level in the chain */ export declare class ContextBinding { readonly context: JSONObject; readonly binding: JSONObject; readonly level: number; readonly id: string; constructor(context: JSONObject, binding: JSONObject, level: number); } /** * A filter function to control if a binding is to be rendered */ export type BindingNodeFilter = (binding: ContextBinding) => boolean; /** * Options for ContextGraph */ export type ContextGraphOptions = { /** * A filter function to select bindings for rendering */ bindingFilter?: BindingNodeFilter; }; /** * A graph for context hierarchy */ export declare class ContextGraph { private readonly options; /** * Root diagram */ private root; /** * Context json objects in the chain from root to leaf */ private readonly contextChain; /** * Tag indexes for the context chain */ private readonly tagIndexes; constructor(ctx: JSONObject, options?: ContextGraphOptions); /** * Assign a unique id for each bindings */ private indexBindings; /** * Recursive render the chain of contexts as subgraphs * @param parent - Parent subgraph * @param level - Level of the context in the chain */ private renderContextChain; /** * Create an edge for a binding to its configuration * @param binding - Binding object * @param level - Context level */ protected renderConfig(parent: ICluster, { binding, level, id }: ContextBinding): IEdge | undefined; /** * Render a binding object * @param parent - Parent subgraph * @param binding - Context Binding object */ protected renderBinding(parent: ICluster, { binding, id }: ContextBinding): INode; /** * Find the binding id by key * @param key - Binding key * @param level - Context level */ private getBinding; /** * Find bindings by tag * @param tag - Tag name * @param level - Context level */ private getBindingsByTag; /** * Render injections for a binding * @param parent - Parent subgraph * @param binding - Binding object * @param level - Context level */ private renderBindingInjections; /** * Find target bindings for an injection * @param injection - Injection object * @param level - Context level */ private getBindingsForInjection; /** * Build a direct graph */ build(): void; /** * Render the context graph in graphviz dot format */ render(): string; }