import * as p_di from "../../../interface/data.js"; import * as p_ri from "../../../interface/refiner.js"; import { type Abort } from "../../../interface/__internal/Abort.js"; /** * Wraps a dictionary and provides entry lookup and transformation methods. */ export declare const dictionary: (dict: p_di.Dictionary) => { /** * Retrieves the entry with the given id. * Calls `abort.no_such_entry` if no entry with that id exists. * @param id the id of the entry to retrieve * @param abort callbacks invoked on error; `no_such_entry` is called when the id is not found * @returns the value of the entry */ get_entry(id: string, abort: { no_such_entry: Abort; }): T; /** * Retrieves the entry with the given id if it exists, otherwise returns a not-set optional. * @param id the id of the entry to retrieve * @returns a set optional containing the entry value, or not-set if the id is not found */ get_possible_entry(id: string): p_di.Optional_Value; /** * Converts the values of the dictionary to a new type using the provided assign_entry function. * @param assign_entry function to convert each entry; receives the current value and the entry id * @returns a new dictionary with the same ids and the converted values */ map: (assign_entry: (value: T, id: string) => New_Type) => p_di.Dictionary; /** * gives the entries in the dictionary a new id. * if a duplicate id is found, the duplicate_id function is called to get the target dictionary * typically, you will use this function in a way where you can guarantee that there will be no duplicate ids, and the duplicate_id function will never be called, * so you typically will have a p_unreachable_code_path() call */ re_id: (get_id: ($: T, id: string) => string, on_duplicate_id: ($: T, id: string) => never) => p_di.Dictionary; /** * Maps each entry to a resolved value, supporting cross-entry lookups during resolution. * * The `acyclic_lookup` allows looking up other entries that should not have any direct or indirect * dependency on the current entry; they are resolved on the spot if not yet resolved. * A `cycle_detected` abort is triggered if a cycle is found. * * The `cyclic_lookup` allows referencing entries that may depend on the current entry. * It returns a handle whose `get_circular_dependent` must not be called until all entries * in the dictionary have been fully resolved; accessing it too early triggers the * `accessing_cyclic_sibling_before_it_is_resolved` abort. * * @param assign_entry function called for each entry with its value, id, and both lookup handles * @returns a new dictionary containing the resolved values */ resolve: (assign_entry: (value: T, id: string, acyclic_lookup: p_ri.lookup.Acyclic, cyclic_lookup: p_ri.lookup.Cyclic) => Resolved) => p_di.Dictionary; }; /** * Wraps a list and provides conversion and transformation methods. */ export declare const list: (list: p_di.List) => { /** * Converts the list to a dictionary using the provided id and value functions. * first asks for the id of an item, then for the value of that item. * Calls `abort.duplicate_id` if two items produce the same id. * @param get_id function to derive the dictionary key from each item * @param get_value function to derive the dictionary value from each item * @param abort callbacks invoked on error; `duplicate_id` is called with the conflicting id * @returns a new dictionary built from the list items */ convert_to_dictionary: (get_id: (item: T) => string, get_value: (item: T) => NT, abort: { duplicate_id: Abort; }) => p_di.Dictionary; /** * Converts the items in the list to a new type using the provided assign_item function. * @param assign_item function to convert each item to a new value * @returns a new list containing the converted values */ map: (assign_item: (item: T) => New_Type) => p_di.List; /** * Maps the items in the list to a new type while maintaining a state that is updated with each item. * @param initial_state the initial value of the state before processing any items * @param assign_item function to convert each item using the current state * @param update_state function to produce the next state from the converted item and the current state * @param wrapup function called once with the final converted list and the final state to produce the result * @returns the result produced by `wrapup` */ map_with_state: (initial_state: State, assign_item: (item: T, state: State) => Target_Item, update_state: (item: Target_Item, state: State) => State, wrapup: (final_list: p_di.List, final_state: State) => Result_Type) => Result_Type; }; /** * Wraps an optional value and provides methods to handle both the set and not-set cases. */ export declare const optional: (optional_value: p_di.Optional_Value) => { /** * Calls `if_set` with the wrapped value if it is set, otherwise calls `if_not_set`. * @param if_set function to call with the value when it is set * @param if_not_set function to call when the value is not set * @returns the result of whichever function was called */ decide: (if_set: ($: T) => RT, if_not_set: () => RT) => RT; /** * Transforms the wrapped value using the provided function if it is set. * If the value is not set, returns a not-set optional. * @param assign_set_value function to transform the value * @returns a new optional containing the transformed value, or not-set if the original was not set */ map: (assign_set_value: (value: T) => New_Type) => p_di.Optional_Value; }; /** * Wraps a state value and provides a method to produce a result from it. */ export declare const state: (state: State) => { /** * Passes the state to the provided function and returns the result. * @param assign function to produce a result from the state * @returns the result produced by `assign` */ decide: (assign: (output: State) => RT) => RT; }; /** * Wraps a string value and provides a method to convert it into a state. */ export declare const text: (string: string) => { /** * Converts the string into a state value using the provided function and context. * @param context additional context passed to `assign_state` * @param assign_state function that receives the context and the string and returns the state * @returns the state produced by `assign_state` */ to_state: (context: Context, assign_state: ($: Context, text: string) => State) => State; };