import { NodeDefinition, NodeLike, StatelessGraphNode, StatelessNodeDefinition, StatelessNodeType } from '../../types/graph'; import { OtherwiseNodeDefinition } from './otherwise'; import { WhenNodeDefinition } from './when'; /** * An instance of the [[switchOn]] node. * See the [[switchOn]] documentation to find out more. */ export interface SwitchOnNode extends StatelessGraphNode<'switchOn', SwitchOnNodeProperties> { } /** * A definition of the [[switchOn]] node. * See the [[switchOn]] documentation to find out more. */ export interface SwitchOnNodeDefinition extends StatelessNodeDefinition<'switchOn', SwitchOnNodeProperties> { } export interface SwitchOnNodeProperties { input: NodeDefinition; options: Array; fallback: OtherwiseNodeDefinition; } /** * The implementation of the [[switchOn]] node. * See the [[switchOn]] documentation to learn more. */ export declare const SwitchOnNodeType: StatelessNodeType<'switchOn', SwitchOnNodeProperties>; /** * Creates a new instance of a [[switchOn]] node, which is used to conditionally return a different value. It works in a similar * way to the [[ifElse]] node, but allows for a more concise definition when defining * more than one condition. * * The conditions are defined with the help of [[when]] and [[otherwise]] * nodes. Each [[switchOn]] can define any number of [[when]] cases, * and MUST define exactly one [[otherwise]] node. * * @example **Simple switchOn node** * ```js * import muster, { otherwise, ref, switchOn, variable, when } from '@dws/muster'; * * const app = muster({ * productType: variable(1), * productTypeName: switchOn(ref('productType'), [ * when(1, 'Vegetable'), * when(2, 'Meat'), * when(3, 'Frozen'), * otherwise('Unknown'), * ]), * }); * * await app.resolve(ref('productTypeName')); // === 'Vegetable' * ``` * * * @example **switchOn with dynamic values** * ```js * import muster, { * computed, * match, * otherwise, * param, * ref, * switchOn, * types, * variable, * when, * } from '@dws/muster'; * * const app = muster({ * productType: variable(1), * productTypeName: switchOn(ref('productType'), [ * when(1, ref('currentLocale', 'productType.vegetable')), * when(2, ref('currentLocale', 'productType.meat')), * when(3, ref('currentLocale', 'productType.frozen')), * otherwise(ref('currentLocale', 'productType.unknown')), * ]), * currentLocale: ref('locales', ref('currentLocaleName')), * currentLocaleName: variable('en-GB'), * locales: { * [match(types.string, 'language')]: { * [match(types.string, 'key')]: computed([param('language'), param('key')], (lang, key) => { * // TODO: Extract correct value from some locale file * return 'test'; * }), * }, * }, * }); * * await app.resolve(ref('productTypeName')); // === 'test' * ``` * * * @example **switchOn with dynamic cases** * ```js * import muster, { otherwise, ref, switchOn, variable, when } from '@dws/muster'; * * const app = muster({ * productType: variable(1), * productTypeName: switchOn(ref('productType'), [ * when(ref('productTypes', 'vegetable'), 'Vegetable'), * when(ref('productTypes', 'meat'), 'Meat'), * when(ref('productTypes', 'frozen'), 'Frozen'), * otherwise('Unknown'), * ]), * productTypes: { * vegetable: 1, * meat: 2, * frozen: 3, * }, * }); * * await app.resolve(ref('productTypeName')); // === 'Vegetable' * ``` * * * @example **switchOn with pattern matching** * ```js * import muster, { * format, * gte, * otherwise, * pattern, * ref, * switchOn, * variable, * when, * } from '@dws/muster'; * * const app = muster({ * subscribersCount: variable(15), * subscribers: switchOn(ref('subscribers'), [ * when(0, 'No subscribers'), * when(pattern((_) => gte(_, 1000)), 'Thousands of subscribers'), * when(pattern((_) => gte(_, 100)), 'Hundreds of subscribers'), * when(pattern((_) => gte(_, 30)), 'Many subscribers'), * otherwise(format('${count} subscribers', { count: ref('subscribers') })), * ]), * }); * * await app.resolve(ref('subscribers')); // === '15 subscribers' * ``` */ export declare function switchOn(input: NodeDefinition | NodeLike, cases: Array): SwitchOnNodeDefinition; export declare function isSwitchOnNodeDefinition(value: NodeDefinition): value is SwitchOnNodeDefinition;