import { NodeDefinition, NodeLike, StatelessGraphNode, StatelessNodeDefinition, StatelessNodeType } from '../../../types/graph'; /** * An instance of the [[take]] node. * See the [[take]] documentation to find out more. */ export interface TakeNode extends StatelessGraphNode<'take', TakeNodeProperties> { } /** * A definition of the [[take]] node. * See the [[take]] documentation to find out more. */ export interface TakeNodeDefinition extends StatelessNodeDefinition<'take', TakeNodeProperties> { } export interface TakeNodeProperties { numItems: NodeDefinition; } /** * The implementation of the [[take]] node. * See the [[take]] documentation to learn more. */ export declare const TakeNodeType: StatelessNodeType<'take', TakeNodeProperties>; /** * Creates a new instance of a [[take]] node, which is a type of collection transform used when limiting * the number of items returned from a collection. * It works in a similar way to the [[slice]], but it cannot change the offset. * * * @example **Take first item** * ```js * import muster, { entries, query, ref, take, withTransforms } from '@dws/muster'; * * const app = muster({ * numbers: [1, 2, 3, 4, 5], * }); * * const firstNumber = await app.resolve(query(ref('numbers'), withTransforms([ * take(1), * ], entries()))); * // firstNumber === [1] * ``` * This example shows how to use the [[take]] to extract the first item of a collection. The * count doesn't have to be a constant. In this particular example, the value is being * converted internally to a [value](_nodes_graph_value_.html#value) node. * This means you can use any other node as the count. * * * @example **Configurable count** * ```js * import muster, { entries, query, ref, set, take, variable, withTransforms } from '@dws/muster'; * * const app = muster({ * numbers: [1, 2, 3, 4, 5], * numbersToTake: variable(1), * }); * * app.resolve(query(ref('numbers'), withTransforms([ * take(ref('numbersToTake')), * ], entries()))).subscribe((numbers) => { * console.log(numbers); * }); * * console.log('Change numbersToTake to 3'); * await app.resolve(set('numbersToTake', 3)); * * // Console output: * // [1] * // Change numbersToTake to 3 * // [1, 2, 3] * ``` * This example shows how to use a [[variable]] node to define the number of items to take. */ export declare function take(numItems: NodeDefinition | NodeLike): TakeNodeDefinition;