-
Notifications
You must be signed in to change notification settings - Fork 13
/
map-processor.ts
27 lines (24 loc) · 941 Bytes
/
map-processor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { DataEntity } from '@terascope/utils';
import { OpConfig } from '../interfaces';
import ProcessorCore from './core/processor-core';
/**
* A variation of Processor that can process a single DataEntity at a time.
* This processor should return a modified DataEntity.
*/
export default abstract class MapProcessor<T = OpConfig> extends ProcessorCore<T> {
/**
* Called by {@link Processor#handle} and will handle single {@link DataEntity}
*
* @returns a DataEntity
*/
abstract map(data: DataEntity, index: number, array: DataEntity[]): DataEntity;
/**
* A generic method called by the Teraslice framework, calls {@link #map}
* @param input an array of DataEntities
*
* @returns an array of DataEntities
*/
async handle(input: DataEntity[]): Promise<DataEntity[]> {
return input.map((data, index, array) => DataEntity.make(this.map(data, index, array)));
}
}