From 86f79f1540bd480688579b0f4b646f735d478315 Mon Sep 17 00:00:00 2001 From: manushak Date: Wed, 7 Aug 2024 20:24:32 +0400 Subject: [PATCH] fix(builtins): merge `parameter-metdata` if there is harcoded data --- src/if-run/builtins/sci-embodied/index.ts | 67 ++++++++++++----------- src/if-run/builtins/sci/index.ts | 28 ++++++---- src/if-run/builtins/time-sync.ts | 26 +++++---- 3 files changed, 67 insertions(+), 54 deletions(-) diff --git a/src/if-run/builtins/sci-embodied/index.ts b/src/if-run/builtins/sci-embodied/index.ts index e8b69cd2b..b304d4ae1 100644 --- a/src/if-run/builtins/sci-embodied/index.ts +++ b/src/if-run/builtins/sci-embodied/index.ts @@ -1,6 +1,7 @@ import {z} from 'zod'; import { ExecutePlugin, + ParameterMetadata, PluginParametersMetadata, PluginParams, } from '@grnsft/if-core/types'; @@ -16,37 +17,41 @@ export const SciEmbodied = ( ): ExecutePlugin => { const metadata = { kind: 'execute', - inputs: parametersMetadata?.inputs || { - 'device/emissions-embodied': { - description: 'total embodied emissions of some component', - unit: 'gCO2e', - 'aggregation-method': 'sum', - }, - 'device/expected-lifespan': { - description: 'Total Expected Lifespan of the Component in Seconds', - unit: 'seconds', - 'aggregation-method': 'sum', - }, - 'resources-reserved': { - description: 'resources reserved for an application', - unit: 'count', - 'aggregation-method': 'none', - }, - 'resources-total': { - description: 'total resources available', - unit: 'count', - 'aggregation-method': 'none', - }, - 'vcpus-allocated': { - description: 'number of vcpus allocated to particular resource', - unit: 'count', - 'aggregation-method': 'none', - }, - 'vcpus-total': { - description: 'total number of vcpus available on a particular resource', - unit: 'count', - 'aggregation-method': 'none', - }, + inputs: { + ...({ + 'device/emissions-embodied': { + description: 'total embodied emissions of some component', + unit: 'gCO2e', + 'aggregation-method': 'sum', + }, + 'device/expected-lifespan': { + description: 'Total Expected Lifespan of the Component in Seconds', + unit: 'seconds', + 'aggregation-method': 'sum', + }, + 'resources-reserved': { + description: 'resources reserved for an application', + unit: 'count', + 'aggregation-method': 'none', + }, + 'resources-total': { + description: 'total resources available', + unit: 'count', + 'aggregation-method': 'none', + }, + 'vcpus-allocated': { + description: 'number of vcpus allocated to particular resource', + unit: 'count', + 'aggregation-method': 'none', + }, + 'vcpus-total': { + description: + 'total number of vcpus available on a particular resource', + unit: 'count', + 'aggregation-method': 'none', + }, + } as ParameterMetadata), + ...parametersMetadata?.inputs, }, outputs: parametersMetadata?.outputs || { 'carbon-embodied': { diff --git a/src/if-run/builtins/sci/index.ts b/src/if-run/builtins/sci/index.ts index 70608fe84..1106f3725 100644 --- a/src/if-run/builtins/sci/index.ts +++ b/src/if-run/builtins/sci/index.ts @@ -5,6 +5,7 @@ import { PluginParams, ConfigParams, PluginParametersMetadata, + ParameterMetadata, } from '@grnsft/if-core/types'; import {validate, allDefined} from '../../../common/util/validations'; @@ -25,18 +26,21 @@ export const Sci = ( ): ExecutePlugin => { const metadata = { kind: 'execute', - inputs: parametersMetadata?.inputs || { - carbon: { - description: 'an amount of carbon emitted into the atmosphere', - unit: 'gCO2e', - 'aggregation-method': 'sum', - }, - 'functional-unit': { - description: - 'the name of the functional unit in which the final SCI value should be expressed, e.g. requests, users', - unit: 'none', - 'aggregation-method': 'sum', - }, + inputs: { + ...({ + carbon: { + description: 'an amount of carbon emitted into the atmosphere', + unit: 'gCO2e', + 'aggregation-method': 'sum', + }, + 'functional-unit': { + description: + 'the name of the functional unit in which the final SCI value should be expressed, e.g. requests, users', + unit: 'none', + 'aggregation-method': 'sum', + }, + } as ParameterMetadata), + ...parametersMetadata?.inputs, }, outputs: parametersMetadata?.outputs || { sci: { diff --git a/src/if-run/builtins/time-sync.ts b/src/if-run/builtins/time-sync.ts index e9f4ee1bc..6619c2ff0 100644 --- a/src/if-run/builtins/time-sync.ts +++ b/src/if-run/builtins/time-sync.ts @@ -10,6 +10,7 @@ import { TimeNormalizerConfig, TimeParams, PluginParametersMetadata, + ParameterMetadata, } from '@grnsft/if-core/types'; import {validate} from '../../common/util/validations'; @@ -57,17 +58,20 @@ export const TimeSync = ( ): ExecutePlugin => { const metadata = { kind: 'execute', - inputs: parametersMetadata?.inputs || { - timestamp: { - description: 'refers to the time of occurrence of the input', - unit: 'RFC3339', - 'aggregation-method': 'none', - }, - duration: { - description: 'refers to the duration of the input', - unit: 'seconds', - 'aggregation-method': 'sum', - }, + inputs: { + ...({ + timestamp: { + description: 'refers to the time of occurrence of the input', + unit: 'RFC3339', + 'aggregation-method': 'none', + }, + duration: { + description: 'refers to the duration of the input', + unit: 'seconds', + 'aggregation-method': 'sum', + }, + } as ParameterMetadata), + ...parametersMetadata?.inputs, }, outputs: parametersMetadata?.outputs, };