Green-Software-Foundation / if

Impact Framework
https://if.greensoftware.foundation/
MIT License
156 stars 41 forks source link

Plugin Factory #989

Closed narekhovhannisyan closed 1 month ago

narekhovhannisyan commented 2 months ago

What

As a developer, I want simple user experience while developing plugins. For that I need to less care about utility functions like mapConfigIfNeeded, mapOutputIfNeeded and so on. As a proposal for solution is to incapsulate mapConfigIfNeeded function in validateConfig (which is abstraction over out old validate function from if-core). mapInputIfNeeded can be incapsulated into validate function.

Why

Context

Prerequisites/resources

SoW (scope of work)

Acceptance criteria

Given (Setup): Describes the initial state of the system or the preconditions for a change.

When (Action): Describes the specific action or behavior that is being tested/changed.

Then (Assertion): Defines the expected outcome or behavior of the system after the action in the "When" step is performed.

zanete commented 2 months ago

please post your thoughts on the solution to improve plugin developer experience as discussed in the planning call

narekhovhannisyan commented 2 months ago
const utils = require('@grnsft/if-core/utils/validations');
const {validate} = utils;

// This one should be in if-core, which will make if-core more reasonable
const PluginInterface = params => input => {
  const {metadata, callback, validateInput, validateConfig, evaluateInput} =
    params;

  return {
    metadata,
    execute: () => {
      const safeInput = validateInput(input);

      const result = callback(safeInput);

      return result;
    },
  };
};

const metadata = {
  inputs: {},
  outputs: {},
};

const callback = inputs => {
  const result = inputs.map(input => (input['carbon-embodied'] = 1));

  return result;
};

module.exports = PluginInterface({metadata, callback});
zanete commented 1 month ago

will integrate the inline arithmetic into this as well after merging #970

zanete commented 1 month ago

expecting the PR early next week

narekhovhannisyan commented 1 month ago

If-core part is here: https://github.com/Green-Software-Foundation/if-core/pull/25