import { NodeDefinition, NodeLike, StatelessGraphNode, StatelessNodeDefinition, StatelessNodeType } from '../../../types/graph'; export interface SortOrderNode extends StatelessGraphNode<'sortOrder', SortOrderNodeProperties> { } export interface SortOrderNodeDefinition extends StatelessNodeDefinition<'sortOrder', SortOrderNodeProperties> { } export interface SortOrderNodeProperties { iteratee: NodeDefinition; descending: boolean; } export declare const SortOrderNodeType: StatelessNodeType<'sortOrder', SortOrderNodeProperties>; export declare function sortOrder(iteratee: NodeDefinition | ((item: NodeDefinition) => NodeLike), options: { descending: boolean; }): SortOrderNodeDefinition; export declare function ascending(iteratee?: NodeDefinition | ((item: NodeDefinition) => NodeLike)): SortOrderNodeDefinition; export declare function descending(iteratee?: NodeDefinition | ((item: NodeDefinition) => NodeLike)): SortOrderNodeDefinition; /** * An instance of the [[sort]] node. * See the [[sort]] documentation to find out more. */ export interface SortNode extends StatelessGraphNode<'sort', SortNodeProperties> { } /** * A definition of the [[sort]] node. * See the [[sort]] documentation to find out more. */ export interface SortNodeDefinition extends StatelessNodeDefinition<'sort', SortNodeProperties> { } export interface SortNodeProperties { order: Array; } /** * The implementation of the [[sort]] node. * See the [[sort]] documentation to learn more. */ export declare const SortNodeType: StatelessNodeType<'sort', SortNodeProperties>; /** * Creates a new instance of a [[sort]] node, which is a type of collection transform used to sort the output of a collection. * The sort order takes an array of [[sortOrder]]s which define the ordering of the sort. * The items of the [[order]] array are assuming a descending order of * priority, with the first item having the highest priority and the last one having the lowest. * * For example, given the following items: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
MakeModelYear
MercedesC 63 AMG2017
MercedesA2009
AudiR82013
AudiA42018
ToyotaCorolla2016
* When the sort order is defined as: *
    *
  1. Sort by `Make` ascending
  2. *
  3. Sort by `Year` descending
  4. *
* The table should look like: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
MakeModelYear
AudiA42018
AudiR82013
MercedesC 63 AMG2017
MercedesA2009
ToyotaCorolla2016
* * Sort order can be defined with the help of two helper functions: * - [[ascending]] * - [[descending]] * * @example **Sorting numbers** * ```js * import muster, { * ascending, * descending, * entries, * query, * ref, * sort, * withTransforms, * } from '@dws/muster'; * * const app = muster({ * numbers: [5, 3, 2, 4, 1], * }); * * const ascendingNumbers = await app.resolve(query(ref('numbers'), withTransforms([ * sort(ascending((item) => item)), * ], entries()))); * // ascendingNumbers === [1, 2, 3, 4, 5] * * const descendingNumbers = await app.resolve(query(ref('numbers'), withTransforms([ * sort(descending((item) => item)), * ], entries()))); * // descendingNumbers === [5, 4, 3, 2, 1] * ``` * This example shows how to apply the most basic sort transform. Although the [[sort]] * officially takes an array of sort orders, you can still define a [[sort]] with * a single [[sortOrder]]. * * Note that the [[ascending]] and [[descending]] node factories are called with a function * returning its parameter (same as `identity` from lodash). You might expect that this function * receives an instance of the item, but that's not the case. In fact this function is a factory * function that gets passed into an [fn](_nodes_graph_fn_.html#fn) node in order to create a Muster function. See the * [fn](_nodes_graph_fn_.html#fn) documentation to learn more about Muster functions. Thanks to that, Muster * internally operates only on [[NodeDefinition]]s, which permits serializing these * nodes to JSON and safely sending them to remote Muster instances without having to * worry about running unsafe JavaScript code on the server. * * * @example **Sorting branches** * ```js * import muster, { * ascending, * descending, * get, * entries, * key, * query, * ref, * sort, * withTransforms, * } from '@dws/muster'; * * const app = muster({ * cars: [ * { make: 'Mercedes', model: 'C 63 AMG', year: 2017 }, * { make: 'Mercedes', model: 'A', year: 2009 }, * { make: 'Audi', model: 'R8', year: 2013 }, * { make: 'Audi', model: 'A4', year: 2018 }, * { make: 'Toyota', model: 'Corolla', year: 2016 }, * ], * }); * * const sortedCars = await app.resolve(query(ref('cars'), withTransforms([ * sort([ * ascending((car) => get(car, 'make')), * descending((car) => get(car, 'year')), * ]), * ], entries({ * make: key('make'), * model: key('model'), * year: key('year'), * })))); * // sortedCars = [ * // { make: 'Audi', model: 'A4', year: 2018 }, * // { make: 'Audi', model: 'R8', year: 2013 }, * // { make: 'Mercedes', model: 'C 63 AMG', year: 2017 }, * // { make: 'Mercedes', model: 'A', year: 2009 }, * // { make: 'Toyota', model: 'Corolla', year: 2016 }, * // ] * ``` * This example shows how to implement a transform that sorts by the given leaves of a branch. * It shows the implementation of the example that was featured in the description of the * [[sort]]. */ export declare function sort(order: NodeDefinition | ((item: NodeDefinition) => NodeLike) | Array NodeLike)>): SortNodeDefinition; export declare type SortValue = null | undefined | boolean | string | number | Date;