import { type U } from "../utils"; import { type MutGraph } from "."; import { type Id } from "./utils"; /** * An operator that creates node data from an id * * The index passed in is the edge index where the id is first seen. */ export type IdNodeDatum = (id: string, index: number) => D; /** * The operators that parametrize {@link Connect} */ export interface ConnectOps { /** the source id operator */ sourceId: Id; /** the target id operator */ targetId: Id; /** the node datum operator */ nodeDatum: IdNodeDatum; } /** * The constraint applied to data passed into {@link Connect} * conditioned on its operators. */ type ConnectLinkDatum = Ops extends ConnectOps ? L : never; /** * an operator that constructs a {@link MutGraph} from link data. * * Create a default connect operator with {@link graphConnect}. The accessor for the * {@link sourceId | source id string}, {@link targetId | target id string}, * and whether to allow {@link single} nodes can all be modified. * * Links in the dag will have the same data as the objects passed in, and nodes * will have the ids referenced as either the source or the target. */ export interface Connect> { /** * convert connect data into a graph * * @param data - an array of each connection * @returns grf - the resulting graph */ >(data: readonly L[]): MutGraph; /** * set the source id accessor * * Sets the source accessor to the given {@link Id} and returns this * Connect. This should return the source id of the link * data. The default accessor is: * * ```ts * ([source, ]) => source * ``` */ sourceId(id: NewId): Connect>; /** Gets the current sourceId accessor. */ sourceId(): Ops["sourceId"]; /** * set the target id accessor * * Sets the target accessor to the given {@link Id} and returns this * Connect. This should return the target id of the link * data. The default accessor is: * * ```ts * ([, target]) => target * ``` */ targetId(id: NewId): Connect>; /** Gets the current targetId accessor. */ targetId(): Ops["targetId"]; /** * set the node datum accessor * * Sets the id node datum accessor to the given {@link IdNodeDatum} and * returns this Connect. This function allows you to decide what data to * attach to nodes created via the connect method. The default is just the id * string. * * ```ts * (data) => data * ``` */ nodeDatum>(data: NewNodeDatumOp & IdNodeDatum): Connect>; /** Get the current id node datum operator */ nodeDatum(): Ops["nodeDatum"]; /** * set the single node allowance * * Sets the allowance for single nodes. If enabled and the source id equals * the target id, then a single node with no parents will be created. * Otherwise a self loop will be created which will result in an error. Note * only single nodes without parents or children need to be specified this * way, otherwise any other connection to a node will create it. * * (default: `false`) */ single(val: boolean): Connect; /** get the current single node setting. */ single(): boolean; } /** default interface for tuples that start with a string */ export interface HasZeroString { /** the zero property */ readonly 0: string; } /** default interface for functions whose second element is a string */ export interface HasOneString { /** the one property */ readonly 1: string; } /** the default connect operator */ export type DefaultConnect = Connect; /** the default target id operator */ targetId: Id; /** the default node datum operator */ nodeDatum: IdNodeDatum; }>; /** * create a new {@link Connect} with default settings * * Connect operators create graphs from link data that contains ids to source * and target nodes. By default it expects link data that are tuples of the * source and target id as strings. * * @example * * If you want to build a graph with the default settings: * * ```ts * const data = [ * ["Euler", "Lagrange"], * ["Lagrange", "Fourier"], * ["Lagrange", "Poisson"], * ["Fourier", "Dirichlet"], * ["Poisson", "Dirichlet"], * ] as const; * * const builder = graphConnect(); * const grf = builder(data); * ``` * * @example * * If you want to use custom data: * * ```ts * const data = [ * { source: "Euler", target: "Lagrange" }, * { source: "Lagrange", target: "Fourier" }, * ] as const; * * const builder = graphConnect() * .sourceId(({ source }: { source: string }) => source) * .targetId(({ target }: { target: string }) => target); * const grf = builder(data); * ``` */ export declare function graphConnect(...args: never[]): DefaultConnect; export {};