From 4e1ee62015ecfd63afaf005e48d45a57888498a3 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 16:52:29 +0400 Subject: [PATCH 01/17] feat(util): introduce if-core utils and types --- src/util/aggregation-helper.ts | 4 ++-- src/util/args.ts | 2 +- src/util/helpers.ts | 2 +- src/util/plugin-storage.ts | 2 +- src/util/validations.ts | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/util/aggregation-helper.ts b/src/util/aggregation-helper.ts index 3caff8c6d..408a4e9f7 100644 --- a/src/util/aggregation-helper.ts +++ b/src/util/aggregation-helper.ts @@ -1,11 +1,11 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; +import {PluginParams} from '@grnsft/if-core/types'; import {parameterize} from '../lib/parameterize'; import {CONFIG, STRINGS} from '../config'; import {AggregationResult} from '../types/aggregation'; -import {PluginParams} from '../types/interface'; const {InvalidAggregationMethodError, MissingAggregationParamError} = ERRORS; const {INVALID_AGGREGATION_METHOD, METRIC_MISSING} = STRINGS; diff --git a/src/util/args.ts b/src/util/args.ts index ee090c1ef..c54117c75 100644 --- a/src/util/args.ts +++ b/src/util/args.ts @@ -1,7 +1,7 @@ import * as path from 'path'; import {parse} from 'ts-command-line-args'; -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {checkIfFileIsYaml} from './yaml'; import {logger} from './logger'; diff --git a/src/util/helpers.ts b/src/util/helpers.ts index 45af8b50c..fcab2e27a 100644 --- a/src/util/helpers.ts +++ b/src/util/helpers.ts @@ -2,7 +2,7 @@ import {createInterface} from 'node:readline/promises'; import {exec} from 'node:child_process'; import {promisify} from 'node:util'; -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {logger} from './logger'; diff --git a/src/util/plugin-storage.ts b/src/util/plugin-storage.ts index da1e45970..1f9711943 100644 --- a/src/util/plugin-storage.ts +++ b/src/util/plugin-storage.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {STRINGS} from '../config'; diff --git a/src/util/validations.ts b/src/util/validations.ts index 30cb1e930..920e7cbdb 100644 --- a/src/util/validations.ts +++ b/src/util/validations.ts @@ -1,11 +1,11 @@ import {ZodIssue, ZodIssueCode, ZodSchema, z} from 'zod'; -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; + +import {STRINGS} from '../config/strings'; import {AGGREGATION_METHODS} from '../types/aggregation'; import {AGGREGATION_TYPES} from '../types/parameters'; -import {STRINGS} from '../config/strings'; - const {ManifestValidationError, InputValidationError} = ERRORS; const {VALIDATING_MANIFEST} = STRINGS; From 8d1244ac8770c0291ee2d15521a7f4ddfa194d87 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 16:53:01 +0400 Subject: [PATCH 02/17] revert(types): drop common and group-by --- src/types/common.ts | 5 ----- src/types/group-by.ts | 3 --- 2 files changed, 8 deletions(-) delete mode 100644 src/types/common.ts delete mode 100644 src/types/group-by.ts diff --git a/src/types/common.ts b/src/types/common.ts deleted file mode 100644 index f7d337392..000000000 --- a/src/types/common.ts +++ /dev/null @@ -1,5 +0,0 @@ -export type KeyValuePair = { - [key: string]: any; -}; - -export type ConfigParams = Record; diff --git a/src/types/group-by.ts b/src/types/group-by.ts deleted file mode 100644 index 72dd6d61b..000000000 --- a/src/types/group-by.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type GroupByConfig = { - group: string[]; -}; From 9ee5885b886731673866c46f3f7b1cffa95e496b Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 16:53:22 +0400 Subject: [PATCH 03/17] feat(types): introduce if-core types --- src/types/compute.ts | 3 ++- src/types/interface.ts | 25 +------------------------ 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/src/types/compute.ts b/src/types/compute.ts index 739d86742..2de3e6e33 100644 --- a/src/types/compute.ts +++ b/src/types/compute.ts @@ -1,4 +1,5 @@ -import {PluginParams} from './interface'; +import {PluginParams} from '@grnsft/if-core/types'; + import {Context} from './manifest'; import {PluginStorageInterface} from './plugin-storage'; diff --git a/src/types/interface.ts b/src/types/interface.ts index f06449bc6..6834a3ebb 100644 --- a/src/types/interface.ts +++ b/src/types/interface.ts @@ -1,27 +1,4 @@ -import {GroupByConfig} from './group-by'; - -export type PluginParams = Record; - -export type ConfigParams = Record; - -export type ExecutePlugin = { - execute: ( - inputs: PluginParams[], - config?: Record - ) => PluginParams[] | Promise; - metadata: { - kind: string; - }; - [key: string]: any; -}; - -export type GroupByPlugin = { - execute: (inputs: PluginParams[], config: GroupByConfig) => {children: any}; - metadata: { - kind: string; - }; - [key: string]: any; -}; +import {ExecutePlugin, GroupByPlugin} from '@grnsft/if-core/types'; export type PluginInterface = ExecutePlugin | GroupByPlugin; From 27c74503d78e79ece685d43c4fff7dcc255e03ba Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 17:43:28 +0400 Subject: [PATCH 04/17] feat(lib): introduce if-core utils and types --- src/lib/aggregate.ts | 7 ++++--- src/lib/compute.ts | 5 +++-- src/lib/exhaust.ts | 2 +- src/lib/initialize.ts | 2 +- src/lib/load.ts | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/lib/aggregate.ts b/src/lib/aggregate.ts index 977f30300..c6eef11cc 100644 --- a/src/lib/aggregate.ts +++ b/src/lib/aggregate.ts @@ -1,10 +1,11 @@ -import {aggregateInputsIntoOne} from '../util/aggregation-helper'; +import {PluginParams} from '@grnsft/if-core/types'; -import {PluginParams} from '../types/interface'; -import {AggregationParams, AggregationParamsSure} from '../types/manifest'; +import {aggregateInputsIntoOne} from '../util/aggregation-helper'; import {STRINGS} from '../config/strings'; +import {AggregationParams, AggregationParamsSure} from '../types/manifest'; + const {AGGREGATING_NODE, AGGREGATING_OUTPUTS} = STRINGS; /** diff --git a/src/lib/compute.ts b/src/lib/compute.ts index 40db1a42a..b83a22d2e 100644 --- a/src/lib/compute.ts +++ b/src/lib/compute.ts @@ -1,9 +1,10 @@ +import {PluginParams, GroupByConfig} from '@grnsft/if-core/types'; + import {debugLogger} from '../util/debug-logger'; import {mergeObjects} from '../util/helpers'; import {ComputeParams, Node, Params} from '../types/compute'; -import {PluginParams, isExecute, isGroupBy} from '../types/interface'; -import {GroupByConfig} from '../types/group-by'; +import {isExecute, isGroupBy} from '../types/interface'; import {STRINGS} from '../config/strings'; diff --git a/src/lib/exhaust.ts b/src/lib/exhaust.ts index a4982681d..1b65ca898 100644 --- a/src/lib/exhaust.ts +++ b/src/lib/exhaust.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; /** * @todo This is temporary solution, will be refactored to support dynamic plugins. diff --git a/src/lib/initialize.ts b/src/lib/initialize.ts index ac01e8e8e..212d98e37 100644 --- a/src/lib/initialize.ts +++ b/src/lib/initialize.ts @@ -1,6 +1,6 @@ import * as path from 'node:path'; -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {logger} from '../util/logger'; import {memoizedLog} from '../util/log-memoize'; diff --git a/src/lib/load.ts b/src/lib/load.ts index 72620e982..61f2b6cf5 100644 --- a/src/lib/load.ts +++ b/src/lib/load.ts @@ -1,5 +1,5 @@ import * as YAML from 'js-yaml'; -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {openYamlFileAsObject} from '../util/yaml'; import {readAndParseJson} from '../util/json'; From fa18a5ee72ffe73a56f0aa8a16e2b9980e0c0e95 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 17:44:00 +0400 Subject: [PATCH 05/17] revert(uiltins): drop local types support --- src/builtins/coefficient/types.ts | 5 ----- src/builtins/exponent/types.ts | 5 ----- src/builtins/interpolation/types.ts | 5 ----- src/builtins/mock-observations/types.ts | 16 ---------------- src/builtins/multiply/types.ts | 4 ---- src/builtins/subtract/types.ts | 4 ---- src/builtins/sum/types.ts | 4 ---- 7 files changed, 43 deletions(-) delete mode 100644 src/builtins/coefficient/types.ts delete mode 100644 src/builtins/exponent/types.ts delete mode 100644 src/builtins/interpolation/types.ts delete mode 100644 src/builtins/mock-observations/types.ts delete mode 100644 src/builtins/multiply/types.ts delete mode 100644 src/builtins/subtract/types.ts delete mode 100644 src/builtins/sum/types.ts diff --git a/src/builtins/coefficient/types.ts b/src/builtins/coefficient/types.ts deleted file mode 100644 index 9cbb78b7d..000000000 --- a/src/builtins/coefficient/types.ts +++ /dev/null @@ -1,5 +0,0 @@ -export type CoefficientConfig = { - 'input-parameter': string; - coefficient: number; - 'output-parameter': string; -}; diff --git a/src/builtins/exponent/types.ts b/src/builtins/exponent/types.ts deleted file mode 100644 index 54e8b2efc..000000000 --- a/src/builtins/exponent/types.ts +++ /dev/null @@ -1,5 +0,0 @@ -export type ExponentConfig = { - 'input-parameter': string; - exponent: number; - 'output-parameter': string; -}; diff --git a/src/builtins/interpolation/types.ts b/src/builtins/interpolation/types.ts deleted file mode 100644 index 09b7abb5e..000000000 --- a/src/builtins/interpolation/types.ts +++ /dev/null @@ -1,5 +0,0 @@ -export enum Method { - LINEAR = 'linear', - SPLINE = 'spline', - POLYNOMIAL = 'polynomial', -} diff --git a/src/builtins/mock-observations/types.ts b/src/builtins/mock-observations/types.ts deleted file mode 100644 index 82591207c..000000000 --- a/src/builtins/mock-observations/types.ts +++ /dev/null @@ -1,16 +0,0 @@ -import {DateTime} from 'luxon'; - -import {Generator} from './interfaces/index'; - -export type ObservationParams = { - duration: number; - timeBucket: DateTime; - component: Record; - generators: Generator[]; -}; - -export type RandIntGeneratorParams = { - name: string; - min: number; - max: number; -}; diff --git a/src/builtins/multiply/types.ts b/src/builtins/multiply/types.ts deleted file mode 100644 index 88f4cae49..000000000 --- a/src/builtins/multiply/types.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type MultiplyConfig = { - 'input-parameters': string[]; - 'output-parameter': string; -}; diff --git a/src/builtins/subtract/types.ts b/src/builtins/subtract/types.ts deleted file mode 100644 index 4dc6775d2..000000000 --- a/src/builtins/subtract/types.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type SubtractConfig = { - 'input-parameters': string[]; - 'output-parameter': string; -}; diff --git a/src/builtins/sum/types.ts b/src/builtins/sum/types.ts deleted file mode 100644 index e30c990e5..000000000 --- a/src/builtins/sum/types.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type SumConfig = { - 'input-parameters': string[]; - 'output-parameter': string; -}; From 89a19ee055e4775ba07a31e542fb733a7e3d94cb Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 17:44:15 +0400 Subject: [PATCH 06/17] feat(builtins): introduce if-core utils and types --- src/builtins/coefficient/index.ts | 11 ++++++----- src/builtins/csv-lookup/index.ts | 5 ++--- src/builtins/divide/index.ts | 5 ++--- src/builtins/exponent/index.ts | 10 ++++++---- src/builtins/export-csv-raw.ts | 6 ++---- src/builtins/export-csv.ts | 6 +++--- src/builtins/export-log.ts | 1 + src/builtins/export-yaml.ts | 3 ++- src/builtins/group-by.ts | 10 ++++++---- src/builtins/interpolation/index.ts | 12 +++++++----- .../helpers/common-generator.ts | 5 +++-- .../helpers/rand-int-generator.ts | 10 ++++------ src/builtins/mock-observations/index.ts | 16 +++++++++------- src/builtins/multiply/index.ts | 10 ++++++---- src/builtins/regex/index.ts | 6 ++---- src/builtins/sci-embodied/index.ts | 3 +-- src/builtins/sci/index.ts | 6 ++---- src/builtins/shell/index.ts | 7 +++---- src/builtins/subtract/index.ts | 10 ++++++---- src/builtins/sum/index.ts | 6 ++---- src/builtins/time-sync.ts | 17 +++++++++-------- 21 files changed, 84 insertions(+), 81 deletions(-) diff --git a/src/builtins/coefficient/index.ts b/src/builtins/coefficient/index.ts index 65404172f..aed444ad3 100644 --- a/src/builtins/coefficient/index.ts +++ b/src/builtins/coefficient/index.ts @@ -1,14 +1,15 @@ import {z} from 'zod'; - -import {ExecutePlugin, PluginParams} from '../../types/interface'; +import {ERRORS} from '@grnsft/if-core/utils'; +import { + CoefficientConfig, + ExecutePlugin, + PluginParams, +} from '@grnsft/if-core/types'; import {validate} from '../../util/validations'; -import {ERRORS} from '@grnsft/if-core'; import {STRINGS} from '../../config'; -import {CoefficientConfig} from './types'; - const {GlobalConfigError} = ERRORS; const {MISSING_GLOBAL_CONFIG} = STRINGS; diff --git a/src/builtins/csv-lookup/index.ts b/src/builtins/csv-lookup/index.ts index 47232e115..8243a6391 100644 --- a/src/builtins/csv-lookup/index.ts +++ b/src/builtins/csv-lookup/index.ts @@ -4,14 +4,13 @@ import {readFile} from 'fs/promises'; import axios from 'axios'; import {z} from 'zod'; import {parse} from 'csv-parse/sync'; +import {ERRORS} from '@grnsft/if-core/utils'; +import {ExecutePlugin, PluginParams} from '@grnsft/if-core/types'; import {validate} from '../../util/validations'; -import {ERRORS} from '@grnsft/if-core'; import {STRINGS} from '../../config'; -import {ExecutePlugin, PluginParams} from '../../types/interface'; - const { FILE_FETCH_FAILED, FILE_READ_FAILED, diff --git a/src/builtins/divide/index.ts b/src/builtins/divide/index.ts index 14e8b4d44..a38e3601b 100644 --- a/src/builtins/divide/index.ts +++ b/src/builtins/divide/index.ts @@ -1,12 +1,11 @@ import {z} from 'zod'; +import {ERRORS} from '@grnsft/if-core/utils'; +import {ExecutePlugin, PluginParams, ConfigParams} from '@grnsft/if-core/types'; -import {ERRORS} from '@grnsft/if-core'; import {validate} from '../../util/validations'; import {STRINGS} from '../../config'; -import {ExecutePlugin, PluginParams, ConfigParams} from '../../types/interface'; - const {GlobalConfigError, MissingInputDataError} = ERRORS; const {MISSING_GLOBAL_CONFIG, MISSING_INPUT_DATA} = STRINGS; diff --git a/src/builtins/exponent/index.ts b/src/builtins/exponent/index.ts index 3a417329b..90d66cd72 100644 --- a/src/builtins/exponent/index.ts +++ b/src/builtins/exponent/index.ts @@ -1,13 +1,15 @@ import {z} from 'zod'; +import {ERRORS} from '@grnsft/if-core/utils'; +import { + ExecutePlugin, + PluginParams, + ExponentConfig, +} from '@grnsft/if-core/types'; -import {ERRORS} from '@grnsft/if-core'; import {validate} from '../../util/validations'; import {STRINGS} from '../../config'; -import {ExecutePlugin, PluginParams} from '../../types/interface'; -import {ExponentConfig} from './types'; - const {MissingInputDataError, InputValidationError} = ERRORS; const {MISSING_INPUT_DATA, NOT_NUMERIC_VALUE} = STRINGS; diff --git a/src/builtins/export-csv-raw.ts b/src/builtins/export-csv-raw.ts index 9ce1edae3..7afc21cb2 100644 --- a/src/builtins/export-csv-raw.ts +++ b/src/builtins/export-csv-raw.ts @@ -1,16 +1,14 @@ import * as fs from 'fs/promises'; - -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {STRINGS} from '../config'; -import {ExhaustPluginInterface} from '../types/exhaust-plugin-interface'; import {Context} from '../types/manifest'; const {ExhaustOutputArgError, WriteFileError} = ERRORS; const {OUTPUT_REQUIRED, WRITE_CSV_ERROR, EXPORTING_RAW_CSV_FILE} = STRINGS; -export const ExportCSVRaw = (): ExhaustPluginInterface => { +export const ExportCSVRaw = () => { /** * handle a tree leaf, where there are no child nodes, by adding it as key->value pair to the flat map * and capturing key as a header diff --git a/src/builtins/export-csv.ts b/src/builtins/export-csv.ts index 9eb03d9cc..53a105733 100644 --- a/src/builtins/export-csv.ts +++ b/src/builtins/export-csv.ts @@ -1,12 +1,12 @@ import {writeFile} from 'fs/promises'; -import {stringify} from 'csv-stringify/sync'; -import {ERRORS} from '@grnsft/if-core'; +import {stringify} from 'csv-stringify/sync'; +import {ERRORS} from '@grnsft/if-core/utils'; +import {PluginParams} from '@grnsft/if-core/types'; import {STRINGS} from '../config'; import {Context} from '../types/manifest'; -import {PluginParams} from '../types/interface'; const {ExhaustOutputArgError} = ERRORS; const {CSV_EXPORT, OUTPUT_REQUIRED, EXPORTING_TO_CSV_FILE} = STRINGS; diff --git a/src/builtins/export-log.ts b/src/builtins/export-log.ts index 3120f3386..fee267dc2 100644 --- a/src/builtins/export-log.ts +++ b/src/builtins/export-log.ts @@ -1,4 +1,5 @@ import * as YAML from 'js-yaml'; + import {Context} from '../types/manifest'; export const ExportLog = () => { diff --git a/src/builtins/export-yaml.ts b/src/builtins/export-yaml.ts index f6a3d71d7..624e1298f 100644 --- a/src/builtins/export-yaml.ts +++ b/src/builtins/export-yaml.ts @@ -1,5 +1,6 @@ +import {ERRORS} from '@grnsft/if-core/utils'; + import {saveYamlFileAs} from '../util/yaml'; -import {ERRORS} from '@grnsft/if-core'; import {STRINGS} from '../config'; diff --git a/src/builtins/group-by.ts b/src/builtins/group-by.ts index 3d38d444a..63c4cd5c5 100644 --- a/src/builtins/group-by.ts +++ b/src/builtins/group-by.ts @@ -1,11 +1,13 @@ import {z} from 'zod'; +import {ERRORS} from '@grnsft/if-core/utils'; +import { + GroupByPlugin, + PluginParams, + GroupByConfig, +} from '@grnsft/if-core/types'; import {STRINGS} from '../config'; -import {GroupByPlugin, PluginParams} from '../types/interface'; -import {GroupByConfig} from '../types/group-by'; - -import {ERRORS} from '@grnsft/if-core'; import {validate} from '../util/validations'; const {InvalidGroupingError, GlobalConfigError} = ERRORS; diff --git a/src/builtins/interpolation/index.ts b/src/builtins/interpolation/index.ts index dfe507c42..98a84ad8a 100644 --- a/src/builtins/interpolation/index.ts +++ b/src/builtins/interpolation/index.ts @@ -1,15 +1,17 @@ import Spline from 'typescript-cubic-spline'; import {z} from 'zod'; - -import {ExecutePlugin, PluginParams, ConfigParams} from '../../types/interface'; +import {ERRORS} from '@grnsft/if-core/utils'; +import { + ExecutePlugin, + PluginParams, + ConfigParams, + Method, +} from '@grnsft/if-core/types'; import {validate} from '../../util/validations'; -import {ERRORS} from '@grnsft/if-core'; import {STRINGS} from '../../config'; -import {Method} from './types'; - const {GlobalConfigError} = ERRORS; const { MISSING_GLOBAL_CONFIG, diff --git a/src/builtins/mock-observations/helpers/common-generator.ts b/src/builtins/mock-observations/helpers/common-generator.ts index 732e7320e..8283cf1bd 100644 --- a/src/builtins/mock-observations/helpers/common-generator.ts +++ b/src/builtins/mock-observations/helpers/common-generator.ts @@ -1,4 +1,5 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; +import {ConfigParams} from '@grnsft/if-core/types'; import {STRINGS} from '../../../config'; @@ -7,7 +8,7 @@ import {Generator} from '../interfaces'; const {GlobalConfigError} = ERRORS; const {MISSING_GLOBAL_CONFIG} = STRINGS; -export const CommonGenerator = (config: Record): Generator => { +export const CommonGenerator = (config: ConfigParams): Generator => { /** * Generates next value by copying the validated config. * Validates the provided config is not null or empty. diff --git a/src/builtins/mock-observations/helpers/rand-int-generator.ts b/src/builtins/mock-observations/helpers/rand-int-generator.ts index 6c0365d35..1cb4d161f 100644 --- a/src/builtins/mock-observations/helpers/rand-int-generator.ts +++ b/src/builtins/mock-observations/helpers/rand-int-generator.ts @@ -1,9 +1,9 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; +import {RandIntGeneratorParams, ConfigParams} from '@grnsft/if-core/types'; import {STRINGS} from '../../../config'; import {Generator} from '../interfaces'; -import {RandIntGeneratorParams} from '../types'; const {GlobalConfigError} = ERRORS; @@ -12,7 +12,7 @@ const {MISSING_GLOBAL_CONFIG, MISSING_MIN_MAX, INVALID_MIN_MAX, INVALID_NAME} = export const RandIntGenerator = ( name: string, - config: Record + config: ConfigParams ): Generator => { const next = () => ({ [validatedName]: generateRandInt(getFieldToPopulate()), @@ -26,9 +26,7 @@ export const RandIntGenerator = ( return name; }; - const validateConfig = ( - config: Record - ): {min: number; max: number} => { + const validateConfig = (config: ConfigParams): {min: number; max: number} => { if (!config || Object.keys(config).length === 0) { throw new GlobalConfigError(MISSING_GLOBAL_CONFIG); } diff --git a/src/builtins/mock-observations/index.ts b/src/builtins/mock-observations/index.ts index b535da757..c7488de0f 100644 --- a/src/builtins/mock-observations/index.ts +++ b/src/builtins/mock-observations/index.ts @@ -1,15 +1,18 @@ import {DateTime, Duration} from 'luxon'; import {z} from 'zod'; +import { + ExecutePlugin, + PluginParams, + ConfigParams, + ObservationParams, +} from '@grnsft/if-core/types'; import {validate} from '../../util/validations'; import {CommonGenerator} from './helpers/common-generator'; import {RandIntGenerator} from './helpers/rand-int-generator'; -import {ExecutePlugin, PluginParams} from '../../types/interface'; -import {ConfigParams, KeyValuePair} from '../../types/common'; import {Generator} from './interfaces/index'; -import {ObservationParams} from './types'; export const MockObservations = (globalConfig: ConfigParams): ExecutePlugin => { const metadata = { @@ -122,11 +125,10 @@ export const MockObservations = (globalConfig: ConfigParams): ExecutePlugin => { CommonGenerator(config), ]; - const createRandIntGenerators = (config: any): Generator[] => { - return Object.entries(config).map(([fieldToPopulate, value]) => - RandIntGenerator(fieldToPopulate, value as KeyValuePair) + const createRandIntGenerators = (config: any): Generator[] => + Object.entries(config).map(([fieldToPopulate, value]) => + RandIntGenerator(fieldToPopulate, value as Record) ); - }; return Object.entries(generatorsConfig).flatMap(([key, value]) => key === 'randint' diff --git a/src/builtins/multiply/index.ts b/src/builtins/multiply/index.ts index 5ceb44c3c..717c68507 100644 --- a/src/builtins/multiply/index.ts +++ b/src/builtins/multiply/index.ts @@ -1,13 +1,15 @@ import {z} from 'zod'; +import {ERRORS} from '@grnsft/if-core/utils'; +import { + ExecutePlugin, + PluginParams, + MultiplyConfig, +} from '@grnsft/if-core/types'; -import {ERRORS} from '@grnsft/if-core'; import {validate} from '../../util/validations'; import {STRINGS} from '../../config'; -import {ExecutePlugin, PluginParams} from '../../types/interface'; -import {MultiplyConfig} from './types'; - const {MissingInputDataError} = ERRORS; const {MISSING_INPUT_DATA} = STRINGS; diff --git a/src/builtins/regex/index.ts b/src/builtins/regex/index.ts index cdcbd13b8..8d382ec74 100644 --- a/src/builtins/regex/index.ts +++ b/src/builtins/regex/index.ts @@ -1,13 +1,11 @@ import {z} from 'zod'; +import {ERRORS} from '@grnsft/if-core/utils'; +import {ExecutePlugin, PluginParams, ConfigParams} from '@grnsft/if-core/types'; -import {ERRORS} from '@grnsft/if-core'; import {validate} from '../../util/validations'; import {STRINGS} from '../../config'; -import {ExecutePlugin, PluginParams} from '../../types/interface'; -import {ConfigParams} from '../../types/common'; - const {MissingInputDataError, GlobalConfigError, RegexMismatchError} = ERRORS; const {MISSING_GLOBAL_CONFIG, MISSING_INPUT_DATA, REGEX_MISMATCH} = STRINGS; diff --git a/src/builtins/sci-embodied/index.ts b/src/builtins/sci-embodied/index.ts index 02f897584..678d41336 100644 --- a/src/builtins/sci-embodied/index.ts +++ b/src/builtins/sci-embodied/index.ts @@ -1,11 +1,10 @@ import {z} from 'zod'; +import {ExecutePlugin, PluginParams} from '@grnsft/if-core/types'; import {validate, allDefined} from '../../util/validations'; import {STRINGS} from '../../config'; -import {ExecutePlugin, PluginParams} from '../../types/interface'; - const {SCI_EMBODIED_ERROR} = STRINGS; export const SciEmbodied = (): ExecutePlugin => { diff --git a/src/builtins/sci/index.ts b/src/builtins/sci/index.ts index c7802213d..223493f3a 100644 --- a/src/builtins/sci/index.ts +++ b/src/builtins/sci/index.ts @@ -1,13 +1,11 @@ import {z} from 'zod'; +import {ERRORS} from '@grnsft/if-core/utils'; +import {ExecutePlugin, PluginParams, ConfigParams} from '@grnsft/if-core/types'; import {validate, allDefined} from '../../util/validations'; -import {ERRORS} from '@grnsft/if-core'; import {STRINGS} from '../../config'; -import {ExecutePlugin, PluginParams} from '../../types/interface'; -import {ConfigParams} from '../../types/common'; - const {MissingInputDataError} = ERRORS; const {MISSING_FUNCTIONAL_UNIT_CONFIG, MISSING_FUNCTIONAL_UNIT_INPUT} = STRINGS; diff --git a/src/builtins/shell/index.ts b/src/builtins/shell/index.ts index 0b894d64b..352ee6bcd 100644 --- a/src/builtins/shell/index.ts +++ b/src/builtins/shell/index.ts @@ -1,12 +1,11 @@ import {spawnSync, SpawnSyncReturns} from 'child_process'; + import {loadAll, dump} from 'js-yaml'; import {z} from 'zod'; - -import {ExecutePlugin, PluginParams} from '../../types/interface'; -import {ConfigParams} from '../../types/common'; +import {ERRORS} from '@grnsft/if-core/utils'; +import {ExecutePlugin, PluginParams, ConfigParams} from '@grnsft/if-core/types'; import {validate} from '../../util/validations'; -import {ERRORS} from '@grnsft/if-core'; const {ProcessExecutionError} = ERRORS; diff --git a/src/builtins/subtract/index.ts b/src/builtins/subtract/index.ts index 87523082e..20a61b5b6 100644 --- a/src/builtins/subtract/index.ts +++ b/src/builtins/subtract/index.ts @@ -1,13 +1,15 @@ import {z} from 'zod'; +import {ERRORS} from '@grnsft/if-core/utils'; +import { + ExecutePlugin, + PluginParams, + SubtractConfig, +} from '@grnsft/if-core/types'; -import {ERRORS} from '@grnsft/if-core'; import {validate} from '../../util/validations'; import {STRINGS} from '../../config'; -import {ExecutePlugin, PluginParams} from '../../types/interface'; -import {SubtractConfig} from './types'; - const {InputValidationError} = ERRORS; const {MISSING_INPUT_DATA, NOT_NUMERIC_VALUE} = STRINGS; diff --git a/src/builtins/sum/index.ts b/src/builtins/sum/index.ts index 676829162..ecce47cf3 100644 --- a/src/builtins/sum/index.ts +++ b/src/builtins/sum/index.ts @@ -1,13 +1,11 @@ import {z} from 'zod'; +import {ERRORS} from '@grnsft/if-core/utils'; +import {ExecutePlugin, PluginParams, SumConfig} from '@grnsft/if-core/types'; import {validate} from '../../util/validations'; -import {ERRORS} from '@grnsft/if-core'; import {STRINGS} from '../../config'; -import {ExecutePlugin, PluginParams} from '../../types/interface'; -import {SumConfig} from './types'; - const {GlobalConfigError, MissingInputDataError} = ERRORS; const {MISSING_INPUT_DATA, MISSING_GLOBAL_CONFIG} = STRINGS; diff --git a/src/builtins/time-sync.ts b/src/builtins/time-sync.ts index 1542b7854..8b37241b8 100644 --- a/src/builtins/time-sync.ts +++ b/src/builtins/time-sync.ts @@ -1,21 +1,22 @@ import {isDate} from 'node:util/types'; + import {Settings, DateTime, DateTimeMaybeValid, Interval} from 'luxon'; import {z} from 'zod'; +import {ERRORS} from '@grnsft/if-core/utils'; +import { + ExecutePlugin, + PluginParams, + PaddingReceipt, + TimeNormalizerConfig, + TimeParams, +} from '@grnsft/if-core/types'; import {parameterize} from '../lib/parameterize'; -import {ERRORS} from '@grnsft/if-core'; import {validate} from '../util/validations'; import {STRINGS} from '../config'; -import {ExecutePlugin, PluginParams} from '../types/interface'; -import { - PaddingReceipt, - TimeNormalizerConfig, - TimeParams, -} from '../types/time-sync'; - Settings.defaultZone = 'utc'; const { From 710b2a32e333cc5e9e8cb0001158ee684c775b0c Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 17:45:25 +0400 Subject: [PATCH 07/17] test(util): introduce if-core util and types --- src/__tests__/unit/util/aggregation-helper.test.ts | 5 ++--- src/__tests__/unit/util/args.test.ts | 2 +- src/__tests__/unit/util/helpers.test.ts | 2 +- src/__tests__/unit/util/plugin-storage.test.ts | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/__tests__/unit/util/aggregation-helper.test.ts b/src/__tests__/unit/util/aggregation-helper.test.ts index eb379e10f..1a23bc3c1 100644 --- a/src/__tests__/unit/util/aggregation-helper.test.ts +++ b/src/__tests__/unit/util/aggregation-helper.test.ts @@ -1,11 +1,10 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; +import {PluginParams} from '@grnsft/if-core/types'; import {aggregateInputsIntoOne} from '../../../util/aggregation-helper'; import {STRINGS} from '../../../config'; -import {PluginParams} from '../../../types/interface'; - const {InvalidAggregationMethodError, MissingAggregationParamError} = ERRORS; const {INVALID_AGGREGATION_METHOD, METRIC_MISSING} = STRINGS; diff --git a/src/__tests__/unit/util/args.test.ts b/src/__tests__/unit/util/args.test.ts index 52e468987..045bf2807 100644 --- a/src/__tests__/unit/util/args.test.ts +++ b/src/__tests__/unit/util/args.test.ts @@ -70,7 +70,7 @@ jest.mock('ts-command-line-args', () => ({ })); import * as path from 'node:path'; -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {parseIEProcessArgs, parseIfDiffArgs} from '../../../util/args'; diff --git a/src/__tests__/unit/util/helpers.test.ts b/src/__tests__/unit/util/helpers.test.ts index 4aaccc5f5..86ea702a4 100644 --- a/src/__tests__/unit/util/helpers.test.ts +++ b/src/__tests__/unit/util/helpers.test.ts @@ -10,7 +10,7 @@ jest.mock('../../../util/logger', () => ({ error: mockError, }, })); -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import { andHandle, checkIfEqual, diff --git a/src/__tests__/unit/util/plugin-storage.test.ts b/src/__tests__/unit/util/plugin-storage.test.ts index 0555b1db5..8b76f36cd 100644 --- a/src/__tests__/unit/util/plugin-storage.test.ts +++ b/src/__tests__/unit/util/plugin-storage.test.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {pluginStorage} from '../../../util/plugin-storage'; From 21c8d0bf00ba33a66884c7642b36a827c45f0302 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 17:45:55 +0400 Subject: [PATCH 08/17] test(lib): drop unused manifests --- src/__tests__/unit/lib/manifest/basic.ts | 48 ------- src/__tests__/unit/lib/manifest/nested.ts | 146 ---------------------- 2 files changed, 194 deletions(-) delete mode 100644 src/__tests__/unit/lib/manifest/basic.ts delete mode 100644 src/__tests__/unit/lib/manifest/nested.ts diff --git a/src/__tests__/unit/lib/manifest/basic.ts b/src/__tests__/unit/lib/manifest/basic.ts deleted file mode 100644 index e5da7c642..000000000 --- a/src/__tests__/unit/lib/manifest/basic.ts +++ /dev/null @@ -1,48 +0,0 @@ -import {Manifest} from '../../../../types/manifest'; - -export const manifest: Manifest = { - name: 'gsf-demo', - description: 'Hello', - tags: { - kind: 'web', - complexity: 'moderate', - category: 'cloud', - }, - initialize: { - plugins: { - 'mock-name': { - model: 'MockaviztaModel', - path: 'mock-path', - 'global-config': { - allocation: 'LINEAR', - verbose: true, - }, - }, - }, - }, - tree: { - children: { - 'front-end': { - pipeline: ['mock-name'], - config: { - 'mock-name': { - 'core-units': 24, - processor: 'Intel® Core™ i7-1185G7', - }, - }, - inputs: [ - { - timestamp: '2023-07-06T00:00', - duration: 3600, - 'cpu/utilization': 18.392, - }, - { - timestamp: '2023-08-06T00:00', - duration: 3600, - 'cpu/utilization': 16, - }, - ], - }, - }, - }, -}; diff --git a/src/__tests__/unit/lib/manifest/nested.ts b/src/__tests__/unit/lib/manifest/nested.ts deleted file mode 100644 index 0c27fad12..000000000 --- a/src/__tests__/unit/lib/manifest/nested.ts +++ /dev/null @@ -1,146 +0,0 @@ -import {Manifest} from '../../../../types/manifest'; - -export const manifestNested: Manifest = { - name: 'nesting-demo', - description: null, - tags: { - kind: 'web', - complexity: 'moderate', - category: 'on-premise', - }, - initialize: { - plugins: { - mockavizta: { - model: 'MockaviztaModel', - path: 'mock-path', - 'global-config': { - allocation: 'LINEAR', - verbose: true, - }, - }, - }, - }, - tree: { - children: { - 'child-0': { - config: { - mockavizta: { - allocation: 'LINEAR', - verbose: true, - }, - }, - pipeline: ['mockavizta'], - children: { - 'child-0-1': { - children: { - 'child-0-1-1': { - pipeline: ['mockavizta'], - inputs: [ - { - timestamp: '2023-07-06T00:00', - duration: 10, - 'cpu/utilization': 50, - 'energy-network': 0.000811, - carbon: 10, - }, - ], - }, - 'child-0-1-2': { - children: { - 'child-1-2-1': { - pipeline: ['mockavizta'], - config: { - mockavizta: { - allocation: 'mock-allocation', - verbose: false, - }, - }, - inputs: [ - { - timestamp: '2023-07-06T00:00', - duration: 10, - 'cpu/utilization': 50, - 'energy-network': 0.000811, - carbon: 10, - }, - ], - }, - }, - }, - }, - }, - }, - }, - }, - }, -}; - -export const manifestNestedNoConfig: Manifest = { - name: 'nesting-demo', - description: null, - tags: { - kind: 'web', - complexity: 'moderate', - category: 'on-premise', - }, - initialize: { - plugins: { - mockavizta: { - model: 'MockaviztaModel', - path: 'mock-path', - 'global-config': { - allocation: 'LINEAR', - verbose: true, - }, - }, - }, - }, - tree: { - children: { - 'child-0': { - config: { - mockavizta: { - allocation: 'LINEAR', - verbose: true, - }, - }, - pipeline: ['mockavizta'], - children: { - 'child-0-1': { - children: { - 'child-0-1-1': { - pipeline: ['mockavizta'], - inputs: [ - { - timestamp: '2023-07-06T00:00', - duration: 10, - 'cpu/utilization': 50, - 'energy-network': 0.000811, - carbon: 10, - }, - ], - }, - 'child-0-1-2': { - children: { - 'child-1-2-1': { - pipeline: ['mockavizta'], - config: {}, - inputs: [ - { - timestamp: '2023-07-06T00:00', - duration: 10, - 'cpu/utilization': 50, - 'energy-network': 0.000811, - carbon: 10, - }, - ], - }, - }, - }, - }, - }, - }, - }, - }, - }, -}; From 6709d12de37aa0582d2d2f722ca0e02412346ca5 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 17:46:10 +0400 Subject: [PATCH 09/17] test(lib): introduce if-core utils and types --- src/__tests__/unit/lib/exhaust.test.ts | 2 +- src/__tests__/unit/lib/initialize.test.ts | 2 +- src/__tests__/unit/lib/load.test.ts | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/__tests__/unit/lib/exhaust.test.ts b/src/__tests__/unit/lib/exhaust.test.ts index 1fa652bb3..49db14370 100644 --- a/src/__tests__/unit/lib/exhaust.test.ts +++ b/src/__tests__/unit/lib/exhaust.test.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ jest.mock('fs', () => require('../../../__mocks__/fs')); -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {exhaust} from '../../../lib/exhaust'; diff --git a/src/__tests__/unit/lib/initialize.test.ts b/src/__tests__/unit/lib/initialize.test.ts index 51d15f0d7..ff3c10c45 100644 --- a/src/__tests__/unit/lib/initialize.test.ts +++ b/src/__tests__/unit/lib/initialize.test.ts @@ -10,7 +10,7 @@ jest.mock('../../../util/log-memoize', () => ({ memoizedLog: mockLog, })); -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {initialize} from '../../../lib/initialize'; diff --git a/src/__tests__/unit/lib/load.test.ts b/src/__tests__/unit/lib/load.test.ts index 95ae6b26b..ba3bca902 100644 --- a/src/__tests__/unit/lib/load.test.ts +++ b/src/__tests__/unit/lib/load.test.ts @@ -38,14 +38,14 @@ jest.mock('../../../util/yaml', () => ({ }, })); -import {load, loadIfDiffFiles} from '../../../lib/load'; +import {PluginParams} from '@grnsft/if-core/types'; -import {PARAMETERS} from '../../../config'; +import {load, loadIfDiffFiles} from '../../../lib/load'; -import {PluginParams} from '../../../types/interface'; +import {PARAMETERS, STRINGS} from '../../../config'; -import {STRINGS} from '../../../config'; import {parseManifestFromStdin} from '../../../util/helpers'; + import {LoadDiffParams} from '../../../types/util/args'; const {INVALID_SOURCE} = STRINGS; From ec2d8c0b57f3650742d2bbf94d01d7280d8cebdf Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 17:46:23 +0400 Subject: [PATCH 10/17] test(builtins): introduce if-core utils and types --- src/__tests__/unit/builtins/CommonGenerator.test.ts | 2 +- src/__tests__/unit/builtins/RandIntGenerator.test.ts | 6 ++---- src/__tests__/unit/builtins/coefficient.test.ts | 2 +- src/__tests__/unit/builtins/csv-lookup.test.ts | 2 +- src/__tests__/unit/builtins/divide.test.ts | 2 +- src/__tests__/unit/builtins/exponent.test.ts | 2 +- src/__tests__/unit/builtins/export-csv-raw.test.ts | 3 ++- src/__tests__/unit/builtins/export-csv.test.ts | 3 ++- src/__tests__/unit/builtins/export-yaml.test.ts | 2 +- src/__tests__/unit/builtins/group-by.test.ts | 2 +- src/__tests__/unit/builtins/interpolation.test.ts | 4 ++-- src/__tests__/unit/builtins/mock-observations.test.ts | 2 +- src/__tests__/unit/builtins/multiply.test.ts | 2 +- src/__tests__/unit/builtins/regex.test.ts | 2 +- src/__tests__/unit/builtins/sci-embodied.test.ts | 2 +- src/__tests__/unit/builtins/sci.test.ts | 2 +- src/__tests__/unit/builtins/shell.test.ts | 2 +- src/__tests__/unit/builtins/subtract.test.ts | 2 +- src/__tests__/unit/builtins/sum.test.ts | 2 +- src/__tests__/unit/builtins/time-sync.test.ts | 2 +- 20 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/__tests__/unit/builtins/CommonGenerator.test.ts b/src/__tests__/unit/builtins/CommonGenerator.test.ts index 23109c117..b0c165d1a 100644 --- a/src/__tests__/unit/builtins/CommonGenerator.test.ts +++ b/src/__tests__/unit/builtins/CommonGenerator.test.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {CommonGenerator} from '../../../builtins/mock-observations/helpers/common-generator'; diff --git a/src/__tests__/unit/builtins/RandIntGenerator.test.ts b/src/__tests__/unit/builtins/RandIntGenerator.test.ts index ca1b60183..328f7d6f4 100644 --- a/src/__tests__/unit/builtins/RandIntGenerator.test.ts +++ b/src/__tests__/unit/builtins/RandIntGenerator.test.ts @@ -1,11 +1,9 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {RandIntGenerator} from '../../../builtins/mock-observations/helpers/rand-int-generator'; import {STRINGS} from '../../../config'; -import {KeyValuePair} from '../../../types/common'; - const {GlobalConfigError} = ERRORS; const {INVALID_NAME, MISSING_MIN_MAX, MISSING_GLOBAL_CONFIG} = STRINGS; @@ -44,7 +42,7 @@ describe('builtins/mock-observations/RandIntGenerator: ', () => { describe('next(): ', () => { it('returns a result with valid data.', async () => { - const config: KeyValuePair = { + const config: Record = { min: 10, max: 90, }; diff --git a/src/__tests__/unit/builtins/coefficient.test.ts b/src/__tests__/unit/builtins/coefficient.test.ts index e7e92adf5..034d20f95 100644 --- a/src/__tests__/unit/builtins/coefficient.test.ts +++ b/src/__tests__/unit/builtins/coefficient.test.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {Coefficient} from '../../../builtins/coefficient'; diff --git a/src/__tests__/unit/builtins/csv-lookup.test.ts b/src/__tests__/unit/builtins/csv-lookup.test.ts index 9e718d537..81e0498b4 100644 --- a/src/__tests__/unit/builtins/csv-lookup.test.ts +++ b/src/__tests__/unit/builtins/csv-lookup.test.ts @@ -2,7 +2,7 @@ jest.mock('fs/promises', () => require('../../../__mocks__/fs')); import axios from 'axios'; import AxiosMockAdapter from 'axios-mock-adapter'; -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {CSVLookup} from '../../../builtins'; diff --git a/src/__tests__/unit/builtins/divide.test.ts b/src/__tests__/unit/builtins/divide.test.ts index c75c926be..79fc6c0b5 100644 --- a/src/__tests__/unit/builtins/divide.test.ts +++ b/src/__tests__/unit/builtins/divide.test.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {Divide} from '../../../builtins'; diff --git a/src/__tests__/unit/builtins/exponent.test.ts b/src/__tests__/unit/builtins/exponent.test.ts index 04d9f7e9b..c139a5608 100644 --- a/src/__tests__/unit/builtins/exponent.test.ts +++ b/src/__tests__/unit/builtins/exponent.test.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {Exponent} from '../../../builtins/exponent'; diff --git a/src/__tests__/unit/builtins/export-csv-raw.test.ts b/src/__tests__/unit/builtins/export-csv-raw.test.ts index 5ff8d20cd..ab71e0e34 100644 --- a/src/__tests__/unit/builtins/export-csv-raw.test.ts +++ b/src/__tests__/unit/builtins/export-csv-raw.test.ts @@ -1,6 +1,7 @@ import * as fs from 'fs/promises'; + import {jest} from '@jest/globals'; -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {ExportCSVRaw} from '../../../builtins/export-csv-raw'; diff --git a/src/__tests__/unit/builtins/export-csv.test.ts b/src/__tests__/unit/builtins/export-csv.test.ts index 942732e2e..78feaf534 100644 --- a/src/__tests__/unit/builtins/export-csv.test.ts +++ b/src/__tests__/unit/builtins/export-csv.test.ts @@ -1,7 +1,8 @@ import * as fs from 'fs/promises'; + import {stringify} from 'csv-stringify/sync'; import {jest} from '@jest/globals'; -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {ExportCSV} from '../../../builtins/export-csv'; diff --git a/src/__tests__/unit/builtins/export-yaml.test.ts b/src/__tests__/unit/builtins/export-yaml.test.ts index 56b155cba..fb7954c1e 100644 --- a/src/__tests__/unit/builtins/export-yaml.test.ts +++ b/src/__tests__/unit/builtins/export-yaml.test.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {ExportYaml} from '../../../builtins/export-yaml'; import {saveYamlFileAs} from '../../../util/yaml'; diff --git a/src/__tests__/unit/builtins/group-by.test.ts b/src/__tests__/unit/builtins/group-by.test.ts index 22ef77f56..3d676148b 100644 --- a/src/__tests__/unit/builtins/group-by.test.ts +++ b/src/__tests__/unit/builtins/group-by.test.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {GroupBy} from '../../../builtins/group-by'; diff --git a/src/__tests__/unit/builtins/interpolation.test.ts b/src/__tests__/unit/builtins/interpolation.test.ts index ead5880bb..6219e01ec 100644 --- a/src/__tests__/unit/builtins/interpolation.test.ts +++ b/src/__tests__/unit/builtins/interpolation.test.ts @@ -1,8 +1,8 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; +import {Method} from '@grnsft/if-core/types'; import {Interpolation} from '../../../builtins'; -import {Method} from '../../../builtins/interpolation/types'; import {STRINGS} from '../../../config'; const {InputValidationError, GlobalConfigError} = ERRORS; diff --git a/src/__tests__/unit/builtins/mock-observations.test.ts b/src/__tests__/unit/builtins/mock-observations.test.ts index 7a46cf79f..fd28d5595 100644 --- a/src/__tests__/unit/builtins/mock-observations.test.ts +++ b/src/__tests__/unit/builtins/mock-observations.test.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {MockObservations} from '../../../builtins/mock-observations'; diff --git a/src/__tests__/unit/builtins/multiply.test.ts b/src/__tests__/unit/builtins/multiply.test.ts index ff168110e..f191ae169 100644 --- a/src/__tests__/unit/builtins/multiply.test.ts +++ b/src/__tests__/unit/builtins/multiply.test.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {Multiply} from '../../../builtins/multiply'; diff --git a/src/__tests__/unit/builtins/regex.test.ts b/src/__tests__/unit/builtins/regex.test.ts index 57cdc5e0c..54a70ed9e 100644 --- a/src/__tests__/unit/builtins/regex.test.ts +++ b/src/__tests__/unit/builtins/regex.test.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {Regex} from '../../../builtins/regex'; diff --git a/src/__tests__/unit/builtins/sci-embodied.test.ts b/src/__tests__/unit/builtins/sci-embodied.test.ts index 1d8f05438..a3f5bcbff 100644 --- a/src/__tests__/unit/builtins/sci-embodied.test.ts +++ b/src/__tests__/unit/builtins/sci-embodied.test.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {SciEmbodied} from '../../../builtins/sci-embodied'; diff --git a/src/__tests__/unit/builtins/sci.test.ts b/src/__tests__/unit/builtins/sci.test.ts index 751804f17..c12085d4e 100644 --- a/src/__tests__/unit/builtins/sci.test.ts +++ b/src/__tests__/unit/builtins/sci.test.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {Sci} from '../../../builtins/sci'; diff --git a/src/__tests__/unit/builtins/shell.test.ts b/src/__tests__/unit/builtins/shell.test.ts index 95f44fb12..96de944f1 100644 --- a/src/__tests__/unit/builtins/shell.test.ts +++ b/src/__tests__/unit/builtins/shell.test.ts @@ -1,6 +1,6 @@ import {spawnSync} from 'child_process'; import {loadAll} from 'js-yaml'; -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {Shell} from '../../../builtins/shell'; diff --git a/src/__tests__/unit/builtins/subtract.test.ts b/src/__tests__/unit/builtins/subtract.test.ts index a1c1e3302..b84b05db8 100644 --- a/src/__tests__/unit/builtins/subtract.test.ts +++ b/src/__tests__/unit/builtins/subtract.test.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {Subtract} from '../../../builtins/subtract'; diff --git a/src/__tests__/unit/builtins/sum.test.ts b/src/__tests__/unit/builtins/sum.test.ts index 7a09958d1..dbd05a783 100644 --- a/src/__tests__/unit/builtins/sum.test.ts +++ b/src/__tests__/unit/builtins/sum.test.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {Sum} from '../../../builtins/sum'; diff --git a/src/__tests__/unit/builtins/time-sync.test.ts b/src/__tests__/unit/builtins/time-sync.test.ts index 63174743a..6dd984659 100644 --- a/src/__tests__/unit/builtins/time-sync.test.ts +++ b/src/__tests__/unit/builtins/time-sync.test.ts @@ -1,4 +1,4 @@ -import {ERRORS} from '@grnsft/if-core'; +import {ERRORS} from '@grnsft/if-core/utils'; import {Settings, DateTime} from 'luxon'; import {TimeSync} from '../../../builtins/time-sync'; From 5ee388aa73e6dffbb3d12d5a017e74ed1d59d38b Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 17:46:36 +0400 Subject: [PATCH 11/17] test(mocks): introduce if-core types --- src/__mocks__/plugin/lib/mockavizta/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__mocks__/plugin/lib/mockavizta/index.ts b/src/__mocks__/plugin/lib/mockavizta/index.ts index 163a0cd24..54feae6a2 100644 --- a/src/__mocks__/plugin/lib/mockavizta/index.ts +++ b/src/__mocks__/plugin/lib/mockavizta/index.ts @@ -1,4 +1,4 @@ -import {PluginParams} from '../../../../types/interface'; +import {PluginParams} from '@grnsft/if-core/types'; /** * Mock model for testing. From b7a54a1fdbc59381dc17dc8cd07a4df626d281e6 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 17:46:53 +0400 Subject: [PATCH 12/17] fix(src): fix imports order in diff --- src/diff.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/diff.ts b/src/diff.ts index 71a57ed17..aad02482c 100644 --- a/src/diff.ts +++ b/src/diff.ts @@ -7,10 +7,11 @@ import {parseIfDiffArgs} from './util/args'; import {formatNotMatchingLog, parseManifestFromStdin} from './util/helpers'; import {validateManifest} from './util/validations'; -import {CONFIG} from './config'; import {logger} from './util/logger'; import {debugLogger} from './util/debug-logger'; +import {CONFIG} from './config'; + const {IF_DIFF} = CONFIG; const {SUCCESS_MESSAGE, FAILURE_MESSAGE} = IF_DIFF; From df7374ad8683ddf20b6368fa3971f5fa4b919c5b Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 17:47:07 +0400 Subject: [PATCH 13/17] feat(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 2ec34c515..885d05d11 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.3", + "@grnsft/if-core": "^0.0.7", "axios": "^1.7.2", "csv-parse": "^5.5.6", "csv-stringify": "^6.4.6", @@ -1181,9 +1181,9 @@ } }, "node_modules/@grnsft/if-core": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.3.tgz", - "integrity": "sha512-ieuUcadEgA4EztIzCbCW5ifK2a6SUU2ioZtLTce8pJ+imgeQ47lQM3UtChtbaUm52rEwvgl1Psp0ysgOjqssFA==", + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.7.tgz", + "integrity": "sha512-+4w8Sq1KRPDb+Jy638wgrTXlXIZzewOBceT+rAy3Oaov1M/veY3gu3AV15SXcPHrsBoFmZ6QeI9g1rF3RKB0ww==", "dependencies": { "typescript": "^5.1.6" }, diff --git a/package.json b/package.json index 5093d2235..1846ec684 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "dependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", - "@grnsft/if-core": "^0.0.3", + "@grnsft/if-core": "^0.0.7", "axios": "^1.7.2", "csv-parse": "^5.5.6", "csv-stringify": "^6.4.6", From 1d39e6b885d974232d9c884dbfbcd0997cc64947 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 17:47:58 +0400 Subject: [PATCH 14/17] chore(config): drop unused module path from jest --- jest.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index ed24da708..2e770bcad 100644 --- a/jest.config.js +++ b/jest.config.js @@ -12,7 +12,6 @@ module.exports = { }, modulePathIgnorePatterns: [ './build', - './src/__tests__/unit/lib/manifest', './src/__tests__/integration/helpers', './src/__tests__/integration/test-data', ], From 8857737bdf2aee115fe9d4b3c35c16158d92903a Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 19:13:08 +0400 Subject: [PATCH 15/17] revert(config): drop issue template message --- src/config/strings.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/config/strings.ts b/src/config/strings.ts index 83283e8fb..7efa57a76 100644 --- a/src/config/strings.ts +++ b/src/config/strings.ts @@ -17,9 +17,6 @@ Incubation projects are experimental, offer no support guarantee, have minimal g NOT_NATIVE_PLUGIN: (path: string) => ` You are using plugin ${path} which is not part of the Impact Framework standard library. You should do your own research to ensure the plugins are up to date and accurate. They may not be actively maintained.`, - ISSUE_TEMPLATE: ` -Impact Framework is an alpha release from the Green Software Foundation and is released to capture early feedback. If you'd like to offer some feedback, please use this issue template: -https://github.com/Green-Software-Foundation/if/issues/new?assignees=&labels=feedback&projects=&template=feedback.md&title=Feedback+-+`, INVALID_MODULE_PATH: (path: string, error?: any) => `Provided module \`${path}\` is invalid or not found. ${error ?? ''} `, @@ -55,6 +52,8 @@ Note that for the '--output' option you also need to define the output type in y TARGET_IS_NOT_YAML: 'Given target is not in yaml format.', INVALID_TARGET: 'Target is invalid.', INVALID_SOURCE: 'Source is invalid.', + UNSUPPORTED_ERROR: (errorName: string) => + `UnsupportedErrorClass: plugin threw error class: ${errorName} that is not recognized by Impact Framework`, /** Plugin messages */ MISSING_GLOBAL_CONFIG: 'Global config is not provided.', MISSING_INPUT_DATA: (param: string) => From 00f0dafda6bed1ce30180a5549de4e7f25618c29 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 19:13:34 +0400 Subject: [PATCH 16/17] test(util): remove changed case --- src/__tests__/unit/util/helpers.test.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/__tests__/unit/util/helpers.test.ts b/src/__tests__/unit/util/helpers.test.ts index 86ea702a4..d8dfe2096 100644 --- a/src/__tests__/unit/util/helpers.test.ts +++ b/src/__tests__/unit/util/helpers.test.ts @@ -30,15 +30,6 @@ describe('util/helpers: ', () => { mockError.mockReset(); }); - it('logs error and warn in case of error is unknown.', () => { - const message = 'mock-message'; - const MockError = class extends Error {}; - - andHandle(new MockError(message)); - expect(mockWarn).toHaveBeenCalledTimes(1); - expect(mockError).toHaveBeenCalledTimes(1); - }); - it('logs error in case of error is unknown.', () => { const message = 'mock-message'; From 3000cc9981c39a006f97e7f25a4cee2a3f57a3e1 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 14 Jun 2024 19:14:32 +0400 Subject: [PATCH 17/17] feat(util): exit on unknown error --- src/util/helpers.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/util/helpers.ts b/src/util/helpers.ts index fcab2e27a..0c422c96f 100644 --- a/src/util/helpers.ts +++ b/src/util/helpers.ts @@ -10,7 +10,7 @@ import {STRINGS} from '../config'; import {Difference} from '../types/lib/compare'; -const {ISSUE_TEMPLATE} = STRINGS; +const {UNSUPPORTED_ERROR} = STRINGS; /** * Impact engine error handler. Logs errors and appends issue template if error is unknown. @@ -21,7 +21,9 @@ export const andHandle = (error: Error) => { logger.error(error); if (!knownErrors.includes(error.name)) { - logger.warn(ISSUE_TEMPLATE); + logger.error(UNSUPPORTED_ERROR(error.name)); + // eslint-disable-next-line no-process-exit + process.exit(2); } };