Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter-metadata into plugins #911

Merged
merged 11 commits into from
Jul 22, 2024
Merged
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 8 additions & 4 deletions src/__tests__/if-run/builtins/coefficient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.', () => {
Expand Down Expand Up @@ -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);

Expand All @@ -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.';

Expand All @@ -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.';

Expand Down
12 changes: 8 additions & 4 deletions src/__tests__/if-run/builtins/copy-param.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.', () => {
Expand Down Expand Up @@ -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);

Expand All @@ -74,7 +78,7 @@ describe('builtins/copy: ', () => {
from: 'original',
to: 'copy',
};
const copy = Copy(globalConfig);
const copy = Copy(globalConfig, parametersMetadata);
expect.assertions(1);

try {
Expand All @@ -99,7 +103,7 @@ describe('builtins/copy: ', () => {
from: 'original',
to: 'copy',
};
const copy = Copy(globalConfig);
const copy = Copy(globalConfig, parametersMetadata);

const expectedResult = [
{
Expand Down
16 changes: 10 additions & 6 deletions src/__tests__/if-run/builtins/divide.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.', () => {
Expand Down Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
8 changes: 6 additions & 2 deletions src/__tests__/if-run/builtins/exponent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.', () => {
Expand Down Expand Up @@ -91,7 +95,7 @@ describe('builtins/exponent: ', () => {
exponent: 4,
'output-parameter': 'carbon',
};
const exponent = Exponent(newConfig);
const exponent = Exponent(newConfig, parametersMetadata);

const data = [
{
Expand Down
20 changes: 12 additions & 8 deletions src/__tests__/if-run/builtins/interpolation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ describe('builtins/interpolation: ', () => {
'input-parameter': 'cpu/utilization',
'output-parameter': 'interpolation-result',
};
const parametersMetadata = {
inputs: {},
outputs: {},
};
const inputs = [
{
timestamp: '2023-07-06T00:00',
duration: 3600,
'cpu/utilization': 45,
},
];
const plugin = Interpolation(globalConfig);
const plugin = Interpolation(globalConfig, parametersMetadata);

describe('init Interpolation: ', () => {
it('initalizes object with properties.', async () => {
Expand Down Expand Up @@ -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 = [
{
Expand All @@ -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 = [
{
Expand All @@ -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 = [
{
Expand All @@ -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 = [
{
Expand Down Expand Up @@ -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 {
Expand All @@ -163,7 +167,7 @@ describe('builtins/interpolation: ', () => {
x: [0, 10, 100],
});

const plugin = Interpolation(config);
const plugin = Interpolation(config, parametersMetadata);

expect.assertions(2);
try {
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 6 additions & 2 deletions src/__tests__/if-run/builtins/multiply.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.', () => {
Expand Down Expand Up @@ -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 = [
{
Expand Down
14 changes: 9 additions & 5 deletions src/__tests__/if-run/builtins/regex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.', () => {
Expand Down Expand Up @@ -55,7 +59,7 @@ describe('builtins/regex: ', () => {
match: '/(?<=_)[^_]+?(?=_|$)/g',
output: 'cloud/instance-type',
};
const regex = Regex(globalConfig);
const regex = Regex(globalConfig, parametersMetadata);

const expectedResult = [
{
Expand Down Expand Up @@ -86,7 +90,7 @@ describe('builtins/regex: ', () => {
match: '[^,]+/',
output: 'cpu/name',
};
const regex = Regex(globalConfig);
const regex = Regex(globalConfig, parametersMetadata);

const expectedResult = [
{
Expand Down Expand Up @@ -117,7 +121,7 @@ describe('builtins/regex: ', () => {
match: '^(^:)+',
output: 'cpu/name',
};
const regex = Regex(globalConfig);
const regex = Regex(globalConfig, parametersMetadata);

expect.assertions(1);

Expand All @@ -140,7 +144,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);

Expand Down
6 changes: 5 additions & 1 deletion src/__tests__/if-run/builtins/sci-embodied.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.', () => {
Expand Down
Loading