import { NodeDefinition, NodeLike, StatelessGraphNode, StatelessNodeDefinition, StatelessNodeType } from '../../../types/graph'; /** * An instance of the [[map]] node. * See the [[map]] documentation to find out more. */ export interface MapNode extends StatelessGraphNode<'map', MapNodeProperties> { } /** * A definition of the [[map]] node. * See the [[map]] documentation to find out more. */ export interface MapNodeDefinition extends StatelessNodeDefinition<'map', MapNodeProperties> { } export interface MapNodeProperties { transform: NodeDefinition; } /** * The implementation of the [[map]] node. * See the [[map]] documentation to learn more. */ export declare const MapNodeType: StatelessNodeType<'map', MapNodeProperties>; /** * Creates a new instance of a [[map]] node, which is a type of collection transform used when mapping items * from one representation from to another. * This type of transform can be thought of as akin to JavaScript's `Array.map` function. * * @example **Simple mapper** * ```js * import muster, { applyTransforms, entries, map, multiply, query, ref } from '@dws/muster'; * * const app = muster({ * numbers: [1, 2, 3, 4], * numbersTimes2: applyTransforms(ref('numbers'), [ * map((item) => multiply(item, 2)), * ]), * }); * * const numbersTimes2 = await app.resolve(query(ref('numbersTimes2'), entries())); * // numbersTimes2 === [2, 4, 6, 8] * ``` * This example shows how to use a [[map]] to multiply every item of the collection by 2. * The multiplication is done with help of an arithmetic graph node, [[multiply]]. * * * @example **Mapping branches** * ```js * import muster, { applyTransforms, get, entries, key, map, query, ref } from '@dws/muster'; * * const app = muster({ * numbers: [1, 2, 3, 4], * numbersAsBranches: applyTransforms(ref('numbers'), [ * map((item) => ({ number: item })), * ]), * }); * * const numbers = await app.resolve(query(ref('numbersAsBranches'), entries({ * number: key('number'), * }))); * // numbers === [ * // { number: 1 }, * // { number: 2 }, * // { number: 3 }, * // { number: 4 }, * // ] * ``` * This example shows how to use a [[map]] transform to change the shape of items. * It converts each item from a simple [value](_nodes_graph_value_.html#value) to a [[tree]] with a branch named `number` * containing the item's original value. */ export declare function map(transform: (item: NodeDefinition) => NodeDefinition | NodeLike): MapNodeDefinition; export declare function map(transform: NodeDefinition | NodeLike): MapNodeDefinition;