import { NodeDefinition, StatelessGraphNode, StatelessNodeDefinition, StatelessNodeType } from '../../types/graph'; import { ContextNodeDefinition } from './context'; /** * An instance of the [fn](../modules/_nodes_graph_fn_.html#fn) node. * See the [fn](../modules/_nodes_graph_fn_.html#fn) documentation to find out more. */ export interface FnNode extends StatelessGraphNode<'fn', FnNodeProperties> { } /** * A definition of the [fn](../modules/_nodes_graph_fn_.html#fn) node. * See the [fn](../modules/_nodes_graph_fn_.html#fn) documentation to learn more. */ export interface FnNodeDefinition extends StatelessNodeDefinition<'fn', FnNodeProperties> { } export interface FnNodeProperties { argIds: Array; body: NodeDefinition; hasNamedArgs: boolean; } /** * The implementation of the [fn](../modules/_nodes_graph_fn_.html#fn). * See the [fn](../modules/_nodes_graph_fn_.html#fn) documentation to learn more. */ export declare const FnNodeType: StatelessNodeType<'fn', FnNodeProperties>; export declare type NamedFnArgs = { [argName: string]: ContextNodeDefinition; }; /** * Creates a new instance of a [[fn]] node, which is a type of a [[NodeDefinition]] used for representing executable * functions implemented with muster [[NodeDefinition]]s. These functions are safely serializable and can be executed * on a remote muster instances. * * The [[fn]] is being used by the collection transforms to represent filters and other types of collection transforms. * * The [[fn]] can be executed with the help of [[call]] and [[apply]]. * * * @example **Create a simple [[fn]]** * ```js * import { fn, value } from '@dws/muster'; * * fn(() => value(true)); * ``` * This example shows how to create a very basic [[fn]] that simply returns a true [[value]] * ever time it gets called. * * * @example **Create an [[fn]] with args** * ```js * import { add, fn } from '@dws/muster'; * * fn((num) => add(num, 5)); * ``` * This example shows how to create an [[fn]] capable of adding 5 to an argument. * * * @example **Calling an [[fn]]** * ```js * import muster, { add, call, fn } from '@dws/muster'; * * const app = muster({ * addFive: fn((num) => add(num, 5)), * }); * * await app.resolve(call('addFive', [3])); * // === 8 * ``` * This example shows how to call an [[fn]]. See the [[call]] and [[apply]] * documentation to learn more about calling callable nodes. * * * @example **Create an [[fn]] with named args** * ```js * import muster, { call, fn, format } from '@dws/muster'; * * const app = muster({ * greet: fn(['name'], ({ name }) => * format('Hello, ${name}!', { name }) * ), * }); * * await app.resolve(call('greet', { name: 'Bob' })); * // === 'Hello, Bob!' * ``` * This example shows how to create and call an [[fn]] node with named arguments. */ export declare function fn(factory: ((...args: Array) => NodeDefinition)): FnNodeDefinition; export declare function fn(argNames: Array, factory: ((args: NamedFnArgs) => NodeDefinition)): FnNodeDefinition; export declare function isFnNodeDefinition(value: NodeDefinition): value is FnNodeDefinition;