From 01936212c1135d86256d059765e25b523ba87bb8 Mon Sep 17 00:00:00 2001 From: chulanovskyi Date: Mon, 21 Oct 2024 16:56:19 +0300 Subject: [PATCH] feat: upgraded the driver, added extra logs on querying the labels step, cleaned up the redundant dependencies --- forward_engineering/api.js | 25 ++--- .../helpers/appDependencies.js | 10 -- .../helpers/applyToInstance.js | 6 +- package-lock.json | 78 ++++++--------- package.json | 5 +- .../neo4j-driver-bolt-connection+4.4.11.patch | 95 ------------------- .../neo4j-driver-bolt-connection+5.26.0.patch | 24 +++++ reverse_engineering/api.js | 49 ++++------ reverse_engineering/appDependencies.js | 11 --- reverse_engineering/neo4jHelper.js | 23 +++-- 10 files changed, 95 insertions(+), 231 deletions(-) delete mode 100644 forward_engineering/helpers/appDependencies.js delete mode 100644 patches/neo4j-driver-bolt-connection+4.4.11.patch create mode 100644 patches/neo4j-driver-bolt-connection+5.26.0.patch delete mode 100644 reverse_engineering/appDependencies.js diff --git a/forward_engineering/api.js b/forward_engineering/api.js index aedd0b8..4452059 100644 --- a/forward_engineering/api.js +++ b/forward_engineering/api.js @@ -1,12 +1,8 @@ -const { dependencies, setDependencies } = require('./helpers/appDependencies'); +const _ = require('lodash'); const applyToInstanceHelper = require('./helpers/applyToInstance'); -let _; -const setAppDependencies = ({ lodash }) => (_ = lodash); module.exports = { - generateContainerScript(data, logger, cb, app) { - setDependencies(app); - setAppDependencies(dependencies); + generateContainerScript(data, logger, cb) { let { collections, relationships, jsonData } = data; const dbVersion = data.modelData[0]?.dbVersion; logger.clear(); @@ -24,7 +20,6 @@ module.exports = { setTimeout(() => { cb({ message: e.message, stack: e.stack }); }, 150); - return; } }, @@ -133,13 +128,12 @@ module.exports = { }, applyToInstance(connectionInfo, logger, callback, app) { - setDependencies(app); logger.clear(); logger.log('info', connectionInfo, 'connectionInfo', connectionInfo.hiddenKeys); const sshService = app.require('@hackolade/ssh-service'); applyToInstanceHelper - .applyToInstance(connectionInfo, dependencies, logger, sshService) + .applyToInstance(connectionInfo, logger, sshService) .then(result => { callback(null, result); }) @@ -149,11 +143,10 @@ module.exports = { }, testConnection(connectionInfo, logger, callback, app) { - setDependencies(app); logger.log('info', connectionInfo, 'connectionInfo', connectionInfo.hiddenKeys); const sshService = app.require('@hackolade/ssh-service'); - applyToInstanceHelper.testConnection(connectionInfo, dependencies, sshService).then(callback, err => { + applyToInstanceHelper.testConnection(connectionInfo, sshService).then(callback, err => { logger.log('error', err, 'Neo4j test connection error'); callback({ ...err, type: 'simpleError' }); }); @@ -246,9 +239,7 @@ module.exports = { parent, relationship, child, - bidirectional: - relationship?.customProperties?.biDirectional && - child.GUID !== parent.GUID, + bidirectional: relationship?.customProperties?.biDirectional && child.GUID !== parent.GUID, }); }); } else if (!hasRelationship[parent.GUID]) { @@ -488,10 +479,7 @@ module.exports = { if (entity.index) { entity.index.forEach(index => { if (index.key) { - const fields = this.findFields( - entity, - index.key.map(getId), - ); + const fields = this.findFields(entity, index.key.map(getId)); if (fields.length) { const indexScript = getIndex({ entity, @@ -630,7 +618,6 @@ module.exports = { const screen = s => `\`${s}\``; const getProperty = (schema, field) => { - setAppDependencies(dependencies); if (_.has(schema, `properties.${field}`)) { return schema.properties[field]; } else if (_.has(schema, `allOf.${field}`)) { diff --git a/forward_engineering/helpers/appDependencies.js b/forward_engineering/helpers/appDependencies.js deleted file mode 100644 index 287e4ac..0000000 --- a/forward_engineering/helpers/appDependencies.js +++ /dev/null @@ -1,10 +0,0 @@ -let dependencies = {}; - -const setDependencies = app => { - dependencies.lodash = app.require('lodash'); -}; - -module.exports = { - setDependencies, - dependencies, -}; diff --git a/forward_engineering/helpers/applyToInstance.js b/forward_engineering/helpers/applyToInstance.js index e4e088b..ae95e57 100644 --- a/forward_engineering/helpers/applyToInstance.js +++ b/forward_engineering/helpers/applyToInstance.js @@ -1,7 +1,7 @@ const neo4jHelper = require('../../reverse_engineering/neo4jHelper'); const applyToInstanceHelper = { - async applyToInstance(connectionInfo, dependencies, logger, sshService) { + async applyToInstance(connectionInfo, logger, sshService) { try { logger.log( 'info', @@ -11,7 +11,6 @@ const applyToInstanceHelper = { 'Neo4j script', ); - neo4jHelper.setDependencies(dependencies); await neo4jHelper.connect(connectionInfo, () => Promise.resolve(), sshService); const instanceSupportMultiDb = await neo4jHelper.supportsMultiDb(); const dbData = connectionInfo.containerData?.[0]; @@ -66,8 +65,7 @@ const applyToInstanceHelper = { } }, - async testConnection(connectionInfo, dependencies, sshService) { - neo4jHelper.setDependencies(dependencies); + async testConnection(connectionInfo, sshService) { await neo4jHelper.connect(connectionInfo, () => Promise.resolve(), sshService); await neo4jHelper.close(sshService); }, diff --git a/package-lock.json b/package-lock.json index a524ad6..3b8eca7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,17 @@ { "name": "Neo4j", - "version": "0.2.1", + "version": "0.2.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "Neo4j", - "version": "0.2.1", + "version": "0.2.3", "hasInstallScript": true, "dependencies": { + "async": "3.2.6", "lodash": "4.17.21", - "neo4j-driver": "4.4.10" + "neo4j-driver": "5.26.0" }, "devDependencies": { "@hackolade/hck-esbuild-plugins-pack": "0.0.1", @@ -33,17 +34,6 @@ "hackoladePlugin": "1.0.0" } }, - "node_modules/@babel/runtime": { - "version": "7.24.6", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.24.6.tgz", - "integrity": "sha512-Ja18XcETdEl5mzzACGd+DKgaGJzPTCow7EglgwTmHdwokzDFYh/MHua6lU6DV/hjF2IaOJ4oX2nqnjG7RElKOw==", - "dependencies": { - "regenerator-runtime": "^0.14.0" - }, - "engines": { - "node": ">=6.9.0" - } - }, "node_modules/@esbuild/aix-ppc64": { "version": "0.20.2", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.20.2.tgz", @@ -1001,6 +991,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", @@ -3087,30 +3082,29 @@ "dev": true }, "node_modules/neo4j-driver": { - "version": "4.4.10", - "resolved": "https://registry.npmjs.org/neo4j-driver/-/neo4j-driver-4.4.10.tgz", - "integrity": "sha512-FLAytWQbR1CkRFBlmt5N5+PDuKQpSARQXT7F+LFJPar3CKjMrP4VNT5UKfkl0tVc5QSrTxF/Aw2YGBzhs1kyCA==", + "version": "5.26.0", + "resolved": "https://registry.npmjs.org/neo4j-driver/-/neo4j-driver-5.26.0.tgz", + "integrity": "sha512-cQEzXHmUxWb2uBOqsvjs3/GxyVtOgP6WsOpozqTvI47Zzopzw/4b/E4uCJQR5bIn1UXdcUfZKJ60jOmAzEvM8A==", "dependencies": { - "@babel/runtime": "^7.5.5", - "neo4j-driver-bolt-connection": "^4.4.10", - "neo4j-driver-core": "^4.4.10", - "rxjs": "^6.6.3" + "neo4j-driver-bolt-connection": "5.26.0", + "neo4j-driver-core": "5.26.0", + "rxjs": "^7.8.1" } }, "node_modules/neo4j-driver-bolt-connection": { - "version": "4.4.11", - "resolved": "https://registry.npmjs.org/neo4j-driver-bolt-connection/-/neo4j-driver-bolt-connection-4.4.11.tgz", - "integrity": "sha512-2sCgx3Lpg7fnYAU/kb9wOKY8ResUeur88MhLNUWyINxa+CMP7aB+t70zBcOlJ7hcCf6ghEiz6ZXhd9WikGW9bA==", + "version": "5.26.0", + "resolved": "https://registry.npmjs.org/neo4j-driver-bolt-connection/-/neo4j-driver-bolt-connection-5.26.0.tgz", + "integrity": "sha512-Tq548RNZJoQdmZhTRcUxDntU1DkNhhKF8oWWuCQ7OtX20EIYpIgVkQYWJu75bSiYyUGxmuSk4U02oXNBdggjgg==", "dependencies": { "buffer": "^6.0.3", - "neo4j-driver-core": "4.4.11", + "neo4j-driver-core": "5.26.0", "string_decoder": "^1.3.0" } }, "node_modules/neo4j-driver-core": { - "version": "4.4.11", - "resolved": "https://registry.npmjs.org/neo4j-driver-core/-/neo4j-driver-core-4.4.11.tgz", - "integrity": "sha512-7+7Ue9RNsg5TAwkPvl4/st2ZdktN3qH8A/MYmJkZ6Ait8MuXP8ppTvZ3ugPxbrSOJEwvZYpKqV+FNZ17mOSfcQ==" + "version": "5.26.0", + "resolved": "https://registry.npmjs.org/neo4j-driver-core/-/neo4j-driver-core-5.26.0.tgz", + "integrity": "sha512-S3nHbqGuKPktWkRGenfx8Dt4MuqqrrUQjo4COhRj9r9P6WOjd0jzF/wyZb8H44pW5Qx/gmqn9B3If+7gfiaRmw==" }, "node_modules/npm-run-path": { "version": "5.3.0", @@ -3462,11 +3456,6 @@ } ] }, - "node_modules/regenerator-runtime": { - "version": "0.14.1", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", - "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==" - }, "node_modules/regexp.prototype.flags": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", @@ -3607,14 +3596,11 @@ } }, "node_modules/rxjs": { - "version": "6.6.7", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", - "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", + "version": "7.8.1", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz", + "integrity": "sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==", "dependencies": { - "tslib": "^1.9.0" - }, - "engines": { - "npm": ">=2.0.0" + "tslib": "^2.1.0" } }, "node_modules/safe-array-concat": { @@ -4002,12 +3988,6 @@ "url": "https://opencollective.com/unts" } }, - "node_modules/synckit/node_modules/tslib": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.3.tgz", - "integrity": "sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==", - "dev": true - }, "node_modules/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", @@ -4051,9 +4031,9 @@ } }, "node_modules/tslib": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.0.tgz", + "integrity": "sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA==" }, "node_modules/type-check": { "version": "0.4.0", diff --git a/package.json b/package.json index 6220e61..1d92d50 100644 --- a/package.json +++ b/package.json @@ -49,8 +49,9 @@ "description": "Hackolade plugin for Neo4j", "disabled": false, "dependencies": { + "async": "3.2.6", "lodash": "4.17.21", - "neo4j-driver": "4.4.10" + "neo4j-driver": "5.26.0" }, "lint-staged": { "*.{js,json}": "prettier --write" @@ -80,4 +81,4 @@ "prettier": "3.2.5", "simple-git-hooks": "2.11.1" } -} \ No newline at end of file +} diff --git a/patches/neo4j-driver-bolt-connection+4.4.11.patch b/patches/neo4j-driver-bolt-connection+4.4.11.patch deleted file mode 100644 index dcbf4aa..0000000 --- a/patches/neo4j-driver-bolt-connection+4.4.11.patch +++ /dev/null @@ -1,95 +0,0 @@ -diff --git a/node_modules/neo4j-driver-bolt-connection/lib/channel/channel-config.js b/node_modules/neo4j-driver-bolt-connection/lib/channel/channel-config.js -index 73dc996..8166cf5 100644 ---- a/node_modules/neo4j-driver-bolt-connection/lib/channel/channel-config.js -+++ b/node_modules/neo4j-driver-bolt-connection/lib/channel/channel-config.js -@@ -35,7 +35,8 @@ var ALLOWED_VALUES_TRUST = [ - undefined, - 'TRUST_ALL_CERTIFICATES', - 'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES', -- 'TRUST_SYSTEM_CA_SIGNED_CERTIFICATES' -+ 'TRUST_SYSTEM_CA_SIGNED_CERTIFICATES', -+ 'TRUST_SERVER_CLIENT_CERTIFICATES' - ]; - var ChannelConfig = /** @class */ (function () { - /** -@@ -52,6 +53,9 @@ var ChannelConfig = /** @class */ (function () { - this.knownHostsPath = extractKnownHostsPath(driverConfig); - this.connectionErrorCode = connectionErrorCode || SERVICE_UNAVAILABLE; - this.connectionTimeout = extractConnectionTimeout(driverConfig); -+ this.cert = driverConfig.cert; -+ this.key = driverConfig.key; -+ this.passphrase = driverConfig.passphrase; - } - return ChannelConfig; - }()); -diff --git a/node_modules/neo4j-driver-bolt-connection/lib/channel/node/node-channel.js b/node_modules/neo4j-driver-bolt-connection/lib/channel/node/node-channel.js -index 5775b37..920cb62 100644 ---- a/node_modules/neo4j-driver-bolt-connection/lib/channel/node/node-channel.js -+++ b/node_modules/neo4j-driver-bolt-connection/lib/channel/node/node-channel.js -@@ -104,7 +104,65 @@ var TrustStrategy = { - }); - socket.on('error', onFailure); - return configureSocket(socket); -- } -+ }, -+ TRUST_SERVER_CLIENT_CERTIFICATES: function (config, onSuccess, onFailure) { -+ if (!config.trustedCertificates || -+ config.trustedCertificates.length === 0) { -+ onFailure((0, neo4j_driver_core_1.newError)('You are using TRUST_CUSTOM_CA_SIGNED_CERTIFICATES as the method ' + -+ 'to verify trust for encrypted connections, but have not configured any ' + -+ 'trustedCertificates. You must specify the path to at least one trusted ' + -+ 'X.509 certificate for this to work. Two other alternatives is to use ' + -+ 'TRUST_ALL_CERTIFICATES or to disable encryption by setting encrypted="' + -+ ENCRYPTION_OFF + -+ '"' + -+ 'in your driver configuration.')); -+ return; -+ } -+ else if (!config.key) { -+ onFailure((0, neo4j_driver_core_1.newError)('You are using TRUST_SERVER_CLIENT_CERTIFICATES as the method ' + -+ 'to verify trust for encrypted connections, but have not configured any' + -+ 'key. You must specify the path to the key for this to work. Two other alternatives is to use ' + -+ 'TRUST_ALL_CERTIFICATES or to disable encryption by setting encrypted="' + -+ ENCRYPTION_OFF + -+ '"' + -+ 'in your driver configuration.')); -+ return; -+ } -+ else if (!config.cert) { -+ onFailure((0, neo4j_driver_core_1.newError)('You are using TRUST_SERVER_CLIENT_CERTIFICATES as the method ' + -+ 'to verify trust for encrypted connections, but have not configured any ' + -+ 'client certificates. You must specify the path to the client certificate for this to work. Two other alternatives is to use ' + -+ 'TRUST_ALL_CERTIFICATES or to disable encryption by setting encrypted="' + -+ ENCRYPTION_OFF + -+ '"' + -+ 'in your driver configuration.')); -+ return; -+ } -+ var tlsOpts = Object.assign({}, newTlsOptions(config.address.host()), { -+ ca: config.trustedCertificates.map(function (f) { return fs_1.default.readFileSync(f); }), -+ key: fs_1.default.readFileSync(config.key), -+ cert: fs_1.default.readFileSync(config.cert), -+ passphrase: config.passphrase -+ }); -+ var socket = tls_1.default.connect(config.address.port(), config.address.resolvedHost(), tlsOpts, function () { -+ if (!socket.authorized) { -+ onFailure((0, neo4j_driver_core_1.newError)('Server certificate is not trusted. If you trust the database you are connecting to, add' + -+ ' the signing certificate, or the server certificate, to the list of certificates trusted by this driver' + -+ " using `neo4j.v1.driver(.., { trustedCertificates:['path/to/certificate.crt']}). This " + -+ ' is a security measure to protect against man-in-the-middle attacks. If you are just trying ' + -+ ' Neo4j out and are not concerned about encryption, simply disable it using `encrypted="' + -+ ENCRYPTION_OFF + -+ '"`' + -+ ' in the driver options. Socket responded with: ' + -+ socket.authorizationError)); -+ } -+ else { -+ onSuccess(); -+ } -+ }); -+ socket.on('error', onFailure); -+ return configureSocket(socket); -+ }, - }; - /** - * Connect using node socket. diff --git a/patches/neo4j-driver-bolt-connection+5.26.0.patch b/patches/neo4j-driver-bolt-connection+5.26.0.patch new file mode 100644 index 0000000..a60e0f3 --- /dev/null +++ b/patches/neo4j-driver-bolt-connection+5.26.0.patch @@ -0,0 +1,24 @@ +diff --git a/node_modules/neo4j-driver-bolt-connection/lib/channel/channel-config.js b/node_modules/neo4j-driver-bolt-connection/lib/channel/channel-config.js +index 804e4d2..bc78cde 100644 +--- a/node_modules/neo4j-driver-bolt-connection/lib/channel/channel-config.js ++++ b/node_modules/neo4j-driver-bolt-connection/lib/channel/channel-config.js +@@ -32,7 +32,8 @@ var ALLOWED_VALUES_TRUST = [ + undefined, + 'TRUST_ALL_CERTIFICATES', + 'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES', +- 'TRUST_SYSTEM_CA_SIGNED_CERTIFICATES' ++ 'TRUST_SYSTEM_CA_SIGNED_CERTIFICATES', ++ 'TRUST_SERVER_CLIENT_CERTIFICATES' + ]; + var ChannelConfig = /** @class */ (function () { + /** +@@ -51,6 +52,9 @@ var ChannelConfig = /** @class */ (function () { + this.connectionErrorCode = connectionErrorCode || SERVICE_UNAVAILABLE; + this.connectionTimeout = driverConfig.connectionTimeout; + this.clientCertificate = clientCertificate; ++ this.cert = driverConfig.cert; ++ this.key = driverConfig.key; ++ this.passphrase = driverConfig.passphrase; + } + return ChannelConfig; + }()); diff --git a/reverse_engineering/api.js b/reverse_engineering/api.js index 60f389f..0491d7d 100644 --- a/reverse_engineering/api.js +++ b/reverse_engineering/api.js @@ -1,11 +1,10 @@ 'use strict'; -const { dependencies, setDependencies } = require('./appDependencies'); +const async = require('async'); +const _ = require('lodash'); const neo4j = require('./neo4jHelper'); const snippetsPath = '../snippets/'; const logHelper = require('./logHelper'); -let _; -let async; const snippets = { 'Cartesian 3D': require(snippetsPath + 'cartesian-3d.json'), @@ -18,8 +17,6 @@ module.exports = { connect: function (connectionInfo, logger, cb, app) { const sshService = app.require('@hackolade/ssh-service'); - initDependencies(app); - neo4j.connect(connectionInfo, checkConnection(logger), sshService).then( () => { logger.log('info', 'Successfully connected to the database instance', 'Connection'); @@ -45,7 +42,6 @@ module.exports = { testConnection: function (connectionInfo, logger, cb, app) { logInfo('Test connection', connectionInfo, logger); - initDependencies(app); this.connect( connectionInfo, logger, @@ -66,30 +62,33 @@ module.exports = { }, getDbCollectionsNames: async function (connectionInfo, logger, cb, app) { - logInfo('Retrieving labels information', connectionInfo, logger); + const step = 'Retrieving labels information'; + + logInfo(step, connectionInfo, logger); try { const sshService = app.require('@hackolade/ssh-service'); - initDependencies(app); neo4j.setTimeOut(connectionInfo); await neo4j.connect(connectionInfo, checkConnection(logger), sshService); logger.log('info', 'Successfully connected to the database instance', 'Connection'); const isMultiDb = await neo4j.supportsMultiDb(); + logger.log('info', `Multi database support: ${isMultiDb}`, step); const databaseNames = await neo4j.getDatabaseName('graph.db', isMultiDb); - logger.log('info', 'Name of database successfully retrieved', 'Retrieving labels information'); - const result = await Promise.all( - databaseNames.map(async name => { - return { - dbName: name, - dbCollections: await neo4j.getLabels(name, isMultiDb), - }; - }), - ); - logger.log('info', 'Labels successfully retrieved', 'Retrieving labels information'); - logger.log('info', 'Information about labels successfully retrieved', 'Retrieving labels information'); - cb(null, result); + logger.log('info', 'Database names are successfully retrieved', step); + + const results = []; + for (let databaseName of databaseNames) { + logger.log('info', `Fetching the labels from ${databaseName}`, step); + results.push({ + dbName: databaseName, + dbCollections: await neo4j.getLabels({ databaseName, isMultiDb, logger }), + }); + } + + logger.log('info', 'Labels are successfully retrieved', step); + cb(null, results); } catch (error) { logger.log( 'error', @@ -97,7 +96,7 @@ module.exports = { message: error.step || 'Process of retrieving labels was interrupted by error', error: prepareError(error), }, - 'Retrieving labels information', + step, ); const mappedError = { @@ -122,7 +121,6 @@ module.exports = { }, getDbCollectionsDataWrapped: async function (data, logger, cb, app) { - initDependencies(app); neo4j.setTimeOut(data); logger.log('info', data, 'Retrieving schema for chosen labels', data.hiddenKeys); @@ -277,13 +275,6 @@ module.exports = { }, }; -const initDependencies = app => { - setDependencies(app); - _ = dependencies.lodash; - async = dependencies.async; - neo4j.setDependencies(dependencies); -}; - const getSampleDocSize = (count, recordSamplingSettings) => { if (recordSamplingSettings.active === 'absolute') { return Number(recordSamplingSettings.absolute.value); diff --git a/reverse_engineering/appDependencies.js b/reverse_engineering/appDependencies.js deleted file mode 100644 index 1a0cfbd..0000000 --- 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/neo4jHelper.js b/reverse_engineering/neo4jHelper.js index f0c6bcf..71b0333 100644 --- a/reverse_engineering/neo4jHelper.js +++ b/reverse_engineering/neo4jHelper.js @@ -1,14 +1,13 @@ const neo4j = require('neo4j-driver'); const fs = require('fs'); +const _ = require('lodash'); let driver; let isSshTunnel = false; -let _; const EXECUTE_TIME_OUT_CODE = 'EXECUTE_TIME_OUT'; let timeout; -const setDependencies = ({ lodash }) => (_ = lodash); const setTimeOut = data => (timeout = data?.queryRequestTimeout || 300000); const connectToInstance = (info, checkConnection) => { @@ -137,16 +136,17 @@ const castInteger = properties => { return result; }; -const getLabels = async (database, isMultiDb) => { +const getLabels = async ({ database, isMultiDb, logger }) => { try { - const labels = await execute('MATCH (n) RETURN DISTINCT labels(n) as label', database, isMultiDb).then(data => { - let labels = []; - data.forEach(record => { - labels = labels.concat(record.label); - }); - return labels; - }); - return labels; + const recordsCounter = await execute( + 'MATCH (n) RETURN DISTINCT COUNT(labels(n)) as labelsCount', + database, + isMultiDb, + ); + logger.log('info', `Found ${_.head(recordsCounter).labelsCount} labels`, 'Retrieving labels information'); + + const records = await execute('MATCH (n) RETURN DISTINCT labels(n) as label', database, isMultiDb); + return _.flatMap(records, record => record.label); } catch (error) { error.step = error.step || 'Error of retrieving labels'; throw error; @@ -434,7 +434,6 @@ module.exports = { getConstraints, supportsMultiDb, getDbVersion, - setDependencies, setTimeOut, isTemporalTypeField, getTemporalFieldSchema,