import { NodeDefinition, NodeLike, StatelessGraphNode, StatelessNodeDefinition, StatelessNodeType } from '../../../types/graph'; /** * An instance of the [[unique]] node. * See the [[unique]] documentation to find out more. */ export interface UniqueNode extends StatelessGraphNode<'unique', UniqueNodeProperties> { } /** * A definition of the [[unique]] node. * See the [[unique]] documentation to find out more. */ export interface UniqueNodeDefinition extends StatelessNodeDefinition<'unique', UniqueNodeProperties> { } /** * The implementation of the [[unique]] node. * See the [[unique]] documentation to learn more. */ export interface UniqueNodeProperties { predicate: NodeDefinition; } /** * The implementation of the [[unique]] node. * See the [[unique]] documentation to learn more. */ export declare const UniqueNodeType: StatelessNodeType<'unique', UniqueNodeProperties>; /** * Creates a new instance of a [[unique]] node, a collection transform that creates a duplicate-free version of an array (using SameValueZero for equality comparisons) in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array. * * `unique` accepts an optional predicate used to identify sub-properties of items to use in comparison. * * * @example **Simple usage** * ```js * import muster, { applyTransforms, unique, entries, query, ref } from '@dws/muster'; * * const app = muster({ * numbers: applyTransforms( * [1, 2, 3, 1, 2], * [unique()], * ), * }); * * const uniqueNumbers = await app.resolve(query(ref('numbers'), entries())); * // uniqueNumbers === [1, 2, 3] * ``` * This example shows how to apply `unique` to a collection. * * @example **Usage with predicates** * ```js * import muster, { applyTransforms, unique, get, entries, key, query, ref } from '@dws/muster'; * * const app = muster({ * books: applyTransforms( * [ * { title: 'Casino Royale', author: 'Ian Fleming', year: 1953 }, * { title: 'Live and Let Die', author: 'Ian Fleming', year: 1953 }, * { title: 'The Big Four', author: 'Agatha Christie', year: 1927 }, * ], * [ * unique((book) => get(book, 'year')), * ], * ), * }); * * const publishingYears = await app.resolve(query(ref('books'), entries({ * year: key('year'), * }))); * // publishingYears === [ * // { year: 1953 }, * // { year: 1927 }, * // ] * ``` * This example demonstrates how to use a predicate to identify an item property to use for unique comparison. * */ export declare function unique(predicate?: NodeDefinition | ((item: NodeDefinition) => NodeDefinition | NodeLike)): UniqueNodeDefinition;