From 548c02917c7228b8c047a72405c8ff06dc8fc0a3 Mon Sep 17 00:00:00 2001 From: manushak Date: Fri, 12 Jul 2024 18:31:21 +0400 Subject: [PATCH 01/10] feat(util): add `parameter-metadata` into manifest validation schema --- src/common/util/validations.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/common/util/validations.ts b/src/common/util/validations.ts index 76b785d6d..98d017c29 100644 --- a/src/common/util/validations.ts +++ b/src/common/util/validations.ts @@ -56,6 +56,30 @@ export const manifestSchema = z.object({ path: z.string(), method: z.string(), 'global-config': z.record(z.string(), z.any()).optional(), + 'parameter-metadata': z + .object({ + inputs: z + .record( + z.string(), + z.object({ + unit: z.string(), + description: z.string(), + }) + ) + .optional() + .nullable(), + outputs: z + .record( + z.string(), + z.object({ + unit: z.string(), + description: z.string(), + }) + ) + .optional() + .nullable(), + }) + .optional(), }) ), }), From 6a2584952bc331cc2dc54b88617e5cb15a94c59e Mon Sep 17 00:00:00 2001 From: manushak Date: Fri, 12 Jul 2024 18:33:08 +0400 Subject: [PATCH 02/10] feat(lib): add `parameter-metadata` as a second parameter of the plugins --- src/if-run/lib/initialize.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/if-run/lib/initialize.ts b/src/if-run/lib/initialize.ts index 5833787ba..5adcc2b18 100644 --- a/src/if-run/lib/initialize.ts +++ b/src/if-run/lib/initialize.ts @@ -79,7 +79,12 @@ const handModule = (method: string, pluginPath: string) => { const initPlugin = async ( initPluginParams: PluginOptions ): Promise => { - const {method, path, 'global-config': globalConfig} = initPluginParams; + const { + method, + path, + 'global-config': globalConfig, + 'parameter-metadata': parameterMetadata, + } = initPluginParams; console.debug(INITIALIZING_PLUGIN(method)); @@ -93,7 +98,7 @@ const initPlugin = async ( const plugin = await handModule(method, path); - return plugin(globalConfig); + return plugin(globalConfig, parameterMetadata); }; /** From 16517ade3ee98d6d51b3ec31685fca6a1011854b Mon Sep 17 00:00:00 2001 From: manushak Date: Fri, 12 Jul 2024 18:36:06 +0400 Subject: [PATCH 03/10] feat(src): update `Coefficient`, `Copy`, `Divide` and `Exponent` plugins code and docs --- src/if-run/builtins/coefficient/README.md | 25 +++++++++++++++- src/if-run/builtins/coefficient/index.ts | 18 +++++++++++- src/if-run/builtins/copy-param/README.md | 36 ++++++++++++++++------- src/if-run/builtins/copy-param/index.ts | 13 ++++++-- src/if-run/builtins/divide/README.md | 15 +++++++++- src/if-run/builtins/divide/index.ts | 14 +++++++-- src/if-run/builtins/exponent/README.md | 15 +++++++++- src/if-run/builtins/exponent/index.ts | 8 ++++- 8 files changed, 125 insertions(+), 19 deletions(-) diff --git a/src/if-run/builtins/coefficient/README.md b/src/if-run/builtins/coefficient/README.md index fb42e32a1..f0e16cb4b 100644 --- a/src/if-run/builtins/coefficient/README.md +++ b/src/if-run/builtins/coefficient/README.md @@ -16,6 +16,20 @@ Three parameters are required in global config: `input-parameter`, `coefficient` - `coefficient`: the value to multiply `input-parameter` by. - `output-parameter`: a string defining the name to use to add the product of the input parameters to the output array. +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` +of the parameters of the inputs and outputs + +- `inputs`: describe parameters of the `input-parameter` of the global config. Each parameter has: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe parameters of the `output-parameter` of the global config. Each parameter has: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs All of `input-parameters` must be available in the input array. @@ -68,6 +82,15 @@ initialize: input-parameter: 'carbon' coefficient: 3 output-parameter: 'carbon-product' + parameter-metadata: + inputs: + carbon: + description: "an amount of carbon emitted into the atmosphere" + unit: "gCO2e" + outputs: + carbon-product: + description: "a product of cabon property and the coefficient" + unit: "gCO2e" tree: children: child: @@ -105,4 +128,4 @@ The required parameters are: You can fix this error by checking you are providing valid values for each parameter in the config. -For more information on our error classes, please visit [our docs](https://if.greensoftware.foundation/reference/errors +For more information on our error classes, please visit [our docs](https://if.greensoftware.foundation/reference/errors) diff --git a/src/if-run/builtins/coefficient/index.ts b/src/if-run/builtins/coefficient/index.ts index 4b80be633..b6c743170 100644 --- a/src/if-run/builtins/coefficient/index.ts +++ b/src/if-run/builtins/coefficient/index.ts @@ -3,6 +3,7 @@ import {ERRORS} from '@grnsft/if-core/utils'; import { CoefficientConfig, ExecutePlugin, + PluginParametersMetadata, PluginParams, } from '@grnsft/if-core/types'; @@ -13,9 +14,24 @@ import {STRINGS} from '../../config'; const {GlobalConfigError} = ERRORS; const {MISSING_GLOBAL_CONFIG} = STRINGS; -export const Coefficient = (globalConfig: CoefficientConfig): ExecutePlugin => { +export const Coefficient = ( + globalConfig: CoefficientConfig, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs || { + carbon: { + description: 'an amount of carbon emitted into the atmosphere', + unit: 'gCO2e', + }, + }, + outputs: parametersMetadata?.outputs || { + 'carbon-product': { + description: 'a product of cabon property and the coefficient', + unit: 'gCO2e', + }, + }, }; /** diff --git a/src/if-run/builtins/copy-param/README.md b/src/if-run/builtins/copy-param/README.md index 78ab5f656..8e6ef563a 100644 --- a/src/if-run/builtins/copy-param/README.md +++ b/src/if-run/builtins/copy-param/README.md @@ -39,6 +39,19 @@ Three parameters are required in config: `from` and `to` and `keep-existing`. `to`: a string defining the name to use to add the result of summing the input parameters to the output array. `keep-existing`: toggles whether to keep or delete the copied parameter (defined in `to`) +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe the parameter of the `from` of the global config. The parameter has the following attributes: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the parameters of the `to` of the global config. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs As with all plugins, `timestamp` and `duration` are required. The key passed to `from` must exist in the `input` data. @@ -47,24 +60,28 @@ As with all plugins, `timestamp` and `duration` are required. The key passed to The plugin adds a new parameter with the name defined in `to` to the `input` data. - ## Implementation To run the plugin, you must first create an instance of `Copy`. Then, you can call `execute()`. ```typescript -import { Copy } from "."; +import {Copy} from '.'; -const plugin = Copy({ 'keep-existing': true, from: 'from-param', to: 'to-param' }); +const plugin = Copy({ + 'keep-existing': true, + from: 'from-param', + to: 'to-param', +}); -const result = plugin.execute([{ - timestamp: "2023-12-12T00:00:13.000Z", +const result = plugin.execute([ + { + timestamp: '2023-12-12T00:00:13.000Z', duration: 30, 'from-param': 'hello', -}]) - -console.log(result) + }, +]); +console.log(result); ``` ## Example manifest @@ -90,9 +107,8 @@ tree: pipeline: - copy-param inputs: - - timestamp: "2023-12-12T00:00:00.000Z" + - timestamp: '2023-12-12T00:00:00.000Z' original: 'hello' - ``` You can run this example by saving it as `./manifests/examples/copy.yml` and executing the following command from the project root: diff --git a/src/if-run/builtins/copy-param/index.ts b/src/if-run/builtins/copy-param/index.ts index cf21cfb8e..7f10bf696 100644 --- a/src/if-run/builtins/copy-param/index.ts +++ b/src/if-run/builtins/copy-param/index.ts @@ -1,6 +1,10 @@ import {z} from 'zod'; import {ERRORS} from '@grnsft/if-core/utils'; -import {ExecutePlugin, PluginParams} from '@grnsft/if-core/types'; +import { + ExecutePlugin, + PluginParametersMetadata, + PluginParams, +} from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; @@ -12,9 +16,14 @@ const {GlobalConfigError} = ERRORS; // from-param: the parameter you are copying from (e.g. cpu/name) // to-field: the parameter you are copying to (e.g. cpu/processor-name) -export const Copy = (globalConfig: Record): ExecutePlugin => { +export const Copy = ( + globalConfig: Record, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** diff --git a/src/if-run/builtins/divide/README.md b/src/if-run/builtins/divide/README.md index 99f8a23ee..98e5c0314 100644 --- a/src/if-run/builtins/divide/README.md +++ b/src/if-run/builtins/divide/README.md @@ -12,6 +12,19 @@ You provide the names of the values you want to divide, and a name to use to add - `denominator` - a parameter by a specific configured number or the number by which `numerator` is divided - `output` - the number to a configured output parameter +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe the parameter of the `numerator` of the global config. The parameter has the following attributes: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the parameter of the `denominator` of the global config. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs - `numerator` - as input parameter, must be available in the input array @@ -42,7 +55,7 @@ const globalConfig = { denominator: 2, output: 'cpu/number-cores', }; -const divide = Divide(globalConfig); +const divide = Divide(globalConfig, parametersMetadata); const input = [ { diff --git a/src/if-run/builtins/divide/index.ts b/src/if-run/builtins/divide/index.ts index 328c4ccff..3d09c130c 100644 --- a/src/if-run/builtins/divide/index.ts +++ b/src/if-run/builtins/divide/index.ts @@ -1,6 +1,11 @@ import {z} from 'zod'; import {ERRORS} from '@grnsft/if-core/utils'; -import {ExecutePlugin, PluginParams, ConfigParams} from '@grnsft/if-core/types'; +import { + ExecutePlugin, + PluginParams, + ConfigParams, + PluginParametersMetadata, +} from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; @@ -9,9 +14,14 @@ import {STRINGS} from '../../config'; const {GlobalConfigError, MissingInputDataError} = ERRORS; const {MISSING_GLOBAL_CONFIG, MISSING_INPUT_DATA, ZERO_DIVISION} = STRINGS; -export const Divide = (globalConfig: ConfigParams): ExecutePlugin => { +export const Divide = ( + globalConfig: ConfigParams, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** diff --git a/src/if-run/builtins/exponent/README.md b/src/if-run/builtins/exponent/README.md index fa36319b8..ed1c74b35 100644 --- a/src/if-run/builtins/exponent/README.md +++ b/src/if-run/builtins/exponent/README.md @@ -16,6 +16,19 @@ Three parameters are required in global config: `input-parameter`, `exponent` an `exponent`: a number defining the exponent. `output-parameter`: a string defining the name to use to add the result of the exponent to the output array. +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe the parameter of the `input-parameter` of the global config. The parameter has the following attributes: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the parameter of the `output-parameter` of the global config. The parameter has the following attributes:: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs `input-parameter` and `exponent` must be available in the input array. @@ -111,4 +124,4 @@ Every element in the `inputs` array must contain: This error arises when an invalid value is passed to `Exponent`. Typically, this can occur when a non-numeric value (such as a string made of alphabetic characters) is passed where a number or numeric string is expected. Please check that the types are correct for all the relevant fields in your `inputs` array. -For more information on our error classes, please visit [our docs](https://if.greensoftware.foundation/reference/errors +For more information on our error classes, please visit [our docs](https://if.greensoftware.foundation/reference/errors) diff --git a/src/if-run/builtins/exponent/index.ts b/src/if-run/builtins/exponent/index.ts index 800b2295e..a821c3a14 100644 --- a/src/if-run/builtins/exponent/index.ts +++ b/src/if-run/builtins/exponent/index.ts @@ -3,13 +3,19 @@ import { ExecutePlugin, PluginParams, ExponentConfig, + PluginParametersMetadata, } from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; -export const Exponent = (globalConfig: ExponentConfig): ExecutePlugin => { +export const Exponent = ( + globalConfig: ExponentConfig, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** From 9b3890ec96cdae98b35f7a9c656ec2de6b5b02d0 Mon Sep 17 00:00:00 2001 From: manushak Date: Fri, 12 Jul 2024 18:38:28 +0400 Subject: [PATCH 04/10] feat(src): update `Interpolation`, `Multiply`, `Regex` and `Sum` plugins and their docs --- src/if-run/builtins/interpolation/README.md | 13 ++++++++++ src/if-run/builtins/interpolation/index.ts | 16 +++++++++--- src/if-run/builtins/multiply/README.md | 15 +++++++++++- src/if-run/builtins/multiply/index.ts | 8 +++++- src/if-run/builtins/regex/README.md | 13 ++++++++++ src/if-run/builtins/regex/index.ts | 14 +++++++++-- src/if-run/builtins/sum/README.md | 27 ++++++++++++++++++++- src/if-run/builtins/sum/index.ts | 14 +++++++++-- 8 files changed, 109 insertions(+), 11 deletions(-) diff --git a/src/if-run/builtins/interpolation/README.md b/src/if-run/builtins/interpolation/README.md index 74c8498a3..dedcfe5e9 100644 --- a/src/if-run/builtins/interpolation/README.md +++ b/src/if-run/builtins/interpolation/README.md @@ -25,6 +25,19 @@ To employ the `Interpolation` plugin, adhere to these steps: `x` and `y` arrays must be equal lengths. +## Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe the parameter of the `input-parameter` of the global config. The parameter has the following attributes: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the parameters of the `output-parameter` of the global config. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ## Input Parameters The plugin expects the following input parameters: diff --git a/src/if-run/builtins/interpolation/index.ts b/src/if-run/builtins/interpolation/index.ts index 03239a004..60fe90e5b 100644 --- a/src/if-run/builtins/interpolation/index.ts +++ b/src/if-run/builtins/interpolation/index.ts @@ -6,6 +6,7 @@ import { PluginParams, ConfigParams, Method, + PluginParametersMetadata, } from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; @@ -20,7 +21,16 @@ const { WITHIN_THE_RANGE, } = STRINGS; -export const Interpolation = (globalConfig: ConfigParams): ExecutePlugin => { +export const Interpolation = ( + globalConfig: ConfigParams, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { + const metadata = { + kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, + }; + /** * Executes the energy consumption calculation for an array of input parameters. */ @@ -189,9 +199,7 @@ export const Interpolation = (globalConfig: ConfigParams): ExecutePlugin => { }; return { - metadata: { - kind: 'execute', - }, + metadata, execute, }; }; diff --git a/src/if-run/builtins/multiply/README.md b/src/if-run/builtins/multiply/README.md index 0ce42c7c0..08ebe9526 100644 --- a/src/if-run/builtins/multiply/README.md +++ b/src/if-run/builtins/multiply/README.md @@ -15,6 +15,19 @@ Two parameters are required in global config: `input-parameters` and `output-par `input-parameters`: an array of strings. Each string should match an existing key in the `inputs` array `output-parameter`: a string defining the name to use to add the product of the input parameters to the output array. +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe parameters of the `input-parameters` of the global config. Each parameter has: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the parameter of the `output-parameter` of the global config. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs All of `input-parameters` must be available in the input array. @@ -41,7 +54,7 @@ const config = { outputParameter: 'energy-product', }; -const mult = Multiply(config); +const mult = Multiply(config, parametersMetadata); const result = await mult.execute([ { duration: 3600, diff --git a/src/if-run/builtins/multiply/index.ts b/src/if-run/builtins/multiply/index.ts index 706e190ec..b51c1a426 100644 --- a/src/if-run/builtins/multiply/index.ts +++ b/src/if-run/builtins/multiply/index.ts @@ -3,13 +3,19 @@ import { ExecutePlugin, PluginParams, MultiplyConfig, + PluginParametersMetadata, } from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; -export const Multiply = (globalConfig: MultiplyConfig): ExecutePlugin => { +export const Multiply = ( + globalConfig: MultiplyConfig, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** diff --git a/src/if-run/builtins/regex/README.md b/src/if-run/builtins/regex/README.md index cba3b6fe4..99685a15b 100644 --- a/src/if-run/builtins/regex/README.md +++ b/src/if-run/builtins/regex/README.md @@ -16,6 +16,19 @@ Intel® Xeon® Platinum 8272CL,Intel® Xeon® 8171M 2.1 GHz,Intel® Xeon® E5-26 - `match` - a regex by which needs to match the `parameter` - `output` - output parameter name in the input +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe the parameter of the `parameter` value of the global config. The parameter has the following attributes: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the parameters of the `output` of the global config. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs - `parameter` - as input parameter, must be available in the input array diff --git a/src/if-run/builtins/regex/index.ts b/src/if-run/builtins/regex/index.ts index 45c65d6f6..59c10154c 100644 --- a/src/if-run/builtins/regex/index.ts +++ b/src/if-run/builtins/regex/index.ts @@ -1,6 +1,11 @@ import {z} from 'zod'; import {ERRORS} from '@grnsft/if-core/utils'; -import {ExecutePlugin, PluginParams, ConfigParams} from '@grnsft/if-core/types'; +import { + ExecutePlugin, + PluginParams, + ConfigParams, + PluginParametersMetadata, +} from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; @@ -9,9 +14,14 @@ import {STRINGS} from '../../config'; const {MissingInputDataError, GlobalConfigError, RegexMismatchError} = ERRORS; const {MISSING_GLOBAL_CONFIG, MISSING_INPUT_DATA, REGEX_MISMATCH} = STRINGS; -export const Regex = (globalConfig: ConfigParams): ExecutePlugin => { +export const Regex = ( + globalConfig: ConfigParams, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** diff --git a/src/if-run/builtins/sum/README.md b/src/if-run/builtins/sum/README.md index 997a6e1cf..4d861f2c9 100644 --- a/src/if-run/builtins/sum/README.md +++ b/src/if-run/builtins/sum/README.md @@ -15,6 +15,19 @@ Two parameters are required in global config: `input-parameters` and `output-par `input-parameters`: an array of strings. Each string should match an existing key in the `inputs` array `output-parameter`: a string defining the name to use to add the result of summing the input parameters to the output array. +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe parameters of the `input-parameters` of the global config. Each parameter has: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the parameter of the `output-parameter` of the global config. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs All of `input-parameters` must be available in the input array. @@ -39,7 +52,7 @@ const config = { outputParameter: 'energy', }; -const sum = Sum(config); +const sum = Sum(config, parametersMetadata); const result = sum.execute([ { timestamp: '2021-01-01T00:00:00Z', @@ -66,6 +79,18 @@ initialize: global-config: input-parameters: ['cpu/energy', 'network/energy'] output-parameter: 'energy' + parameter-metadata: + inputs: + cpu/energy: + description: energy consumed by the cpu + unit: kWh + network/energy: + description: energy consumed by data ingress and egress + unit: kWh + outputs: + energy: + description: sum of energy components + unit: kWh tree: children: child: diff --git a/src/if-run/builtins/sum/index.ts b/src/if-run/builtins/sum/index.ts index 62ba479e6..da642dd13 100644 --- a/src/if-run/builtins/sum/index.ts +++ b/src/if-run/builtins/sum/index.ts @@ -1,6 +1,11 @@ import {z} from 'zod'; import {ERRORS} from '@grnsft/if-core/utils'; -import {ExecutePlugin, PluginParams, SumConfig} from '@grnsft/if-core/types'; +import { + ExecutePlugin, + PluginParams, + SumConfig, + PluginParametersMetadata, +} from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; @@ -9,9 +14,14 @@ import {STRINGS} from '../../config'; const {GlobalConfigError} = ERRORS; const {MISSING_GLOBAL_CONFIG} = STRINGS; -export const Sum = (globalConfig: SumConfig): ExecutePlugin => { +export const Sum = ( + globalConfig: SumConfig, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** From 61b089d8793226b3af0ecd4f0cf35e04ab339e5f Mon Sep 17 00:00:00 2001 From: manushak Date: Fri, 12 Jul 2024 18:51:24 +0400 Subject: [PATCH 05/10] feat(src): update `Sci`, `SciEmbodied` and `Subtract` plugins and their docs --- src/if-run/builtins/csv-lookup/README.md | 4 +-- src/if-run/builtins/sci-embodied/README.md | 13 +++++++ src/if-run/builtins/sci-embodied/index.ts | 42 ++++++++++++++++++++-- src/if-run/builtins/sci/README.md | 13 +++++++ src/if-run/builtins/sci/index.ts | 29 +++++++++++++-- src/if-run/builtins/subtract/README.md | 13 +++++++ src/if-run/builtins/subtract/index.ts | 8 ++++- 7 files changed, 115 insertions(+), 7 deletions(-) diff --git a/src/if-run/builtins/csv-lookup/README.md b/src/if-run/builtins/csv-lookup/README.md index 61af5b292..317f3c897 100644 --- a/src/if-run/builtins/csv-lookup/README.md +++ b/src/if-run/builtins/csv-lookup/README.md @@ -84,7 +84,7 @@ const globalConfig = { }, output: ['cpu-tdp', 'tdp'], }; -const divide = CSVLookup(globalConfig); +const csvLookup = CSVLookup(globalConfig); const input = [ { @@ -173,4 +173,4 @@ The required parameters are: You can fix this error by checking you are providing valid values for each parameter in the config. -For more information on our error classes, please visit [our docs](https://if.greensoftware.foundation/reference/errors +For more information on our error classes, please visit [our docs](https://if.greensoftware.foundation/reference/errors) diff --git a/src/if-run/builtins/sci-embodied/README.md b/src/if-run/builtins/sci-embodied/README.md index b4d71304b..21266fba7 100644 --- a/src/if-run/builtins/sci-embodied/README.md +++ b/src/if-run/builtins/sci-embodied/README.md @@ -10,6 +10,19 @@ Read more on [embodied carbon](https://github.com/Green-Software-Foundation/sci/ Not Needed +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe the parameters of the `inputs`. Each parameter has: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the `carbon-embodied` parameter. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs - `device/emissions-embodied`: the sum of Life Cycle Assessment (LCA) emissions for the component diff --git a/src/if-run/builtins/sci-embodied/index.ts b/src/if-run/builtins/sci-embodied/index.ts index 2fffc09ed..e2a60edd6 100644 --- a/src/if-run/builtins/sci-embodied/index.ts +++ b/src/if-run/builtins/sci-embodied/index.ts @@ -1,5 +1,9 @@ import {z} from 'zod'; -import {ExecutePlugin, PluginParams} from '@grnsft/if-core/types'; +import { + ExecutePlugin, + PluginParametersMetadata, + PluginParams, +} from '@grnsft/if-core/types'; import {validate, allDefined} from '../../../common/util/validations'; @@ -7,9 +11,43 @@ import {STRINGS} from '../../config'; const {SCI_EMBODIED_ERROR} = STRINGS; -export const SciEmbodied = (): ExecutePlugin => { +export const SciEmbodied = ( + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs || { + 'device/emissions-embodied': { + description: 'total embodied emissions of some component', + unit: 'gCO2e', + }, + 'device/expected-lifespan': { + description: 'Total Expected Lifespan of the Component in Seconds', + unit: 'seconds', + }, + 'resources-reserved': { + description: 'resources reserved for an application', + unit: 'count', + }, + 'resources-total': { + description: 'total resources available', + unit: 'count', + }, + 'vcpus-allocated': { + description: 'number of vcpus allocated to particular resource', + unit: 'count', + }, + 'vcpus-total': { + description: 'total number of vcpus available on a particular resource', + unit: 'count', + }, + }, + outputs: parametersMetadata?.outputs || { + 'carbon-embodied': { + description: 'embodied emissions of the component', + unit: 'gCO2e', + }, + }, }; const METRICS = [ diff --git a/src/if-run/builtins/sci/README.md b/src/if-run/builtins/sci/README.md index d40ca93ed..4d9544ad2 100644 --- a/src/if-run/builtins/sci/README.md +++ b/src/if-run/builtins/sci/README.md @@ -8,6 +8,19 @@ - `functional-unit`: the name of the functional unit in which to express the carbon impact (required) +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe parameters of the `inputs`. Each parameter has: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the `sci` parameter which has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs - `carbon`: total carbon in gCO2eq (required) diff --git a/src/if-run/builtins/sci/index.ts b/src/if-run/builtins/sci/index.ts index f11f6c2b8..90cf55fb7 100644 --- a/src/if-run/builtins/sci/index.ts +++ b/src/if-run/builtins/sci/index.ts @@ -1,6 +1,11 @@ import {z} from 'zod'; import {ERRORS} from '@grnsft/if-core/utils'; -import {ExecutePlugin, PluginParams, ConfigParams} from '@grnsft/if-core/types'; +import { + ExecutePlugin, + PluginParams, + ConfigParams, + PluginParametersMetadata, +} from '@grnsft/if-core/types'; import {validate, allDefined} from '../../../common/util/validations'; @@ -14,9 +19,29 @@ const { ZERO_DIVISION, } = STRINGS; -export const Sci = (globalConfig: ConfigParams): ExecutePlugin => { +export const Sci = ( + globalConfig: ConfigParams, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs || { + carbon: { + description: 'an amount of carbon emitted into the atmosphere', + unit: 'gCO2e', + }, + 'functional-unit': { + description: + 'the name of the functional unit in which the final SCI value should be expressed, e.g. requests, users', + unit: 'none', + }, + }, + outputs: parametersMetadata?.outputs || { + sci: { + description: 'carbon expressed in terms of the given functional unit', + unit: 'gCO2e', + }, + }, }; /** diff --git a/src/if-run/builtins/subtract/README.md b/src/if-run/builtins/subtract/README.md index 726f982b2..9916404bc 100644 --- a/src/if-run/builtins/subtract/README.md +++ b/src/if-run/builtins/subtract/README.md @@ -15,6 +15,19 @@ Two parameters are required in global config: `input-parameters` and `output-par `input-parameters`: an array of strings. Each string should match an existing key in the `inputs` array `output-parameter`: a string defining the name to use to add the result of the diff to the output array. +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe parameters of the `input-parameters` of the global config. Each parameter has the following attributes: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the parameter of the `output-parameter` of the global config. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs All of `input-parameters` must be available in the input array. diff --git a/src/if-run/builtins/subtract/index.ts b/src/if-run/builtins/subtract/index.ts index bd5af0603..2598ecb8a 100644 --- a/src/if-run/builtins/subtract/index.ts +++ b/src/if-run/builtins/subtract/index.ts @@ -1,15 +1,21 @@ import {z} from 'zod'; import { ExecutePlugin, + PluginParametersMetadata, PluginParams, SubtractConfig, } from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; -export const Subtract = (globalConfig: SubtractConfig): ExecutePlugin => { +export const Subtract = ( + globalConfig: SubtractConfig, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** From 2574f4ff93fb65d8adbc2eeb978825f8edbde0d8 Mon Sep 17 00:00:00 2001 From: manushak Date: Fri, 12 Jul 2024 18:54:29 +0400 Subject: [PATCH 06/10] test(builtins): add `parametersMetadata` into the tests --- .../if-run/builtins/coefficient.test.ts | 12 +++-- .../if-run/builtins/copy-param.test.ts | 12 +++-- src/__tests__/if-run/builtins/divide.test.ts | 16 +++--- .../if-run/builtins/exponent.test.ts | 8 ++- .../if-run/builtins/interpolation.test.ts | 20 +++++--- .../if-run/builtins/multiply.test.ts | 8 ++- src/__tests__/if-run/builtins/regex.test.ts | 12 +++-- .../if-run/builtins/sci-embodied.test.ts | 6 ++- src/__tests__/if-run/builtins/sci.test.ts | 51 +++++++++++++------ .../if-run/builtins/subtract.test.ts | 8 ++- src/__tests__/if-run/builtins/sum.test.ts | 10 ++-- 11 files changed, 111 insertions(+), 52 deletions(-) diff --git a/src/__tests__/if-run/builtins/coefficient.test.ts b/src/__tests__/if-run/builtins/coefficient.test.ts index 1660edffe..8d99c3e87 100644 --- a/src/__tests__/if-run/builtins/coefficient.test.ts +++ b/src/__tests__/if-run/builtins/coefficient.test.ts @@ -14,7 +14,11 @@ describe('builtins/coefficient: ', () => { coefficient: 3, 'output-parameter': 'carbon-product', }; - const coefficient = Coefficient(globalConfig); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const coefficient = Coefficient(globalConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -51,7 +55,7 @@ describe('builtins/coefficient: ', () => { it('throws an error when global config is not provided.', () => { const config = undefined; - const coefficient = Coefficient(config!); + const coefficient = Coefficient(config!, parametersMetadata); expect.assertions(1); @@ -76,7 +80,7 @@ describe('builtins/coefficient: ', () => { coefficient: 3, 'output-parameter': 'carbon-product', }; - const coefficient = Coefficient(invalidConfig); + const coefficient = Coefficient(invalidConfig, parametersMetadata); const expectedMessage = '"input-parameter" parameter is string must contain at least 1 character(s). Error code: too_small.'; @@ -103,7 +107,7 @@ describe('builtins/coefficient: ', () => { coefficient: 10, 'output-parameter': '', }; - const coefficient = Coefficient(invalidConfig); + const coefficient = Coefficient(invalidConfig, parametersMetadata); const expectedMessage = '"output-parameter" parameter is string must contain at least 1 character(s). Error code: too_small.'; diff --git a/src/__tests__/if-run/builtins/copy-param.test.ts b/src/__tests__/if-run/builtins/copy-param.test.ts index 8ac621538..952546505 100644 --- a/src/__tests__/if-run/builtins/copy-param.test.ts +++ b/src/__tests__/if-run/builtins/copy-param.test.ts @@ -14,7 +14,11 @@ describe('builtins/copy: ', () => { from: 'original', to: 'copy', }; - const copy = Copy(globalConfig); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const copy = Copy(globalConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -49,7 +53,7 @@ describe('builtins/copy: ', () => { it('throws an error when global config is not provided.', () => { const config = undefined; - const copy = Copy(config!); + const copy = Copy(config!, parametersMetadata); expect.assertions(1); @@ -74,7 +78,7 @@ describe('builtins/copy: ', () => { from: 'original', to: 'copy', }; - const copy = Copy(globalConfig); + const copy = Copy(globalConfig, parametersMetadata); expect.assertions(1); try { @@ -99,7 +103,7 @@ describe('builtins/copy: ', () => { from: 'original', to: 'copy', }; - const copy = Copy(globalConfig); + const copy = Copy(globalConfig, parametersMetadata); const expectedResult = [ { diff --git a/src/__tests__/if-run/builtins/divide.test.ts b/src/__tests__/if-run/builtins/divide.test.ts index b9d1d9456..e0a472998 100644 --- a/src/__tests__/if-run/builtins/divide.test.ts +++ b/src/__tests__/if-run/builtins/divide.test.ts @@ -14,7 +14,11 @@ describe('builtins/divide: ', () => { denominator: 2, output: 'cpu/number-cores', }; - const divide = Divide(globalConfig); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const divide = Divide(globalConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -54,7 +58,7 @@ describe('builtins/divide: ', () => { denominator: 'duration', output: 'vcpus-allocated-per-second', }; - const divide = Divide(globalConfig); + const divide = Divide(globalConfig, parametersMetadata); const input = [ { @@ -86,7 +90,7 @@ describe('builtins/divide: ', () => { denominator: 3600, output: 'vcpus-allocated-per-second', }; - const divide = Divide(globalConfig); + const divide = Divide(globalConfig, parametersMetadata); expect.assertions(1); @@ -107,7 +111,7 @@ describe('builtins/divide: ', () => { it('throws an error on missing global config.', async () => { const config = undefined; - const divide = Divide(config!); + const divide = Divide(config!, parametersMetadata); expect.assertions(1); @@ -131,7 +135,7 @@ describe('builtins/divide: ', () => { denominator: 0, output: 'vcpus-allocated-per-second', }; - const divide = Divide(globalConfig); + const divide = Divide(globalConfig, parametersMetadata); expect.assertions(1); @@ -159,7 +163,7 @@ describe('builtins/divide: ', () => { denominator: '10', output: 'vcpus-allocated-per-second', }; - const divide = Divide(globalConfig); + const divide = Divide(globalConfig, parametersMetadata); expect.assertions(1); diff --git a/src/__tests__/if-run/builtins/exponent.test.ts b/src/__tests__/if-run/builtins/exponent.test.ts index 3b88df0cb..2e0419686 100644 --- a/src/__tests__/if-run/builtins/exponent.test.ts +++ b/src/__tests__/if-run/builtins/exponent.test.ts @@ -11,7 +11,11 @@ describe('builtins/exponent: ', () => { exponent: 3, 'output-parameter': 'energy', }; - const exponent = Exponent(globalConfig); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const exponent = Exponent(globalConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -91,7 +95,7 @@ describe('builtins/exponent: ', () => { exponent: 4, 'output-parameter': 'carbon', }; - const exponent = Exponent(newConfig); + const exponent = Exponent(newConfig, parametersMetadata); const data = [ { diff --git a/src/__tests__/if-run/builtins/interpolation.test.ts b/src/__tests__/if-run/builtins/interpolation.test.ts index 8dbd1295c..6634556dd 100644 --- a/src/__tests__/if-run/builtins/interpolation.test.ts +++ b/src/__tests__/if-run/builtins/interpolation.test.ts @@ -22,6 +22,10 @@ describe('builtins/interpolation: ', () => { 'input-parameter': 'cpu/utilization', 'output-parameter': 'interpolation-result', }; + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; const inputs = [ { timestamp: '2023-07-06T00:00', @@ -29,7 +33,7 @@ describe('builtins/interpolation: ', () => { 'cpu/utilization': 45, }, ]; - const plugin = Interpolation(globalConfig); + const plugin = Interpolation(globalConfig, parametersMetadata); describe('init Interpolation: ', () => { it('initalizes object with properties.', async () => { @@ -59,7 +63,7 @@ describe('builtins/interpolation: ', () => { 'input-parameter': 'cpu/utilization', 'output-parameter': 'interpolation-result', }; - const plugin = Interpolation(globalConfig); + const plugin = Interpolation(globalConfig, parametersMetadata); const outputs = [ { @@ -75,7 +79,7 @@ describe('builtins/interpolation: ', () => { it('returns result when the `method` is `spline`.', () => { const config = Object.assign({}, globalConfig, {method: Method.SPLINE}); - const plugin = Interpolation(config); + const plugin = Interpolation(config, parametersMetadata); const outputs = [ { @@ -93,7 +97,7 @@ describe('builtins/interpolation: ', () => { const config = Object.assign({}, globalConfig, { method: Method.POLYNOMIAL, }); - const plugin = Interpolation(config); + const plugin = Interpolation(config, parametersMetadata); const outputs = [ { @@ -111,7 +115,7 @@ describe('builtins/interpolation: ', () => { const config = Object.assign({}, globalConfig, { x: [0, 10, 100, 50], }); - const plugin = Interpolation(config); + const plugin = Interpolation(config, parametersMetadata); const outputs = [ { @@ -147,7 +151,7 @@ describe('builtins/interpolation: ', () => { it('throws an when the global config is not provided.', () => { const config = undefined; - const plugin = Interpolation(config!); + const plugin = Interpolation(config!, parametersMetadata); expect.assertions(2); try { @@ -163,7 +167,7 @@ describe('builtins/interpolation: ', () => { x: [0, 10, 100], }); - const plugin = Interpolation(config); + const plugin = Interpolation(config, parametersMetadata); expect.assertions(2); try { @@ -198,7 +202,7 @@ describe('builtins/interpolation: ', () => { 'output-parameter': 'interpolation-result', }; const config = Object.assign({}, globalConfig, {method: Method.SPLINE}); - const plugin = Interpolation(config); + const plugin = Interpolation(config, parametersMetadata); const inputs = [ { timestamp: '2023-07-06T00:00', diff --git a/src/__tests__/if-run/builtins/multiply.test.ts b/src/__tests__/if-run/builtins/multiply.test.ts index 07dedf5ea..b3856dfd4 100644 --- a/src/__tests__/if-run/builtins/multiply.test.ts +++ b/src/__tests__/if-run/builtins/multiply.test.ts @@ -10,7 +10,11 @@ describe('builtins/multiply: ', () => { 'input-parameters': ['cpu/energy', 'network/energy', 'memory/energy'], 'output-parameter': 'energy', }; - const multiply = Multiply(globalConfig); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const multiply = Multiply(globalConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -72,7 +76,7 @@ describe('builtins/multiply: ', () => { 'input-parameters': ['carbon', 'other-carbon'], 'output-parameter': 'carbon-product', }; - const multiply = Multiply(newConfig); + const multiply = Multiply(newConfig, parametersMetadata); const data = [ { diff --git a/src/__tests__/if-run/builtins/regex.test.ts b/src/__tests__/if-run/builtins/regex.test.ts index 6ac6bd4e9..6d039363d 100644 --- a/src/__tests__/if-run/builtins/regex.test.ts +++ b/src/__tests__/if-run/builtins/regex.test.ts @@ -14,7 +14,11 @@ describe('builtins/regex: ', () => { match: '^[^,]+', output: 'cpu/name', }; - const regex = Regex(globalConfig); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const regex = Regex(globalConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -59,7 +63,7 @@ describe('builtins/regex: ', () => { match: '[^,]+/', output: 'cpu/name', }; - const regex = Regex(globalConfig); + const regex = Regex(globalConfig, parametersMetadata); const expectedResult = [ { @@ -90,7 +94,7 @@ describe('builtins/regex: ', () => { match: '^(^:)+', output: 'cpu/name', }; - const regex = Regex(globalConfig); + const regex = Regex(globalConfig, parametersMetadata); expect.assertions(1); @@ -113,7 +117,7 @@ describe('builtins/regex: ', () => { it('throws an error on missing global config.', async () => { const config = undefined; - const regex = Regex(config!); + const regex = Regex(config!, parametersMetadata); expect.assertions(1); diff --git a/src/__tests__/if-run/builtins/sci-embodied.test.ts b/src/__tests__/if-run/builtins/sci-embodied.test.ts index 0c1b504ac..0e2c234f7 100644 --- a/src/__tests__/if-run/builtins/sci-embodied.test.ts +++ b/src/__tests__/if-run/builtins/sci-embodied.test.ts @@ -9,7 +9,11 @@ const {SCI_EMBODIED_ERROR} = STRINGS; describe('builtins/sci-embodied:', () => { describe('SciEmbodied: ', () => { - const sciEmbodied = SciEmbodied(); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const sciEmbodied = SciEmbodied(parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { diff --git a/src/__tests__/if-run/builtins/sci.test.ts b/src/__tests__/if-run/builtins/sci.test.ts index 2d75ea170..0360149a9 100644 --- a/src/__tests__/if-run/builtins/sci.test.ts +++ b/src/__tests__/if-run/builtins/sci.test.ts @@ -6,7 +6,11 @@ const {MissingInputDataError} = ERRORS; describe('builtins/sci:', () => { describe('Sci: ', () => { - const sci = Sci({'functional-unit': 'users'}); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const sci = Sci({'functional-unit': 'users'}, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -17,9 +21,12 @@ describe('builtins/sci:', () => { describe('execute():', () => { it('returns a result with valid inputs.', async () => { - const sci = Sci({ - 'functional-unit': 'users', - }); + const sci = Sci( + { + 'functional-unit': 'users', + }, + parametersMetadata + ); const inputs = [ { timestamp: '2021-01-01T00:00:00Z', @@ -48,9 +55,12 @@ describe('builtins/sci:', () => { }); it('returns the same result regardless of input duration.', async () => { - const sci = Sci({ - 'functional-unit': 'requests', - }); + const sci = Sci( + { + 'functional-unit': 'requests', + }, + parametersMetadata + ); const inputs = [ { timestamp: '2021-01-01T00:00:00Z', @@ -96,9 +106,12 @@ describe('builtins/sci:', () => { }); it('throws exception on invalid functional unit data.', async () => { - const sci = Sci({ - 'functional-unit': 'requests', - }); + const sci = Sci( + { + 'functional-unit': 'requests', + }, + parametersMetadata + ); const inputs = [ { timestamp: '2021-01-01T00:00:00Z', @@ -118,9 +131,12 @@ describe('builtins/sci:', () => { }); it('throws exception if functional unit value is not positive integer.', async () => { - const sci = Sci({ - 'functional-unit': 'requests', - }); + const sci = Sci( + { + 'functional-unit': 'requests', + }, + parametersMetadata + ); const inputs = [ { timestamp: '2021-01-01T00:00:00Z', @@ -142,9 +158,12 @@ describe('builtins/sci:', () => { }); it('fallbacks to carbon value, if functional unit is 0.', async () => { - const sci = Sci({ - 'functional-unit': 'requests', - }); + const sci = Sci( + { + 'functional-unit': 'requests', + }, + parametersMetadata + ); const inputs = [ { timestamp: '2021-01-01T00:00:00Z', diff --git a/src/__tests__/if-run/builtins/subtract.test.ts b/src/__tests__/if-run/builtins/subtract.test.ts index 33ba137ab..134cebfa7 100644 --- a/src/__tests__/if-run/builtins/subtract.test.ts +++ b/src/__tests__/if-run/builtins/subtract.test.ts @@ -10,7 +10,11 @@ describe('builtins/subtract: ', () => { 'input-parameters': ['cpu/energy', 'network/energy', 'memory/energy'], 'output-parameter': 'energy/diff', }; - const subtract = Subtract(globalConfig); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const subtract = Subtract(globalConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -72,7 +76,7 @@ describe('builtins/subtract: ', () => { 'input-parameters': ['carbon', 'other-carbon'], 'output-parameter': 'carbon-diff', }; - const subtract = Subtract(newConfig); + const subtract = Subtract(newConfig, parametersMetadata); const data = [ { diff --git a/src/__tests__/if-run/builtins/sum.test.ts b/src/__tests__/if-run/builtins/sum.test.ts index d7530827c..9ccc64378 100644 --- a/src/__tests__/if-run/builtins/sum.test.ts +++ b/src/__tests__/if-run/builtins/sum.test.ts @@ -13,7 +13,11 @@ describe('builtins/sum: ', () => { 'input-parameters': ['cpu/energy', 'network/energy', 'memory/energy'], 'output-parameter': 'energy', }; - const sum = Sum(globalConfig); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const sum = Sum(globalConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -52,7 +56,7 @@ describe('builtins/sum: ', () => { it('throws an error when global config is not provided.', () => { const config = undefined; - const sum = Sum(config!); + const sum = Sum(config!, parametersMetadata); expect.assertions(1); @@ -98,7 +102,7 @@ describe('builtins/sum: ', () => { 'input-parameters': ['carbon', 'other-carbon'], 'output-parameter': 'carbon-sum', }; - const sum = Sum(newConfig); + const sum = Sum(newConfig, parametersMetadata); const data = [ { From b20c3bd093c1b103eb014a842e386e1989b6f28f Mon Sep 17 00:00:00 2001 From: manushak Date: Thu, 18 Jul 2024 18:04:50 +0400 Subject: [PATCH 07/10] fix(package): update if-core version --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index f01b0fb13..57230e0e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", - "@grnsft/if-core": "^0.0.10", + "@grnsft/if-core": "^0.0.12", "axios": "^1.7.2", "csv-parse": "^5.5.6", "csv-stringify": "^6.4.6", @@ -1185,9 +1185,9 @@ } }, "node_modules/@grnsft/if-core": { - "version": "0.0.10", - "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.10.tgz", - "integrity": "sha512-WHCdr7H/dFO9gT5fbjrthjOU+4RoLZ5P1F84pbGwJiKLmcU7dvYRuNQKDVIQQ7YJfZl76KSaS7sYgqA+QG8Wpw==", + "version": "0.0.12", + "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.12.tgz", + "integrity": "sha512-wBn/mC/I7UPvzTVlhgr+ODEa6upYc9lUONqNiPXcn/6s8wXHUx0tHsxjwz6rpp3wUEnRxTMbcy0jV7+tjoK00Q==", "dependencies": { "typescript": "^5.1.6" }, diff --git a/package.json b/package.json index 7c80610c5..3a0f5af32 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "dependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", - "@grnsft/if-core": "^0.0.10", + "@grnsft/if-core": "^0.0.12", "axios": "^1.7.2", "csv-parse": "^5.5.6", "csv-stringify": "^6.4.6", From 5a7847687601c86358f646b3e5706ad1655a2c70 Mon Sep 17 00:00:00 2001 From: manushak Date: Thu, 18 Jul 2024 18:05:52 +0400 Subject: [PATCH 08/10] test(builtins): update rege test --- src/__tests__/if-run/builtins/regex.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__tests__/if-run/builtins/regex.test.ts b/src/__tests__/if-run/builtins/regex.test.ts index 795bbd36d..ea45c49d1 100644 --- a/src/__tests__/if-run/builtins/regex.test.ts +++ b/src/__tests__/if-run/builtins/regex.test.ts @@ -59,7 +59,7 @@ describe('builtins/regex: ', () => { match: '/(?<=_)[^_]+?(?=_|$)/g', output: 'cloud/instance-type', }; - const regex = Regex(globalConfig); + const regex = Regex(globalConfig, parametersMetadata); const expectedResult = [ { From 2b5a591a43d520f5a58fff1caa8333c0ec7712d3 Mon Sep 17 00:00:00 2001 From: Manushak Keramyan Date: Mon, 22 Jul 2024 13:13:01 +0400 Subject: [PATCH 09/10] Update src/if-run/builtins/multiply/README.md Co-authored-by: Narek Hovhannisyan Signed-off-by: Manushak Keramyan --- src/if-run/builtins/multiply/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/if-run/builtins/multiply/README.md b/src/if-run/builtins/multiply/README.md index 08ebe9526..0514ce0fd 100644 --- a/src/if-run/builtins/multiply/README.md +++ b/src/if-run/builtins/multiply/README.md @@ -54,7 +54,7 @@ const config = { outputParameter: 'energy-product', }; -const mult = Multiply(config, parametersMetadata); +const multiply = Multiply(config, parametersMetadata); const result = await mult.execute([ { duration: 3600, From 9ed8e1aad5916d5cf6a37c3a9eefd7e146c600e8 Mon Sep 17 00:00:00 2001 From: Manushak Keramyan Date: Mon, 22 Jul 2024 13:13:18 +0400 Subject: [PATCH 10/10] Update src/if-run/builtins/multiply/README.md Co-authored-by: Narek Hovhannisyan Signed-off-by: Manushak Keramyan --- src/if-run/builtins/multiply/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/if-run/builtins/multiply/README.md b/src/if-run/builtins/multiply/README.md index 0514ce0fd..6acbb847a 100644 --- a/src/if-run/builtins/multiply/README.md +++ b/src/if-run/builtins/multiply/README.md @@ -55,7 +55,7 @@ const config = { }; const multiply = Multiply(config, parametersMetadata); -const result = await mult.execute([ +const result = await multiply.execute([ { duration: 3600, timestamp: '2021-01-01T00:00:00Z',