import { Result } from '../base'; import { Converter, ConverterFunc } from '../conversion'; import { Validator } from '../validation'; /** * An item that can be collected by some {@link ConvertingCollector | Collector}. * @public */ export interface ICollectible { readonly key: TKEY; readonly index: TINDEX | undefined; setIndex(index: number): Result; } /** * Infer the key type from an {@link Collections.ICollectible | ICollectible} type. * @public */ export type CollectibleKey = TITEM extends ICollectible ? TKEY : never; /** * Infer the index type from an {@link Collections.ICollectible | ICollectible} type. * @public */ export type CollectibleIndex = TITEM extends ICollectible ? TINDEX : never; /** * Factory function for creating a new {@link Collections.ICollectible | ICollectible} instance given a key, an index and a source representation * of the item to be added. * @public */ export type CollectibleFactory, TSRC> = (key: CollectibleKey, index: number, item: TSRC) => Result; /** * Factory function for creating a new {@link Collections.ICollectible | ICollectible} instance given a key and an index. * @public */ export type CollectibleFactoryCallback> = (key: CollectibleKey, index: number) => Result; /** * Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance with * a defined, strongly-typed index. * @public */ export interface ICollectibleConstructorParamsWithIndex { key: TKEY; index: TINDEX; } /** * Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance with an * index converter. * @public */ export interface ICollectibleConstructorParamsWithConverter { key: TKEY; index?: number; indexConverter: Validator | Converter | ConverterFunc; } /** * Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance. * @public */ export type ICollectibleConstructorParams = ICollectibleConstructorParamsWithIndex | ICollectibleConstructorParamsWithConverter; /** * Simple implementation of {@link Collections.ICollectible | ICollectible} which does not allow the index to be * changed once set. * @public */ export declare class Collectible implements ICollectible { /** * {@link Collections.ICollectible.key} */ readonly key: TKEY; /** * {@link Collections.ICollectible.index} */ get index(): TINDEX | undefined; protected _index: TINDEX | undefined; protected readonly _indexConverter?: Validator | Converter; /** * Constructs a new {@link Collections.Collectible | Collectible} instance * with a defined, strongly-typed index. * @param params - {@link Collections.ICollectibleConstructorParamsWithIndex | Parameters} for constructing * the collectible. */ constructor(params: ICollectibleConstructorParamsWithIndex); /** * Constructs a new {@link Collections.Collectible | Collectible} instance with * an undefined index and an index converter to validate te index when it is set. * @param params - {@link Collections.ICollectibleConstructorParamsWithConverter | Parameters} for constructing * the collectible. */ constructor(params: ICollectibleConstructorParamsWithConverter); /** * Constructs a new {@link Collections.Collectible | Collectible} instance. * @param params - {@link Collections.ICollectibleConstructorParams | Parameters} for constructing * the collectible. */ constructor(params: ICollectibleConstructorParams); /** * Creates a new {@link Collections.Collectible | Collectible} instance with a defined, strongly-typed index. * @param params - {@link Collections.ICollectibleConstructorParamsWithIndex | Parameters} for constructing * the collectible. * @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise. */ static createCollectible(params: ICollectibleConstructorParamsWithIndex): Result>; /** * Creates a new {@link Collections.Collectible | Collectible} instance with an undefined index and an index * converter to validate the index when it is set. * @param params - {@link Collections.ICollectibleConstructorParamsWithConverter | Parameters} for constructing * the collectible. * @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise. */ static createCollectible(params: ICollectibleConstructorParamsWithConverter): Result>; /** * Creates a new {@link Collections.Collectible | Collectible} instance. * @param params - {@link Collections.ICollectibleConstructorParams | Parameters} for constructing * the collectible. * @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise * @public */ static createCollectible(params: ICollectibleConstructorParams): Result>; /** * {@link Collections.ICollectible.setIndex} */ setIndex(index: number): Result; } //# sourceMappingURL=collectible.d.ts.map