metagraph
Version:
A framework for building higher-order graph data structures
103 lines • 4.16 kB
TypeScript
import { PatternDefinition, DataflowInstance, Node } from './types.js';
/**
* Creates a dataflow input node that reads data from the input namespace.
*
* @param path - Optional path to the input data (defaults to node key)
* @returns A dataflow node specification for reading input data
*
* @example
* ```typescript
* // Read from 'data.nodeList'
* const nodeInput = input('data.nodeList');
*
* // Read from default path
* const defaultInput = input();
* ```
*/
export declare const input: (path?: string) => {
calc: (fnode: Node) => (defn: PatternDefinition) => (flow: DataflowInstance) => () => unknown;
};
/**
* Creates a dataflow output node that passes through its input unchanged.
* Used as a terminal node in dataflow graphs.
*
* @param name - Optional output name (unused in current implementation)
* @param namespace - Optional output namespace (unused in current implementation)
* @returns A dataflow node specification that passes through input data
*/
export declare const output: (name?: string, namespace?: string) => {
calc: (fnode: Node) => (defn: PatternDefinition) => (flow: DataflowInstance) => (x: unknown) => unknown;
};
/**
* Creates a dataflow node that builds a map from array data using pattern-defined accessors.
* Maps each item in the input array to a wrapped object using the pattern's key accessor.
*
* @returns A dataflow node specification for creating maps from arrays
*
* @example
* ```typescript
* // In a pattern definition
* const mapNode = map(); // Creates {key1: wrappedItem1, key2: wrappedItem2, ...}
* ```
*/
export declare const map: () => {
calc: (fnode: Node) => (defn: PatternDefinition) => (flow: DataflowInstance) => (data: unknown[]) => Record<string, unknown>;
};
/**
* Creates a dataflow node representing a singleton that must be initialized elsewhere.
* Throws an error if accessed before initialization.
*
* @returns A dataflow node specification for singleton values
* @throws Error when accessed before proper initialization
*/
export declare const singleton: () => {
calc: (fnode: Node) => (defn: PatternDefinition) => (flow: DataflowInstance) => () => never;
};
/**
* Creates a dataflow node that converts a map back to a list using array order.
* Takes input data array and map, returns array of mapped objects in original order.
*
* @returns A dataflow node specification for creating ordered lists from maps
*
* @example
* ```typescript
* // Convert map back to ordered array
* const listNode = list(); // [data[0] -> map[key0], data[1] -> map[key1], ...]
* ```
*/
export declare const list: () => {
calc: (fnode: Node) => (defn: PatternDefinition) => (flow: DataflowInstance) => (data: unknown[], map: Record<string, unknown>) => unknown[];
};
/**
* Creates a dataflow node that groups array items into lists based on a grouping function.
* Useful for creating adjacency lists or grouping related items.
*
* @param accessor - Function to extract the grouping key from each item
* @returns A dataflow node specification for grouping items into lists
*
* @example
* ```typescript
* // Group edges by source node
* const outEdges = map_of_lists(edge => edge.source);
* // Result: {nodeA: [edge1, edge2], nodeB: [edge3], ...}
* ```
*/
export declare const map_of_lists: (accessor: (val: unknown) => string) => {
calc: (fnode: Node) => (defn: PatternDefinition) => (flow: DataflowInstance) => (data: unknown[], map: Record<string, unknown>) => Record<string, unknown[]>;
};
/**
* Creates a dataflow node that filters array items to include only those with keys in a specified set.
* Used for creating subgraphs or filtering collections.
*
* @returns A dataflow node specification for filtering arrays by key membership
*
* @example
* ```typescript
* // Keep only nodes with keys in the specified set
* const filteredNodes = subset(); // filters items where item.key ∈ keySet
* ```
*/
export declare const subset: () => {
calc: (fnode: Node) => (defn: PatternDefinition) => (flow: DataflowInstance) => (items: unknown[], keys: string[]) => unknown[];
};
//# sourceMappingURL=dataflow_calcs.d.ts.map