Skip to content

Commit 1159d95

Browse files
authored
feat(returner): add new type (#20)
https://make.atlassian.net/browse/CDM-13296 add new `returner` type to proto lib this type will be used to return data from scenarios
1 parent 93e3d87 commit 1159d95

6 files changed

+35
-0
lines changed

src/base.ts

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export enum ModuleType {
3030
CONVERGER = 9,
3131
HITL = 10,
3232
PAUSER = 11,
33+
RETURNER = 12,
3334
}
3435

3536
/**
@@ -60,6 +61,7 @@ export class IMTBase extends EventEmitter {
6061
public static readonly MODULETYPE_CONVERGER = ModuleType.CONVERGER;
6162
public static readonly MODULETYPE_HITL = ModuleType.HITL;
6263
public static readonly MODULETYPE_PAUSER = ModuleType.PAUSER;
64+
public static readonly MODULETYPE_RETURNER = ModuleType.RETURNER;
6365

6466
public common: CommonData | null = null;
6567
public data: ModuleData | null = null;

src/global.ts

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ declare global {
4646
var IMTFeeder: typeof publicApi.IMTFeeder;
4747
var IMTTransformer: typeof publicApi.IMTTransformer;
4848
var IMTHITL: typeof publicApi.IMTHITL;
49+
var IMTReturner: typeof publicApi.IMTReturner;
4950
/* eslint-enable no-var */
5051
}
5152

@@ -98,4 +99,5 @@ if (!global.IMT_PROTO_LOADED) {
9899
global.IMTFeeder = publicApi.IMTFeeder;
99100
global.IMTTransformer = publicApi.IMTTransformer;
100101
global.IMTHITL = publicApi.IMTHITL;
102+
global.IMTReturner = publicApi.IMTReturner;
101103
}

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export * from './listener';
1515
export * from './converger';
1616
export * from './aggregator';
1717
export * from './transformer';
18+
export * from './returner';

src/returner.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { IMTBase, ModuleType } from './base';
2+
import { Bundle, DoneWithResultCallback } from './types';
3+
4+
export class IMTReturner extends IMTBase {
5+
public readonly type = ModuleType.RETURNER;
6+
7+
/**
8+
* Returns data.
9+
*
10+
* @param {Object} bundle Collection of data to process.
11+
* @callback done Callback to call when operations are done.
12+
* @param {Error} err Error on error, otherwise null.
13+
* @param {Bundle} bundle Collection of returned data.
14+
*
15+
*/
16+
17+
returnData(bundle: Bundle, done: DoneWithResultCallback): void {
18+
void bundle;
19+
void done;
20+
throw new Error("Must override a superclass method 'returnData'.");
21+
}
22+
}

test/legacy-compatibility.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('Legacy Compatibility', () => {
2020
IMTRPC,
2121
IMTFeeder,
2222
IMTTransformer,
23+
IMTReturner,
2324
];
2425

2526
it('exports global variables', () => {
@@ -66,6 +67,7 @@ describe('Legacy Compatibility', () => {
6667
expect(global.IMTFeeder).toBeDefined();
6768
expect(global.IMTTransformer).toBeDefined();
6869
expect(global.IMTHITL).toBeDefined();
70+
expect(global.IMTReturner).toBeDefined();
6971
});
7072

7173
it('should have same values for globals and for public API', () => {
@@ -107,6 +109,7 @@ describe('Legacy Compatibility', () => {
107109
expect(global.IMTFeeder === publicApi.IMTFeeder).toBe(true);
108110
expect(global.IMTTransformer === publicApi.IMTTransformer).toBe(true);
109111
expect(global.IMTHITL === publicApi.IMTHITL).toBe(true);
112+
expect(global.IMTReturner === publicApi.IMTReturner).toBe(true);
110113
});
111114

112115
it('should be compatible with CoffeeScript classes', () => {

test/module-type.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
IMTRouter,
1010
IMTTransformer,
1111
IMTTrigger,
12+
IMTReturner,
1213
ModuleType,
1314
} from '../src';
1415

@@ -25,6 +26,7 @@ describe('ModuleType', () => {
2526
new IMTRouter(),
2627
new IMTTransformer(),
2728
new IMTTrigger(),
29+
new IMTReturner(),
2830
];
2931

3032
for (const module of allModuleTypes) {
@@ -60,6 +62,9 @@ describe('ModuleType', () => {
6062
case ModuleType.PAUSER:
6163
expect(module).toBeInstanceOf(IMTPauser);
6264
break;
65+
case ModuleType.RETURNER:
66+
expect(module).toBeInstanceOf(IMTReturner);
67+
break;
6368
default:
6469
throw new Error('Unexpected module type');
6570
}

0 commit comments

Comments
 (0)