Skip to content

Commit 4e74a85

Browse files
HCK-9614: adapt FE to work in the browser (#19)
* HCK-9614: adapt FE to work in the browser * feat: await dynamic module * feat: await callstack * HCK-9614: add postinstall * HCK-9614: fix comments --------- Co-authored-by: chulanovskyi <oleg.chulanovskyi@binary-studio.com>
1 parent 7bd291a commit 4e74a85

File tree

8 files changed

+71
-48
lines changed

8 files changed

+71
-48
lines changed

api/fe.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const { generateScript } = require('../forward_engineering/helpers/generateScript');
2+
3+
module.exports = {
4+
generateScript,
5+
};

esbuild.package.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const RELEASE_FOLDER_PATH = path.join(DEFAULT_RELEASE_FOLDER_PATH, `${packageDat
1111
esbuild
1212
.build({
1313
entryPoints: [
14+
path.resolve(__dirname, 'api', 'fe.js'),
1415
path.resolve(__dirname, 'forward_engineering', 'api.js'),
1516
path.resolve(__dirname, 'reverse_engineering', 'api.js'),
1617
],

forward_engineering/api.js

+3-33
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,5 @@
1-
module.exports = {
2-
generateScript(data, logger, cb) {
3-
let { jsonSchema, entityData } = data;
4-
5-
try {
6-
jsonSchema = JSON.parse(jsonSchema);
7-
} catch (err) {
8-
return cb(err);
9-
}
10-
11-
let columnFailies = this.getColumnFamilies(jsonSchema.properties);
12-
let script = `create '${entityData.collectionName.toLowerCase()}'`;
13-
14-
columnFailies.forEach(item => {
15-
script = `${script}, '${item}'`;
16-
});
1+
const { generateScript } = require('./helpers/generateScript');
172

18-
return cb(null, script);
19-
},
20-
21-
getColumnFamilies(props = {}) {
22-
let columnFamilies = [];
23-
for (let prop in props) {
24-
if (props[prop] && props[prop].type === 'colFam') {
25-
columnFamilies.push(prop);
26-
}
27-
}
28-
29-
if (!columnFamilies.length) {
30-
columnFamilies.push('<columnFamily>');
31-
}
32-
33-
return columnFamilies;
34-
},
3+
module.exports = {
4+
generateScript,
355
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { getColumnFamilies } = require('./getColumnFamilies');
2+
3+
function generateScript(data, logger, cb) {
4+
const { entityData } = data;
5+
let { jsonSchema } = data;
6+
7+
try {
8+
jsonSchema = JSON.parse(jsonSchema);
9+
} catch (err) {
10+
return cb(err);
11+
}
12+
13+
const columnFamilies = getColumnFamilies(jsonSchema.properties);
14+
let script = `create '${entityData.collectionName.toLowerCase()}'`;
15+
16+
columnFamilies.forEach(item => {
17+
script = `${script}, '${item}'`;
18+
});
19+
20+
return cb(null, script);
21+
}
22+
23+
module.exports = {
24+
generateScript,
25+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function getColumnFamilies(props = {}) {
2+
const columnFamilies = [];
3+
4+
for (const prop in props) {
5+
if (props[prop] && props[prop].type === 'colFam') {
6+
columnFamilies.push(prop);
7+
}
8+
}
9+
10+
if (!columnFamilies.length) {
11+
columnFamilies.push('<columnFamily>');
12+
}
13+
14+
return columnFamilies;
15+
}
16+
17+
module.exports = {
18+
getColumnFamilies,
19+
};

package-lock.json

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"description": "Hackolade plugin for Apache HBase",
2828
"scripts": {
2929
"lint": "eslint . --max-warnings=0",
30-
"package": "node esbuild.package.js"
30+
"package": "node esbuild.package.js",
31+
"postinstall": "npx simple-git-hooks"
3132
},
3233
"dependencies": {
3334
"async": "^3.2.4",
@@ -56,4 +57,4 @@
5657
"pre-commit": "npx lint-staged",
5758
"pre-push": "npx eslint ."
5859
}
59-
}
60+
}

reverse_engineering/api.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ let clientKrb = null;
1414
const DEFAULT_NAMESPACE = 'No Namespace';
1515

1616
module.exports = {
17-
connect: function (connectionInfo, logger, cb, app) {
18-
const kerberos = app.require('kerberos');
17+
connect: async function (connectionInfo, logger, cb, app) {
18+
const kerberos = await app.require('kerberos');
1919
logger.log('info', connectionInfo, 'Connection information', connectionInfo.hiddenKeys);
2020

2121
let options = setAuthData(
@@ -29,7 +29,7 @@ module.exports = {
2929
if (!clientKrb && options.krb5) {
3030
logger.log(
3131
'info',
32-
Object.assign({}, options.krb5, { platform: process.platform }),
32+
{ ...options.krb5, platform: process.platform },
3333
'Kerberos options',
3434
connectionInfo.hiddenKeys,
3535
);
@@ -57,10 +57,10 @@ module.exports = {
5757
}
5858
},
5959

60-
testConnection: function (connectionInfo, logger, cb, app) {
60+
testConnection: async function (connectionInfo, logger, cb, app) {
6161
logger.clear();
6262

63-
this.connect(
63+
await this.connect(
6464
connectionInfo,
6565
logger,
6666
err => {
@@ -81,10 +81,10 @@ module.exports = {
8181
);
8282
},
8383

84-
getDbCollectionsNames: function (connectionInfo, logger, cb, app) {
84+
getDbCollectionsNames: async function (connectionInfo, logger, cb, app) {
8585
logger.clear();
8686

87-
this.connect(
87+
await this.connect(
8888
connectionInfo,
8989
logger,
9090
err => {
@@ -606,7 +606,7 @@ function handleVersion(version, versions) {
606606
}
607607

608608
function setAuthData(options, connectionInfo) {
609-
let authParams = {};
609+
const authParams = {};
610610

611611
if (connectionInfo.auth === 'kerberos') {
612612
authParams.krb5 = {
@@ -616,9 +616,10 @@ function setAuthData(options, connectionInfo) {
616616
};
617617
}
618618

619-
options = Object.assign(options, authParams);
620-
621-
return options;
619+
return {
620+
...options,
621+
...authParams,
622+
};
622623
}
623624

624625
const handleResponse = response => {

0 commit comments

Comments
 (0)