UNPKG

metagraph

Version:

A framework for building higher-order graph data structures

153 lines 5.89 kB
import { PatternDefinition, DataflowInstance, Graph, Edge, Node } from './types.js'; /** * Creates an interface specification for objects that can create instances. * Typically used for Graph patterns to enable the 'create' method. * * @param flowkey - The key in the environment where the created instance will be stored * @returns An interface specification with a 'create' class member * * @example * ```typescript * // Used in graph patterns to enable graph.create(data) * const graphInterface = createable('graph'); * ``` */ export declare const createable: (flowkey: string) => { class_members: { create: (flowspec: Graph, inode: Node) => { defn: (defn: PatternDefinition) => (data: unknown) => unknown; }; }; }; /** * Creates an interface specification for a method that calls a function on the object's value. * Commonly used to create 'key' and 'value' accessor methods. * * @param methodname - The name of the method to create * @returns A function that takes an accessor function and returns an interface specification * * @example * ```typescript * // Create key() and value() methods * const keyMethod = call('key')(obj => obj.key); * const valueMethod = call('value')(obj => obj.value); * ``` */ export declare const call: (methodname: string) => (f: (val: unknown) => unknown) => { members: { key: string; value: (flowspec: Graph, inode: Node) => { accessor: (val: unknown) => unknown; defn: (defn: PatternDefinition, flow: DataflowInstance, val: unknown) => () => unknown; }; }[]; }; /** * Pre-configured method for accessing the 'key' property of objects. */ export declare const key: (f: (val: unknown) => unknown) => { members: { key: string; value: (flowspec: Graph, inode: Node) => { accessor: (val: unknown) => unknown; defn: (defn: PatternDefinition, flow: DataflowInstance, val: unknown) => () => unknown; }; }[]; }; /** * Pre-configured method for accessing the 'value' property of objects. */ export declare const value: (f: (val: unknown) => unknown) => { members: { key: string; value: (flowspec: Graph, inode: Node) => { accessor: (val: unknown) => unknown; defn: (defn: PatternDefinition, flow: DataflowInstance, val: unknown) => () => unknown; }; }[]; }; /** * Creates a reference to another interface node. * Used for connecting interface elements together. * * @param inode - The interface node to reference * @returns A reference specification */ export declare const reference: (inode: Node) => { reference: Node<any>; }; /** * Creates an interface method that fetches (returns) its input unchanged. * Acts as a pass-through for data flow. * * @returns An interface specification for fetching data */ export declare const fetch: () => { funfun: (flowspec: Graph, iedge: Edge) => (defn: PatternDefinition, flow: DataflowInstance) => (x: unknown) => () => unknown; }; /** * Creates an interface method that looks up values in a map using function arguments. * The lookup key is derived by applying an optional accessor function to the argument. * * @param access - Optional function to transform the lookup key (defaults to identity) * @returns An interface specification for argument-based map lookup * * @example * ```typescript * // Direct lookup: map[key] * const directLookup = lookupArg(); * * // Transform key before lookup: map[key.id] * const idLookup = lookupArg(key => key.id); * ``` */ export declare const lookupArg: (access?: (x: unknown) => unknown) => { funfun: (flowspec: Graph, iedge: Edge) => (defn: PatternDefinition, flow: DataflowInstance, val: unknown) => (map: Record<string, unknown>) => (key: unknown) => unknown; }; /** * Creates an interface method that looks up values in a map using the object's own value. * The lookup key is derived by applying an accessor function to the object's value. * * @param access - Function to extract the lookup key from the object's value * @returns An interface specification for value-based map lookup * * @example * ```typescript * // Lookup using edge.source: map[edge.value.source] * const sourceLookup = lookupFVal(edge => edge.source); * ``` */ export declare const lookupFVal: (access: (val: unknown) => unknown) => { funfun: (flowspec: Graph, iedge: Edge) => (defn: PatternDefinition, flow: DataflowInstance, val: unknown) => (map: Record<string, unknown>) => () => unknown; }; /** * Creates an interface method that looks up values using the source node's key accessor. * Commonly used for accessing lists associated with specific keys (like adjacency lists). * * @returns An interface specification for key-based map lookup with fallback to empty array * * @example * ```typescript * // Get outgoing edges for a node: outEdges[node.key()] || [] * const nodeOuts = lookupKVal(); * ``` */ export declare const lookupKVal: () => { funfun: (flowspec: Graph, iedge: Edge) => (defn: PatternDefinition, flow: DataflowInstance, val: unknown) => (map: Record<string, unknown>) => () => {}; }; /** * Creates an interface method for generating subgraphs from a parent graph. * Supports complex dataflow with multiple pattern compositions and data filtering. * * @returns An interface specification for subgraph creation * * @example * ```typescript * // Used in subgraph patterns to enable parent.subgraph(nodeKeys, edgeKeys, data) * const subgraphMethod = subgraph(); * ``` */ export declare const subgraph: () => { funfun: (flowspec: Graph, iedge: Edge, flowspecs?: Record<string, Graph>) => (defn: PatternDefinition, flow: DataflowInstance, val: unknown) => () => (nodeKeys: string[], edgeKeys: string[], gdata: unknown) => unknown; }; //# sourceMappingURL=interface.d.ts.map