-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upgraded redshift-related packages to latest, eliminated redund…
…ant setDependencies module, fixed sonar remarks (#48)
- Loading branch information
1 parent
1c93381
commit 79a379a
Showing
18 changed files
with
944 additions
and
1,008 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
5 changes: 3 additions & 2 deletions
5
forward_engineering/helpers/alterScriptHelpers/alterContainerHelper.js
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
16 changes: 10 additions & 6 deletions
16
forward_engineering/helpers/alterScriptHelpers/alterEntityHelper.js
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
3 changes: 2 additions & 1 deletion
3
forward_engineering/helpers/alterScriptHelpers/alterViewHelper.js
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
240 changes: 119 additions & 121 deletions
240
forward_engineering/helpers/alterScriptHelpers/common.js
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 |
---|---|---|
@@ -1,137 +1,135 @@ | ||
module.exports = app => { | ||
const _ = app.require('lodash'); | ||
const _ = require('lodash'); | ||
|
||
const checkFieldPropertiesChanged = (compMod, propertiesToCheck) => { | ||
return propertiesToCheck.some(prop => compMod?.oldField[prop] !== compMod?.newField[prop]); | ||
}; | ||
const checkFieldPropertiesChanged = (compMod, propertiesToCheck) => { | ||
return propertiesToCheck.some(prop => compMod?.oldField[prop] !== compMod?.newField[prop]); | ||
}; | ||
|
||
const modifyGroupItems = ({ data, key, hydrate, drop, create, filter = Boolean }) => { | ||
const compMod = getCompMod(data); | ||
const parentName = data.code || data.name || data.collectionName; | ||
const modifyGroupItems = ({ data, key, hydrate, drop, create, filter = Boolean }) => { | ||
const compMod = getCompMod(data); | ||
const parentName = data.code || data.name || data.collectionName; | ||
|
||
const { removed, added, modified } = getModifiedGroupItems(compMod[key] || {}, hydrate, filter); | ||
const { removed, added, modified } = getModifiedGroupItems(compMod[key] || {}, hydrate, filter); | ||
|
||
const removedScripts = removed.map(item => drop(item, parentName)); | ||
const addedScripts = added.map(item => create(item, parentName)); | ||
const modifiedScripts = modified.map(item => create({ ...item, orReplace: true }, parentName)); | ||
const removedScripts = removed.map(item => drop(item, parentName)); | ||
const addedScripts = added.map(item => create(item, parentName)); | ||
const modifiedScripts = modified.map(item => create({ ...item, orReplace: true }, parentName)); | ||
|
||
return [].concat(modifiedScripts).concat(removedScripts).concat(addedScripts).filter(Boolean).join('\n\n'); | ||
}; | ||
return [].concat(modifiedScripts).concat(removedScripts).concat(addedScripts).filter(Boolean).join('\n\n'); | ||
}; | ||
|
||
const getModifiedGroupItems = ({ new: newItems = [], old: oldItems = [] }, hydrate, filter) => { | ||
const oldHydrated = oldItems.map(hydrate).filter(filter); | ||
const newHydrated = newItems.map(hydrate).filter(filter); | ||
|
||
const { removed, added, modified } = oldHydrated.reduce( | ||
(accumulator, oldItem) => { | ||
const newItem = newHydrated.find(item => item.name === oldItem.name); | ||
const itemsAreNotEqual = !isGroupItemsEqual(newItem, oldItem); | ||
|
||
if (!newItem) { | ||
return { | ||
removed: [...accumulator.removed, oldItem], | ||
modified: accumulator.modified, | ||
added: accumulator.added, | ||
}; | ||
} | ||
|
||
if (itemsAreNotEqual) { | ||
return { | ||
removed: accumulator.removed, | ||
modified: [...accumulator.modified, newItem], | ||
added: accumulator.added, | ||
}; | ||
} | ||
|
||
return accumulator; | ||
}, | ||
{ | ||
removed: [], | ||
modified: [], | ||
added: newHydrated.filter(newItem => !oldHydrated.some(item => item.name === newItem.name)), | ||
}, | ||
); | ||
const getModifiedGroupItems = ({ new: newItems = [], old: oldItems = [] }, hydrate, filter) => { | ||
const oldHydrated = oldItems.map(hydrate).filter(filter); | ||
const newHydrated = newItems.map(hydrate).filter(filter); | ||
|
||
const { removed, added, modified } = oldHydrated.reduce( | ||
(accumulator, oldItem) => { | ||
const newItem = newHydrated.find(item => item.name === oldItem.name); | ||
const itemsAreNotEqual = !isGroupItemsEqual(newItem, oldItem); | ||
|
||
if (!newItem) { | ||
return { | ||
removed: [...accumulator.removed, oldItem], | ||
modified: accumulator.modified, | ||
added: accumulator.added, | ||
}; | ||
} | ||
|
||
return { removed, added, modified }; | ||
}; | ||
if (itemsAreNotEqual) { | ||
return { | ||
removed: accumulator.removed, | ||
modified: [...accumulator.modified, newItem], | ||
added: accumulator.added, | ||
}; | ||
} | ||
|
||
const isGroupItemsEqual = (leftItem, rightItem) => _.isEqual(leftItem, rightItem); | ||
|
||
const getCompMod = containerData => containerData.role?.compMod ?? {}; | ||
|
||
const checkCompModEqual = ({ new: newItem, old: oldItem } = {}) => _.isEqual(newItem, oldItem); | ||
|
||
const setTableKeys = (idToNameHashTable, idToActivatedHashTable, table) => { | ||
return { | ||
...table, | ||
distKey: [ | ||
{ | ||
...(table.distKey?.[0] ?? {}), | ||
compositeDistKey: | ||
table.distKey?.[0]?.compositeDistKey?.map(key => ({ | ||
...key, | ||
name: idToNameHashTable[key.keyId], | ||
isActivated: idToActivatedHashTable[key.keyId], | ||
})) || [], | ||
}, | ||
], | ||
sortKey: [ | ||
{ | ||
...(table.sortKey?.[0] ?? {}), | ||
compositeSortKey: | ||
table.sortKey?.[0]?.compositeSortKey?.map(key => ({ | ||
...key, | ||
name: idToNameHashTable[key.keyId], | ||
isActivated: idToActivatedHashTable[key.keyId], | ||
})) || [], | ||
}, | ||
], | ||
primaryKey: [ | ||
{ | ||
...(table.primaryKey?.[0] ?? {}), | ||
compositePrimaryKey: | ||
table.primaryKey?.[0]?.compositePrimaryKey?.map(key => ({ | ||
...key, | ||
name: idToNameHashTable[key.keyId], | ||
isActivated: idToActivatedHashTable[key.keyId], | ||
})) || [], | ||
}, | ||
], | ||
uniqueKey: [ | ||
{ | ||
...(table.uniqueKey?.[0] ?? {}), | ||
compositeUniqueKey: | ||
table.uniqueKey?.[0]?.compositeUniqueKey?.map(key => ({ | ||
...key, | ||
name: idToNameHashTable[key.keyId], | ||
isActivated: idToActivatedHashTable[key.keyId], | ||
})) || [], | ||
}, | ||
], | ||
}; | ||
}; | ||
return accumulator; | ||
}, | ||
{ | ||
removed: [], | ||
modified: [], | ||
added: newHydrated.filter(newItem => !oldHydrated.some(item => item.name === newItem.name)), | ||
}, | ||
); | ||
|
||
const getKeys = keys => _.map(keys, 'name'); | ||
return { removed, added, modified }; | ||
}; | ||
|
||
const setNewProperties = jsonSchema => { | ||
const compMod = getCompMod(jsonSchema); | ||
const isGroupItemsEqual = (leftItem, rightItem) => _.isEqual(leftItem, rightItem); | ||
|
||
return _.toPairs(compMod).reduce((jsonSchema, [key, compMod]) => { | ||
if (compMod.new) { | ||
return { ...jsonSchema, [key]: compMod.new }; | ||
} | ||
const getCompMod = containerData => containerData.role?.compMod ?? {}; | ||
|
||
return jsonSchema; | ||
}, jsonSchema); | ||
}; | ||
const checkCompModEqual = ({ new: newItem, old: oldItem } = {}) => _.isEqual(newItem, oldItem); | ||
|
||
const setTableKeys = (idToNameHashTable, idToActivatedHashTable, table) => { | ||
return { | ||
checkFieldPropertiesChanged, | ||
getCompMod, | ||
modifyGroupItems, | ||
checkCompModEqual, | ||
setTableKeys, | ||
getKeys, | ||
setNewProperties, | ||
...table, | ||
distKey: [ | ||
{ | ||
...(table.distKey?.[0] ?? {}), | ||
compositeDistKey: | ||
table.distKey?.[0]?.compositeDistKey?.map(key => ({ | ||
...key, | ||
name: idToNameHashTable[key.keyId], | ||
isActivated: idToActivatedHashTable[key.keyId], | ||
})) || [], | ||
}, | ||
], | ||
sortKey: [ | ||
{ | ||
...(table.sortKey?.[0] ?? {}), | ||
compositeSortKey: | ||
table.sortKey?.[0]?.compositeSortKey?.map(key => ({ | ||
...key, | ||
name: idToNameHashTable[key.keyId], | ||
isActivated: idToActivatedHashTable[key.keyId], | ||
})) || [], | ||
}, | ||
], | ||
primaryKey: [ | ||
{ | ||
...(table.primaryKey?.[0] ?? {}), | ||
compositePrimaryKey: | ||
table.primaryKey?.[0]?.compositePrimaryKey?.map(key => ({ | ||
...key, | ||
name: idToNameHashTable[key.keyId], | ||
isActivated: idToActivatedHashTable[key.keyId], | ||
})) || [], | ||
}, | ||
], | ||
uniqueKey: [ | ||
{ | ||
...(table.uniqueKey?.[0] ?? {}), | ||
compositeUniqueKey: | ||
table.uniqueKey?.[0]?.compositeUniqueKey?.map(key => ({ | ||
...key, | ||
name: idToNameHashTable[key.keyId], | ||
isActivated: idToActivatedHashTable[key.keyId], | ||
})) || [], | ||
}, | ||
], | ||
}; | ||
}; | ||
|
||
const getKeys = keys => _.map(keys, 'name'); | ||
|
||
const setNewProperties = jsonSchema => { | ||
const compMod = getCompMod(jsonSchema); | ||
|
||
return _.toPairs(compMod).reduce((jsonSchema, [key, compMod]) => { | ||
if (compMod.new) { | ||
return { ...jsonSchema, [key]: compMod.new }; | ||
} | ||
|
||
return jsonSchema; | ||
}, jsonSchema); | ||
}; | ||
|
||
module.exports = { | ||
checkFieldPropertiesChanged, | ||
getCompMod, | ||
modifyGroupItems, | ||
checkCompModEqual, | ||
setTableKeys, | ||
getKeys, | ||
setNewProperties, | ||
}; |
Oops, something went wrong.