import ImportRecord from './ImportRecord'; import { Pipe } from './PipeParser'; import Provider from './Provider'; export type TransformerCallback = (record: ImportRecord, key: string, ...args: string[]) => Promise | string; export default class Transformer { private throttle; private provider; /** * Registry of transformers. * * A transformer is a function that takes a record, a key, and a set of arguments and returns a string. * * Some rules to have in mind when creating a transformer: * - The transformer should return a string. * - The transformer should not modify the record directly. Instead, it should return the new value. * - The transformer should not throw an error. Instead, it should return the string unchanged. * - Maintain an alphabetical order when adding transformers. * * @param record The record to transform. * @param key The key of the field to transform. * @param args The arguments to pass to the transformer. */ private registry; constructor(throttle?: false | number); setThrottle(throttle: number): void; transform(record: ImportRecord, rules: { [key: string]: Pipe[] | null; }): Promise; transformMany(records: ImportRecord[], rules: { [key: string]: Pipe[] | null; } | null): Promise; /** * Returns the transformers applicable for the specified field * * @param field The field to get the transformers for * @param rules The rules to get the transformers from */ getTransformersForField(field: string, rules: { [key: string]: Pipe[] | null; }): Pipe[] | null; addTransformer(name: string, transformer: TransformerCallback): void; getTransformer(name: string): TransformerCallback; setProvider(provider: Provider): void; }