-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently, we're removing parameters set by the user that match the d…
…efault value intending to have less verbose routes. There's an issue with the `file` component, detailed as follows: ``` from: file:someFile.txt parameters: noop: true ``` In the previous route, `noop=true` implicitly set `idempotent=true` **IF THE VALUE HAS NOT BEEN SET TO EITHER TRUE OR FALSE**, usually this is OK and doesn't represent a problem. In case the user wants to set `noop=true` and `idempotent=false` to force the `file` component to re-read the files when the scheduler kicks in, like the following: ``` from: file:someFile.txt parameters: noop: true idempotent: false ``` Then we will remove the `idempotent=false` as it is the default value for the `idempotent` parameter, effectively blocking the user from setting a different behavior for the `file` component. This commit aims to keep values set by the user, even in case they are the default ones. fixes: #633
- Loading branch information
Showing
6 changed files
with
177 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { JSONSchemaType } from 'ajv'; | ||
import { getNonDefaultProperties } from './get-non-default-properties'; | ||
|
||
describe('getNonDefaultProperties()', () => { | ||
const schema = { | ||
type: 'object', | ||
properties: { | ||
parameters: { | ||
properties: { | ||
events: { | ||
type: 'string', | ||
default: 'CREATE,MODIFY,DELETE', | ||
title: 'Events', | ||
}, | ||
concurrentConsumers: { | ||
type: 'integer', | ||
default: 1, | ||
title: 'Concurrent Consumers', | ||
}, | ||
bridgeErrorHandler: { | ||
type: 'boolean', | ||
default: false, | ||
title: 'Bridge Error Handler', | ||
}, | ||
}, | ||
}, | ||
}, | ||
} as unknown as JSONSchemaType<unknown>; | ||
|
||
const newModel: Record<string, unknown> = { | ||
id: 'from-7126', | ||
description: 'test', | ||
steps: [], | ||
uri: 'file-watch', | ||
parameters: { | ||
events: 'CREATE', | ||
concurrentConsumers: '1', | ||
bridgeErrorHandler: false, | ||
}, | ||
}; | ||
|
||
const newModelExpected: Record<string, unknown> = { | ||
id: 'from-7126', | ||
description: 'test', | ||
steps: [], | ||
uri: 'file-watch', | ||
parameters: { | ||
events: 'CREATE', | ||
}, | ||
}; | ||
|
||
it('should return only the properties which are different from default', () => { | ||
const newModelClean = getNonDefaultProperties(schema?.properties.parameters.properties, newModel); | ||
expect(newModelClean).toMatchObject(newModelExpected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { JSONSchemaType } from 'ajv'; | ||
|
||
export function getNonDefaultProperties( | ||
obj1: JSONSchemaType<unknown>, | ||
obj2: Record<string, unknown>, | ||
): Record<string, unknown> { | ||
const newModelUpdated = Object.entries(obj2.parameters as object).reduce( | ||
(acc: [string, unknown][], currentValue: [string, unknown]) => { | ||
if (!(obj1[currentValue[0]]['default'] == currentValue[1])) { | ||
acc.push(currentValue); | ||
} | ||
return acc; | ||
}, | ||
[], | ||
); | ||
return { ...obj2, parameters: Object.fromEntries(newModelUpdated) }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { JSONSchemaType } from 'ajv'; | ||
import { getNonDefaultProperties } from './get-non-default-properties'; | ||
import { getNonEmptyProperties } from './get-non-empty-properties'; | ||
|
||
describe('CanvasForm getNonEmptyProperties()', () => { | ||
const schema = { | ||
type: 'object', | ||
properties: { | ||
parameters: { | ||
properties: { | ||
events: { | ||
type: 'string', | ||
default: 'CREATE,MODIFY,DELETE', | ||
title: 'Events', | ||
}, | ||
concurrentConsumers: { | ||
type: 'integer', | ||
default: 1, | ||
title: 'Concurrent Consumers', | ||
}, | ||
bridgeErrorHandler: { | ||
type: 'boolean', | ||
default: false, | ||
title: 'Bridge Error Handler', | ||
}, | ||
exchangePattern: { | ||
type: 'object', | ||
title: 'Exchange Pattern', | ||
}, | ||
}, | ||
}, | ||
}, | ||
} as unknown as JSONSchemaType<unknown>; | ||
|
||
const newModel: Record<string, unknown> = { | ||
id: 'from-7126', | ||
description: 'test', | ||
steps: [], | ||
uri: 'file-watch', | ||
parameters: { | ||
events: 'CREATE', | ||
concurrentConsumers: '', | ||
bridgeErrorHandler: false, | ||
exchangePattern: {}, | ||
}, | ||
}; | ||
|
||
const newModelIntermediate: Record<string, unknown> = { | ||
id: 'from-7126', | ||
description: 'test', | ||
steps: [], | ||
uri: 'file-watch', | ||
parameters: { | ||
events: 'CREATE', | ||
concurrentConsumers: '', | ||
exchangePattern: {}, | ||
}, | ||
}; | ||
|
||
const newModelExpected: Record<string, unknown> = { | ||
id: 'from-7126', | ||
description: 'test', | ||
steps: [], | ||
uri: 'file-watch', | ||
parameters: { | ||
events: 'CREATE', | ||
}, | ||
}; | ||
|
||
it('should return only the properties which are different from default', () => { | ||
const newModelClean = getNonDefaultProperties(schema?.properties.parameters.properties, newModel); | ||
expect(newModelClean).toMatchObject(newModelIntermediate); | ||
}); | ||
|
||
it('should return only the non-empty properties', () => { | ||
const newModelClean = getNonEmptyProperties(newModel); | ||
expect(newModelClean).toMatchObject(newModelExpected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export function getNonEmptyProperties(obj: Record<string, unknown>): Record<string, unknown> { | ||
const result = Object.entries(obj.parameters as object).reduce( | ||
(acc: [string, unknown][], currentValue: [string, unknown]) => { | ||
switch (typeof currentValue[1]) { | ||
case 'string': | ||
if (currentValue[1].trim().length !== 0) { | ||
acc.push(currentValue); | ||
} | ||
break; | ||
case 'object': | ||
if (Object.keys(currentValue[1] as object).length !== 0) { | ||
acc.push(currentValue); | ||
} | ||
break; | ||
default: | ||
acc.push(currentValue); | ||
} | ||
return acc; | ||
}, | ||
[], | ||
); | ||
return { ...obj, parameters: Object.fromEntries(result) }; | ||
} |