Skip to content

Commit

Permalink
added CommonGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
pazbardanl committed Dec 31, 2023
1 parent 6dc47bc commit 29350ab
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/lib/mock-observations/helpers/CommonGenerator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Generator } from '../interfaces';

class CommonGenerator implements Generator {
private name: String;

Check failure on line 4 in src/lib/mock-observations/helpers/CommonGenerator.ts

View workflow job for this annotation

GitHub Actions / build

Property 'name' has no initializer and is not definitely assigned in the constructor.

Check failure on line 4 in src/lib/mock-observations/helpers/CommonGenerator.ts

View workflow job for this annotation

GitHub Actions / build

'name' is declared but its value is never read.
private generateObject: Object;

Check failure on line 5 in src/lib/mock-observations/helpers/CommonGenerator.ts

View workflow job for this annotation

GitHub Actions / build

Property 'generateObject' has no initializer and is not definitely assigned in the constructor.

initialise(name: String, config:Object): void {
this.name = this.validateName(name);
// TODO PB -- validate config is not null, not empty and a valid yml object, use yaml.parse(input)
// TODO PB -- object immutabilty - copy by value here
this.generateObject = config;
}

next(historical: Object[]): Object {

Check failure on line 14 in src/lib/mock-observations/helpers/CommonGenerator.ts

View workflow job for this annotation

GitHub Actions / build

'historical' is declared but its value is never read.
// TODO PB -- object immutabilty - copy by value here
return this.generateObject
}

private validateName(name: String | null): String {
if (name === null || name.trim() === '') {
// TODO PB - custom / more specific error?
throw new Error('name is empty or null');
}
return name;
}
}

export default CommonGenerator;
14 changes: 12 additions & 2 deletions src/lib/mock-observations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,33 @@
// import {ERRORS} from '../../util/errors';
import {buildErrorMessage} from '../../util/helpers';

import {KeyValuePair, ModelParams} from '../../types/common';
import {ModelParams} from '../../types/common';
import {ModelPluginInterface} from '../../interfaces';

// const {AuthorizationError, InputValidationError, APIRequestError} = ERRORS;

export class MockObservations implements ModelPluginInterface {
staticParams: object | undefined;
errorBuilder = buildErrorMessage(WattTimeGridEmissions);
errorBuilder = buildErrorMessage(MockObservations);

async authenticate(authParams: object): Promise<void> {
// TODO PB -- remove dummy line
this.staticParams = authParams;
// return authParams;
}

async execute(inputs: ModelParams[]): Promise<ModelParams[]> {
// TODO PB -- remove dummy line
this.staticParams = inputs;
// TODO PB -- remove dummy line
return inputs;
}

async configure(
staticParams: object | undefined
): Promise<ModelPluginInterface> {
// TODO PB -- remove dummy line
this.staticParams = staticParams;
return this;
}
}

0 comments on commit 29350ab

Please sign in to comment.