import type { FilterFieldValidatorMap } from '../types/validation.js'; /** * NOTE: * This util is supposed to be used as a one-off migration helper. If you are dynamically generating `FilterFieldValidatorMap` * objects, you should update your code to produce the new format directly instead of using this function. * * Converts a `FilterFieldValidatorMap` from the deprecated object notation of `keyPredicates` * to the new array notation. * * The following transformations are applied: * - Each object key is moved into the `key` field of a `FilterFieldKeySuggestionConfig`. * - A bare type predicate (`{ type: 'String' }`) used as valuePredicate for a key is * moved to the `valueType` prop. * - A `FilterFieldValidatorMapTypePredicate` used inside a `valuePredicate` array * is extracted to `valueType`. If it was the only item in a `valuePredicate` array, that * array is dropped entirely. * - Multiple type predicates in a `valuePredicate` array are merged and deduplicated into * a single `valueType`. * - Deprecated `FilterFieldDuration` objects in `valuePredicate` (and inside * `FilterFieldValueSuggestionGroupConfig.suggestions`) are converted to their string * equivalents (e.g. `{ value: 10, unit: 'ms' }` → `'10ms'`). * - All other configuration props (`comparisonOperators`, `fallbackKey`, * `suggestStatementOnValueMatch`, `displayValue`, `details`) are preserved as-is. * * If `keyPredicates` is already in array notation or is `undefined`, the original map * object is returned unchanged. * * @example * ```ts * const validatorMap = migrateFilterFieldKeyPredicatesToArray({ * keyPredicates: { * myKey1: { type: 'String' }, * myKey2: { valuePredicate: { type: ['String', 'Number'] }, comparisonOperators: ['equals'] }, * myKey3: { valuePredicate: [{ type: 'String' }, 'literal1', 'literal2'] }, * myKey4: { valuePredicate: [{ value: 10, unit: 'ms' }, { value: 1, unit: 's' }] }, * }, * }); * // Result: * // { * // keyPredicates: [ * // { key: 'myKey1', valueType: 'String' }, * // { key: 'myKey2', valueType: ['String', 'Number'], comparisonOperators: ['equals'] }, * // { key: 'myKey3', valueType: 'String', valuePredicate: ['literal1', 'literal2'] }, * // { key: 'myKey4', valuePredicate: ['10ms', '1s'] }, * // ], * // } * ``` * @public */ export declare function migrateFilterFieldKeyPredicatesToArray(validatorMap: FilterFieldValidatorMap): FilterFieldValidatorMap;