import { DetailedResult, Result } from '../base'; import { ICollectible, CollectibleFactoryCallback, CollectibleFactory, CollectibleKey } from './collectible'; import { Collector, CollectorResultDetail } from './collector'; import { KeyValueEntry } from './common'; /** * Parameters for constructing a {@link Collections.ConvertingCollector | ConvertingCollector}. * @public */ export interface IConvertingCollectorConstructorParams, TSRC = TITEM> { /** * The default {@link Collections.CollectibleFactory | factory} to create items. */ factory: CollectibleFactory; /** * An optional array of entries to add to the collector. */ entries?: KeyValueEntry, TSRC>[]; } /** * A {@link Collector | collector} that collects {@link Collections.ICollectible | ICollectible} items, * optionally converting them from a source representation to the target representation using a factory * supplied at default or at the time of collection. * @public */ export declare class ConvertingCollector, TSRC = TITEM> extends Collector { private _factory; /** * Constructs a new {@link Collections.ConvertingCollector | ConvertingCollector}. * @param params - Parameters for constructing the collector. */ constructor(params: IConvertingCollectorConstructorParams); /** * Creates a new {@link Collections.ConvertingCollector | ConvertingCollector}. * @param params - Required parameters for constructing the collector. * @returns Returns {@link Success | Success} with the new collector if it is created, or {@link Failure | Failure} * with an error if the collector cannot be created. */ static createConvertingCollector, TSRC = TITEM>(params: IConvertingCollectorConstructorParams): Result>; /** * {@inheritdoc Collections.Collector.add} */ add(item: TITEM): DetailedResult; /** * Adds an item to the collector using the default {@link Collections.CollectibleFactory | factory} * at a specified key, failing if an item with that key already exists. * @param key - The key of the item to add. * @param item - The source representation of the item to be added. * @returns Returns {@link Success | Success} with the item if it is added, or {@link Failure | Failure} with * an error if the item cannot be created and indexed. * @public */ add(key: CollectibleKey, item: TSRC): DetailedResult; /** * Adds an item to the collector using a supplied {@link Collections.CollectibleFactoryCallback | factory callback} * at a specified key, failing if an item with that key already exists or if the created item is invalid. * @param key - The key of the item to add. * @param callback - The factory callback to create the item. * @returns Returns {@link Success | Success} with the item if it is added, or {@link Failure | Failure} with * an error if the item cannot be created and indexed. */ add(key: CollectibleKey, cb: CollectibleFactoryCallback): DetailedResult; /** * {@inheritdoc Collections.Collector.(getOrAdd:1)} */ getOrAdd(item: TITEM): DetailedResult; /** * {@inheritdoc Collections.Collector.(getOrAdd:2)} */ getOrAdd(key: CollectibleKey, callback: CollectibleFactoryCallback): DetailedResult; /** * Gets an item by key if it exists, or creates a new item and adds it using the default {@link Collections.CollectibleFactory | factory} if not. * @param key - The key of the item to retrieve. * @param item - The source representation of the item to be added if it does not exist. * @returns Returns {@link Success | Success} with the item if it exists or could be created, or {@link Failure | Failure} with an error if the * item cannot be created and indexed. */ getOrAdd(key: CollectibleKey, item: TSRC): DetailedResult; /** * Helper method for derived classes to determine if a supplied * itemOrCb parameter is a factory callback. * @param itemOrCb - Overloaded parameter is either `CollectibleKey` or * a {@link Collections.CollectibleFactoryCallback | factory callback}. * @returns Returns `true` if the parameter is a factory callback, `false` otherwise. * @public */ protected _isFactoryCB(itemOrCb: TSRC | CollectibleFactoryCallback): itemOrCb is CollectibleFactoryCallback; /** * Helper method for derived classes to determine if a supplied * keyOrItem parameter is an item. * @param keyOrItem - Overloaded parameter is either `CollectibleKey` or `TITEM`. * @param itemOrCb - Overloaded parameter is either `TSRC`, a {@link Collections.CollectibleFactoryCallback | factory callback} * or `undefined`. * @returns Returns `true` if the parameter is an item, `false` otherwise. * @public */ protected _overloadIsItem(keyOrItem: CollectibleKey | TITEM, itemOrCb?: TSRC | CollectibleFactoryCallback): keyOrItem is TITEM; /** * Helper method for derived classes to build an item from a key and a source representation using * a default or supplied factory. * @param key - The key of the item to build. * @param itemOrCb - The source representation of the item to build, or a factory callback to create it. * @returns Returns {@link Success | Success} with the item if it is built, or {@link Failure | Failure} * with an error if the item cannot be built. * @public */ protected _buildItem(key: CollectibleKey, itemOrCb: TSRC | CollectibleFactoryCallback): Result; } //# sourceMappingURL=convertingCollector.d.ts.map