Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(returner): add new type #20

Merged
merged 3 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export enum ModuleType {
CONVERGER = 9,
HITL = 10,
PAUSER = 11,
RETURNER = 12,
}

/**
Expand Down Expand Up @@ -60,6 +61,7 @@ export class IMTBase extends EventEmitter {
public static readonly MODULETYPE_CONVERGER = ModuleType.CONVERGER;
public static readonly MODULETYPE_HITL = ModuleType.HITL;
public static readonly MODULETYPE_PAUSER = ModuleType.PAUSER;
public static readonly MODULETYPE_RETURNER = ModuleType.RETURNER;

public common: CommonData | null = null;
public data: ModuleData | null = null;
Expand Down
2 changes: 2 additions & 0 deletions src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ declare global {
var IMTFeeder: typeof publicApi.IMTFeeder;
var IMTTransformer: typeof publicApi.IMTTransformer;
var IMTHITL: typeof publicApi.IMTHITL;
var IMTReturner: typeof publicApi.IMTReturner;
/* eslint-enable no-var */
}

Expand Down Expand Up @@ -98,4 +99,5 @@ if (!global.IMT_PROTO_LOADED) {
global.IMTFeeder = publicApi.IMTFeeder;
global.IMTTransformer = publicApi.IMTTransformer;
global.IMTHITL = publicApi.IMTHITL;
global.IMTReturner = publicApi.IMTReturner;
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export * from './listener';
export * from './converger';
export * from './aggregator';
export * from './transformer';
export * from './returner';
22 changes: 22 additions & 0 deletions src/returner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { IMTBase, ModuleType } from './base';
import { Bundle, DoneWithResultCallback } from './types';

export class IMTReturner extends IMTBase {
public readonly type = ModuleType.RETURNER;

/**
* Returns data.
*
* @param {Object} bundle Collection of data to process.
* @callback done Callback to call when operations are done.
* @param {Error} err Error on error, otherwise null.
* @param {Bundle} bundle Collection of returned data.
*
*/

returnData(bundle: Bundle, done: DoneWithResultCallback): void {
void bundle;
void done;
throw new Error("Must override a superclass method 'returnData'.");
}
}
3 changes: 3 additions & 0 deletions test/legacy-compatibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('Legacy Compatibility', () => {
IMTRPC,
IMTFeeder,
IMTTransformer,
IMTReturner,
];

it('exports global variables', () => {
Expand Down Expand Up @@ -66,6 +67,7 @@ describe('Legacy Compatibility', () => {
expect(global.IMTFeeder).toBeDefined();
expect(global.IMTTransformer).toBeDefined();
expect(global.IMTHITL).toBeDefined();
expect(global.IMTReturner).toBeDefined();
});

it('should have same values for globals and for public API', () => {
Expand Down Expand Up @@ -107,6 +109,7 @@ describe('Legacy Compatibility', () => {
expect(global.IMTFeeder === publicApi.IMTFeeder).toBe(true);
expect(global.IMTTransformer === publicApi.IMTTransformer).toBe(true);
expect(global.IMTHITL === publicApi.IMTHITL).toBe(true);
expect(global.IMTReturner === publicApi.IMTReturner).toBe(true);
});

it('should be compatible with CoffeeScript classes', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/module-type.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
IMTRouter,
IMTTransformer,
IMTTrigger,
IMTReturner,
ModuleType,
} from '../src';

Expand All @@ -25,6 +26,7 @@ describe('ModuleType', () => {
new IMTRouter(),
new IMTTransformer(),
new IMTTrigger(),
new IMTReturner(),
];

for (const module of allModuleTypes) {
Expand Down Expand Up @@ -60,6 +62,9 @@ describe('ModuleType', () => {
case ModuleType.PAUSER:
expect(module).toBeInstanceOf(IMTPauser);
break;
case ModuleType.RETURNER:
expect(module).toBeInstanceOf(IMTReturner);
break;
default:
throw new Error('Unexpected module type');
}
Expand Down