Skip to content

Commit

Permalink
HCK-7311: http requester (#49)
Browse files Browse the repository at this point in the history
* feat: replaced aws sdk with direct glue client package

* fix: handle the missing Type of the column (#39)

* feat: added fetch-http-handler

* chore: move HttpHandler to its own place

* temp: skeleton for a controller

* feat: replaced @aws-sdk/fetch-http-handler with own HttpHandler that uses electron.net.fetch explicitly

* chore: refactored lodash dependency usage

* chore: removed `@aws-sdk/fetch-http-handler` package

* feat: start using own request handler in FE

* chore: use lodash discreetly

* fix: declared `electron` as external package

* chore: declared `electron` as peer dependency

* fix: preserve error trace in reject

* Update shared/httpHandler/httpHandler.js

Co-authored-by: Ugo Bechameil <[email protected]>

* chore: replace Promise.reject with a throw statement

* fix: replaced own implementation of query builder with native URLSearchParams

* chore: made the contract more explicit

* chore: updated package-lock.json

---------

Co-authored-by: Ugo Bechameil <[email protected]>
  • Loading branch information
chulanovskyi-bs and bigorn0 authored Aug 30, 2024
1 parent b6f7f26 commit f70c1a2
Show file tree
Hide file tree
Showing 21 changed files with 866 additions and 412 deletions.
1 change: 1 addition & 0 deletions esbuild.package.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ esbuild
}),
addReleaseFlag(path.resolve(RELEASE_FOLDER_PATH, 'package.json')),
],
external: ['electron'],
})
.catch(() => process.exit(1));
36 changes: 16 additions & 20 deletions forward_engineering/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const { get } = require('lodash');
const { GlueClient, CreateDatabaseCommand, CreateTableCommand, GetDatabasesCommand } = require('@aws-sdk/client-glue');
const { getDatabaseStatement } = require('./helpers/databaseHelper');
const { getTableStatement } = require('./helpers/tableHelper');
Expand All @@ -9,12 +10,11 @@ const { getGlueDatabaseCreateStatement } = require('./helpers/awsCliScriptHelper
const { getGlueTableCreateStatement } = require('./helpers/awsCliScriptHelpers/glueTableHelper');
const { getApiStatements } = require('./helpers/awsCliScriptHelpers/applyToInstanceHelper');
const sqlFormatter = require('./custom_modules/sql-formatter');
const { setDependencies, dependencies } = require('./appDependencies');
const { HttpHandler } = require('../shared/httpHandler/httpHandler');

module.exports = {
generateScript(data, logger, callback, app) {
generateScript(data, logger, callback) {
try {
setDependencies(app);
const jsonSchema = JSON.parse(data.jsonSchema);
const modelDefinitions = JSON.parse(data.modelDefinitions);
const internalDefinitions = JSON.parse(data.internalDefinitions);
Expand All @@ -24,9 +24,7 @@ module.exports = {

if (data.options.targetScriptOptions && data.options.targetScriptOptions.keyword === 'hiveQl') {
const needMinify = (
dependencies.lodash
.get(data, 'options.additionalOptions', [])
.find(option => option.id === 'minify') || {}
get(data, 'options.additionalOptions', []).find(option => option.id === 'minify') || {}
).value;

return callback(
Expand Down Expand Up @@ -58,9 +56,8 @@ module.exports = {
}
},

generateContainerScript(data, logger, callback, app) {
generateContainerScript(data, logger, callback) {
try {
setDependencies(app);
const containerData = data.containerData;
const modelDefinitions = JSON.parse(data.modelDefinitions);
const externalDefinitions = JSON.parse(data.externalDefinitions);
Expand All @@ -69,9 +66,7 @@ module.exports = {
const internalDefinitions = parseEntities(data.entities, data.internalDefinitions);
if (data.options.targetScriptOptions && data.options.targetScriptOptions.keyword === 'hiveQl') {
const needMinify = (
dependencies.lodash
.get(data, 'options.additionalOptions', [])
.find(option => option.id === 'minify') || {}
get(data, 'options.additionalOptions', []).find(option => option.id === 'minify') || {}
).value;

const foreignKeyHashTable = foreignKeyHelper.getForeignKeyHashTable(
Expand Down Expand Up @@ -124,16 +119,15 @@ module.exports = {
}
},

async applyToInstance(data, logger, callback, app) {
setDependencies(app);
async applyToInstance(data, logger, callback) {
if (!data.script) {
return callback({ message: 'Empty script' });
}

logger.clear();
logger.log('info', data, data.hiddenKeys);

const glueInstance = getGlueInstance(data, app);
const glueInstance = getGlueInstance({ connectionInfo: data, logger });

try {
const { db, table } = getApiStatements(data.script);
Expand Down Expand Up @@ -162,11 +156,10 @@ module.exports = {
}
},

async testConnection(connectionInfo, logger, callback, app) {
setDependencies(app);
async testConnection(connectionInfo, logger, callback) {
logger.log('info', connectionInfo, 'Test connection', connectionInfo.hiddenKeys);

const glueInstance = getGlueInstance(connectionInfo, app);
const glueInstance = getGlueInstance({ connectionInfo, logger });

try {
const command = new GetDatabasesCommand();
Expand All @@ -188,20 +181,23 @@ const buildAWSCLIScript = (containerData, tableSchema) => {
const buildAWSCLIModelScript = (containerData, tablesSchemas = {}) => {
const dbStatement = getGlueDatabaseCreateStatement(containerData[0]);
const tablesStatements = Object.entries(tablesSchemas).map(([key, value]) => {
return getGlueTableCreateStatement(value, dependencies.lodash.get(containerData[0], 'name', ''));
return getGlueTableCreateStatement(value, get(containerData[0], 'name', ''));
});
return composeCLIStatements([dbStatement, ...tablesStatements]);
};

const getGlueInstance = (connectionInfo, app) => {
const { accessKeyId, secretAccessKey, region, sessionToken } = connectionInfo;
const getGlueInstance = ({ connectionInfo, logger }) => {
const { accessKeyId, secretAccessKey, region, sessionToken, queryRequestTimeout } = connectionInfo;
const httpHandler = new HttpHandler({ logger, requestTimeout: queryRequestTimeout });

return new GlueClient({
region,
credentials: {
accessKeyId,
secretAccessKey,
sessionToken,
},
requestHandler: httpHandler,
});
};

Expand Down
10 changes: 0 additions & 10 deletions forward_engineering/appDependencies.js

This file was deleted.

7 changes: 3 additions & 4 deletions forward_engineering/helpers/generalHelper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const { dependencies } = require('../appDependencies');
const { partition, findLastIndex } = require('lodash');

const buildStatement = (mainStatement, isActivated) => {
let composeStatements = (...statements) => {
Expand Down Expand Up @@ -84,7 +83,7 @@ const commentDeactivatedStatements = (statement, isActivated = true) => {
};

const commentDeactivatedInlineKeys = (keys, deactivatedKeyNames) => {
const [activatedKeys, deactivatedKeys] = dependencies.lodash.partition(
const [activatedKeys, deactivatedKeys] = partition(
keys,
key => !(deactivatedKeyNames.has(key) || deactivatedKeyNames.has(key.slice(1, -1))),
);
Expand Down Expand Up @@ -114,7 +113,7 @@ const removeRedundantTrailingCommaFromStatement = statement => {
if (splitedStatement.length < 4 || !splitedStatement[splitedStatement.length - 2].trim().startsWith('--')) {
return statement;
}
const lineWithTrailingCommaIndex = dependencies.lodash.findLastIndex(splitedStatement, line => {
const lineWithTrailingCommaIndex = findLastIndex(splitedStatement, line => {
if (line.trim() !== ');' && !line.trim().startsWith('--')) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions forward_engineering/helpers/indexHelper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { dependencies } = require('../appDependencies');
const { partition } = require('lodash');
const { getTab, buildStatement, getName, replaceSpaceWithUnderscore } = require('./generalHelper');
const schemaHelper = require('./jsonSchemaHelper');
const { getItemByPath } = require('./jsonSchemaHelper');
Expand Down Expand Up @@ -36,7 +36,7 @@ const getIndexKeys = (keys, jsonSchema, definitions) => {
[jsonSchema, ...definitions],
);
const idToNameHashTable = schemaHelper.getIdToNameHashTable([jsonSchema, ...definitions]);
const [activatedKeys, deactivatedKeys] = dependencies.lodash.partition(paths, path => {
const [activatedKeys, deactivatedKeys] = partition(paths, path => {
const item = getItemByPath(path, jsonSchema);
return item ? item.isActivated : true;
});
Expand Down
6 changes: 3 additions & 3 deletions forward_engineering/helpers/tableHelper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const { partition } = require('lodash');
const {
buildStatement,
getName,
Expand All @@ -12,7 +13,6 @@ const {
} = require('./generalHelper');
const { getColumnsStatement, getColumnStatement, getColumns } = require('./columnHelper');
const keyHelper = require('./keyHelper');
const { dependencies } = require('../appDependencies');

const getCreateStatement = ({
dbName,
Expand Down Expand Up @@ -105,7 +105,7 @@ const getSortedKeys = (sortedKeys, deactivatedColumnNames, isParentItemActivated
if (!Array.isArray(sortedKeys) || !sortedKeys.length) {
return '';
}
const [activatedKeys, deactivatedKeys] = dependencies.lodash.partition(
const [activatedKeys, deactivatedKeys] = partition(
sortedKeys,
keyData => !deactivatedColumnNames.has(keyData.name),
);
Expand All @@ -129,7 +129,7 @@ const getPartitionKeyStatement = (keys, isParentActivated) => {
return '';
}

const [activatedKeys, deactivatedKeys] = dependencies.lodash.partition(keys, key => key.isActivated);
const [activatedKeys, deactivatedKeys] = partition(keys, key => key.isActivated);
if (!isParentActivated || deactivatedKeys.length === 0) {
return { isAllKeysDeactivated: false, keysString: getKeysStatement(keys) };
}
Expand Down
Loading

0 comments on commit f70c1a2

Please sign in to comment.