diff --git a/esbuild.package.js b/esbuild.package.js index abf352dc..68066ccc 100644 --- a/esbuild.package.js +++ b/esbuild.package.js @@ -2,6 +2,7 @@ const fs = require('fs'); const path = require('path'); const esbuild = require('esbuild'); const { clean } = require('esbuild-plugin-clean'); +const { copy } = require('esbuild-plugin-copy'); const { copyFolderFiles, addReleaseFlag } = require('@hackolade/hck-esbuild-plugins-pack'); const { EXCLUDED_EXTENSIONS, EXCLUDED_FILES, DEFAULT_RELEASE_FOLDER_PATH } = require('./buildConstants'); @@ -22,10 +23,17 @@ esbuild outdir: RELEASE_FOLDER_PATH, minify: true, logLevel: 'info', + external: ['lodash'], plugins: [ clean({ patterns: [DEFAULT_RELEASE_FOLDER_PATH], }), + copy({ + assets: { + from: [path.join('node_modules', 'lodash', '**', '*')], + to: [path.join('node_modules', 'lodash')], + }, + }), copyFolderFiles({ fromPath: __dirname, targetFolderPath: RELEASE_FOLDER_PATH, diff --git a/forward_engineering/alterScript/alterScriptBuilder.js b/forward_engineering/alterScript/alterScriptBuilder.js index 40024086..48682be0 100644 --- a/forward_engineering/alterScript/alterScriptBuilder.js +++ b/forward_engineering/alterScript/alterScriptBuilder.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { getAlterScriptDtos, joinAlterScriptDtosIntoAlterScript } = require('./alterScriptFromDeltaHelper'); const { AlterScriptDto } = require('./types/AlterScriptDto'); const { CoreData, App } = require('../types/coreApplicationTypes'); @@ -64,7 +65,6 @@ const doesEntityLevelAlterScriptContainDropStatements = (data, app) => entityLev const getContainerLevelAlterScriptDtos = (data, app) => ({ internalDefinitions, externalDefinitions, modelDefinitions, entitiesJsonSchema }) => { - const _ = app.require('lodash'); const deltaModelSchema = _.first(Object.values(entitiesJsonSchema)) || {}; const definitions = [modelDefinitions, internalDefinitions, externalDefinitions]; return getAlterScriptDtos(deltaModelSchema, definitions, data, app); diff --git a/forward_engineering/alterScript/alterScriptFromDeltaHelper.js b/forward_engineering/alterScript/alterScriptFromDeltaHelper.js index ddc03c4c..54523935 100644 --- a/forward_engineering/alterScript/alterScriptFromDeltaHelper.js +++ b/forward_engineering/alterScript/alterScriptFromDeltaHelper.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { getDeleteContainerScriptDto, getModifyContainerScriptDtos, @@ -60,7 +61,7 @@ const assertNoEmptyStatements = scripts => { /** * @return {Array} * */ -const getAlterContainersScriptDtos = ({ schema, isUnityCatalogSupports, provider, _, data }) => { +const getAlterContainersScriptDtos = ({ schema, isUnityCatalogSupports, provider, data }) => { const dbVersion = data.modelData[0].dbVersion; const addedScriptDtos = getItems(schema, 'containers', 'added') .map(getAddContainerScriptDto(isUnityCatalogSupports, dbVersion)) @@ -69,7 +70,7 @@ const getAlterContainersScriptDtos = ({ schema, isUnityCatalogSupports, provider .map(getDeleteContainerScriptDto(provider, dbVersion)) .filter(Boolean); const modifiedScriptDtos = getItems(schema, 'containers', 'modified') - .flatMap(getModifyContainerScriptDtos(provider, _, isUnityCatalogSupports, dbVersion)) + .flatMap(getModifyContainerScriptDtos(provider, isUnityCatalogSupports, dbVersion)) .filter(Boolean); return [...deletedScriptDtos, ...addedScriptDtos, ...modifiedScriptDtos]; @@ -108,7 +109,7 @@ const filterOutExistingStatements = ({ alterScriptDtos, existingAlterStatements /** * @return Array * */ -const getAlterCollectionsScriptDtos = ({ schema, definitions, provider, data, _, app }) => { +const getAlterCollectionsScriptDtos = ({ schema, definitions, provider, data, app }) => { const existingAlterStatements = new Set(); const getCollectionScripts = (items, compMode, getScript) => items.filter(item => item.compMod?.[compMode]).flatMap(getScript); @@ -156,7 +157,7 @@ const getAlterCollectionsScriptDtos = ({ schema, definitions, provider, data, _, let modifiedCollectionPrimaryKeysScriptDtos = []; if (getDBVersionNumber(dbVersion) >= Runtime.RUNTIME_SUPPORTING_PK_FK_CONSTRAINTS) { modifiedCollectionPrimaryKeysScriptDtos = getItems(schema, 'entities', 'modified').flatMap(item => - getModifyPkConstraintsScripts(_, provider)({ collection: item, dbVersion }), + getModifyPkConstraintsScripts(provider)({ collection: item, dbVersion }), ); } @@ -210,7 +211,7 @@ const getAlterCollectionsScriptDtos = ({ schema, definitions, provider, data, _, /** * @return Array * */ -const getAlterViewsScriptDtos = (schema, provider, _, dbVersion) => { +const getAlterViewsScriptDtos = (schema, provider, dbVersion) => { /** * @return Array * */ @@ -231,7 +232,7 @@ const getAlterViewsScriptDtos = (schema, provider, _, dbVersion) => { const addedViewScriptDtos = getViewScripts( getItems(schema, 'views', 'added'), 'created', - getAddViewsScripts(provider, _), + getAddViewsScripts(provider), ); const deletedViewScriptDtos = getViewScripts( getItems(schema, 'views', 'deleted'), @@ -240,7 +241,7 @@ const getAlterViewsScriptDtos = (schema, provider, _, dbVersion) => { ); const modifiedViewScriptDtos = getColumnScripts( getItems(schema, 'views', 'modified'), - getModifyViewsScripts(provider, _, dbVersion), + getModifyViewsScripts(provider, dbVersion), ); return [...deletedViewScriptDtos, ...addedViewScriptDtos, ...modifiedViewScriptDtos]; @@ -249,7 +250,7 @@ const getAlterViewsScriptDtos = (schema, provider, _, dbVersion) => { /** * @return Array * */ -const getAlterRelationshipsScriptDtos = ({ schema, ddlProvider, _ }) => { +const getAlterRelationshipsScriptDtos = ({ schema, ddlProvider }) => { const deletedRelationships = getItems(schema, 'relationships', 'deleted').filter( relationship => relationship.role?.compMod?.deleted, ); @@ -258,9 +259,9 @@ const getAlterRelationshipsScriptDtos = ({ schema, ddlProvider, _ }) => { ); const modifiedRelationships = getItems(schema, 'relationships', 'modified'); - const deleteFkScripts = getDeleteForeignKeyScripts(ddlProvider, _)(deletedRelationships); - const addFkScripts = getAddForeignKeyScripts(ddlProvider, _)(addedRelationships); - const modifiedFkScripts = getModifyForeignKeyScripts(ddlProvider, _)(modifiedRelationships); + const deleteFkScripts = getDeleteForeignKeyScripts(ddlProvider)(deletedRelationships); + const addFkScripts = getAddForeignKeyScripts(ddlProvider)(addedRelationships); + const modifiedFkScripts = getModifyForeignKeyScripts(ddlProvider)(modifiedRelationships); return [...deleteFkScripts, ...addFkScripts, ...modifiedFkScripts]; }; @@ -300,15 +301,14 @@ const getAlterStatementsWithCommentedUnwantedDDL = (scriptDtos, data) => { * */ const getAlterScriptDtos = (schema, definitions, data, app) => { const provider = require('../ddlProvider/ddlProvider')(app); - const _ = app.require('lodash'); const dbVersion = data.modelData[0].dbVersion; const isUnityCatalogSupports = isSupportUnityCatalog(dbVersion); - const containersScriptDtos = getAlterContainersScriptDtos({ schema, isUnityCatalogSupports, provider, _, data }); - const collectionsScriptDtos = getAlterCollectionsScriptDtos({ schema, definitions, provider, data, _, app }); - const viewsScriptDtos = getAlterViewsScriptDtos(schema, provider, _, dbVersion); + const containersScriptDtos = getAlterContainersScriptDtos({ schema, isUnityCatalogSupports, provider, data }); + const collectionsScriptDtos = getAlterCollectionsScriptDtos({ schema, definitions, provider, data, app }); + const viewsScriptDtos = getAlterViewsScriptDtos(schema, provider, dbVersion); let relationshipsScriptDtos = []; if (isUnityCatalogSupports) { - relationshipsScriptDtos = getAlterRelationshipsScriptDtos({ schema, ddlProvider: provider, _ }); + relationshipsScriptDtos = getAlterRelationshipsScriptDtos({ schema, ddlProvider: provider }); } return [...containersScriptDtos, ...collectionsScriptDtos, ...viewsScriptDtos, ...relationshipsScriptDtos]; diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterContainerHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterContainerHelper.js index 095cdc29..c1ef6424 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/alterContainerHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/alterContainerHelper.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { getDatabaseStatement, getDatabaseAlterStatement, getBucketKeyword } = require('../../helpers/databaseHelper'); const { getEntityData, @@ -82,11 +83,11 @@ const extractNamesFromCompMod = compMod => { /** * @return {(container: Object) => Array} * */ -const getModifyContainerScriptDtos = (provider, _, isUnityCatalogSupports, dbVersion) => container => { +const getModifyContainerScriptDtos = (provider, isUnityCatalogSupports, dbVersion) => container => { const compMod = _.get(container, 'role.compMod', {}); const names = extractNamesFromCompMod(compMod); - const didPropertiesChange = getIsChangeProperties(_)({ ...compMod, name: names }, otherContainerProperties); + const didPropertiesChange = getIsChangeProperties({ ...compMod, name: names }, otherContainerProperties); const containerData = { ...getContainerData(compMod), name: names.new }; const catalogName = isSupportUnityCatalog(dbVersion) ? prepareName(compMod?.catalogName?.new) : undefined; const databaseName = getDatabaseName({ role: { ...containerData, name: names.old } }); diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js index 0957a073..3ee66aaa 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { getColumns, getColumnsString } = require('../../helpers/columnHelper'); const { getIndexes } = require('../../helpers/indexHelper'); const { getTableStatement } = require('../../helpers/tableHelper'); @@ -20,46 +21,42 @@ const { getModifiedDefaultColumnValueScriptDtos } = require('./columnHelpers/def const { getUpdateTypesScriptDtos } = require('./columnHelpers/alterTypeHelper'); const { getModifyUnityColumnTagsScriptDtos } = require('./columnHelpers/alterUnityTagsHelper'); -const hydrateAlterColumnName = - _ => - ({ entity, properties = {}, dbVersion }) => { - const collectionName = generateFullEntityName({ entity, dbVersion }); - const columns = Object.values(properties).map(property => { - const compMod = _.get(property, 'compMod', {}); - const { newField = {}, oldField = {} } = compMod; - return newField.name && oldField.name && newField.name !== oldField.name - ? { oldName: oldField.name, newName: newField.name } - : ''; - }); - return { collectionName, columns: columns.filter(Boolean) }; - }; +const hydrateAlterColumnName = ({ entity, properties = {}, dbVersion }) => { + const collectionName = generateFullEntityName({ entity, dbVersion }); + const columns = Object.values(properties).map(property => { + const compMod = _.get(property, 'compMod', {}); + const { newField = {}, oldField = {} } = compMod; + return newField.name && oldField.name && newField.name !== oldField.name + ? { oldName: oldField.name, newName: newField.name } + : ''; + }); + return { collectionName, columns: columns.filter(Boolean) }; +}; -const hydrateAlterColumnType = - _ => - (properties = {}) => { - const isChangedType = (newField, oldField) => - newField.type && oldField.type && (newField.type !== oldField.type || newField.mode !== oldField.mode); - const columns = Object.values(properties).map(property => { - const compMod = _.get(property, 'compMod', {}); - const { newField = {}, oldField = {} } = compMod; - return isChangedType(oldField, newField) || - (newField.items && - oldField.items && - newField.items.some((field, index) => isChangedType(field, oldField.items[index]))) || - (newField.properties && - oldField.properties && - Object.keys(newField.properties).some(key => - isChangedType(newField.properties[key], oldField.properties[key]), - )) - ? { oldName: oldField.name, newName: newField.name } - : ''; - }); - const columnsToDelete = columns.map(column => column.oldName).filter(name => Boolean(name)); - const columnsToAdd = columns.map(column => column.newName).filter(name => Boolean(name)); - return { columnsToDelete, columnsToAdd }; - }; +const hydrateAlterColumnType = (properties = {}) => { + const isChangedType = (newField, oldField) => + newField.type && oldField.type && (newField.type !== oldField.type || newField.mode !== oldField.mode); + const columns = Object.values(properties).map(property => { + const compMod = _.get(property, 'compMod', {}); + const { newField = {}, oldField = {} } = compMod; + return isChangedType(oldField, newField) || + (newField.items && + oldField.items && + newField.items.some((field, index) => isChangedType(field, oldField.items[index]))) || + (newField.properties && + oldField.properties && + Object.keys(newField.properties).some(key => + isChangedType(newField.properties[key], oldField.properties[key]), + )) + ? { oldName: oldField.name, newName: newField.name } + : ''; + }); + const columnsToDelete = columns.map(column => column.oldName).filter(name => Boolean(name)); + const columnsToAdd = columns.map(column => column.newName).filter(name => Boolean(name)); + return { columnsToDelete, columnsToAdd }; +}; -const hydrateCollection = _ => (entity, definitions) => { +const hydrateCollection = (entity, definitions) => { const compMod = _.get(entity, 'role.compMod', {}); const entityData = _.get(entity, 'role', {}); const properties = getEntityProperties(entity); @@ -71,10 +68,9 @@ const hydrateCollection = _ => (entity, definitions) => { * @return {(entity: Object) => Array} * */ const getAddCollectionsScripts = (app, definitions, dbVersion) => entity => { - const _ = app.require('lodash'); const properties = getEntityProperties(entity); const indexes = _.get(entity, 'role.BloomIndxs', []); - const hydratedCollection = hydrateCollection(_)(entity, definitions); + const hydratedCollection = hydrateCollection(entity, definitions); const arePkFkConstraintsAvailable = isSupportUnityCatalog(dbVersion); const areNotNullConstraintsAvailable = isSupportNotNullConstraints(dbVersion); const collectionScript = getTableStatement(app)( @@ -85,7 +81,7 @@ const getAddCollectionsScripts = (app, definitions, dbVersion) => entity => { dbVersion, true, ); - const indexScript = getIndexes(_)(...hydrateAddIndexes(_)(entity, indexes, properties, definitions)); + const indexScript = getIndexes(...hydrateAddIndexes(entity, indexes, properties, definitions)); return [collectionScript, indexScript].filter(Boolean).map(script => ({ isActivated: true, @@ -102,11 +98,10 @@ const getAddCollectionsScripts = (app, definitions, dbVersion) => entity => { * @return {(entity: Object) => Array} * */ const getDeleteCollectionsScripts = (app, provider, dbVersion) => entity => { - const _ = app.require('lodash'); const entityData = { ...entity, ..._.get(entity, 'role', {}) }; const fullCollectionName = generateFullEntityName({ entity, dbVersion }); const collectionScript = provider.dropTable(fullCollectionName); - const indexScript = provider.dropTableIndex(hydrateDropIndexes(_)(entityData)); + const indexScript = provider.dropTableIndex(hydrateDropIndexes(entityData)); return [indexScript, collectionScript].filter(Boolean).map(script => ({ isActivated: true, @@ -123,7 +118,6 @@ const getDeleteCollectionsScripts = (app, provider, dbVersion) => entity => { * @return {(entity: Object) => Array} * */ const getModifyCollectionsScripts = (app, definitions, ddlProvider, dbVersion) => collection => { - const _ = app.require('lodash'); const properties = getEntityProperties(collection); const { script: modifyTableScriptDtos } = generateModifyCollectionScript(app)( collection, @@ -131,14 +125,14 @@ const getModifyCollectionsScripts = (app, definitions, ddlProvider, dbVersion) = ddlProvider, dbVersion, ); - const { hydratedAddIndex, hydratedDropIndex } = hydrateIndex(_)({ + const { hydratedAddIndex, hydratedDropIndex } = hydrateIndex({ entity: collection, properties, definitions, dbVersion, }); const dropIndexScript = ddlProvider.dropTableIndex(hydratedDropIndex); - const addIndexScript = getIndexes(_)(...hydratedAddIndex); + const addIndexScript = getIndexes(...hydratedAddIndex); const dropIndexScriptDto = AlterScriptDto.getInstance([dropIndexScript], true, true); const addIndexScriptDto = AlterScriptDto.getInstance([addIndexScript], true, false); @@ -147,7 +141,6 @@ const getModifyCollectionsScripts = (app, definitions, ddlProvider, dbVersion) = }; const getDeleteColumnsScripts = (app, definitions, provider, dbVersion) => entity => { - const _ = app.require('lodash'); const entityData = { ...entity, ..._.omit(entity.role, ['properties']), @@ -157,10 +150,10 @@ const getDeleteColumnsScripts = (app, definitions, provider, dbVersion) => entit const properties = getEntityProperties(entity); const columnStatement = getColumnsString(Object.keys(columns)); const fullCollectionName = generateFullEntityName({ entity, dbVersion }); - const { hydratedAddIndex, hydratedDropIndex } = hydrateIndex(_)({ entity, properties, definitions, dbVersion }); + const { hydratedAddIndex, hydratedDropIndex } = hydrateIndex({ entity, properties, definitions, dbVersion }); const modifyScript = generateModifyCollectionScript(app)(entity, definitions, provider, dbVersion); const dropIndexScript = provider.dropTableIndex(hydratedDropIndex); - const addIndexScript = getIndexes(_)(...hydratedAddIndex); + const addIndexScript = getIndexes(...hydratedAddIndex); const deleteColumnScript = provider.dropTableColumns({ name: fullCollectionName, columns: columnStatement }); const dropIndexScriptDto = AlterScriptDto.getInstance([dropIndexScript], true, true); @@ -180,16 +173,15 @@ const getDeleteColumnsScripts = (app, definitions, provider, dbVersion) => entit * @return {(entity: Object) => Array} * */ const getDeleteColumnScripsForOlderRuntime = (app, definitions, provider, dbVersion) => entity => { - const _ = app.require('lodash'); const deleteColumnsName = _.filter(Object.keys(entity.properties || {}), name => !entity.properties[name].compMod); const properties = _.omit(_.get(entity, 'role.properties', {}), deleteColumnsName); const entityData = { role: { ..._.omit(entity.role, ['properties']), properties } }; - const { hydratedAddIndex, hydratedDropIndex } = hydrateIndex(_)({ entity, properties, definitions, dbVersion }); + const { hydratedAddIndex, hydratedDropIndex } = hydrateIndex({ entity, properties, definitions, dbVersion }); const fullCollectionName = generateFullEntityName({ entity, dbVersion }); const dropIndexScript = provider.dropTableIndex(hydratedDropIndex); - const addIndexScript = getIndexes(_)(...hydratedAddIndex); + const addIndexScript = getIndexes(...hydratedAddIndex); const deleteCollectionScript = provider.dropTable(fullCollectionName); - const hydratedCollection = hydrateCollection(_)(entityData, definitions); + const hydratedCollection = hydrateCollection(entityData, definitions); const arePkFkConstraintsAvailable = isSupportUnityCatalog(dbVersion); const areNotNullConstraintsAvailable = isSupportNotNullConstraints(dbVersion); const addCollectionScript = getTableStatement(app)( @@ -213,7 +205,6 @@ const getDeleteColumnScripsForOlderRuntime = (app, definitions, provider, dbVers * @return {(entity: Object) => Array} * */ const getModifyColumnsScripts = (app, definitions, ddlProvider, dbVersion) => collection => { - const _ = app.require('lodash'); const properties = _.get(collection, 'properties', {}); const unionProperties = _.unionWith( Object.entries(properties), @@ -227,31 +218,31 @@ const getModifyColumnsScripts = (app, definitions, ddlProvider, dbVersion) => co properties: Object.fromEntries(unionProperties), }, }; - const hydratedAlterColumnName = hydrateAlterColumnName(_)({ entity: collection, properties, dbVersion }); + const hydratedAlterColumnName = hydrateAlterColumnName({ entity: collection, properties, dbVersion }); const alterColumnScripts = ddlProvider.alterTableColumnName(hydratedAlterColumnName); const modifiedScript = generateModifyCollectionScript(app)(entityData, definitions, ddlProvider, dbVersion); - const { hydratedAddIndex, hydratedDropIndex } = hydrateIndex(_)({ + const { hydratedAddIndex, hydratedDropIndex } = hydrateIndex({ entity: collection, properties, definitions, dbVersion, }); const dropIndexScript = ddlProvider.dropTableIndex(hydratedDropIndex); - const addIndexScript = getIndexes(_)(...hydratedAddIndex); + const addIndexScript = getIndexes(...hydratedAddIndex); - const modifiedCommentOnColumnsScriptDtos = getModifiedCommentOnColumnScriptDtos( - _, - ddlProvider, - )({ collection, dbVersion }); - const modifyNotNullConstraintsScriptDtos = getModifyNonNullColumnsScriptDtos( - _, - ddlProvider, - )({ collection, dbVersion }); - const modifyCheckConstraintsScriptDtos = getCheckConstraintsScriptDtos(_, ddlProvider)({ collection, dbVersion }); - const modifiedDefaultColumnValueScriptDtos = getModifiedDefaultColumnValueScriptDtos( - _, - ddlProvider, - )({ collection, dbVersion }); + const modifiedCommentOnColumnsScriptDtos = getModifiedCommentOnColumnScriptDtos(ddlProvider)({ + collection, + dbVersion, + }); + const modifyNotNullConstraintsScriptDtos = getModifyNonNullColumnsScriptDtos(ddlProvider)({ + collection, + dbVersion, + }); + const modifyCheckConstraintsScriptDtos = getCheckConstraintsScriptDtos(ddlProvider)({ collection, dbVersion }); + const modifiedDefaultColumnValueScriptDtos = getModifiedDefaultColumnValueScriptDtos(ddlProvider)({ + collection, + dbVersion, + }); const dropIndexScriptDto = AlterScriptDto.getInstance([dropIndexScript], true, true); const addIndexScriptDto = AlterScriptDto.getInstance([addIndexScript], true, false); @@ -267,7 +258,7 @@ const getModifyColumnsScripts = (app, definitions, ddlProvider, dbVersion) => co return [dropIndexScriptDto, ...(modifiedScript.script || []), addIndexScriptDto].filter(Boolean); } - const updateTypeScriptDtos = getUpdateTypesScriptDtos(_, ddlProvider)(collection, definitions, dbVersion); + const updateTypeScriptDtos = getUpdateTypesScriptDtos(ddlProvider)(collection, definitions, dbVersion); return [ dropIndexScriptDto, @@ -287,7 +278,6 @@ const getModifyColumnsScripts = (app, definitions, ddlProvider, dbVersion) => co * @return {(entity: Object) => Array} * */ const getModifyColumnsScriptsForOlderRuntime = (app, definitions, ddlProvider, dbVersion) => collection => { - const _ = app.require('lodash'); const properties = _.get(collection, 'properties', {}); const unionProperties = _.unionWith( Object.entries(properties), @@ -301,34 +291,34 @@ const getModifyColumnsScriptsForOlderRuntime = (app, definitions, ddlProvider, d properties: Object.fromEntries(unionProperties), }, }; - const hydratedAlterColumnName = hydrateAlterColumnName(_)({ entity: collection, properties, dbVersion }); + const hydratedAlterColumnName = hydrateAlterColumnName({ entity: collection, properties, dbVersion }); const alterColumnScripts = ddlProvider.alterTableColumnName(hydratedAlterColumnName); const modifiedScript = generateModifyCollectionScript(app)(entityData, definitions, ddlProvider, dbVersion); - const { hydratedAddIndex, hydratedDropIndex } = hydrateIndex(_)({ + const { hydratedAddIndex, hydratedDropIndex } = hydrateIndex({ entity: collection, properties, definitions, dbVersion, }); const dropIndexScript = ddlProvider.dropTableIndex(hydratedDropIndex); - const addIndexScript = getIndexes(_)(...hydratedAddIndex); + const addIndexScript = getIndexes(...hydratedAddIndex); - const { columnsToDelete } = hydrateAlterColumnType(_)(properties); - const modifiedCommentOnColumnsScriptDtos = getModifiedCommentOnColumnScriptDtos( - _, - ddlProvider, - )({ collection, dbVersion }); - const modifyNotNullConstraintsScriptDtos = getModifyNonNullColumnsScriptDtos( - _, - ddlProvider, - )({ collection, dbVersion }); - const modifyCheckConstraintsScriptDtos = getCheckConstraintsScriptDtos(_, ddlProvider)({ collection, dbVersion }); + const { columnsToDelete } = hydrateAlterColumnType(properties); + const modifiedCommentOnColumnsScriptDtos = getModifiedCommentOnColumnScriptDtos(ddlProvider)({ + collection, + dbVersion, + }); + const modifyNotNullConstraintsScriptDtos = getModifyNonNullColumnsScriptDtos(ddlProvider)({ + collection, + dbVersion, + }); + const modifyCheckConstraintsScriptDtos = getCheckConstraintsScriptDtos(ddlProvider)({ collection, dbVersion }); let tableModificationScriptDtos = []; if (!_.isEmpty(columnsToDelete)) { const fullCollectionName = generateFullEntityName({ entity: collection, dbVersion }); const deleteCollectionScript = ddlProvider.dropTable(fullCollectionName); - const hydratedCollection = hydrateCollection(_)(entityData, definitions); + const hydratedCollection = hydrateCollection(entityData, definitions); const arePkFkConstraintsAvailable = isSupportUnityCatalog(dbVersion); const areNotNullConstraintsAvailable = isSupportNotNullConstraints(dbVersion); const addCollectionScript = getTableStatement(app)( diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterRelationshipsHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterRelationshipsHelper.js index e8112c02..774f6e93 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/alterRelationshipsHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/alterRelationshipsHelper.js @@ -28,7 +28,7 @@ const getFullChildTableName = relationship => { /** * @return {(relationship: Object) => string} * */ -const getAddSingleForeignKeyScript = (ddlProvider, _) => relationship => { +const getAddSingleForeignKeyScript = ddlProvider => relationship => { const compMod = relationship.role.compMod; const parentTableName = getFullParentTableName(relationship); @@ -69,11 +69,11 @@ const canRelationshipBeAdded = relationship => { /** * @return {(addedRelationships: Array) => Array} * */ -const getAddForeignKeyScripts = (ddlProvider, _) => addedRelationships => { +const getAddForeignKeyScripts = ddlProvider => addedRelationships => { return addedRelationships .filter(relationship => canRelationshipBeAdded(relationship)) .map(relationship => { - const script = getAddSingleForeignKeyScript(ddlProvider, _)(relationship); + const script = getAddSingleForeignKeyScript(ddlProvider)(relationship); return { isActivated: Boolean(relationship.role?.compMod?.isActivated?.new), scripts: [ @@ -90,7 +90,7 @@ const getAddForeignKeyScripts = (ddlProvider, _) => addedRelationships => { /** * @return {(relationship: Object) => string} * */ -const getDeleteSingleForeignKeyScript = (ddlProvider, _) => relationship => { +const getDeleteSingleForeignKeyScript = ddlProvider => relationship => { const compMod = relationship.role.compMod; const childTableName = getFullChildTableName(relationship); @@ -115,11 +115,11 @@ const canRelationshipBeDeleted = relationship => { /** * @return {(deletedRelationships: Array) => Array} * */ -const getDeleteForeignKeyScripts = (ddlProvider, _) => deletedRelationships => { +const getDeleteForeignKeyScripts = ddlProvider => deletedRelationships => { return deletedRelationships .filter(relationship => canRelationshipBeDeleted(relationship)) .map(relationship => { - const script = getDeleteSingleForeignKeyScript(ddlProvider, _)(relationship); + const script = getDeleteSingleForeignKeyScript(ddlProvider)(relationship); return { isActivated: Boolean(relationship.role?.compMod?.isActivated?.new), scripts: [ @@ -136,12 +136,12 @@ const getDeleteForeignKeyScripts = (ddlProvider, _) => deletedRelationships => { /** * @return {(modifiedRelationships: Array) => Array} * */ -const getModifyForeignKeyScripts = (ddlProvider, _) => modifiedRelationships => { +const getModifyForeignKeyScripts = ddlProvider => modifiedRelationships => { return modifiedRelationships .filter(relationship => canRelationshipBeAdded(relationship) && canRelationshipBeDeleted(relationship)) .map(relationship => { - const deleteScript = getDeleteSingleForeignKeyScript(ddlProvider, _)(relationship); - const addScript = getAddSingleForeignKeyScript(ddlProvider, _)(relationship); + const deleteScript = getDeleteSingleForeignKeyScript(ddlProvider)(relationship); + const addScript = getAddSingleForeignKeyScript(ddlProvider)(relationship); return { isActivated: Boolean(relationship.role?.compMod?.isActivated?.new), scripts: [ diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterViewHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterViewHelper.js index 28536f93..5f68e30e 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/alterViewHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/alterViewHelper.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { hydrateTableProperties } = require('../../helpers/tableHelper'); const { getEntityData, @@ -14,7 +15,7 @@ const { getModifyUnityViewTagsScriptDtos } = require('./entityHelpers/alterUnity const viewProperties = ['code', 'name', 'tableProperties', 'selectStatement', 'unityViewTags']; const otherViewProperties = ['viewTemporary', 'viewOrReplace', 'isGlobal', 'description']; -const compareProperties = _ => (view, properties) => { +const compareProperties = (view, properties) => { const compMod = _.get(view, 'role.compMod', {}); return properties.some(property => { const { new: newProperty, old: oldProperty } = compMod[property] || {}; @@ -46,7 +47,7 @@ const prepareRefsDefinitionsMap = definitions => {}, ); -const hydrateView = _ => view => { +const hydrateView = view => { const compMod = _.get(view, 'role.compMod', {}); const properties = prepareColumnGuids(getEntityProperties(view)); const roleData = getEntityData(compMod, viewProperties.concat(otherViewProperties)); @@ -65,14 +66,14 @@ const hydrateView = _ => view => { /** * @return {function(*): {dataProperties: {add: string, drop: *}, rename: {newName: string, oldName: string}, dbName: *, fullName: string, selectStatement: *|string}} * */ -const hydrateAlterView = _ => view => { +const hydrateAlterView = view => { const compMod = _.get(view, 'role.compMod', {}); const rename = getEntityName(compMod, 'name'); const dbName = getContainerName(compMod); const fullName = getFullEntityName(dbName, rename.newName); const tableProperties = _.get(compMod, 'tableProperties', ''); const { new: newSelect, old: oldSelect } = _.get(compMod, 'selectStatement', ''); - const { dataProperties } = hydrateTableProperties(_)(tableProperties, fullName); + const { dataProperties } = hydrateTableProperties(tableProperties, fullName); return { selectStatement: !_.isEqual(newSelect, oldSelect) && newSelect ? newSelect : '', @@ -86,8 +87,8 @@ const hydrateAlterView = _ => view => { /** * @return {(view: Object) => AlterScriptDto} * */ -const getAddViewsScripts = (provider, _) => view => { - const hydratedView = hydrateView(_)(view); +const getAddViewsScripts = provider => view => { + const hydratedView = hydrateView(view); const script = provider.createView(hydratedView); return { @@ -121,11 +122,11 @@ const getDeleteViewsScripts = (provider, dbVersion) => view => { /** * @return {(view: Object) => Array} * */ -const getModifyViewsScripts = (provider, _, dbVersion) => view => { - const comparedProperties = compareProperties(_)(view, viewProperties); +const getModifyViewsScripts = (provider, dbVersion) => view => { + const comparedProperties = compareProperties(view, viewProperties); const viewName = generateFullEntityName({ entity: view, dbVersion }); if (comparedProperties) { - const hydratedAlterView = hydrateAlterView(_)(view); + const hydratedAlterView = hydrateAlterView(view); const alterViewScript = prepareScript(...provider.alterView(hydratedAlterView)); const alterUnityViewTagsScriptDtos = getModifyUnityViewTagsScriptDtos({ ddlProvider: provider })({ viewData: view, @@ -136,7 +137,7 @@ const getModifyViewsScripts = (provider, _, dbVersion) => view => { return [...alterViewScriptDtos, ...alterUnityViewTagsScriptDtos]; } const dropViewScript = provider.dropView(viewName); - const hydratedView = hydrateView(_)(view); + const hydratedView = hydrateView(view); const addViewScript = provider.createView(hydratedView); const dropViewScriptDto = AlterScriptDto.getInstance([dropViewScript], true, true); const addViewScriptDto = AlterScriptDto.getInstance([addViewScript], true, false); diff --git a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/alterTypeHelper.js b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/alterTypeHelper.js index ae8e1b4a..cf179f63 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/alterTypeHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/alterTypeHelper.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { AlterScriptDto } = require('../../types/AlterScriptDto'); const { checkFieldPropertiesChanged, generateFullEntityName, prepareName } = require('../../../utils/general'); const { getColumns, getColumnStatement } = require('../../../helpers/columnHelper'); @@ -32,7 +33,7 @@ const hasPrecisionOrScaleChanged = (collection, oldFieldName, currentJsonSchema) * role: Object, * }} * */ -const getEntityData = _ => collection => { +const getEntityData = collection => { const properties = _.get(collection, 'properties', {}); const unionProperties = _.unionWith( Object.entries(properties), @@ -55,9 +56,9 @@ const getEntityData = _ => collection => { /** * @return {(collection: Object, definitions: any, dbVersion: string) => AlterScriptDto[]} * */ -const getUpdateTypesScriptDtos = (_, ddlProvider) => (collection, definitions, dbVersion) => { +const getUpdateTypesScriptDtos = ddlProvider => (collection, definitions, dbVersion) => { const fullTableName = generateFullEntityName({ entity: collection, dbVersion }); - const entityData = getEntityData(_)(collection); + const entityData = getEntityData(collection); const { columns: columnsInfo } = getColumns(entityData.role, definitions, dbVersion); return _.toPairs(collection.properties) diff --git a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/checkConstraintHelper.js b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/checkConstraintHelper.js index 6a2c5397..a8856270 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/checkConstraintHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/checkConstraintHelper.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { generateFullEntityName, wrapInTicks } = require('../../../utils/general'); const { AlterScriptDto } = require('../../types/AlterScriptDto'); @@ -23,10 +24,9 @@ const getCheckConstraintNameForDdlProvider = (constraintName = '', columnName) = /** * @param ddlProvider {Object} - * @param _ {Object} * @returns {GetAlterScriptDtoFunction} */ -const getAddCheckConstraintsScriptsDtos = (ddlProvider, _) => (fullTableName, collection) => { +const getAddCheckConstraintsScriptsDtos = ddlProvider => (fullTableName, collection) => { return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { const oldName = jsonSchema.compMod.oldField.name; @@ -43,10 +43,9 @@ const getAddCheckConstraintsScriptsDtos = (ddlProvider, _) => (fullTableName, co /** * @param ddlProvider {Object} - * @param _ {Object} * @returns {GetAlterScriptDtoFunction} */ -const getRemoveCheckConstraintsScriptsDtos = (ddlProvider, _) => (fullTableName, collection) => { +const getRemoveCheckConstraintsScriptsDtos = ddlProvider => (fullTableName, collection) => { return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { const oldName = jsonSchema.compMod.oldField.name; @@ -64,10 +63,9 @@ const getRemoveCheckConstraintsScriptsDtos = (ddlProvider, _) => (fullTableName, /** * @param ddlProvider {Object} - * @param _ {Object} * @returns {GetAlterScriptDtoFunction} */ -const getModifyCheckConstraintsScriptDtos = (ddlProvider, _) => (fullTableName, collection) => { +const getModifyCheckConstraintsScriptDtos = ddlProvider => (fullTableName, collection) => { return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { const oldName = jsonSchema.compMod.oldField.name; @@ -103,18 +101,15 @@ const getModifyCheckConstraintsScriptDtos = (ddlProvider, _) => (fullTableName, * @return {({ collection, dbVersion }: { collection: Object, dbVersion: string }) => Array} * */ const getCheckConstraintsScriptDtos = - (_, ddlProvider) => + ddlProvider => ({ collection, dbVersion }) => { const fullTableName = generateFullEntityName({ entity: collection, dbVersion }); - const addCheckConstraintsScriptDtos = getAddCheckConstraintsScriptsDtos(ddlProvider, _)( + const addCheckConstraintsScriptDtos = getAddCheckConstraintsScriptsDtos(ddlProvider)(fullTableName, collection); + const modifyCheckConstraintsScripts = getModifyCheckConstraintsScriptDtos(ddlProvider)( fullTableName, collection, ); - const modifyCheckConstraintsScripts = getModifyCheckConstraintsScriptDtos(ddlProvider, _)( - fullTableName, - collection, - ); - const removeCheckConstraintScripts = getRemoveCheckConstraintsScriptsDtos(ddlProvider, _)( + const removeCheckConstraintScripts = getRemoveCheckConstraintsScriptsDtos(ddlProvider)( fullTableName, collection, ); diff --git a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/commentsHelper.js b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/commentsHelper.js index 32e0e4bb..911392a5 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/commentsHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/commentsHelper.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { generateFullEntityName, prepareName, wrapInSingleQuotes } = require('../../../utils/general'); const { AlterScriptDto } = require('../../types/AlterScriptDto'); @@ -5,7 +6,7 @@ const { AlterScriptDto } = require('../../types/AlterScriptDto'); * @return {({ collection, dbVersion }: { collection: Object, dbVersion: string }) => Array} * */ const getUpdatedCommentOnColumnScriptDtos = - (_, ddlProvider) => + ddlProvider => ({ collection, dbVersion }) => { return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { @@ -31,7 +32,7 @@ const getUpdatedCommentOnColumnScriptDtos = * @return {({ collection, dbVersion }: { collection: Object, dbVersion: string }) => Array} * */ const getDeletedCommentOnColumnScripts = - (_, ddlProvider) => + ddlProvider => ({ collection, dbVersion }) => { return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { @@ -55,10 +56,10 @@ const getDeletedCommentOnColumnScripts = * @return {({ collection, dbVersion }: { collection: Object, dbVersion: string }) => Array} * */ const getModifiedCommentOnColumnScriptDtos = - (_, ddlProvider) => + ddlProvider => ({ collection, dbVersion }) => { - const updatedCommentScripts = getUpdatedCommentOnColumnScriptDtos(_, ddlProvider)({ collection, dbVersion }); - const deletedCommentScripts = getDeletedCommentOnColumnScripts(_, ddlProvider)({ collection, dbVersion }); + const updatedCommentScripts = getUpdatedCommentOnColumnScriptDtos(ddlProvider)({ collection, dbVersion }); + const deletedCommentScripts = getDeletedCommentOnColumnScripts(ddlProvider)({ collection, dbVersion }); return [...updatedCommentScripts, ...deletedCommentScripts]; }; diff --git a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/defaultValueHelper.js b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/defaultValueHelper.js index f534dcb2..87515df5 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/defaultValueHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/defaultValueHelper.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { AlterScriptDto } = require('../../types/AlterScriptDto'); const { generateFullEntityName, prepareName } = require('../../../utils/general'); @@ -5,7 +6,7 @@ const { generateFullEntityName, prepareName } = require('../../../utils/general' * @return {({ collection, dbVersion }: { collection: Object, dbVersion: string }) => Array} * */ const getUpdatedDefaultColumnValueScriptDtos = - (_, ddlProvider) => + ddlProvider => ({ collection, dbVersion }) => { return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { @@ -31,7 +32,7 @@ const getUpdatedDefaultColumnValueScriptDtos = * @return {({ collection, dbVersion }: { collection: Object, dbVersion: string }) => Array} * */ const getDeletedDefaultColumnValueScriptDtos = - (_, ddlProvider) => + ddlProvider => ({ collection, dbVersion }) => { return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { @@ -55,16 +56,16 @@ const getDeletedDefaultColumnValueScriptDtos = * @return {({ collection, dbVersion }: { collection: Object, dbVersion: string }) => Array} * */ const getModifiedDefaultColumnValueScriptDtos = - (_, ddlProvider) => + ddlProvider => ({ collection, dbVersion }) => { - const updatedDefaultValuesScriptDtos = getUpdatedDefaultColumnValueScriptDtos( - _, - ddlProvider, - )({ collection, dbVersion }); - const dropDefaultValuesScriptDtos = getDeletedDefaultColumnValueScriptDtos( - _, - ddlProvider, - )({ collection, dbVersion }); + const updatedDefaultValuesScriptDtos = getUpdatedDefaultColumnValueScriptDtos(ddlProvider)({ + collection, + dbVersion, + }); + const dropDefaultValuesScriptDtos = getDeletedDefaultColumnValueScriptDtos(ddlProvider)({ + collection, + dbVersion, + }); return [...updatedDefaultValuesScriptDtos, ...dropDefaultValuesScriptDtos]; }; diff --git a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/nonNullConstraintHelper.js b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/nonNullConstraintHelper.js index d423501c..17fdd3c6 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/nonNullConstraintHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/nonNullConstraintHelper.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { generateFullEntityName, prepareName } = require('../../../utils/general'); const { AlterScriptDto } = require('../../types/AlterScriptDto'); @@ -5,7 +6,7 @@ const { AlterScriptDto } = require('../../types/AlterScriptDto'); * @return {({ collection, dbVersion }: { collection: Object, dbVersion: string }) => Array} * */ const getModifyNonNullColumnsScriptDtos = - (_, ddlProvider) => + ddlProvider => ({ collection, dbVersion }) => { const fullTableName = generateFullEntityName({ entity: collection, dbVersion }); diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/addColumnsHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/addColumnsHelper.js index a45d6e87..a7ce4d16 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/addColumnsHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/addColumnsHelper.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { getColumns, getColumnsStatement } = require('../../../helpers/columnHelper'); const { getEntityProperties, @@ -23,7 +24,7 @@ const { getColumnTagsStatement } = require('../../../helpers/unityTagsHelper'); /** * @return {(columns: Columns) => Columns } * */ -const getColumnsWithoutNotNullConstraint = _ => columns => { +const getColumnsWithoutNotNullConstraint = columns => { const nameToJsonSchema = _.toPairs(columns).map(([name, jsonSchema]) => { if (!jsonSchema?.constraints) { return [name, jsonSchema]; @@ -44,7 +45,7 @@ const getColumnsWithoutNotNullConstraint = _ => columns => { * @return {({ collection, columns, dbVersion }: { collection: Object, columns: Columns, dbVersion: string }) => Array } * */ const getAddNotNullConstraintScriptDtos = - (_, ddlProvider) => + ddlProvider => ({ collection, columns, dbVersion }) => { const fullTableName = generateFullEntityName({ entity: collection, dbVersion }); @@ -62,25 +63,25 @@ const getAddNotNullConstraintScriptDtos = }; const getAddColumnsScriptsForModifyModifyCollectionScript = - (_, provider) => (entity, definitions, modifyScript, dbVersion) => { + provider => (entity, definitions, modifyScript, dbVersion) => { const entityData = { ...entity, ..._.omit(entity.role, ['properties']) }; const { columns } = getColumns(entityData, definitions, dbVersion); // "NOT NULL" constraint is baked right into the "column statement". We are unsetting "not null" constraint // property on each column so that we could add these constraints in separate statements and not have it duplicated. - const columnsWithoutNotNull = getColumnsWithoutNotNullConstraint(_)(columns); + const columnsWithoutNotNull = getColumnsWithoutNotNullConstraint(columns); const properties = getEntityProperties(entity); const columnStatement = getColumnsStatement(columnsWithoutNotNull, entity.role?.isActivated ?? true); const fullCollectionName = generateFullEntityName({ entity, dbVersion }); - const { hydratedAddIndex, hydratedDropIndex } = hydrateIndex(_)({ entity, properties, definitions, dbVersion }); + const { hydratedAddIndex, hydratedDropIndex } = hydrateIndex({ entity, properties, definitions, dbVersion }); const dropIndexScript = provider.dropTableIndex(hydratedDropIndex); - const addIndexScript = getIndexes(_)(...hydratedAddIndex); + const addIndexScript = getIndexes(...hydratedAddIndex); const addColumnScript = provider.addTableColumns({ name: fullCollectionName, columns: columnStatement }); const isUnityTagsSupported = getDBVersionNumber(dbVersion) >= Runtime.MINIMUM_UNITY_TAGS_SUPPORT_VERSION; const columnsUnityTagsScript = isUnityTagsSupported - ? getColumnTagsStatement(_, properties, fullCollectionName) + ? getColumnTagsStatement(properties, fullCollectionName) : []; const addColumnScriptWithUnityTags = isUnityTagsSupported ? [addColumnScript, ...columnsUnityTagsScript].join('\n') @@ -89,10 +90,11 @@ const getAddColumnsScriptsForModifyModifyCollectionScript = const dropIndexScriptDto = AlterScriptDto.getInstance([dropIndexScript], true, true); const addIndexScriptDto = AlterScriptDto.getInstance([addIndexScript], true, false); const addColumnScriptDto = AlterScriptDto.getInstance([addColumnScriptWithUnityTags], true, false); - const notNullConstraintScriptDtos = getAddNotNullConstraintScriptDtos( - _, - provider, - )({ collection: entity, columns, dbVersion }); + const notNullConstraintScriptDtos = getAddNotNullConstraintScriptDtos(provider)({ + collection: entity, + columns, + dbVersion, + }); return [ dropIndexScriptDto, @@ -103,39 +105,26 @@ const getAddColumnsScriptsForModifyModifyCollectionScript = ].filter(Boolean); }; -const getAddColumnsScriptsForNewModifyCollectionScript = - (_, provider) => (entity, definitions, modifyScript, dbVersion) => { - const properties = getEntityProperties(entity); - const { hydratedAddIndex, hydratedDropIndex } = hydrateIndex(_)({ entity, properties, definitions, dbVersion }); - const dropIndexScript = provider.dropTableIndex(hydratedDropIndex); - const addIndexScript = getIndexes(_)(...hydratedAddIndex); - const dropIndexScriptDto = AlterScriptDto.getInstance([dropIndexScript], true, true); - const addIndexScriptDto = AlterScriptDto.getInstance([addIndexScript], true, false); +const getAddColumnsScriptsForNewModifyCollectionScript = provider => (entity, definitions, modifyScript, dbVersion) => { + const properties = getEntityProperties(entity); + const { hydratedAddIndex, hydratedDropIndex } = hydrateIndex({ entity, properties, definitions, dbVersion }); + const dropIndexScript = provider.dropTableIndex(hydratedDropIndex); + const addIndexScript = getIndexes(...hydratedAddIndex); + const dropIndexScriptDto = AlterScriptDto.getInstance([dropIndexScript], true, true); + const addIndexScriptDto = AlterScriptDto.getInstance([addIndexScript], true, false); - return [dropIndexScriptDto, ...(modifyScript.script || []), addIndexScriptDto].filter(Boolean); - }; + return [dropIndexScriptDto, ...(modifyScript.script || []), addIndexScriptDto].filter(Boolean); +}; /** * @return {(entity: Object) => Array} * */ const getAddColumnsScripts = (app, definitions, provider, dbVersion) => entity => { - const _ = app.require('lodash'); - const modifyScript = generateModifyCollectionScript(app)(entity, definitions, provider, dbVersion); if (modifyScript.type === 'new') { - return getAddColumnsScriptsForNewModifyCollectionScript(_, provider)( - entity, - definitions, - modifyScript, - dbVersion, - ); + return getAddColumnsScriptsForNewModifyCollectionScript(provider)(entity, definitions, modifyScript, dbVersion); } - return getAddColumnsScriptsForModifyModifyCollectionScript(_, provider)( - entity, - definitions, - modifyScript, - dbVersion, - ); + return getAddColumnsScriptsForModifyModifyCollectionScript(provider)(entity, definitions, modifyScript, dbVersion); }; module.exports = { diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/indexHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/indexHelper.js index 2f8aede4..bbda0b73 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/indexHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/indexHelper.js @@ -1,27 +1,26 @@ +const _ = require('lodash'); const { generateFullEntityName, getContainerName, getDifferentItems } = require('../../../utils/general'); -const hydrateDropIndexes = _ => (entity, dbVersion) => { +const hydrateDropIndexes = (entity, dbVersion) => { const bloomIndex = _.get(entity, 'BloomIndxs', []); return bloomIndex.length ? generateFullEntityName({ entity, dbVersion }) : ''; }; -const hydrateAddIndexes = _ => (entity, BloomIndxs, properties, definitions) => { +const hydrateAddIndexes = (entity, BloomIndxs, properties, definitions) => { const compMod = _.get(entity, 'role.compMod', {}); const entityData = _.get(entity, 'role', {}); const containerData = { name: getContainerName(compMod) }; return [[containerData], [entityData, {}, { BloomIndxs }], { ...entityData, properties }, definitions]; }; -const hydrateIndex = - _ => - ({ entity, properties, definitions, dbVersion }) => { - const bloomIndex = _.get(entity, 'role.compMod.BloomIndxs', {}); - const { drop, add } = getDifferentItems(_)(bloomIndex.new, bloomIndex.old); - return { - hydratedDropIndex: hydrateDropIndexes(_)({ ...entity, BloomIndxs: drop }, dbVersion), - hydratedAddIndex: hydrateAddIndexes(_)(entity, add, properties, definitions), - }; +const hydrateIndex = ({ entity, properties, definitions, dbVersion }) => { + const bloomIndex = _.get(entity, 'role.compMod.BloomIndxs', {}); + const { drop, add } = getDifferentItems(bloomIndex.new, bloomIndex.old); + return { + hydratedDropIndex: hydrateDropIndexes({ ...entity, BloomIndxs: drop }, dbVersion), + hydratedAddIndex: hydrateAddIndexes(entity, add, properties, definitions), }; +}; module.exports = { hydrateDropIndexes, diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/modifyCollectionScript.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/modifyCollectionScript.js index 78c065e9..0eee663c 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/modifyCollectionScript.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/modifyCollectionScript.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { getIsChangeProperties, generateFullEntityName, @@ -49,7 +50,7 @@ const otherTableProperties = [ 'location', ]; -const hydrateSerDeProperties = _ => (compMod, name) => { +const hydrateSerDeProperties = (compMod, name) => { const { serDeProperties, serDeLibrary } = compMod; return { properties: !_.isEqual(serDeProperties?.new, serDeProperties?.old) && serDeProperties?.new, @@ -69,7 +70,7 @@ const hydrateAlterTableName = compMod => { }; }; -const hydrateCollection = _ => (entity, definitions) => { +const hydrateCollection = (entity, definitions) => { const compMod = _.get(entity, 'role.compMod', {}); const entityData = _.get(entity, 'role', {}); const properties = getEntityProperties(entity); @@ -84,12 +85,10 @@ const hydrateCollection = _ => (entity, definitions) => { * }} * */ const getDropAndRecreateCollectionScriptDtos = (app, ddlProvider) => (collection, definitions, dbVersion) => { - const _ = app.require('lodash'); - const compMod = _.get(collection, 'role.compMod', {}); const fullCollectionName = generateFullEntityName({ entity: collection, dbVersion }); const roleData = getEntityData(compMod, tableProperties.concat(otherTableProperties)); - const hydratedCollection = hydrateCollection(_)( + const hydratedCollection = hydrateCollection( { ...collection, role: { ...collection.role, ...roleData }, @@ -122,8 +121,6 @@ const getDropAndRecreateCollectionScriptDtos = (app, ddlProvider) => (collection const getModifyLocationScriptDto = (app, ddlProvider) => ({ collection, dbVersion }) => { - const _ = app.require('lodash'); - const compMod = _.get(collection, 'role.compMod', {}); const location = _.get(compMod, 'location', {}); const oldLocation = location.old; @@ -150,18 +147,13 @@ const getModifyLocationScriptDto = const getModifyCollectionScriptDtos = (app, ddlProvider) => ({ collection, dbVersion }) => { - const _ = app.require('lodash'); - const compMod = _.get(collection, 'role.compMod', {}); const fullCollectionName = generateFullEntityName({ entity: collection, dbVersion }); const alterTableNameScript = ddlProvider.alterTableName(hydrateAlterTableName(compMod)); - const hydratedSerDeProperties = hydrateSerDeProperties(_)(compMod, fullCollectionName); + const hydratedSerDeProperties = hydrateSerDeProperties(compMod, fullCollectionName); const checkConstraintsDtos = getModifyCheckConstraintsScriptDtos(ddlProvider)(fullCollectionName, collection); - const tablePropertiesScriptDtos = getModifiedTablePropertiesScriptDtos( - _, - ddlProvider, - )({ collection, dbVersion }); + const tablePropertiesScriptDtos = getModifiedTablePropertiesScriptDtos(ddlProvider)({ collection, dbVersion }); const serDeProperties = ddlProvider.alterSerDeProperties(hydratedSerDeProperties); const modifyLocationScriptDto = getModifyLocationScriptDto(app, ddlProvider)({ collection, dbVersion }); const unityEntityTagsDtos = getModifyUnityEntityTagsScriptDtos({ ddlProvider })({ @@ -189,9 +181,8 @@ const getModifyCollectionScriptDtos = * }} * */ const generateModifyCollectionScript = app => (collection, definitions, ddlProvider, dbVersion) => { - const _ = app.require('lodash'); const compMod = _.get(collection, 'role.compMod', {}); - const shouldDropAndRecreate = getIsChangeProperties(_)(compMod, tableProperties); + const shouldDropAndRecreate = getIsChangeProperties(compMod, tableProperties); if (shouldDropAndRecreate) { return getDropAndRecreateCollectionScriptDtos(app, ddlProvider)(collection, definitions, dbVersion); diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/modifyPropertiesHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/modifyPropertiesHelper.js index 0e597279..3ba5e2ba 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/modifyPropertiesHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/modifyPropertiesHelper.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { DiffMap } = require('../../types/DiffMap'); const { getTablePropertiesClause } = require('../../../helpers/tableHelper'); const { AlterScriptDto } = require('../../types/AlterScriptDto'); @@ -38,8 +39,8 @@ const buildTablePropertiesDiffMap = tableProperties => { return diffMap; }; -const getAddTablePropertyScriptDto = (_, ddlProvider) => (properties, fullCollectionName) => { - const addPropertiesDdlString = getTablePropertiesClause(_)(properties); +const getAddTablePropertyScriptDto = ddlProvider => (properties, fullCollectionName) => { + const addPropertiesDdlString = getTablePropertiesClause(properties); const ddlConfig = { name: fullCollectionName, properties: addPropertiesDdlString, @@ -48,12 +49,12 @@ const getAddTablePropertyScriptDto = (_, ddlProvider) => (properties, fullCollec return AlterScriptDto.getInstance([script], true, false); }; -const getDeleteTablePropertyScriptDto = (_, ddlProvider) => (properties, fullCollectionName) => { +const getDeleteTablePropertyScriptDto = ddlProvider => (properties, fullCollectionName) => { const propertiesWithNoValues = properties.map(prop => ({ ...prop, propertyValue: undefined, })); - const dropPropertiesDdlString = getTablePropertiesClause(_)(propertiesWithNoValues); + const dropPropertiesDdlString = getTablePropertiesClause(propertiesWithNoValues); const ddlConfig = { name: fullCollectionName, properties: dropPropertiesDdlString, @@ -63,24 +64,24 @@ const getDeleteTablePropertyScriptDto = (_, ddlProvider) => (properties, fullCol }; const getModifiedTablePropertiesScriptDtos = - (_, ddlProvider) => + ddlProvider => ({ collection, dbVersion }) => { const compMod = _.get(collection, 'role.compMod', {}); const tableProperties = compMod.tableProperties || {}; const fullCollectionName = generateFullEntityName({ entity: collection, dbVersion }); const propertiesDiffMap = buildTablePropertiesDiffMap(tableProperties); - const addedPropertiesScriptDto = getAddTablePropertyScriptDto(_, ddlProvider)( + const addedPropertiesScriptDto = getAddTablePropertyScriptDto(ddlProvider)( propertiesDiffMap.added, fullCollectionName, ); - const deletedPropertiesScriptDto = getDeleteTablePropertyScriptDto(_, ddlProvider)( + const deletedPropertiesScriptDto = getDeleteTablePropertyScriptDto(ddlProvider)( propertiesDiffMap.deleted, fullCollectionName, ); const modifiedPropertiesScriptDtos = propertiesDiffMap.modified.map(({ newItem }) => { - return getAddTablePropertyScriptDto(_, ddlProvider)([newItem], fullCollectionName); + return getAddTablePropertyScriptDto(ddlProvider)([newItem], fullCollectionName); }); return [addedPropertiesScriptDto, deletedPropertiesScriptDto, ...modifiedPropertiesScriptDtos].filter(Boolean); diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js index c258c765..bd5d1828 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js @@ -1,10 +1,11 @@ +const _ = require('lodash'); const { generateFullEntityName, getEntityNameFromCollection, prepareName } = require('../../../utils/general'); const { AlterScriptDto } = require('../../types/AlterScriptDto'); /** * @return {(collection: Object, guid: string) => Object | undefined} * */ -const getPropertyNameByGuid = _ => (collection, guid) => { +const getPropertyNameByGuid = (collection, guid) => { const propertyInArray = _.toPairs(collection?.role?.properties) .filter(([name, jsonSchema]) => jsonSchema.GUID === guid) .map(([name]) => name); @@ -17,14 +18,14 @@ const getPropertyNameByGuid = _ => (collection, guid) => { /** * @return {(collection: Object, guids: string[]) => Array} * */ -const getPropertiesNamesByGuids = _ => (collection, guids) => { - return guids.map(guid => getPropertyNameByGuid(_)(collection, guid)).filter(Boolean); +const getPropertiesNamesByGuids = (collection, guids) => { + return guids.map(guid => getPropertyNameByGuid(collection, guid)).filter(Boolean); }; /** * @return {(collection: Object) => boolean} * */ -const didCompositePkChange = _ => collection => { +const didCompositePkChange = collection => { const pkDto = collection?.role?.compMod?.primaryKey || {}; const newPrimaryKeys = pkDto.new || []; const oldPrimaryKeys = pkDto.old || []; @@ -34,17 +35,17 @@ const didCompositePkChange = _ => collection => { if (newPrimaryKeys.length === 0 && oldPrimaryKeys.length === 0) { return false; } - const areKeyArraysEqual = _(oldPrimaryKeys).differenceWith(newPrimaryKeys, _.isEqual).isEmpty(); - return !areKeyArraysEqual; + + return !_.isEmpty(_.differenceWith(oldPrimaryKeys, newPrimaryKeys, _.isEqual)); }; /** * @return {({collection, dbVersion }: {collection: Object, dbVersion: string }) => Array} * */ const getAddCompositePkScripts = - (_, ddlProvider) => + ddlProvider => ({ collection, dbVersion }) => { - const didPkChange = didCompositePkChange(_)(collection); + const didPkChange = didCompositePkChange(collection); if (!didPkChange) { return []; } @@ -57,7 +58,7 @@ const getAddCompositePkScripts = .map(newPk => { const compositePrimaryKey = newPk.compositePrimaryKey || []; const guidsOfColumnsInPk = compositePrimaryKey.map(compositePkEntry => compositePkEntry.keyId); - const columnNamesForDDL = getPropertiesNamesByGuids(_)(collection, guidsOfColumnsInPk); + const columnNamesForDDL = getPropertiesNamesByGuids(collection, guidsOfColumnsInPk); if (!columnNamesForDDL.length) { return undefined; } @@ -78,9 +79,9 @@ const getAddCompositePkScripts = * @return {({collection, dbVersion }: {collection: Object, dbVersion: string }) => Array} * */ const getDropCompositePkScripts = - (_, ddlProvider) => + ddlProvider => ({ collection, dbVersion }) => { - const didPkChange = didCompositePkChange(_)(collection); + const didPkChange = didCompositePkChange(collection); if (!didPkChange) { return []; } @@ -103,10 +104,10 @@ const getDropCompositePkScripts = * @return {({collection, dbVersion }: {collection: Object, dbVersion: string }) => Array} * */ const getModifyCompositePkScripts = - (_, ddlProvider) => + ddlProvider => ({ collection, dbVersion }) => { - const dropCompositePkScripts = getDropCompositePkScripts(_, ddlProvider)({ collection, dbVersion }); - const addCompositePkScripts = getAddCompositePkScripts(_, ddlProvider)({ collection, dbVersion }); + const dropCompositePkScripts = getDropCompositePkScripts(ddlProvider)({ collection, dbVersion }); + const addCompositePkScripts = getAddCompositePkScripts(ddlProvider)({ collection, dbVersion }); return [...dropCompositePkScripts, ...addCompositePkScripts]; }; @@ -115,7 +116,7 @@ const getModifyCompositePkScripts = * @return {({collection, dbVersion }: {collection: Object, dbVersion: string }) => Array} * */ const getAddPkScripts = - (_, ddlProvider) => + ddlProvider => ({ collection, dbVersion }) => { const fullTableName = generateFullEntityName({ entity: collection, dbVersion }); const constraintName = getEntityNameFromCollection(collection) + '_pk'; @@ -146,7 +147,7 @@ const getAddPkScripts = * @return {({collection, dbVersion }: {collection: Object, dbVersion: string }) => Array} * */ const getDropPkScripts = - (_, ddlProvider) => + ddlProvider => ({ collection, dbVersion }) => { const fullTableName = generateFullEntityName({ entity: collection, dbVersion }); @@ -176,10 +177,10 @@ const getDropPkScripts = * @return {({collection, dbVersion }: {collection: Object, dbVersion: string }) => Array} * */ const getModifyPkScripts = - (_, ddlProvider) => + ddlProvider => ({ collection, dbVersion }) => { - const dropPkScripts = getDropPkScripts(_, ddlProvider)({ collection, dbVersion }); - const addPkScripts = getAddPkScripts(_, ddlProvider)({ collection, dbVersion }); + const dropPkScripts = getDropPkScripts(ddlProvider)({ collection, dbVersion }); + const addPkScripts = getAddPkScripts(ddlProvider)({ collection, dbVersion }); return [...dropPkScripts, ...addPkScripts]; }; @@ -188,10 +189,10 @@ const getModifyPkScripts = * @return {({collection, dbVersion }: {collection: Object, dbVersion: string }) => Array} * */ const getModifyPkConstraintsScripts = - (_, ddlProvider) => + ddlProvider => ({ collection, dbVersion }) => { - const modifyCompositePkScripts = getModifyCompositePkScripts(_, ddlProvider)({ collection, dbVersion }); - const modifyPkScripts = getModifyPkScripts(_, ddlProvider)({ collection, dbVersion }); + const modifyCompositePkScripts = getModifyCompositePkScripts(ddlProvider)({ collection, dbVersion }); + const modifyPkScripts = getModifyPkScripts(ddlProvider)({ collection, dbVersion }); return [...modifyCompositePkScripts, ...modifyPkScripts]; }; diff --git a/forward_engineering/api.js b/forward_engineering/api.js index 0d974b42..bf79f665 100644 --- a/forward_engineering/api.js +++ b/forward_engineering/api.js @@ -1,5 +1,6 @@ 'use strict'; +const _ = require('lodash'); const { getDatabaseStatement, getUseCatalogStatement } = require('./helpers/databaseHelper'); const { getCleanedUrl, buildScript, isSupportUnityCatalog, getDBVersionNumber } = require('./utils/general'); const fetchRequestHelper = require('../reverse_engineering/helpers/fetchRequestHelper'); @@ -164,7 +165,7 @@ const getScriptAndSampleResponse = (script, sample) => { * */ const getContainerScriptWithSeparateBuckets = async (app, data) => { const parsedData = parseDataForContainerLevelScript(data); - const sampleGenerationOptions = getSampleGenerationOptions(app, data); + const sampleGenerationOptions = getSampleGenerationOptions(data); const scriptData = await buildContainerLevelFEScriptDto( data, @@ -189,9 +190,8 @@ const getContainerScriptWithSeparateBuckets = async (app, data) => { * @return {Promise>} * */ const getContainerScriptWithNotSeparateBuckets = async (app, data) => { - const _ = app.require('lodash'); const parsedData = parseDataForContainerLevelScript(data); - const sampleGenerationOptions = getSampleGenerationOptions(app, data); + const sampleGenerationOptions = getSampleGenerationOptions(data); const scriptData = await buildContainerLevelFEScriptDto( data, app, @@ -206,7 +206,7 @@ const getContainerScriptWithNotSeparateBuckets = async (app, data) => { } if (parsedData.jsonData) { - const demoSample = generateSampleForDemonstration(app, parsedData, 'container'); + const demoSample = generateSampleForDemonstration(parsedData, 'container'); return getScriptAndSampleResponse(scripts, demoSample); } @@ -214,7 +214,7 @@ const getContainerScriptWithNotSeparateBuckets = async (app, data) => { const sampleScripts = []; for (const entityData of Object.values(parsedData.entitiesData || {})) { - const samples = await generateSamplesForEntity(_)(entityData); + const samples = await generateSamplesForEntity(entityData); sampleScripts.push(...samples); } @@ -237,11 +237,11 @@ module.exports = { callback(null, scripts); } else { const scripts = buildEntityLevelFEScript(data, app)(parsedData); - const sampleGenerationOptions = getSampleGenerationOptions(app, data); + const sampleGenerationOptions = getSampleGenerationOptions(data); if (!sampleGenerationOptions.isSampleGenerationRequired) { return callback(null, scripts); } - const demoSample = generateSampleForDemonstration(app, parsedData, 'entity'); + const demoSample = generateSampleForDemonstration(parsedData, 'entity'); return callback(null, getScriptAndSampleResponse(scripts, demoSample)); } } catch (e) { @@ -325,9 +325,8 @@ module.exports = { entitiesData: data.entitiesData, }; - const _ = app.require('lodash'); try { - await fetchRequestHelper.fetchApplyToInstance(_)(connectionData, logger); + await fetchRequestHelper.fetchApplyToInstance(connectionData, logger); cb(); } catch (err) { logger.log('error', { message: err.message, stack: err.stack, error: err }, 'Apply to instance'); diff --git a/forward_engineering/ddlProvider/ddlProvider.js b/forward_engineering/ddlProvider/ddlProvider.js index b76515e6..623a2901 100644 --- a/forward_engineering/ddlProvider/ddlProvider.js +++ b/forward_engineering/ddlProvider/ddlProvider.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const templates = require('./ddlTemplates'); const { getFullEntityName, @@ -15,7 +16,6 @@ const viewHelper = require('../helpers/viewHelper'); module.exports = app => { const { assignTemplates } = app.require('@hackolade/ddl-fe-utils'); - const _ = app.require('lodash'); return { dropView(name) { @@ -58,12 +58,11 @@ module.exports = app => { schemaBinding: '', comment: viewHelper.getCommentStatement(schema.description), tablePropertyStatements: tableProperties.length - ? `TBLPROPERTIES (${getTablePropertiesClause(_)(tableProperties)})` + ? `TBLPROPERTIES (${getTablePropertiesClause(tableProperties)})` : '', query: schema.selectStatement ? `AS ${schema.selectStatement}` : viewHelper.getTableSelectStatement({ - _, collectionRefsDefinitionsMap, columns, }), diff --git a/forward_engineering/helpers/constrainthelper.js b/forward_engineering/helpers/constrainthelper.js index 3b8b4b37..6d1c9276 100644 --- a/forward_engineering/helpers/constrainthelper.js +++ b/forward_engineering/helpers/constrainthelper.js @@ -9,7 +9,7 @@ const getPrimaryKeyOptions = (entityJsonSchema, keysNames) => { return entityJsonSchema.properties?.[primaryKeyFieldName]?.primaryKeyOptions; }; -const getPrimaryKeyStatement = _ => (entityJsonSchema, keysNames, deactivatedColumnNames, isParentItemActivated) => { +const getPrimaryKeyStatement = (entityJsonSchema, keysNames, deactivatedColumnNames, isParentItemActivated) => { const getStatement = ({ keys, constraintName, notEnforced, deferrable, initiallyDeferrable, noRely }) => { let statement = ''; statement += constraintName ? `CONSTRAINT ${constraintName} ` : ''; @@ -36,7 +36,7 @@ const getPrimaryKeyStatement = _ => (entityJsonSchema, keysNames, deactivatedCol return getStatement({ ...options, keys: keysNames.join(', ') }); } - const { isAllKeysDeactivated, keysString } = commentDeactivatedInlineKeys(_)(keysNames, deactivatedColumnNames); + const { isAllKeysDeactivated, keysString } = commentDeactivatedInlineKeys(keysNames, deactivatedColumnNames); if (isAllKeysDeactivated) { return '-- ' + getStatement({ ...options, keys: keysString }); } diff --git a/forward_engineering/helpers/entityHelpers/checkConstraintHelper.js b/forward_engineering/helpers/entityHelpers/checkConstraintHelper.js index 4518cd41..6c8f7863 100644 --- a/forward_engineering/helpers/entityHelpers/checkConstraintHelper.js +++ b/forward_engineering/helpers/entityHelpers/checkConstraintHelper.js @@ -2,7 +2,6 @@ const { wrapInTicks } = require('../../utils/general'); /** * @typedef GetStatementsFunction - * @param _ {Object} * @param tableName {string} * @returns Array */ diff --git a/forward_engineering/helpers/entityHelpers/primaryKeyHelper.js b/forward_engineering/helpers/entityHelpers/primaryKeyHelper.js index 595face5..924d553c 100644 --- a/forward_engineering/helpers/entityHelpers/primaryKeyHelper.js +++ b/forward_engineering/helpers/entityHelpers/primaryKeyHelper.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { prepareName, getName, getFullEntityName } = require('../../utils/general'); /** @@ -12,7 +13,7 @@ const doesTableHaveAnyPK = entityJsonSchema => { /** * @return {(entitiesJsonSchema: Object, dbName: string) => string} * */ -const getCreatePKConstraintScript = (_, ddlProvider) => (entityJsonSchema, dbName) => { +const getCreatePKConstraintScript = ddlProvider => (entityJsonSchema, dbName) => { const pkColumnNames = _.toPairs(entityJsonSchema.properties) .filter(([name, jsonSchema]) => Boolean(jsonSchema.primaryKey)) .map(([name]) => name) @@ -33,10 +34,9 @@ const getCreatePKConstraintsScript = app => (entityJsonSchema, dbName) => { return ''; } - const _ = app.require('lodash'); const ddlProvider = require('../../ddlProvider/ddlProvider')(app); - return getCreatePKConstraintScript(_, ddlProvider)(entityJsonSchema, dbName); + return getCreatePKConstraintScript(ddlProvider)(entityJsonSchema, dbName); }; module.exports = { diff --git a/forward_engineering/helpers/feScriptBuilder.js b/forward_engineering/helpers/feScriptBuilder.js index 8b7ea132..7286e89d 100644 --- a/forward_engineering/helpers/feScriptBuilder.js +++ b/forward_engineering/helpers/feScriptBuilder.js @@ -27,6 +27,7 @@ * }} ContainerLevelEntityDto * */ +const _ = require('lodash'); const { getDatabaseStatement, getUseCatalogStatement } = require('./databaseHelper'); const { getCreateRelationshipScripts } = require('./relationshipHelper'); const { getTableStatement } = require('./tableHelper'); @@ -86,7 +87,6 @@ const buildEntityLevelFEScript = entityData, modelData, }) => { - const _ = app.require('lodash'); const dbVersion = data.modelData[0].dbVersion; const arePkFkConstraintsAvailable = isSupportUnityCatalog(dbVersion); const areNotNullConstraintsAvailable = isSupportNotNullConstraints(dbVersion); @@ -103,7 +103,7 @@ const buildEntityLevelFEScript = null, dbVersion, ); - const indexScript = getIndexes(_)(containerData, entityData, jsonSchema, definitions); + const indexScript = getIndexes(containerData, entityData, jsonSchema, definitions); let relationshipScripts = []; if (arePkFkConstraintsAvailable) { @@ -128,10 +128,9 @@ const buildEntityLevelFEScript = /** * @param data {CoreData} - * @param _ {any} * @return {Array} * */ -const getContainerLevelViewScriptDtos = (data, provider, _) => { +const getContainerLevelViewScriptDtos = (data, provider) => { return data.views .map(viewId => { const viewSchema = JSON.parse(data.jsonSchema[viewId] || '{}'); @@ -161,27 +160,30 @@ const getContainerLevelViewScriptDtos = (data, provider, _) => { * entityId: string, * }) => Promise} */ -const getSampleScriptForContainerLevelScript = - _ => - async ({ data, includeSamplesInEntityScripts, entitiesJsonSchema, entityId }) => { - const sampleScripts = []; - if (includeSamplesInEntityScripts) { - const { jsonData, entitiesData } = getDataForSampleGeneration(data, entitiesJsonSchema); - const entityJsonSchema = entitiesJsonSchema[entityId] || {}; - if (jsonData) { - const demoSampleJsonData = jsonData[entityId] || {}; - const demoSample = generateSamplesScript(_)(entityJsonSchema, [demoSampleJsonData]); - sampleScripts.push(demoSample); - } - if (entitiesData) { - const entityData = entitiesData[entityId]; - const samples = await generateSamplesForEntity(_)(entityData); - sampleScripts.push(...samples); - } +const getSampleScriptForContainerLevelScript = async ({ + data, + includeSamplesInEntityScripts, + entitiesJsonSchema, + entityId, +}) => { + const sampleScripts = []; + if (includeSamplesInEntityScripts) { + const { jsonData, entitiesData } = getDataForSampleGeneration(data, entitiesJsonSchema); + const entityJsonSchema = entitiesJsonSchema[entityId] || {}; + if (jsonData) { + const demoSampleJsonData = jsonData[entityId] || {}; + const demoSample = generateSamplesScript(entityJsonSchema, [demoSampleJsonData]); + sampleScripts.push(demoSample); } + if (entitiesData) { + const entityData = entitiesData[entityId]; + const samples = await generateSamplesForEntity(entityData); + sampleScripts.push(...samples); + } + } - return sampleScripts.join('\n\n'); - }; + return sampleScripts.join('\n\n'); +}; /** * @param data {CoreData} @@ -202,7 +204,6 @@ const getContainerLevelEntitiesScriptDtos = includeSamplesInEntityScripts, relatedSchemas, }) => { - const _ = app.require('lodash'); const scriptDtos = []; for (const entityId of data.entities) { @@ -222,7 +223,7 @@ const getContainerLevelEntitiesScriptDtos = dbVersion, ); - const indexScript = getIndexes(_)(...createTableStatementArgs); + const indexScript = getIndexes(...createTableStatementArgs); let relationshipScripts = []; if (includeRelationshipsInEntityScripts && arePkFkConstraintsAvailable) { @@ -236,7 +237,7 @@ const getContainerLevelEntitiesScriptDtos = }); } - const sampleScript = await getSampleScriptForContainerLevelScript(_)({ + const sampleScript = await getSampleScriptForContainerLevelScript({ data, entitiesJsonSchema, entityId, @@ -289,14 +290,13 @@ const buildContainerLevelFEScriptDto = includeSamplesInEntityScripts, relatedSchemas, }) => { - const _ = app.require('lodash'); const dbVersion = data.modelData[0].dbVersion; const arePkFkConstraintsAvailable = isSupportUnityCatalog(dbVersion); const areNotNullConstraintsAvailable = isSupportNotNullConstraints(dbVersion); const provider = require('../ddlProvider/ddlProvider')(app); const useCatalogStatement = arePkFkConstraintsAvailable ? getUseCatalogStatement(containerData) : ''; - const viewsScriptDtos = getContainerLevelViewScriptDtos(data, provider, _); + const viewsScriptDtos = getContainerLevelViewScriptDtos(data, provider); const databaseStatement = getDatabaseStatement(containerData, arePkFkConstraintsAvailable, dbVersion); const entityScriptDtos = await getContainerLevelEntitiesScriptDtos( app, diff --git a/forward_engineering/helpers/indexHelper.js b/forward_engineering/helpers/indexHelper.js index 10662087..bdf018a1 100644 --- a/forward_engineering/helpers/indexHelper.js +++ b/forward_engineering/helpers/indexHelper.js @@ -1,5 +1,6 @@ 'use strict'; +const _ = require('lodash'); const { getTab, buildStatement, prepareName, getName, replaceSpaceWithUnderscore } = require('../utils/general'); const schemaHelper = require('./jsonSchemaHelper'); const { getItemByPath } = require('./jsonSchemaHelper'); @@ -11,9 +12,9 @@ const getIndexStatement = ({ tableName, dbName, columns, options, isActivated }) )(options, `OPTIONS (${options})`)(true, ';')(); }; -const getIndexKeys = _ => (keys, jsonSchema, definitions) => { +const getIndexKeys = (keys, jsonSchema, definitions) => { if (!Array.isArray(keys)) { - return ''; + return { isIndexActivated: false, columns: '' }; } const paths = schemaHelper.getPathsByIds( keys.map(key => key.keyId), @@ -45,7 +46,7 @@ const getIndexKeys = _ => (keys, jsonSchema, definitions) => { /** * @return {(containerData: any, entityData: any, jsonSchema: any, definitions: any) => string} * */ -const getIndexes = _ => (containerData, entityData, jsonSchema, definitions) => { +const getIndexes = (containerData, entityData, jsonSchema, definitions) => { const dbData = getTab(0, containerData); const dbName = replaceSpaceWithUnderscore(prepareName(getName(dbData))); const tableData = getTab(0, entityData); @@ -54,7 +55,7 @@ const getIndexes = _ => (containerData, entityData, jsonSchema, definitions) => return indexesData .filter(indexData => !_.isEmpty(indexData.forColumns)) .map(indexData => { - const { columns, isIndexActivated = true } = getIndexKeys(_)(indexData.forColumns, jsonSchema, definitions); + const { columns, isIndexActivated = true } = getIndexKeys(indexData.forColumns, jsonSchema, definitions); return getIndexStatement({ dbName: dbName || 'default', tableName: tableName, diff --git a/forward_engineering/helpers/relationshipHelper.js b/forward_engineering/helpers/relationshipHelper.js index c2751669..f8dc9d53 100644 --- a/forward_engineering/helpers/relationshipHelper.js +++ b/forward_engineering/helpers/relationshipHelper.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { getFullEntityName, replaceSpaceWithUnderscore, @@ -11,7 +12,7 @@ const { /** * @return {(collection: Object, propertiesIds: Array) => Array} * */ -const getCollectionPropertyNamesByIds = _ => (collection, propertiesIds) => { +const getCollectionPropertyNamesByIds = (collection, propertiesIds) => { return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => propertiesIds.includes(jsonSchema.GUID)) .map(([name]) => name); @@ -41,7 +42,7 @@ const getParentFieldIds = relationship => { * @returns {({ relationship: Object, jsonSchemas: Record, relatedSchemas?: Record }) => string} */ const createSingleRelationship = - (_, ddlProvider) => + ddlProvider => ({ relationship, jsonSchemas, relatedSchemas }) => { const parentTable = jsonSchemas[relationship.parentCollection] ?? relatedSchemas?.[relationship.parentCollection]; @@ -55,8 +56,8 @@ const createSingleRelationship = const childFieldIds = getChildFieldIds(relationship); const parentFieldIds = getParentFieldIds(relationship); - const parentColumnNames = getCollectionPropertyNamesByIds(_)(parentTable, parentFieldIds); - const childColumnNames = getCollectionPropertyNamesByIds(_)(childTable, childFieldIds); + const parentColumnNames = getCollectionPropertyNamesByIds(parentTable, parentFieldIds); + const childColumnNames = getCollectionPropertyNamesByIds(childTable, childFieldIds); if (!parentColumnNames?.length || !childColumnNames?.length) { return ''; } @@ -85,14 +86,10 @@ const createSingleRelationship = const getCreateRelationshipScripts = app => ({ relationships, jsonSchemas, relatedSchemas }) => { - const _ = app.require('lodash'); const ddlProvider = require('../ddlProvider/ddlProvider')(app); return relationships .map(relationship => - createSingleRelationship( - _, - ddlProvider, - )({ + createSingleRelationship(ddlProvider)({ relationship, jsonSchemas, relatedSchemas, diff --git a/forward_engineering/helpers/tableHelper.js b/forward_engineering/helpers/tableHelper.js index 94ed8822..4601ee31 100644 --- a/forward_engineering/helpers/tableHelper.js +++ b/forward_engineering/helpers/tableHelper.js @@ -1,5 +1,6 @@ 'use strict'; +const _ = require('lodash'); const { buildStatement, getName, @@ -24,103 +25,57 @@ const constraintHelper = require('./constrainthelper'); const { getColumnTagsStatement } = require('./unityTagsHelper'); const { Runtime } = require('../enums/runtime'); -const getCreateStatement = - _ => - ({ - fullTableName, - isTemporary, - isExternal, - using, - likeStatement, - columnStatement, - primaryKeyStatement, - foreignKeyStatement, - comment, - partitionedByKeys, - clusteredKeys, - sortedKeys, - numBuckets, - skewedStatement, - rowFormatStatement, - storedAsStatement, - location, - tableProperties, - selectStatement, - isActivated, - tableOptions, - orReplace, - ifNotExists, - }) => { - const temporary = isTemporary ? 'TEMPORARY' : ''; - const external = isExternal ? 'EXTERNAL' : ''; - const orReplaceStatement = orReplace ? 'OR REPLACE' : ''; - const isNotExistsStatement = ifNotExists ? ' IF NOT EXISTS' : ''; - const tempExtStatement = - ' ' + - [orReplaceStatement, temporary, external] - .filter(d => d) - .map(item => item + ' ') - .join(''); - - if (using && likeStatement) { - return getCreateLikeStatement(_)({ - tempExtStatement, - fullTableName, - using, - likeStatement, - columnStatement, - primaryKeyStatement, - foreignKeyStatement, - comment, - partitionedByKeys, - clusteredKeys, - sortedKeys, - numBuckets, - skewedStatement, - rowFormatStatement, - storedAsStatement, - location, - tableProperties, - selectStatement, - isActivated, - tableOptions, - isNotExistsStatement, - }); - } - - if (using) { - return getCreateUsingStatement(_)({ - tempExtStatement, - fullTableName, - using, - columnStatement, - primaryKeyStatement, - foreignKeyStatement, - comment, - partitionedByKeys, - clusteredKeys, - sortedKeys, - numBuckets, - skewedStatement, - rowFormatStatement, - storedAsStatement, - location, - tableProperties, - selectStatement, - isActivated, - tableOptions, - isNotExistsStatement, - }); - } - - return getCreateHiveStatement(_)({ +const getCreateStatement = ({ + fullTableName, + isTemporary, + isExternal, + using, + likeStatement, + columnStatement, + primaryKeyStatement, + foreignKeyStatement, + comment, + partitionedByKeys, + clusteredKeys, + sortedKeys, + numBuckets, + skewedStatement, + rowFormatStatement, + storedAsStatement, + location, + tableProperties, + selectStatement, + isActivated, + tableOptions, + orReplace, + ifNotExists, +}) => { + const temporary = isTemporary ? 'TEMPORARY' : ''; + const external = isExternal ? 'EXTERNAL' : ''; + const orReplaceStatement = orReplace ? 'OR REPLACE' : ''; + const isNotExistsStatement = ifNotExists ? ' IF NOT EXISTS' : ''; + const tempExtStatement = + ' ' + + [orReplaceStatement, temporary, external] + .filter(d => d) + .map(item => item + ' ') + .join(''); + + if (using && likeStatement) { + return getCreateLikeStatement({ tempExtStatement, fullTableName, + using, + likeStatement, columnStatement, primaryKeyStatement, foreignKeyStatement, comment, partitionedByKeys, + clusteredKeys, + sortedKeys, + numBuckets, + skewedStatement, rowFormatStatement, storedAsStatement, location, @@ -130,51 +85,34 @@ const getCreateStatement = tableOptions, isNotExistsStatement, }); - }; + } -const getCreateUsingStatement = - _ => - ({ - tempExtStatement, - fullTableName, - using, - columnStatement, - primaryKeyStatement, - comment, - partitionedByKeys, - clusteredKeys, - sortedKeys, - numBuckets, - location, - tableProperties, - selectStatement, - isActivated, - tableOptions, - isNotExistsStatement, - rowFormatStatement, - storedAsStatement, - }) => { - return buildStatement(`CREATE${tempExtStatement}TABLE${isNotExistsStatement} ${fullTableName} (`, isActivated)( + if (using) { + return getCreateUsingStatement({ + tempExtStatement, + fullTableName, + using, columnStatement, - columnStatement + (primaryKeyStatement ? ',' : ''), - )(primaryKeyStatement, primaryKeyStatement)(true, ')')(using, `${getUsing(using)}`)( - rowFormatStatement, - `ROW FORMAT ${rowFormatStatement}`, - )(storedAsStatement, storedAsStatement)(partitionedByKeys, `PARTITIONED BY (${partitionedByKeys})`)( + primaryKeyStatement, + foreignKeyStatement, + comment, + partitionedByKeys, clusteredKeys, - `CLUSTERED BY (${clusteredKeys})`, - )(sortedKeys && clusteredKeys, `SORTED BY (${sortedKeys})`)( - numBuckets && clusteredKeys, - `INTO ${numBuckets} BUCKETS`, - )(location, `LOCATION '${location}'`)(comment, `COMMENT '${encodeStringLiteral(comment)}'`)( + sortedKeys, + numBuckets, + skewedStatement, + rowFormatStatement, + storedAsStatement, + location, tableProperties, - `TBLPROPERTIES (${getTablePropertiesClause(_)(tableProperties)})`, - )(tableOptions, `OPTIONS ${tableOptions}`)(selectStatement, `AS ${selectStatement}`)(true, ';')(); - }; + selectStatement, + isActivated, + tableOptions, + isNotExistsStatement, + }); + } -const getCreateHiveStatement = - _ => - ({ + return getCreateHiveStatement({ tempExtStatement, fullTableName, columnStatement, @@ -190,71 +128,126 @@ const getCreateHiveStatement = isActivated, tableOptions, isNotExistsStatement, - }) => { - const isAddBrackets = columnStatement || primaryKeyStatement || foreignKeyStatement; - return buildStatement(`CREATE${tempExtStatement}TABLE${isNotExistsStatement} ${fullTableName} `, isActivated)( - isAddBrackets, - '(', - )(columnStatement, columnStatement + (primaryKeyStatement ? ',' : ''))( - primaryKeyStatement, - primaryKeyStatement, - )(foreignKeyStatement, foreignKeyStatement)(isAddBrackets, ')')( - comment, - `COMMENT '${encodeStringLiteral(comment)}'`, - )(partitionedByKeys, `PARTITIONED BY (${partitionedByKeys})`)( - rowFormatStatement, - `ROW FORMAT ${rowFormatStatement}`, - )(storedAsStatement, storedAsStatement)(location, `LOCATION '${location}'`)( - tableProperties, - `TBLPROPERTIES (${getTablePropertiesClause(_)(tableProperties)})`, - )(tableOptions, `OPTIONS ${tableOptions}`)(selectStatement, `AS ${selectStatement}`)(true, ';')(); - }; + }); +}; -const getCreateLikeStatement = - _ => - ({ - tempExtStatement, - fullTableName, - using, +const getCreateUsingStatement = ({ + tempExtStatement, + fullTableName, + using, + columnStatement, + primaryKeyStatement, + comment, + partitionedByKeys, + clusteredKeys, + sortedKeys, + numBuckets, + location, + tableProperties, + selectStatement, + isActivated, + tableOptions, + isNotExistsStatement, + rowFormatStatement, + storedAsStatement, +}) => { + return buildStatement(`CREATE${tempExtStatement}TABLE${isNotExistsStatement} ${fullTableName} (`, isActivated)( columnStatement, - primaryKeyStatement, - foreignKeyStatement, + columnStatement + (primaryKeyStatement ? ',' : ''), + )(primaryKeyStatement, primaryKeyStatement)(true, ')')(using, `${getUsing(using)}`)( rowFormatStatement, - storedAsStatement, - location, + `ROW FORMAT ${rowFormatStatement}`, + )(storedAsStatement, storedAsStatement)(partitionedByKeys, `PARTITIONED BY (${partitionedByKeys})`)( + clusteredKeys, + `CLUSTERED BY (${clusteredKeys})`, + )(sortedKeys && clusteredKeys, `SORTED BY (${sortedKeys})`)( + numBuckets && clusteredKeys, + `INTO ${numBuckets} BUCKETS`, + )(location, `LOCATION '${location}'`)(comment, `COMMENT '${encodeStringLiteral(comment)}'`)( tableProperties, + `TBLPROPERTIES (${getTablePropertiesClause(tableProperties)})`, + )(tableOptions, `OPTIONS ${tableOptions}`)(selectStatement, `AS ${selectStatement}`)(true, ';')(); +}; + +const getCreateHiveStatement = ({ + tempExtStatement, + fullTableName, + columnStatement, + primaryKeyStatement, + foreignKeyStatement, + comment, + partitionedByKeys, + rowFormatStatement, + storedAsStatement, + location, + tableProperties, + selectStatement, + isActivated, + tableOptions, + isNotExistsStatement, +}) => { + const isAddBrackets = columnStatement || primaryKeyStatement || foreignKeyStatement; + return buildStatement(`CREATE${tempExtStatement}TABLE${isNotExistsStatement} ${fullTableName} `, isActivated)( + isAddBrackets, + '(', + )(columnStatement, columnStatement + (primaryKeyStatement ? ',' : ''))(primaryKeyStatement, primaryKeyStatement)( + foreignKeyStatement, + foreignKeyStatement, + )(isAddBrackets, ')')(comment, `COMMENT '${encodeStringLiteral(comment)}'`)( + partitionedByKeys, + `PARTITIONED BY (${partitionedByKeys})`, + )(rowFormatStatement, `ROW FORMAT ${rowFormatStatement}`)(storedAsStatement, storedAsStatement)( + location, + `LOCATION '${location}'`, + )(tableProperties, `TBLPROPERTIES (${getTablePropertiesClause(tableProperties)})`)( + tableOptions, + `OPTIONS ${tableOptions}`, + )(selectStatement, `AS ${selectStatement}`)(true, ';')(); +}; + +const getCreateLikeStatement = ({ + tempExtStatement, + fullTableName, + using, + columnStatement, + primaryKeyStatement, + foreignKeyStatement, + rowFormatStatement, + storedAsStatement, + location, + tableProperties, + isActivated, + isNotExistsStatement, + tableOptions, + likeStatement, +}) => { + return buildStatement( + `CREATE${tempExtStatement}TABLE${isNotExistsStatement} ${fullTableName} ${likeStatement} (`, isActivated, - isNotExistsStatement, + )(columnStatement, columnStatement + (primaryKeyStatement ? ',' : ''))(primaryKeyStatement, primaryKeyStatement)( + foreignKeyStatement, + foreignKeyStatement, + )(true, ')')(using, `${getUsing(using)}`)(rowFormatStatement, `ROW FORMAT ${rowFormatStatement}`)( + storedAsStatement, + storedAsStatement, + )(tableProperties, `TBLPROPERTIES (${getTablePropertiesClause(tableProperties)})`)( tableOptions, - likeStatement, - }) => { - return buildStatement( - `CREATE${tempExtStatement}TABLE${isNotExistsStatement} ${fullTableName} ${likeStatement} (`, - isActivated, - )(columnStatement, columnStatement + (primaryKeyStatement ? ',' : ''))( - primaryKeyStatement, - primaryKeyStatement, - )(foreignKeyStatement, foreignKeyStatement)(true, ')')(using, `${getUsing(using)}`)( - rowFormatStatement, - `ROW FORMAT ${rowFormatStatement}`, - )(storedAsStatement, storedAsStatement)( - tableProperties, - `TBLPROPERTIES (${getTablePropertiesClause(_)(tableProperties)})`, - )(tableOptions, `OPTIONS ${tableOptions}`)(location, `LOCATION '${location}'`)(true, ';')(); - }; + `OPTIONS ${tableOptions}`, + )(location, `LOCATION '${location}'`)(true, ';')(); +}; -const getClusteringKeys = _ => (clusteredKeys, deactivatedColumnNames, isParentItemActivated) => { +const getClusteringKeys = (clusteredKeys, deactivatedColumnNames, isParentItemActivated) => { if (!Array.isArray(clusteredKeys) || !clusteredKeys.length) { return ''; } if (!isParentItemActivated) { return clusteredKeys.join(', '); } - const { keysString } = commentDeactivatedInlineKeys(_)(clusteredKeys, deactivatedColumnNames); + const { keysString } = commentDeactivatedInlineKeys(clusteredKeys, deactivatedColumnNames); return keysString; }; -const getSortedKeys = _ => (sortedKeys, deactivatedColumnNames, isParentItemActivated) => { +const getSortedKeys = (sortedKeys, deactivatedColumnNames, isParentItemActivated) => { const getSortKeysStatement = keys => keys.map(sortedKey => `${sortedKey.name} ${sortedKey.type}`).join(', '); if (!Array.isArray(sortedKeys) || !sortedKeys.length) { @@ -274,7 +267,7 @@ const getSortedKeys = _ => (sortedKeys, deactivatedColumnNames, isParentItemActi return `${getSortKeysStatement(activatedKeys)} /*, ${getSortKeysStatement(deactivatedKeys)} */`; }; -const getPartitionKeyStatement = _ => (keys, isParentActivated, using) => { +const getPartitionKeyStatement = (keys, isParentActivated, using) => { const getKeysStatement = keys => { if (using === 'Hive') { return keys.map(key => `${key.name} ${key.type}`).join(', '); @@ -323,28 +316,24 @@ const getTableColumnsStatement = (columns, using, partitionKeys) => { return columns; }; -const getSkewedKeyStatement = - _ => (skewedKeys, skewedOn, asDirectories, deactivatedColumnNames, isParentItemActivated) => { - const getStatement = keysString => - `SKEWED BY (${keysString}) ON ${skewedOn} ${asDirectories ? 'STORED AS DIRECTORIES' : ''}`; +const getSkewedKeyStatement = (skewedKeys, skewedOn, asDirectories, deactivatedColumnNames, isParentItemActivated) => { + const getStatement = keysString => + `SKEWED BY (${keysString}) ON ${skewedOn} ${asDirectories ? 'STORED AS DIRECTORIES' : ''}`; - if (!Array.isArray(skewedKeys) || !skewedKeys.length) { - return ''; - } + if (!Array.isArray(skewedKeys) || !skewedKeys.length) { + return ''; + } - if (!isParentItemActivated) { - return getStatement(skewedKeys.join(', ')); - } + if (!isParentItemActivated) { + return getStatement(skewedKeys.join(', ')); + } - const { isAllKeysDeactivated, keysString } = commentDeactivatedInlineKeys(_)( - skewedKeys, - deactivatedColumnNames, - ); - if (isAllKeysDeactivated) { - return '-- ' + getStatement(keysString); - } - return getStatement(keysString); - }; + const { isAllKeysDeactivated, keysString } = commentDeactivatedInlineKeys(skewedKeys, deactivatedColumnNames); + if (isAllKeysDeactivated) { + return '-- ' + getStatement(keysString); + } + return getStatement(keysString); +}; const getRowFormat = tableData => { if (tableData.rowFormat === 'delimited') { @@ -422,7 +411,6 @@ const getTableStatement = dbVersion, isCalledFromAlterScript = false, ) => { - const _ = app.require('lodash'); const ddlProvider = require('../ddlProvider/ddlProvider')(app); const { getEntityTagsStatement } = require('../helpers/unityTagsHelper'); @@ -439,14 +427,14 @@ const getTableStatement = const keyNames = keyHelper.getKeyNames(tableData, entityJsonSchema, definitions); const tableColumns = getTableColumnsStatement(columns, tableData.using, keyNames.compositePartitionKey); const primaryKeyStatement = arePkFkConstraintsAvailable - ? constraintHelper.getPrimaryKeyStatement(_)( + ? constraintHelper.getPrimaryKeyStatement( entityJsonSchema, keyNames.primaryKeys, deactivatedColumnNames, isTableActivated, ) : ''; - let tableStatement = getCreateStatement(_)({ + let tableStatement = getCreateStatement({ fullTableName, isTemporary: tableData.temporaryTable, isExternal: tableData.externalTable, @@ -457,19 +445,15 @@ const getTableStatement = likeStatement: getLikeStatement(getTab(0, likeTableData)), columnStatement: getColumnsStatement(tableColumns, isTableActivated), comment: tableData.description, - partitionedByKeys: getPartitionKeyStatement(_)( + partitionedByKeys: getPartitionKeyStatement( getPartitionsKeys(columns, keyNames.compositePartitionKey), isTableActivated, tableData.using, ), - clusteredKeys: getClusteringKeys(_)( - keyNames.compositeClusteringKey, - deactivatedColumnNames, - isTableActivated, - ), - sortedKeys: getSortedKeys(_)(keyNames.sortedByKey, deactivatedColumnNames, isTableActivated), + clusteredKeys: getClusteringKeys(keyNames.compositeClusteringKey, deactivatedColumnNames, isTableActivated), + sortedKeys: getSortedKeys(keyNames.sortedByKey, deactivatedColumnNames, isTableActivated), numBuckets: tableData.numBuckets, - skewedStatement: getSkewedKeyStatement(_)( + skewedStatement: getSkewedKeyStatement( keyNames.skewedby, tableData.skewedOn, tableData.skewStoredAsDir, @@ -507,7 +491,7 @@ const getTableStatement = } if (getDBVersionNumber(dbVersion) >= Runtime.MINIMUM_UNITY_TAGS_SUPPORT_VERSION) { - const columnsUnityTags = getColumnTagsStatement(_, entityJsonSchema.properties, fullTableName); + const columnsUnityTags = getColumnTagsStatement(entityJsonSchema.properties, fullTableName); tableStatement = [tableStatement, ...columnsUnityTags].join('\n'); } @@ -551,7 +535,7 @@ const getCorrectUsing = using => { * propertyValue: any | undefined * }>) => string} * */ -const getTablePropertiesClause = _ => tableProperties => { +const getTablePropertiesClause = tableProperties => { const isText = _.overEvery([value => _.isNaN(_.toNumber(value)), value => value !== 'true' && value !== 'false']); const tablePropertyStatements = (tableProperties || []).map(({ propertyKey, propertyValue = undefined }) => { let value = propertyValue; @@ -566,17 +550,15 @@ const getTablePropertiesClause = _ => tableProperties => { return tablePropertyStatements.join(', '); }; -const hydrateTableProperties = - _ => - ({ new: newItems, old: oldItems }, name) => { - const preparePropertiesName = properties => _.map(properties, ({ propertyKey }) => propertyKey).join(', '); - const { add, drop } = getDifferentItems(_)(newItems, oldItems); - const dataProperties = { - add: getTablePropertiesClause(_)(add), - drop: preparePropertiesName(drop), - }; - return { dataProperties, name }; +const hydrateTableProperties = ({ new: newItems, old: oldItems }, name) => { + const preparePropertiesName = properties => _.map(properties, ({ propertyKey }) => propertyKey).join(', '); + const { add, drop } = getDifferentItems(newItems, oldItems); + const dataProperties = { + add: getTablePropertiesClause(add), + drop: preparePropertiesName(drop), }; + return { dataProperties, name }; +}; const adjustPropertyKey = propertyKey => { if (/^\s*\(/.test(propertyKey) && !/\)\s*$/.test(propertyKey)) { diff --git a/forward_engineering/helpers/unityTagsHelper.js b/forward_engineering/helpers/unityTagsHelper.js index 79726c20..73b21977 100644 --- a/forward_engineering/helpers/unityTagsHelper.js +++ b/forward_engineering/helpers/unityTagsHelper.js @@ -1,5 +1,7 @@ 'use strict'; +const _ = require('lodash'); + /** * @typedef {Object} UnityTag * @property {string} id @@ -70,7 +72,7 @@ const getEntityTagsStatement = (entity, fullTableName) => { return `ALTER TABLE ${fullTableName} SET TAGS (${tags});`; }; -const getColumnTagsStatement = (_, columns, fullTableName) => { +const getColumnTagsStatement = (columns, fullTableName) => { return _.toPairs(columns) .map(([colName, schema]) => { if (!schema.unityColumnTags?.length) { diff --git a/forward_engineering/helpers/viewHelper.js b/forward_engineering/helpers/viewHelper.js index 95492b92..ae0e976e 100644 --- a/forward_engineering/helpers/viewHelper.js +++ b/forward_engineering/helpers/viewHelper.js @@ -1,8 +1,9 @@ 'use strict'; +const _ = require('lodash'); const { prepareName, encodeStringLiteral, commentDeactivatedStatement } = require('../utils/general'); -const getColumnNames = _ => (collectionRefsDefinitionsMap, columns) => { +const getColumnNames = (collectionRefsDefinitionsMap, columns) => { return _.uniq( Object.entries(columns).map(([name, definition]) => { const id = _.get(columns, [name, 'GUID']); @@ -27,7 +28,7 @@ const getColumnNames = _ => (collectionRefsDefinitionsMap, columns) => { ).filter(_.identity); }; -const getFromStatement = _ => (collectionRefsDefinitionsMap, columns) => { +const getFromStatement = (collectionRefsDefinitionsMap, columns) => { const sourceCollections = _.uniq( Object.keys(columns) .map(name => { @@ -106,9 +107,9 @@ function getDefaultColumnList(properties) { return list ? `\n(${list}\n)` : ''; } -function getTableSelectStatement({ _, collectionRefsDefinitionsMap, columns }) { - const fromStatement = getFromStatement(_)(collectionRefsDefinitionsMap, columns); - const columnsNames = getColumnNames(_)(collectionRefsDefinitionsMap, columns); +function getTableSelectStatement({ collectionRefsDefinitionsMap, columns }) { + const fromStatement = getFromStatement(collectionRefsDefinitionsMap, columns); + const columnsNames = getColumnNames(collectionRefsDefinitionsMap, columns); if (fromStatement && columnsNames?.length) { return `\nAS SELECT ${joinColumnNames(columnsNames)}\n${fromStatement}`; diff --git a/forward_engineering/sampleGeneration/sampleGenerationService.js b/forward_engineering/sampleGeneration/sampleGenerationService.js index 1d9b0979..08ca4402 100644 --- a/forward_engineering/sampleGeneration/sampleGenerationService.js +++ b/forward_engineering/sampleGeneration/sampleGenerationService.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { prepareName, generateFullEntityNameFromBucketAndTableNames } = require('../utils/general'); const { mapInsertSampleToDml } = require('./mapInsertSampleToDml'); const { CoreData, App } = require('../types/coreApplicationTypes'); @@ -11,15 +12,13 @@ const { batchProcessFile } = require('../../reverse_engineering/helpers/fileHelp */ /** - * @param {App} app * @param {CoreData} data * @return {{ * isSampleGenerationRequired: boolean, * shouldAppendSamplesToTheResultScript: boolean * }} */ -const getSampleGenerationOptions = (app, data) => { - const _ = app.require('lodash'); +const getSampleGenerationOptions = data => { const insertSamplesOption = _.get(data, 'options.additionalOptions', []).find(option => option.id === 'INCLUDE_SAMPLES') || {}; const isSampleGenerationRequired = Boolean(insertSamplesOption?.value); @@ -72,7 +71,7 @@ const getValuesClauseColumnDelimiter = (columnIndex, maxColumnsInLineOfValuesCla * ) => string * } * */ -const generateSamples = _ => (entityJsonSchema, samples) => { +const generateSamples = (entityJsonSchema, samples) => { if (!samples.length) { return ''; } @@ -117,7 +116,7 @@ const generateSamples = _ => (entityJsonSchema, samples) => { /** * @return {(parsedData: Object) => string} * */ -const generateSampleForDemonstrationOnContainerLevel = _ => parsedData => { +const generateSampleForDemonstrationOnContainerLevel = parsedData => { /** * @type {ContainerLevelParsedJsonData} * */ @@ -128,7 +127,7 @@ const generateSampleForDemonstrationOnContainerLevel = _ => parsedData => { .map(collectionId => { const entityJsonSchema = (parsedData.entitiesJsonSchema || {})[collectionId] || {}; const collectionSampleData = sampleData[collectionId] || {}; - return generateSamples(_)(entityJsonSchema, [collectionSampleData]); + return generateSamples(entityJsonSchema, [collectionSampleData]); }) .concat(['']) .join('\n\n'); @@ -137,7 +136,7 @@ const generateSampleForDemonstrationOnContainerLevel = _ => parsedData => { /** * @return {(parsedData: Object) => string} * */ -const generateSampleForDemonstrationOnEntityLevel = _ => parsedData => { +const generateSampleForDemonstrationOnEntityLevel = parsedData => { /** * @type {ContainerLevelParsedJsonData} * */ @@ -149,23 +148,20 @@ const generateSampleForDemonstrationOnEntityLevel = _ => parsedData => { bucketName: containerData.name, ...(parsedData.jsonSchema || {}), }; - return generateSamples(_)(entityJsonSchema, [sampleData]); + return generateSamples(entityJsonSchema, [sampleData]); }; /** - * @param app {App} * @param parsedData {Object} * @param level {'entity' | 'container'} * @return {string} * */ -const generateSampleForDemonstration = (app, parsedData, level) => { - const _ = app.require('lodash'); - +const generateSampleForDemonstration = (parsedData, level) => { if (level === 'entity') { - return generateSampleForDemonstrationOnEntityLevel(_)(parsedData); + return generateSampleForDemonstrationOnEntityLevel(parsedData); } if (level === 'container') { - return generateSampleForDemonstrationOnContainerLevel(_)(parsedData); + return generateSampleForDemonstrationOnContainerLevel(parsedData); } return ''; }; @@ -178,14 +174,14 @@ const generateSampleForDemonstration = (app, parsedData, level) => { * ) => string * } * */ -const generateSamplesScript = _ => (entityJsonSchema, samples) => { +const generateSamplesScript = (entityJsonSchema, samples) => { if (!samples?.length) { return ''; } if (!(entityJsonSchema.bucketName && entityJsonSchema.collectionName)) { return ''; } - return generateSamples(_)(entityJsonSchema, samples); + return generateSamples(entityJsonSchema, samples); }; /** @@ -220,10 +216,10 @@ const getDataForSampleGeneration = (data, entitiesJsonSchema) => { * @param {EntityData} entityData * @return {Promise>} */ -const generateSamplesForEntity = _ => async entityData => { +const generateSamplesForEntity = async entityData => { const { filePath, jsonSchema, jsonData } = entityData; - const demoSample = generateSamplesScript(_)(jsonSchema, [jsonData]); + const demoSample = generateSamplesScript(jsonSchema, [jsonData]); const samples = [demoSample]; @@ -232,7 +228,7 @@ const generateSamplesForEntity = _ => async entityData => { batchSize: 1, parseLine: line => JSON.parse(line), batchHandler: async batch => { - const sample = generateSamplesScript(_)(jsonSchema, batch); + const sample = generateSamplesScript(jsonSchema, batch); samples.push(sample); }, }); diff --git a/forward_engineering/utils/general.js b/forward_engineering/utils/general.js index 15640dfb..11f50eb8 100644 --- a/forward_engineering/utils/general.js +++ b/forward_engineering/utils/general.js @@ -1,5 +1,6 @@ 'use strict'; +const _ = require('lodash'); const sqlFormatter = require('@sqltools/formatter'); const { RESERVED_WORDS_AS_ARRAY } = require('../enums/reservedWords'); const { Runtime } = require('../enums/runtime'); @@ -142,7 +143,7 @@ const commentDeactivatedStatements = (statement, isActivated = true) => { return insertBeforeEachLine(statement, '-- '); }; -const commentDeactivatedInlineKeys = _ => (keys, deactivatedKeyNames) => { +const commentDeactivatedInlineKeys = (keys, deactivatedKeyNames) => { const [activatedKeys, deactivatedKeys] = _.partition( keys, key => !(deactivatedKeyNames.has(key) || deactivatedKeyNames.has(key.slice(1, -1))), @@ -267,27 +268,23 @@ const getDBVersionNumber = dbVersionString => // eslint-disable-next-line no-bitwise typeof dbVersionString === 'number' ? dbVersionString : ~~dbVersionString.split(' ')[1]; -const getDifferentItems = - _ => - (newItems = [], oldItems = []) => { - const intersection = _.intersectionWith(newItems, oldItems, _.isEqual); - return { - add: _.xorWith(newItems, intersection, _.isEqual), - drop: _.xorWith(oldItems, intersection, _.isEqual), - }; +const getDifferentItems = (newItems = [], oldItems = []) => { + const intersection = _.intersectionWith(newItems, oldItems, _.isEqual); + return { + add: _.xorWith(newItems, intersection, _.isEqual), + drop: _.xorWith(oldItems, intersection, _.isEqual), }; +}; -const compareProperties = - _ => - ({ new: newProperty, old: oldProperty }) => { - if (!newProperty && !oldProperty) { - return; - } - return !_.isEqual(newProperty, oldProperty); - }; +const compareProperties = ({ new: newProperty, old: oldProperty }) => { + if (!newProperty && !oldProperty) { + return; + } + return !_.isEqual(newProperty, oldProperty); +}; -const getIsChangeProperties = _ => (compMod, properties) => - properties.some(property => compareProperties(_)(compMod[property] || {})); +const getIsChangeProperties = (compMod, properties) => + properties.some(property => compareProperties(compMod[property] || {})); const isSupportUnityCatalog = (dbVersion = '') => { const runtimeVersion = getDBVersionNumber(dbVersion); diff --git a/package-lock.json b/package-lock.json index 5a8f0ee4..b330285e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,17 @@ { "name": "DeltaLake", - "version": "0.2.1", + "version": "0.2.11", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "DeltaLake", - "version": "0.2.1", + "version": "0.2.11", "dependencies": { "@sqltools/formatter": "1.2.5", "abort-controller": "3.0.0", "antlr4": "4.9.2", + "async": "3.2.6", "lodash": "4.17.21", "node-fetch": "2.6.7" }, @@ -20,6 +21,7 @@ "@typescript-eslint/parser": "7.11.0", "esbuild": "0.20.2", "esbuild-plugin-clean": "1.0.1", + "esbuild-plugin-copy": "2.1.1", "eslint": "8.57.0", "eslint-config-prettier": "9.1.0", "eslint-formatter-teamcity": "^1.0.0", @@ -31,7 +33,7 @@ "simple-git-hooks": "2.11.1" }, "engines": { - "hackolade": "6.5.3", + "hackolade": "7.7.10", "hackoladePlugin": "1.2.0" } }, @@ -887,6 +889,19 @@ "node": ">=14" } }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dev": true, + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -1016,6 +1031,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/async": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz", + "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==" + }, "node_modules/available-typed-arrays": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", @@ -1037,6 +1057,18 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, + "node_modules/binary-extensions": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", + "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", + "dev": true, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -1103,6 +1135,42 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, + "node_modules/chokidar": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", + "dev": true, + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/chokidar/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/clean-stack": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", @@ -1546,6 +1614,35 @@ "esbuild": ">= 0.14.0" } }, + "node_modules/esbuild-plugin-copy": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/esbuild-plugin-copy/-/esbuild-plugin-copy-2.1.1.tgz", + "integrity": "sha512-Bk66jpevTcV8KMFzZI1P7MZKZ+uDcrZm2G2egZ2jNIvVnivDpodZI+/KnpL3Jnap0PBdIHU7HwFGB8r+vV5CVw==", + "dev": true, + "dependencies": { + "chalk": "^4.1.2", + "chokidar": "^3.5.3", + "fs-extra": "^10.0.1", + "globby": "^11.0.3" + }, + "peerDependencies": { + "esbuild": ">= 0.14.0" + } + }, + "node_modules/esbuild-plugin-copy/node_modules/fs-extra": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/escape-string-regexp": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", @@ -2089,6 +2186,20 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -2485,6 +2596,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/is-boolean-object": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.2.tgz", @@ -3067,6 +3190,15 @@ } } }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/npm-run-path": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.3.0.tgz", @@ -3417,6 +3549,18 @@ } ] }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, "node_modules/regexp.prototype.flags": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", diff --git a/package.json b/package.json index d5aedb35..eda774a1 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "@sqltools/formatter": "1.2.5", "abort-controller": "3.0.0", "antlr4": "4.9.2", + "async": "3.2.6", "lodash": "4.17.21", "node-fetch": "2.6.7" }, @@ -80,6 +81,7 @@ "@typescript-eslint/parser": "7.11.0", "esbuild": "0.20.2", "esbuild-plugin-clean": "1.0.1", + "esbuild-plugin-copy": "2.1.1", "eslint": "8.57.0", "eslint-config-prettier": "9.1.0", "eslint-formatter-teamcity": "^1.0.0", @@ -90,4 +92,4 @@ "prettier": "3.2.5", "simple-git-hooks": "2.11.1" } -} \ No newline at end of file +} diff --git a/reverse_engineering/adaptJsonSchema.js b/reverse_engineering/adaptJsonSchema.js index 7c0dc19c..df148489 100644 --- a/reverse_engineering/adaptJsonSchema.js +++ b/reverse_engineering/adaptJsonSchema.js @@ -1,16 +1,14 @@ -const { setDependencies } = require('./appDependencies'); +const _ = require('lodash'); const mapJsonSchema = require('./thriftService/mapJsonSchema'); const adaptJsonSchema = (data, logger, callback, app) => { try { - setDependencies(app); - const _ = app.require('lodash'); const jsonSchema = JSON.parse(data.jsonSchema); - const result = mapJsonSchema(_)(jsonSchema, {}, (schema, parentJsonSchema, key) => { + const result = mapJsonSchema(jsonSchema, {}, (schema, parentJsonSchema, key) => { if (schema.type === 'array' && !schema.subtype) { return { ...schema, - subtype: getArraySubtypeByChildren(_, schema), + subtype: getArraySubtypeByChildren(schema), }; } else { return schema; @@ -31,7 +29,7 @@ const adaptJsonSchema = (data, logger, callback, app) => { } }; -const getArraySubtypeByChildren = (_, arraySchema) => { +const getArraySubtypeByChildren = arraySchema => { const subtype = type => `array<${type}>`; if (!arraySchema.items) { diff --git a/reverse_engineering/api.js b/reverse_engineering/api.js index 1b657bb3..ec4a1367 100644 --- a/reverse_engineering/api.js +++ b/reverse_engineering/api.js @@ -1,5 +1,6 @@ 'use strict'; +const async = require('async'); const logHelper = require('./logHelper'); let connectionData = null; @@ -14,7 +15,6 @@ const { isTableDdl, getTemplateDocByJsonSchema, } = require('./helpers/utils'); -const { setDependencies, dependencies } = require('./appDependencies'); const fs = require('fs'); const { getCleanedUrl } = require('../forward_engineering/utils/general'); const { parseViewStatement } = require('./parseViewStatement'); @@ -35,8 +35,6 @@ module.exports = { testConnection: async (connectionInfo, logger, cb, app) => { try { - setDependencies(app); - connectionData = { host: getCleanedUrl(connectionInfo.host), clusterId: connectionInfo.clusterId, @@ -65,8 +63,6 @@ module.exports = { logInfo('Retrieving databases information', connectionInfo, logger); try { - setDependencies(app); - const connectionData = { host: getCleanedUrl(connectionInfo.host), clusterId: connectionInfo.clusterId, @@ -111,8 +107,6 @@ module.exports = { logger.log('info', connectionInfo, 'Retrieving tables and views information', connectionInfo.hiddenKeys); try { - setDependencies(app); - connectionData = { host: getCleanedUrl(connectionInfo.host), clusterId: connectionInfo.clusterId, @@ -174,10 +168,6 @@ module.exports = { let modelData; try { - setDependencies(app); - - const async = dependencies.async; - modelData = await databricksHelper.getClusterStateInfo(connectionData, logger); logger.log('info', modelData, 'Cluster state info'); @@ -452,7 +442,6 @@ module.exports = { }, reFromFile: async (data, logger, callback, app) => { try { - setDependencies(app); const input = await handleFileData(data.filePath); const { result, info, relationships } = parseDDLStatements(input); callback(null, result, info, relationships, 'multipleSchema'); diff --git a/reverse_engineering/appDependencies.js b/reverse_engineering/appDependencies.js deleted file mode 100644 index 1a0cfbd2..00000000 --- a/reverse_engineering/appDependencies.js +++ /dev/null @@ -1,11 +0,0 @@ -let dependencies = {}; - -const setDependencies = app => { - dependencies.lodash = app.require('lodash'); - dependencies.async = app.require('async'); -}; - -module.exports = { - setDependencies, - dependencies, -}; diff --git a/reverse_engineering/commandsService.js b/reverse_engineering/commandsService.js index 69d8aec9..5136c2d4 100644 --- a/reverse_engineering/commandsService.js +++ b/reverse_engineering/commandsService.js @@ -1,4 +1,4 @@ -const { dependencies } = require('./appDependencies'); +const _ = require('lodash'); const cleanUpSelectStatement = require('./helpers/cleanUpSelectStatement'); const { set, @@ -54,7 +54,7 @@ const convertCommandsToEntities = (commands, originalScript) => { const bucket = statementData.bucketName || entitiesData.currentBucket; - if (dependencies.lodash.keys(COMMANDS_ACTION_MAP).includes(command)) { + if (_.keys(COMMANDS_ACTION_MAP).includes(command)) { return COMMANDS_ACTION_MAP[command](entitiesData, bucket, statementData, originalScript); } @@ -250,7 +250,7 @@ const updateField = (entitiesData, bucket, statementData) => { } const entity = entities[index]; - const field = dependencies.lodash.get(entity, 'schema.properties', {})[statementData.name]; + const field = _.get(entity, 'schema.properties', {})[statementData.name]; if (!field) { return entitiesData; } @@ -367,7 +367,6 @@ const isAllIndexKeysHasSameOptions = (columnsData, indexOptions) => { }; const createBloomfilterIndexes = (columnsData = [], indexOptions) => { - const _ = dependencies.lodash; indexOptions = indexOptions || _.get(_.first(columnsData), 'options', ''); const useSameOptions = isAllIndexKeysHasSameOptions(columnsData, indexOptions); @@ -414,7 +413,7 @@ const addBloomfilterIndexToCollection = (entitiesData, bucket, statementData) => }; }; -const filterCollectionBloomfilterIndexes = _ => (bloomIndexes, indexKeysToRemove) => +const filterCollectionBloomfilterIndexes = (bloomIndexes, indexKeysToRemove) => _.chain(bloomIndexes || []) .map(bloomIndex => { const indexKeys = bloomIndex.forColumns.filter(key => !_.includes(indexKeysToRemove, key)); @@ -431,7 +430,6 @@ const filterCollectionBloomfilterIndexes = _ => (bloomIndexes, indexKeysToRemove .value(); const removeBloomfilterIndexFromCollection = (entitiesData, bucket, statementData) => { - const _ = dependencies.lodash; const { entities } = entitiesData; const entityIndex = findEntityIndex(entities, bucket, statementData.collectionName); if (entityIndex === -1) { @@ -441,7 +439,7 @@ const removeBloomfilterIndexFromCollection = (entitiesData, bucket, statementDat const entity = entities[entityIndex]; const entityLevelData = entity.entityLevelData || {}; const indexKeysToRemove = statementData.columns.map(column => column.name); - const indexes = filterCollectionBloomfilterIndexes(_)(entityLevelData.BloomIndxs, indexKeysToRemove); + const indexes = filterCollectionBloomfilterIndexes(entityLevelData.BloomIndxs, indexKeysToRemove); return { ...entitiesData, @@ -520,8 +518,6 @@ const addRelationship = (entitiesData, bucket, statementData) => { }; const updateProperties = (properties, statementData) => { - const _ = dependencies.lodash; - return _.fromPairs( _.keys(properties).map(columnName => { if (!statementData?.fields?.includes(columnName)) { @@ -591,9 +587,9 @@ const addToResourcePlan = (entitiesData, bucket, statementData) => { const updatedResourcePlan = { ...resourcePlans[resourcePlanIndex], - [identifier + 's']: dependencies.lodash - .get(resourcePlans, `${resourcePlanIndex}.${identifier + 's'}`, []) - .concat(statementData[identifier]), + [identifier + 's']: _.get(resourcePlans, `${resourcePlanIndex}.${identifier + 's'}`, []).concat( + statementData[identifier], + ), }; return { @@ -615,7 +611,7 @@ const addMapping = (entitiesData, bucket, statementData) => { } const planPools = resourcePlans[resourceIndex].pools || []; - const poolIndex = dependencies.lodash.findIndex(planPools, ({ name }) => name === statementData.poolName); + const poolIndex = _.findIndex(planPools, ({ name }) => name === statementData.poolName); if (poolIndex < 0) { return entitiesData; } @@ -811,7 +807,7 @@ const removeMapping = (entitiesData, bucket, statementData) => { } const planPools = resourcePlans[resourceIndex].pools || []; - const poolIndex = dependencies.lodash.findIndex(planPools, ({ mappings }) => + const poolIndex = _.findIndex(planPools, ({ mappings }) => (mappings || []).find(({ name }) => name === statementData.name), ); if (poolIndex < 0) { @@ -887,11 +883,11 @@ const updateCatalogLevelData = (entitiesData, bucket, statementData) => { }; const getResourcePlanIndex = (resourcePlans, resourceName) => { - return dependencies.lodash.findIndex(resourcePlans, plan => plan.name === resourceName); + return _.findIndex(resourcePlans, plan => plan.name === resourceName); }; const addMappingToPoolByIndex = (pools, poolIndex, mapping) => { - return { ...pools[poolIndex], mappings: dependencies.lodash.get(pools[poolIndex], 'mappings', []).concat(mapping) }; + return { ...pools[poolIndex], mappings: _.get(pools[poolIndex], 'mappings', []).concat(mapping) }; }; const removeMappingFromPool = (pools, poolIndex, mappingName) => { @@ -899,7 +895,6 @@ const removeMappingFromPool = (pools, poolIndex, mappingName) => { }; const getResourcePlanAndItemIndexes = (resourcePlans, statementData, identifier) => { - const _ = dependencies.lodash; const resourcePlanIndex = getResourcePlanIndex(resourcePlans, statementData.resourceName); const items = _.get(resourcePlans, `${resourcePlanIndex}.${identifier + 's'}`, []); const itemIndex = _.findIndex(items, ({ name }) => name === statementData[identifier]); diff --git a/reverse_engineering/helpers/databricksHelper.js b/reverse_engineering/helpers/databricksHelper.js index f29db18f..bab9d32b 100644 --- a/reverse_engineering/helpers/databricksHelper.js +++ b/reverse_engineering/helpers/databricksHelper.js @@ -1,5 +1,7 @@ 'use strict'; -const { dependencies } = require('../appDependencies'); + +const _ = require('lodash'); +const async = require('async'); const fetchRequestHelper = require('./fetchRequestHelper'); const { convertCustomTags, cleanEntityName, isSupportGettingListOfViews } = require('./utils'); @@ -8,7 +10,6 @@ const getEntityCreateStatement = (connectionInfo, dbName, entityName, logger) => }; const getFirstDatabaseCollectionName = async (connectionInfo, sparkVersion, logger) => { - const _ = dependencies.lodash; const databasesNames = await fetchRequestHelper.fetchClusterDatabasesNames(connectionInfo); logger.log('info', databasesNames, `Schema list`); if (_.isEmpty(databasesNames)) { @@ -62,8 +63,6 @@ const getDatabaseViewNames = async (dbName, connectionInfo, sparkVersion, logger }; const getDatabaseCollectionNames = async (connectionInfo, sparkVersion, logger) => { - const async = dependencies.async; - if (isSupportUnityCatalog(sparkVersion)) { await fetchRequestHelper.useCatalog(connectionInfo); } @@ -87,7 +86,7 @@ const getDatabaseCollectionNames = async (connectionInfo, sparkVersion, logger) return { dbName, dbCollections, - isEmpty: dependencies.lodash.isEmpty(dbCollections), + isEmpty: _.isEmpty(dbCollections), }; }); }; @@ -130,8 +129,7 @@ const isSupportUnityCatalog = sparkVersion => { const isEnabledUnityCatalog = data_security_mode => ['SINGLE_USER', 'USER_ISOLATION'].includes(data_security_mode); const getEntitiesDDL = (connectionInfo, databasesNames, collectionsNames, sparkVersion, logger) => { - const async = dependencies.async; - const entitiesNames = dependencies.lodash.flatMap(databasesNames, dbName => { + const entitiesNames = _.flatMap(databasesNames, dbName => { return (collectionsNames[dbName] || []).map(entityName => ({ dbName, name: entityName })); }); diff --git a/reverse_engineering/helpers/fetchRequestHelper.js b/reverse_engineering/helpers/fetchRequestHelper.js index 1ba50377..6de75de0 100644 --- a/reverse_engineering/helpers/fetchRequestHelper.js +++ b/reverse_engineering/helpers/fetchRequestHelper.js @@ -1,7 +1,9 @@ 'use strict'; + +const async = require('async'); +const _ = require('lodash'); const nodeFetch = require('node-fetch'); const AbortController = require('abort-controller'); -const { dependencies } = require('../appDependencies'); const { getClusterData, getViewNamesCommand } = require('./pythonScriptGeneratorHelper'); const { prepareNamesForInsertionIntoScalaCode, removeParentheses } = require('./utils'); const { generateSamplesScript } = require('../../forward_engineering/sampleGeneration/sampleGenerationService'); @@ -91,8 +93,8 @@ const destroyActiveContext = () => { * entityJsonSchema: Object, * ) => Promise} * */ -const sendSampleBatch = _ => (connectionInfo, samples, entityJsonSchema) => { - const script = generateSamplesScript(_)(entityJsonSchema, samples); +const sendSampleBatch = (connectionInfo, samples, entityJsonSchema) => { + const script = generateSamplesScript(entityJsonSchema, samples); return executeCommand(connectionInfo, script, 'sql'); }; @@ -120,7 +122,7 @@ const logProgressOfSendingSampleBatches = logger => (lineIndex, amountOfLines) = logger.progress({ message }); }; -const sendSampleBatches = (_, logger) => async connectionInfo => { +const sendSampleBatches = logger => async connectionInfo => { const { entitiesData } = connectionInfo; for (const entityData of Object.values(entitiesData)) { @@ -132,14 +134,14 @@ const sendSampleBatches = (_, logger) => async connectionInfo => { batchSize: BATCH_SIZE, parseLine: line => JSON.parse(line), batchHandler: batch => { - return sendSampleBatch(_)(connectionInfo, batch, jsonSchema); + return sendSampleBatch(connectionInfo, batch, jsonSchema); }, logProgress: logProgressOfSendingSampleBatches(logger), }); } }; -const fetchApplyToInstance = _ => async (connectionInfo, logger) => { +const fetchApplyToInstance = async (connectionInfo, logger) => { const progress = message => { logger.log('info', message, 'Applying to instance'); logger.progress({ message }); @@ -149,7 +151,7 @@ const fetchApplyToInstance = _ => async (connectionInfo, logger) => { await Promise.race([ executeCommand(connectionInfo, connectionInfo.script, 'sql').then(() => { - return sendSampleBatches(_, logger)(connectionInfo); + return sendSampleBatches(logger)(connectionInfo); }), new Promise((_r, rej) => setTimeout(() => { @@ -169,7 +171,7 @@ const getSampleDocSize = async ({ connectionInfo, dbName, tableName, recordSampl `SELECT COUNT(*) FROM \`${dbName}\`.\`${tableName}\``, 'sql', ); - const count = dependencies.lodash.get(countResult, '[0][0]', 0); + const count = _.get(countResult, '[0][0]', 0); const limit = Math.ceil((count * recordSamplingSettings.relative.value) / 100); logger.log('info', { message: `Found ${count} records`, dbName, tableName }, 'Getting documents'); @@ -280,12 +282,12 @@ const useCatalog = async connectionInfo => { const fetchClusterCatalogNames = async connectionInfo => { const result = await executeCommand(connectionInfo, 'SHOW CATALOGS', 'sql'); - return dependencies.lodash.flattenDeep(result); + return _.flattenDeep(result); }; const fetchClusterDatabasesNames = async connectionInfo => { const result = await executeCommand(connectionInfo, 'SHOW DATABASES', 'sql'); - return dependencies.lodash.flattenDeep(result); + return _.flattenDeep(result); }; const fetchDatabaseViewsNames = (dbName, connectionInfo) => @@ -304,7 +306,6 @@ const fetchClusterData = async ( isManagedLocationSupports, logger, ) => { - const async = dependencies.async; const databasesPropertiesResult = await async.mapLimit(databasesNames, 40, async dbName => { logger.log('info', '', `Start describe schema: ${dbName} `); const dbInfoResult = await executeCommand(connectionInfo, `DESCRIBE DATABASE EXTENDED \`${dbName}\``, 'sql'); @@ -337,8 +338,8 @@ const fetchClusterData = async ( (clusterData, dbName) => ({ ...clusterData, [dbName]: { - dbTables: dependencies.lodash.get(databasesTablesInfo, dbName, {}), - dbProperties: dependencies.lodash.get(databasesProperties, dbName, {}), + dbTables: _.get(databasesTablesInfo, dbName, {}), + dbProperties: _.get(databasesProperties, dbName, {}), }, }), {}, @@ -444,7 +445,7 @@ const getFilteredEntities = (tableNames, parsedData) => { }; const mergeChunksOfData = (leftObj, rightObj) => { - return dependencies.lodash.mergeWith(leftObj, rightObj, (objValue, srcValue) => { + return _.mergeWith(leftObj, rightObj, (objValue, srcValue) => { if (Array.isArray(objValue) && Array.isArray(srcValue)) { return objValue.concat(srcValue); } @@ -454,7 +455,7 @@ const mergeChunksOfData = (leftObj, rightObj) => { const fetchCreateStatementRequest = async (entityName, connectionInfo, logger) => { try { const result = await executeCommand(connectionInfo, `SHOW CREATE TABLE ${entityName};`, 'sql'); - return dependencies.lodash.get(result, '[0][0]', ''); + return _.get(result, '[0][0]', ''); } catch (error) { logger.log('error', error, `Error during retrieve create table DDL statement. Table name: ${entityName}`); return ''; @@ -662,7 +663,6 @@ const getCommandExecutionResult = (query, options, commandOptions) => { }; const convertDbPropertyValue = value => { - const _ = dependencies.lodash; const isNumber = value => !_.isNaN(_.toNumber(value)); const isBoolean = value => _.toLower(value) === 'false' || _.toLower(value) === 'true'; const convertToBoolean = value => { @@ -684,7 +684,6 @@ const convertDbPropertyValue = value => { }; const splitStatementsByBrackets = statements => { - const _ = dependencies.lodash; let result = []; let startIndex = 0; let skippedBrackets = 0; diff --git a/reverse_engineering/helpers/schemaHelper.js b/reverse_engineering/helpers/schemaHelper.js index 94c8aa5e..e4ffe1c4 100644 --- a/reverse_engineering/helpers/schemaHelper.js +++ b/reverse_engineering/helpers/schemaHelper.js @@ -1,4 +1,4 @@ -const { dependencies } = require('../appDependencies'); +const _ = require('lodash'); const cleanContent = str => { const start = str.indexOf('<'); @@ -178,7 +178,7 @@ const parseArray = ([content], sample = []) => { const parsePrimitive = ([type]) => { const preparedType = type.trim(); const hiveType = preparedType.replace(/\(.*?\)$/, ''); - const modifiers = dependencies.lodash.get(preparedType.match(/\((.*?)\)$/), '[1]', '').split(','); + const modifiers = _.get(preparedType.match(/\((.*?)\)$/), '[1]', '').split(','); switch (hiveType) { case 'string': @@ -242,7 +242,7 @@ const parseUnion = (types, sample) => { if (!complexTypes) { return { - type: dependencies.lodash.uniq(jsonSchemas.map(schema => schema.type)), + type: _.uniq(jsonSchemas.map(schema => schema.type)), }; } diff --git a/reverse_engineering/helpers/tableDDLHelper.js b/reverse_engineering/helpers/tableDDLHelper.js index e02ff71c..f5c91eb0 100644 --- a/reverse_engineering/helpers/tableDDLHelper.js +++ b/reverse_engineering/helpers/tableDDLHelper.js @@ -1,10 +1,10 @@ +const antlr4 = require('antlr4'); +const _ = require('lodash'); const SqlBaseLexer = require('../parser/SQLBase/SqlBaseLexer'); const SqlBaseParser = require('../parser/SQLBase/SqlBaseParser'); const SqlBaseToCollectionVisitor = require('../sqlBaseToCollectionsVisitor'); const ExprErrorListener = require('../antlrErrorListener'); const columnREHelper = require('./columnsREHelper'); -const antlr4 = require('antlr4'); -const { dependencies } = require('../appDependencies'); const { applyUnityTagsToTable, applyUnityTagsToTableProperties } = require('./unityTagsHelper'); const getTableData = async (table, data, logger) => { @@ -42,7 +42,7 @@ const getTableData = async (table, data, logger) => { schema: tableSchema, requiredColumns, }; - if (!dependencies.lodash.isEmpty(BloomIndxs)) { + if (!_.isEmpty(BloomIndxs)) { return Object.assign(tableData, { 'propertiesPane': { ...tableData.propertiesPane, BloomIndxs } }); } return tableData; @@ -60,7 +60,7 @@ const getTableDataFromDDl = statement => { const tree = parser.singleStatement(); const sqlBaseToCollectionVisitor = new SqlBaseToCollectionVisitor(statement); let parsedTableData = tree.accept(sqlBaseToCollectionVisitor); - if (!dependencies.lodash.isEmpty(parsedTableData.query)) { + if (!_.isEmpty(parsedTableData.query)) { parsedTableData.query = statement.substring( parsedTableData.query.select.start, parsedTableData.query.select.stop, @@ -135,7 +135,7 @@ const isValidIndex = indexObject => const convertIndexes = indexes => { const indexMap = Object.keys(indexes) - .filter(columnName => !dependencies.lodash.isEmpty(indexes[columnName]) && isValidIndex(indexes[columnName])) + .filter(columnName => !_.isEmpty(indexes[columnName]) && isValidIndex(indexes[columnName])) .reduce((indexMap, columnName) => { const indexObject = indexes[columnName]; const indexString = `fpp = ${indexObject['delta.bloomFilter.fpp']}, numItems = ${indexObject['delta.bloomFilter.numItems']}, maxExpectedFpp = ${indexObject['delta.bloomFilter.maxExpectedFpp']}, enabled = ${indexObject['delta.bloomFilter.enabled']}`; diff --git a/reverse_engineering/helpers/utils.js b/reverse_engineering/helpers/utils.js index 6f329e7d..e43248f1 100644 --- a/reverse_engineering/helpers/utils.js +++ b/reverse_engineering/helpers/utils.js @@ -1,7 +1,7 @@ -const { dependencies } = require('../appDependencies'); +const _ = require('lodash'); const splitTableAndViewNames = names => { - const namesByCategory = dependencies.lodash.partition(names, isView); + const namesByCategory = _.partition(names, isView); return { views: namesByCategory[0].map(name => name.slice(0, -4)), tables: namesByCategory[1] }; }; diff --git a/reverse_engineering/helpers/viewDDLHelper.js b/reverse_engineering/helpers/viewDDLHelper.js index cb0a9104..9f6487d6 100644 --- a/reverse_engineering/helpers/viewDDLHelper.js +++ b/reverse_engineering/helpers/viewDDLHelper.js @@ -1,13 +1,12 @@ +const _ = require('lodash'); +const antlr4 = require('antlr4'); const SqlBaseLexer = require('../parser/SQLBase/SqlBaseLexer'); const SqlBaseParser = require('../parser/SQLBase/SqlBaseParser'); const SqlBaseToCollectionVisitor = require('../sqlBaseToCollectionsVisitor'); const ExprErrorListener = require('../antlrErrorListener'); -const antlr4 = require('antlr4'); -const { dependencies } = require('../appDependencies'); const schemaHelper = require('./schemaHelper'); const getViewDataFromDDl = statement => { - const _ = dependencies.lodash; const chars = new antlr4.InputStream(statement); const lexer = new SqlBaseLexer.SqlBaseLexer(chars); lexer.removeErrorListeners(); diff --git a/reverse_engineering/hqlToCollectionsVisitor.js b/reverse_engineering/hqlToCollectionsVisitor.js index dab0b805..0a881c52 100644 --- a/reverse_engineering/hqlToCollectionsVisitor.js +++ b/reverse_engineering/hqlToCollectionsVisitor.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const { HiveParserVisitor } = require('./parser/Hive/HiveParserVisitor'); const { HiveParser } = require('./parser/Hive/HiveParser'); const { @@ -34,7 +35,6 @@ const { } = require('./commandsService'); const schemaHelper = require('./thriftService/schemaHelper'); -const { dependencies } = require('./appDependencies'); const { removeParentheses } = require('./helpers/utils'); const { getCheckConstraintsFromTableProperties, @@ -90,7 +90,6 @@ class Visitor extends HiveParserVisitor { } visitCreateTableStatement(ctx) { - const _ = dependencies.lodash; const [tableName, tableLikeName] = this.visit(ctx.tableName()); const tableDataSource = this.visitWhenExists(ctx, 'tableUsingDataSource'); const compositePartitionKey = this.visitWhenExists(ctx, 'tablePartition', [])?.[0] || []; @@ -897,7 +896,7 @@ class Visitor extends HiveParserVisitor { if (!complexTypes) { return { - type: dependencies.lodash.uniq(types.map(schema => schema.type)), + type: _.uniq(types.map(schema => schema.type)), }; } @@ -1038,7 +1037,7 @@ class Visitor extends HiveParserVisitor { return { ...(ctx.KW_NOT() && ctx.KW_NULL() ? { required: true } : {}), ...(ctx.tableConstraintType?.KW_UNIQUE ? { unique: true } : {}), - ...((ctx.tableConstraintType())?.KW_PRIMARY ? { primaryKey: true } : {}), + ...(ctx.tableConstraintType()?.KW_PRIMARY ? { primaryKey: true } : {}), ...(ctx.KW_DEFAULT() ? { default: this.visit(ctx.defaultVal()) } : {}), ...(ctx.checkConstraint() ? { check: this.visitWhenExists(ctx, 'checkConstraint', '') } : {}), ...(ctx.columnGeneratedAs() ? { generatedDefaultValue: this.visit(ctx.columnGeneratedAs()) } : {}), @@ -1201,7 +1200,6 @@ class Visitor extends HiveParserVisitor { } visitCreateIndexStatement(ctx) { - const _ = dependencies.lodash; const { name, database, table, columns, SecIndxHandler } = this.visit(ctx.createIndexMainStatement()); const SecIndxWithDeferredRebuild = Boolean(ctx.KW_WITH() && ctx.KW_DEFERRED() && ctx.KW_REBUILD()); const SecIndxProperties = this.visitWhenExists(ctx, 'tableProperties'); @@ -1343,7 +1341,7 @@ class Visitor extends HiveParserVisitor { } visitRpAssignList(ctx) { - return this.visit(ctx.rpAssign()).find(({ parallelism }) => !dependencies.lodash.isEmpty(parallelism)); + return this.visit(ctx.rpAssign()).find(({ parallelism }) => !_.isEmpty(parallelism)); } visitRpAssign(ctx) { diff --git a/reverse_engineering/parseDDLStatements.js b/reverse_engineering/parseDDLStatements.js index 11a53257..e8dcec83 100644 --- a/reverse_engineering/parseDDLStatements.js +++ b/reverse_engineering/parseDDLStatements.js @@ -1,10 +1,10 @@ +const _ = require('lodash'); const antlr4 = require('antlr4'); const HiveLexer = require('./parser/Hive/HiveLexer.js'); const HiveParser = require('./parser/Hive/HiveParser.js'); const hqlToCollectionsVisitor = require('./hqlToCollectionsVisitor.js'); const commandsService = require('./commandsService'); const ExprErrorListener = require('./antlrErrorListener'); -const { dependencies } = require('./appDependencies'); module.exports = { parseDDLStatements(input) { @@ -21,6 +21,6 @@ module.exports = { const hqlToCollectionsGenerator = new hqlToCollectionsVisitor(input); const commands = tree.accept(hqlToCollectionsGenerator); - return commandsService.convertCommandsToReDocs(dependencies.lodash.flatten(commands).filter(Boolean), input); + return commandsService.convertCommandsToReDocs(_.flatten(commands).filter(Boolean), input); }, }; diff --git a/reverse_engineering/parseViewStatement.js b/reverse_engineering/parseViewStatement.js index a091ebaa..6a08f760 100644 --- a/reverse_engineering/parseViewStatement.js +++ b/reverse_engineering/parseViewStatement.js @@ -1,11 +1,9 @@ -const { setDependencies } = require('./appDependencies'); const { getErrorMessage } = require('./helpers/utils'); const { parseDDLStatements } = require('./parseDDLStatements'); module.exports = { parseViewStatement(data, logger, callback, app) { try { - setDependencies(app); const statement = data.statement; const { result } = parseDDLStatements('CREATE VIEW `db`.`name` AS ' + statement + ';\n'); diff --git a/reverse_engineering/sqlBaseToCollectionsVisitor.js b/reverse_engineering/sqlBaseToCollectionsVisitor.js index 4404900c..c2eb8205 100644 --- a/reverse_engineering/sqlBaseToCollectionsVisitor.js +++ b/reverse_engineering/sqlBaseToCollectionsVisitor.js @@ -1,5 +1,5 @@ +const _ = require('lodash'); const { SqlBaseVisitor } = require('./parser/SQLBase/SqlBaseVisitor'); -const { dependencies } = require('./appDependencies'); const { getFilteredTableProperties, getCheckConstraintsFromTableProperties } = require('./helpers/visitorsHelper'); global.SQL_standard_keyword_behavior = false; @@ -449,7 +449,7 @@ const getCommentValue = (context, label) => { }; const getName = context => { - if (!context || dependencies.lodash.isEmpty(context)) { + if (!context || _.isEmpty(context)) { return ''; } return removeQuotes(context.getText()); diff --git a/reverse_engineering/thriftService/mapJsonSchema.js b/reverse_engineering/thriftService/mapJsonSchema.js index 8f1b5683..d2e5e6ba 100644 --- a/reverse_engineering/thriftService/mapJsonSchema.js +++ b/reverse_engineering/thriftService/mapJsonSchema.js @@ -1,4 +1,6 @@ -const mapJsonSchema = _ => (jsonSchema, parentJsonSchema, callback, key) => { +const _ = require('lodash'); + +const mapJsonSchema = (jsonSchema, parentJsonSchema, callback, key) => { const mapProperties = (properties, mapper) => Object.keys(properties).reduce((newProperties, propertyName) => { const schema = mapper(properties[propertyName], propertyName); @@ -60,7 +62,7 @@ const mapJsonSchema = _ => (jsonSchema, parentJsonSchema, callback, key) => { const schema = mapper(jsonSchema[propertyName], propertyName); if (_.isEmpty(schema)) { - const copySchema = {...jsonSchema}; + const copySchema = { ...jsonSchema }; delete copySchema[propertyName]; @@ -76,8 +78,8 @@ const mapJsonSchema = _ => (jsonSchema, parentJsonSchema, callback, key) => { if (!_.isPlainObject(jsonSchema)) { return jsonSchema; } - const copyJsonSchema = {...jsonSchema}; - const mapper = _.partial(mapJsonSchema(_), _, copyJsonSchema, callback); + const copyJsonSchema = { ...jsonSchema }; + const mapper = _.partial(mapJsonSchema, _, copyJsonSchema, callback); const propertiesLike = ['properties', 'definitions', 'patternProperties']; const itemsLike = ['items', 'not']; const choices = ['oneOf', 'allOf', 'anyOf'];