Socket
Socket
Sign inDemoInstall

@sap/hdi

Package Overview
Dependencies
Maintainers
3
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sap/hdi - npm Package Compare versions

Comparing version 1.1.4 to 2.0.3

lib/main/Container.js

29

CHANGELOG.md

@@ -1,17 +0,22 @@

## 1.1.4
Features:
- Updated dependencies
## 2.0.3
Fixes:
- Locking now uses a second connection
- Improved typeCheck to correctly detect arrays when using the API with xsjs
## 1.1.3
## 2.0.2
Features:
- Updated dependencies
- Passes a complete credentials object to the hdb driver, which allows passing additional parameters to the hdb connection.
- Allows all instances of Readable as content for FileWithContent or FolderWithContent
## 1.1.2
Features:
- Added npm-shrinkwrap.json
Fixes:
- Fixed a spelling error in ResultTuple
## 1.1.1
## 2.0.1
Fixes:
- Fixed a type check error when passing an empty array as parameter
## 2.0.0
Features:
- Updated dependencies
- Added README.md
- Added CHANGELOG.md
- Provides access to the Container Group API
- Clearer split between the APIs, different classes for SYS_DI, Container and Container Group API
- Removed dependency on async library

@@ -1,942 +0,49 @@

/* jshint node: true */
'use strict';
var async = require('async');
var hdb = require('hdb');
const DependencyResultTuple = require('./lib/result/DependencyResultTuple');
const LibraryInformationResultTuple = require('./lib/result/LibraryInformationResultTuple');
const MakeGroupResultTuple = require('./lib/result/MakeGroupResultTuple');
const MetadataResultTuple = require('./lib/result/MetadataResultTuple');
const MetadataContentResultTuple = require('./lib/result/MetadataContentResultTuple');
const StatusResultTuple = require('./lib/result/StatusResultTuple');
const ResultTuple = require('./lib/ResultTuple');
var TempTables = require('./lib/tempTables.js');
var procHandler = require('./lib/callProcedure.js');
var jobWatcher = require('./lib/jobWatcher.js');
const APIPrivilege = require('./lib/parameter/APIPrivilege');
const File = require('./lib/parameter/File');
const FileWithContent = require('./lib/parameter/FileWithContent');
const Folder = require('./lib/parameter/Folder');
const FolderWithContent = require('./lib/parameter/FolderWithContent');
const HDIObject = require('./lib/parameter/HDIObject');
const LibraryConfiguration = require('./lib/parameter/LibraryConfiguration');
const Parameter = require('./lib/parameter/Parameter');
const PathParameter = require('./lib/parameter/PathParameter');
const SchemaPrivilege = require('./lib/parameter/SchemaPrivilege');
const SchemaRole = require('./lib/parameter/SchemaRole');
/*
* helper functions
*/
const HDI = require('./lib/main/HDI');
const ContainerGroup = require('./lib/main/ContainerGroup');
const Container = require('./lib/main/Container');
function _quoted_sql_identifier(identifier) {
return '"' + identifier.replace(/\"/g, '""') + '"';
}
function _connect(target, loggerCB, callback) {
target.connection.connect(function(err) {
if (err) {
return callback(err);
}
if (loggerCB) {
loggerCB('OK: connected to DB.');
}
callback(null, 'OK: connected to DB.');
});
}
// set the default schema to <container>#DI
function _set_schema(target, loggerCB, callback) {
target.schema = '_SYS_DI';
if (target.container) {
target.schema = target.container + '#DI';
}
target.connection.exec('SET SCHEMA ' + _quoted_sql_identifier(target.schema), function(err) {
if (err) {
return callback(err);
}
if (loggerCB) {
loggerCB('OK: schema set to ' + target.schema + '.');
}
callback(null, 'OK: schema set to ' + target.schema + '.');
});
}
// creates the required temporary tables if necessary
function _create_SYS_DI_temp_tables(target, logger, callback) {
if (target.sysDiTempTables.init) {
return callback(null, null);
}
var tasks = [
function(asyncCB) { target.tempTables.createSysDi(asyncCB); }
];
async.series(tasks, function(err, results) {
if (err) {
return callback(err);
}
target.sysDiTempTables.init = true;
return callback(null, results);
});
}
function _create_temp_tables(target, logger, callback) {
if (target.tempTables.init) {
return callback(null, null);
}
var tasks = [
//function(asyncCB) { _set_schema(target, logger, asyncCB); },
function(asyncCB) { target.tempTables.create(target.container, asyncCB); }
];
async.series(tasks, function(err, results) {
if (err) {
return callback(err);
}
target.tempTables.init = true;
return callback(null, results);
});
}
/*
* API
*/
// general DI procedures
function _configure_di(hdb, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var sql = "CALL _SYS_DI.CONFIGURE_DI(_SYS_DI.#PARAMETERS, ?, ?, ? )";
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _configure_di_parameters(hdb, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var sql = "CALL _SYS_DI.CONFIGURE_DI_PARAMETERS(_SYS_DI.#CONFIG_PARAMETERS, _SYS_DI.#PARAMETERS, ?, ?, ? )";
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _create_container(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var sql = "CALL _SYS_DI.CREATE_CONTAINER('" + container + "', _SYS_DI.#PARAMETERS, ?, ?, ?)";
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _delete_container(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var sql = "CALL _SYS_DI.DROP_CONTAINER('" + container + "', _SYS_DI.#PARAMETERS, ?, ?, ?)";
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
// returns a result set with structure like _SYS_DI.TT_LIBRARY_INFORMATION
function _list_libraries(hdb, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var sql = "CALL _SYS_DI.LIST_LIBRARIES(_SYS_DI.#PARAMETERS, ?, ?, ?, ?)";
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
// container-specific procedures
function _configure_container(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.CONFIGURE_CONTAINER(' + schema + '.#PARAMETERS, ?, ?, ? )';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _configure_container_parameters(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.CONFIGURE_CONTAINER_PARAMETERS(' + schema + '.#CONFIG_PARAMETERS, ' + schema + '.#PARAMETERS, ?, ?, ? )';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _configure_libraries(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.CONFIGURE_LIBRARIES(' + schema + '.#LIBRARY_CONFIG, ' + schema + '.#PARAMETERS, ?, ?, ? )';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _list_configured_libraries(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.LIST_CONFIGURED_LIBRARIES(' + schema + '.#PARAMETERS, ?, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _lock(hdb, container, timeout, callback) {
if (typeof timeout !== 'number') {
return callback(new Error('Parameter "timeout" must be a number.'));
}
var sql_params = {
'TIMEOUT': timeout,
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.LOCK(?, ' + schema + '.#PARAMETERS, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
// show the status of the given files/folders in the containers file systems
// OUT: RETURN_CODE, REQUEST_ID, MESSAGES, RESULT (FILESFOLDELDERS_STATUS)
function _status(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.STATUS(' + schema + '.#PATHS, ' + schema + '.#PARAMETERS, ?, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
// read the requested files/folders from the container's work file system
// OUT: RETURN_CODE, REQUEST_ID, MESSAGES, RESULT (FILESFOLDELDERS_METADATA_CONTENT)
function _read(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.READ(' + schema + '.#PATHS, ' + schema + '.#PARAMETERS, ?, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
// read metadata for the given files/folders from the conatiner's deployed file system
// OUT: RETURN_CODE, REQUEST_ID, MESSAGES, RESULT (FILESFOLDELDERS_METADATA)
function _list_deployed(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.LIST_DEPLOYED(' + schema + '.#PATHS, ' + schema + '.#PARAMETERS, ?, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
// read the requested files/folders from the container's deployed file system
// OUT: RETURN_CODE, REQUEST_ID, MESSAGES, RESULT (FILESFOLDELDERS_METADATA_CONTENT)
function _read_deployed(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.READ_DEPLOYED(' + schema + '.#PATHS, ' + schema + '.#PARAMETERS, ?, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _write(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.WRITE(' + schema + '.#PATHS_CONTENT, ' + schema + '.#PARAMETERS, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _delete(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.DELETE(' + schema + '.#PATHS, ' + schema + '.#PARAMETERS, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
// determine groups of objects which can be deployed independently
// OUT: RETURN_CODE, REQUEST_ID, MESSAGES, RESULT (MAKE_GROUPS)
function _get_make_groups(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.GET_MAKE_GROUPS(' + schema + '.#DEPLOY_PATHS, ' + schema + '.#UNDEPLOY_PATHS, ' + schema + '.#PATH_PARAMETERS, ' + schema + '.#PARAMETERS, ?, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _make(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.MAKE(' + schema + '.#DEPLOY_PATHS, ' + schema + '.#UNDEPLOY_PATHS, ' + schema + '.#PATH_PARAMETERS, ' + schema + '.#PARAMETERS, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _make_async(hdb, container, callback, listener) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.MAKE_ASYNC(' + schema + '.#DEPLOY_PATHS, ' + schema + '.#UNDEPLOY_PATHS, ' + schema + '.#PATH_PARAMETERS, ' + schema + '.#PARAMETERS, ?, ?, ?)';
function internalCB(err, results) {
if (err) {
return callback(err);
}
jobWatcher.waitForCompletion(hdb, container, results, listener);
return callback(null, results);
}
if (typeof listener === 'undefined' || listener === null) {
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
} else {
return procHandler.callHDIProcedure(hdb, sql, sql_params, internalCB);
}
}
function _grant_api_privileges(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.GRANT_CONTAINER_API_PRIVILEGES(' + schema + '.#API_PRIVILEGES, ' + schema + '.#PARAMETERS, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _grant_api_privileges_with_grant_option(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.GRANT_CONTAINER_API_PRIVILEGES_WITH_GRANT_OPTION(' + schema + '.#API_PRIVILEGES, ' + schema + '.#PARAMETERS, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _revoke_api_privileges(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.REVOKE_CONTAINER_API_PRIVILEGES(' + schema + '.#API_PRIVILEGES, ' + schema + '.#PARAMETERS, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _grant_schema_privileges(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.GRANT_CONTAINER_SCHEMA_PRIVILEGES(' + schema + '.#SCHEMA_PRIVILEGES, ' + schema + '.#PARAMETERS, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _revoke_schema_privileges(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.REVOKE_CONTAINER_SCHEMA_PRIVILEGES(' + schema + '.#SCHEMA_PRIVILEGES, ' + schema + '.#PARAMETERS, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _grant_schema_roles(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.GRANT_CONTAINER_SCHEMA_ROLES(' + schema + '.#SCHEMA_ROLES, ' + schema + '.#PARAMETERS, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
function _revoke_schema_roles(hdb, container, callback) {
var sql_params = {
'RETURN_CODE': null,
'REQUEST_ID': null
};
var schema = _quoted_sql_identifier(container + '#DI');
var sql = 'CALL ' + schema + '.REVOKE_CONTAINER_SCHEMA_ROLES(' + schema + '.#SCHEMA_ROLES, ' + schema + '.#PARAMETERS, ?, ?, ?)';
return procHandler.callHDIProcedure(hdb, sql, sql_params, callback);
}
/*
* module exports
*/
module.exports = function(container, loggerCB, credentials) {
var logger = loggerCB;
var target = {};
var target2 = {};
target.container = container;
target.connection = hdb.createClient(credentials);
target.connection.on('error', function(err) {
loggerCB('Network connection error: ' + err);
});
target.tempTables = new TempTables(target.connection, container, logger);
target.tempTables.init = false;
target.sysDiTempTables = {};
target.sysDiTempTables.init = false;
this.connect = function(externCB) {
return _connect(target, logger, externCB);
};
// only for testing; normally it will be called implicitely
this.createTempTables = function(externCB) {
return _create_temp_tables(target, logger, externCB);
};
/*
* general DI methods
*/
this.configureDI = function(call_params, externCB) {
var tasks = [
function(callback) { _create_SYS_DI_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillSysDiParameters(call_params, callback); },
function(callback) { _configure_di(target.connection, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
return externCB(null, lastResult);
});
};
this.configureDIParameters = function(di_params, call_params, externCB) {
var tasks = [
function(callback) { _create_SYS_DI_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillSysDiCOnfigParameters(call_params, callback); },
function(callback) { target.tempTables.fillSysDiParameters(call_params, callback); },
function(callback) { _configure_di_parameters(target.connection, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
return externCB(null, lastResult);
});
};
this.createContainer = function(container, call_params, externCB) {
var tasks = [
function(callback) { _create_SYS_DI_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillSysDiParameters(call_params, callback); },
function(callback) { _create_container(target.connection, container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
return externCB(null, lastResult);
});
};
this.dropContainer = function(container, call_params, externCB) {
var tasks = [
function(callback) { _create_SYS_DI_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillSysDiParameters(call_params, callback); },
function(callback) { _delete_container(target.connection, container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
return externCB(null, lastResult);
});
};
this.listLibraries = function(call_params, externCB) {
var tasks = [
function(callback) { _create_SYS_DI_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillSysDiParameters(call_params, callback); },
function(callback) { _list_libraries(target.connection, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
return externCB(null, lastResult);
});
};
/*
* container-specific methods
*/
this.configureContainer = function(call_params, externCB) {
var tasks = [
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _configure_container(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
return externCB(null, lastResult);
});
};
this.configureContainerParameters = function(container_params, call_params, externCB) {
var tasks = [
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillConfigParameters(container_params, callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _configure_container_parameters(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
return externCB(null, lastResult);
});
};
this.configureLibraries = function(libconfig, call_params, externCB) {
var tasks = [
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillLibraryConfig(libconfig, callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _configure_libraries(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
return externCB(null, lastResult);
});
};
this.listConfiguredLibraries = function(call_params, externCB) {
var tasks = [
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _list_configured_libraries(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
return externCB(null, lastResult);
});
};
this.lock = function(timeout, call_params, externCB) {
target2.container = container;
target2.connection = hdb.createClient(credentials);
target2.connection.setAutoCommit(false);
target2.connection.on('error', function(err) {
logger('Network connection2 error: ' + err);
});
target2.tempTables = new TempTables(target2.connection, container, logger);
target2.tempTables.init = false;
var tasks = [
function(callback) { _connect(target2, logger, callback); },
function(callback) { _create_temp_tables(target2, logger, callback); },
function(callback) { target2.tempTables.fillParameters(call_params, callback); },
function(callback) { _lock(target2.connection, target2.container, timeout, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
target2.tempTables = null;
target2.connection.close();
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
return externCB(null, lastResult);
});
};
this.unlock = function(externCB) {
target2.tempTables = null;
target2.connection.close();
externCB(null, null);
};
/**
* Shows the status of the given files/folders in the container's file systems.
* @param paths An array of path names (strings)
* @param call_params An object whose properties are either strings or lists of strings
*/
this.status = function(paths, call_params, externCB) {
var tasks = [
//function(callback) { _set_schema(target, logger, callback); }, // schema must already exist
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillPaths(paths, '#PATHS', callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _status(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
if (logger) {
logger(lastResult.MESSAGES);
}
return externCB(null, lastResult);
});
};
this.read = function(paths, call_params, externCB) {
var tasks = [
//function(callback) { _set_schema(target, logger, callback); }, // schema must already exist
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillPaths(paths, '#PATHS', callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _read(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
if (logger) {
logger(lastResult.MESSAGES);
}
return externCB(null, lastResult);
});
};
this.listDeployed = function(paths, call_params, externCB) {
var tasks = [
//function(callback) { _set_schema(target, logger, callback); }, // schema must already exist
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillPaths(paths, '#PATHS', callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _list_deployed(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
if (logger) {
logger(lastResult.MESSAGES);
}
return externCB(null, lastResult);
});
};
this.readDeployed = function(paths, call_params, externCB) {
var tasks = [
//function(callback) { _set_schema(target, logger, callback); }, // schema must already exist
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillPaths(paths, '#PATHS', callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _read_deployed(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
if (logger) {
logger(lastResult.MESSAGES);
}
return externCB(null, lastResult);
});
};
this.write = function(paths_content, call_params, externCB) {
var tasks = [
//function(callback) { _set_schema(target, logger, callback); }, // schema must already exist
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillPathsAndContent(paths_content, callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _write(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
if (logger) {
logger(lastResult.MESSAGES);
}
return externCB(null, lastResult);
});
};
this.delete = function(paths, call_params, externCB) {
var tasks = [
//function(callback) { _set_schema(target, logger, callback); }, // schema must already exist
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillPaths(paths, '#PATHS', callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _delete(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
if (logger) {
logger(lastResult.MESSAGES);
}
return externCB(null, lastResult);
});
};
this.getMakeGroups = function(deploy_paths, undeploy_paths, path_parameters, call_params, externCB) {
var tasks = [
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillPaths(deploy_paths, '#DEPLOY_PATHS', callback); },
function(callback) { target.tempTables.fillPaths(undeploy_paths, '#UNDEPLOY_PATHS', callback); },
function(callback) { target.tempTables.fillPathParameters(path_parameters, callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _get_make_groups(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
if (logger) {
logger(lastResult.MESSAGES);
}
return externCB(null, lastResult);
});
};
this.make = function(deploy_paths, undeploy_paths, path_parameters, call_params, externCB) {
var tasks = [
//function(callback) { _set_schema(target, logger, callback); }, // schema must already exist
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillPaths(deploy_paths, '#DEPLOY_PATHS', callback); },
function(callback) { target.tempTables.fillPaths(undeploy_paths, '#UNDEPLOY_PATHS', callback); },
function(callback) { target.tempTables.fillPathParameters(path_parameters, callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _make(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
if (logger) {
logger(lastResult.MESSAGES);
}
return externCB(null, lastResult);
});
};
this.makeAsync = function(deploy_paths, undeploy_paths, path_parameters, call_params, externCB, listenerCB) {
var tasks = [
//function(callback) { _set_schema(target, logger, callback); }, // schema must already exist
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillPaths(deploy_paths, '#DEPLOY_PATHS', callback); },
function(callback) { target.tempTables.fillPaths(undeploy_paths, '#UNDEPLOY_PATHS', callback); },
function(callback) { target.tempTables.fillPathParameters(path_parameters, callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _make_async(target.connection, target.container, callback, listenerCB); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
//console.log(">>> results: ", results);
if (logger && lastResult) {
logger(lastResult.MESSAGES);
}
return externCB(null, lastResult);
});
};
this.grantContainerApiPrivileges = function(privileges, call_params, externCB) {
var tasks = [
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillApiPrivileges(privileges, callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _grant_api_privileges(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
if (logger) {
logger(lastResult.MESSAGES);
}
return externCB(null, lastResult);
});
};
this.grantContainerApiPrivilegesWithGrantOption = function(privileges, call_params, externCB) {
var tasks = [
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillApiPrivileges(privileges, callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _grant_api_privileges_with_grant_option(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
if (logger) {
logger(lastResult.MESSAGES);
}
return externCB(null, lastResult);
});
};
this.revokeContainerApiPrivileges = function(privileges, call_params, externCB) {
var tasks = [
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillApiPrivileges(privileges, callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _revoke_api_privileges(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
if (logger) {
logger(lastResult.MESSAGES);
}
return externCB(null, lastResult);
});
};
this.grantContainerSchemaPrivileges = function(privileges, call_params, externCB) {
var tasks = [
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillSchemaPrivileges(privileges, callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _grant_schema_privileges(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
if (logger) {
logger(lastResult.MESSAGES);
}
return externCB(null, lastResult);
});
};
this.revokeContainerSchemaPrivileges = function(privileges, call_params, externCB) {
var tasks = [
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillSchemaPrivileges(privileges, callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _revoke_schema_privileges(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
if (logger) {
logger(lastResult.MESSAGES);
}
return externCB(null, lastResult);
});
};
this.grantContainerSchemaRoles = function(roles, call_params, externCB) {
var tasks = [
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillSchemaRoles(roles, callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _grant_schema_roles(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
if (logger) {
logger(lastResult.MESSAGES);
}
return externCB(null, lastResult);
});
};
this.revokeContainerSchemaRoles = function(roles, call_params, externCB) {
var tasks = [
function(callback) { _create_temp_tables(target, logger, callback); },
function(callback) { target.tempTables.fillSchemaRoles(roles, callback); },
function(callback) { target.tempTables.fillParameters(call_params, callback); },
function(callback) { _revoke_schema_roles(target.connection, target.container, callback); }
];
async.series(tasks, function(err, results) {
if (err) {
return externCB(err);
}
var lastResult = (results.length > 0) ? results[results.length - 1] : results;
if (logger) {
logger(lastResult.MESSAGES);
}
return externCB(null, lastResult);
});
};
this.disconnect = function() {
target.tempTables = null;
target.connection.close();
};
this.info = function() {
return target;
};
};
module.exports = {
HDI,
ContainerGroup,
Container,
ResultTuple,
DependencyResultTuple,
LibraryInformationResultTuple,
MakeGroupResultTuple,
MetadataResultTuple,
MetadataContentResultTuple,
StatusResultTuple,
APIPrivilege,
File,
FileWithContent,
Folder,
FolderWithContent,
HDIObject,
LibraryConfiguration,
Parameter,
PathParameter,
SchemaPrivilege,
SchemaRole,
};
{
"name": "@sap/hdi",
"version": "1.1.4",
"version": "2.0.3",
"dependencies": {
"async": {
"version": "2.6.1"
},
"hdb": {
"version": "0.15.4"
"version": "0.15.1"
},
"iconv-lite": {
"version": "0.4.24"
},
"lodash": {
"version": "4.17.11"
},
"safer-buffer": {
"version": "2.1.2"
"version": "0.4.19"
}
}
}

@@ -1,1 +0,1 @@

{"bundleDependencies":false,"dependencies":{"async":"2.6.1","hdb":"0.15.4"},"deprecated":false,"description":"HDI client library for node.js","devDependencies":{"filter-node-package":"2.0.0","jshint":"2.9.4","mocha":"3.2.0","should":"11.1.1"},"engines":{"node":">=6.0.0"},"main":"index.js","name":"@sap/hdi","repository":{"type":"git"},"scripts":{"lint":"jshint *.js lib/*.js","prepare-release":"clean-packages && npm prune --production && ls -al","test":"jshint *.js lib/*.js","test2":"mocha test/test.js"},"version":"1.1.4","license":"SEE LICENSE IN developer-license-3.1.txt"}
{"dependencies":{"hdb":"0.15.1"},"description":"HDI client library for node.js","devDependencies":{"command-line-args":"^4.0.7","command-line-usage":"^4.0.2","eslint":"4.10.0","eslint-plugin-node":"5.2.1","filter-node-package":"2.0.0","ink-docstrap":"1.3.0","istanbul":"^0.4.5","jsdoc":"3.5.5","jshint":"2.9.4","mocha":"3.2.0","node-style":"2.0.1","nyc":"11.2.1","shelljs":"0.6.0","should":"^13.1.3"},"engines":{"node":">=6.0.0"},"main":"index.js","maintainers":[{"name":"https-support.sap.com","email":"do-not-reply@sap.com"}],"name":"@sap/hdi","optionalDependencies":{},"readme":"@sap/hdi\n===============\n\n`@sap/hdi` is a [Node.js](https://nodejs.org) library that allows access to the SQL based API through Node.js. It provides access to the HDI-, Container-Group- and the Container-API.\n\n## Table of contents\n **Using the library**:\n- [General things](#general-things)\n- [Using the HDI API](#using-the-hdi-api)\n- [Using the Container Group API](#using-the-container-group-api)\n- [Using the Container API](#using-the-container-api)\n- [Using the API with xsjs](#using-the-api-with-xsjs)\n\n## General things\n\nAssuming that your **npm registry** is correctly configured and has access to SAP packages, simply running `npm install --save @sap/hdi` will install the package and add it as a dependency to your **package.json**.\n\nWe recommend using version 2.0.0 or higher. V2 of the API brings access to the Container Group API, major refactoring of the HDI and Container API into separate components and lots of pre-defined classes to make working with the API easier.\n\nNote that V2 is not backwards compatible to V1, code written with the old API will ***NOT*** run with new API. This documentation is for the V2 API.\n\nAll APIs require that the connected user has EXECUTE privileges for the corresponding SQL procedures and SELECT for all table types in SYS_DI (TT*).\n\nAlmost all methods are asynchronous and require a standard node-style callback, where the first parameter is any errors that occured and the second is the result.\n\n**This document only provides a really high-level and shallow overview of the API. For a more detailed, technical documentation, refer to the JSDoc. To generate the documentation, run `npm install jsdoc`,`npm install ink-docstrap` and then `npm run documentation`. The documentation can then be found in the `docs` folder.**\n\n\n## Using the HDI API\nAccess to the _SYS_DI API is provided by the `HDI` class. Access to this API requires HANA server version: 1.00.120 or newer. To work with the API, simply construct a new object, as can be seen in the following (ES6-based) example:\n\n```javascript\nconst { HDI } = require('@sap/hdi');\n\n#This credentials object will be directly passed to the hdb client. Any options accepted by the hdb client can be passed.\nconst credentials = {\n host : <host>,\n port : <port>,\n user : <user>,\n password: <password>\n};\n\nconst hdi = new HDI(credentials, parameterSchema);\n\nhdi.connect((error,result) => {\n if(error){\n throw error;\n }\n\n hdi.listLibraries(null,(error,result) => {\n if(error){\n throw error;\n }\n\n console.log(result);\n })\n})\n```\n\nTo construct an access object, you need the credentials for the HANA system and the `parameterSchema`. This schema will be used to create temporary tables to supply data to the underlying sql procedures.\n\n## Using the Container Group API\nThe Container Group API provides access to an **existing** container group. In order to use the API, you might need to first grant the correct rights by using `grantContainerGroupAPIPrivileges` of the HDI class.\n\nTo construct an access object, you need the credentials for the HANA system, the `parameterSchema` and the name of the container group.\n\n## Using the Container API\nThe Container API provides access to an **existing** container. In order to use the API, you might need to first grant the correct rights by using `grantContainerAPIPrivileges` of the ContainerGroup class.\n\nTo construct an access object, you need the credentials for the HANA system, the `parameterSchema` and the name of the container.\n\nExample: Deploying files to a container\n\n```javascript\n'use strict';\n\nconst fs = require('fs');\nconst async = require('async');\nconst path = require('path');\n\nconst {Container, HDI, FileWithContent, FolderWithContent, File, Parameter} = require('@sap/hdi');\n\n// This credentials object will be directly passed to the hdb client. Any options accepted by the hdb client can be passed.\nconst credentials = {\n host: 'host',\n port: 'port',\n user: 'user',\n password: 'password'\n};\n\nconst containerUserCredentials = {\n host: 'host',\n port: 'port',\n user: 'user',\n password: 'password'\n};\n\nconst containerName = 'container_name';\n\nconst hdi = new HDI(credentials, // Credentials to use for the HANA system.\n credentials.user // Schema where the user used for the connection has privileges to create temporary tables, for example the user's own schema.\n);\n\nconst containerUser = new Container(containerName, // Name of the container. Does not have to exist yet but has to exist before calling any methods.\n containerUserCredentials, // Credentials to use for the HANA system.\n containerUserCredentials.user // Schema where the user used for the connection has privileges to create temporary tables, for example the user's own schema.\n);\n\nconst fPath = 'folder/';\n\nconst cPath = 'folder/.hdiconfig';\nconst cContent = fs.createReadStream(`${__dirname}${path.sep}testdata${path.sep}.hdiconfig`);\n\nconst tPath = 'folder/table1.hdbtable';\nconst tContent = fs.createReadStream(`${__dirname}${path.sep}testdata${path.sep}table1.hdbtable`);\n\nconst rContent = fs.createReadStream(`${__dirname}${path.sep}testdata${path.sep}role.hdbrole`);\nconst rPath = 'folder/role.hdbrole';\n\nconst filesFoldersContent = [\n new FolderWithContent(fPath),\n new FileWithContent(cPath, cContent),\n new FileWithContent(tPath, tContent),\n new FileWithContent(rPath, rContent)\n];\n\nconst files = [new File(rPath), new File(cPath), new File(tPath)];\nconst params = [new Parameter('ignore_work', 'TRUE'), new Parameter('ignore_deployed', 'TRUE')];\n/**\n * Get the default privileges to work with a container and grant them to the container user.\n */\nconst handlePrivileges = (cb) => {\n hdi.getDefaultContainerUserPrivileges('', containerUserCredentials.user, (e, privileges) => {\n if (e) {\n return cb(e);\n }\n hdi.grantContainerApiPrivileges(containerName, privileges, null, cb);\n });\n};\n/**\n * Get the default libraries and allow them for the container.\n */\nconst handleLibraries = (cb) => {\n hdi.getDefaultLibraries((e, libraries) => {\n if (e) {\n return cb(e);\n }\n hdi.configureLibraries(containerName, libraries, null, cb);\n });\n};\nconst tasks = [\n (cb) => hdi.connect(cb),\n (cb) => hdi.createContainer(containerName, null, cb),\n handleLibraries,\n handlePrivileges,\n (cb) => containerUser.connect(cb),\n (cb) => containerUser.lock(0, null, cb),\n (cb) => containerUser.write(filesFoldersContent, null, cb),\n (cb) => containerUser.status(null, null, cb),\n (cb) => containerUser.list(null, null, cb),\n (cb) => containerUser.make(files, null, null, null, cb),\n (cb) => containerUser.unlock(cb),\n (cb) => {\n containerUser.disconnect(); cb(null, 'OK: disconnected.');\n },\n (cb) => hdi.dropContainer(containerName, params, cb)\n];\n\nasync.series(tasks, (e, results) => {\n /*\n *Check for errors\n *Check if all results have return code (rc) equal 0\n *If all rc are 0 and there are no errors, everything was successful.\n */\n});\n```\n\n## Using the API with xsjs\nSince most of the methods of the HDI, ContainerGroup and Container class are asynchronous, you need to use the provided `sync` functionality to use them in xsjs code.\nBe aware that this requires a version of xsjs that uses at least `\"@sap/fibrous\": \"0.5.0-0\"` as a dependency. This fixes issues with `sync` in combination with class methods.\n\nIf your version of xsjs is up to date in that regard, simply add `sync` before your method calls. This\n\n```javascript\nconst { HDI } = require('@sap/hdi');\n\n#This credentials object will be directly passed to the hdb client. Any options accepted by the hdb client can be passed.\nconst credentials = {\n host : <host>,\n port : <port>,\n user : <user>,\n password: <password>\n};\n\nconst hdi = new HDI(credentials, parameterSchema);\n\nhdi.connect((error,result) => {\n if(error){\n throw error;\n }\n\n hdi.listLibraries(null,(error,result) => {\n if(error){\n throw error;\n }\n\n console.log(result);\n })\n})\n```\nturns into this:\n```javascript\nvar { HDI } = $.require('@sap/hdi');\n\n#This credentials object will be directly passed to the hdb client. Any options accepted by the hdb client can be passed.\nvar credentials = {\n host : <host>,\n port : <port>,\n user : <user>,\n password: <password>\n};\n\nvar hdi = new HDI(credentials, parameterSchema);\n\nhdi.sync.connect();\nvar libraries = hdi.sync.listLibraries(null);\nconsole.log(libraries);\n```\n","readmeFilename":"README.md","repository":{"type":"git"},"scripts":{"coverage":"nyc --reporter=html mocha test/test.js","documentation":"jsdoc -d ./docs -t ./node_modules/ink-docstrap/template -R README.md -r index.js ./lib/","eslint":"eslint index.js lib/ test/","full_test":"node test/manage.js","lint":"jshint index.js lib/","pre-commit":"mocha test/test.js --reporter progress && npm run lint -- --fix","prepare-release":"clean-packages && npm prune --production && ls -al","test":"jshint index.js lib/","test-all.js":"node test-all-filtered.js","test-dev":"mocha test/test.js"},"version":"2.0.3","license":"SEE LICENSE IN developer-license-3.1.txt"}
@sap/hdi
===============
This is the node.js-based client library for HANA DI (HDI).
`@sap/hdi` is a [Node.js](https://nodejs.org) library that allows access to the SQL based API through Node.js. It provides access to the HDI-, Container-Group- and the Container-API.
Currently, the module provides the following asynchronous methods to access HDI functionality:
## Table of contents
**Using the library**:
- [General things](#general-things)
- [Using the HDI API](#using-the-hdi-api)
- [Using the Container Group API](#using-the-container-group-api)
- [Using the Container API](#using-the-container-api)
- [Using the API with xsjs](#using-the-api-with-xsjs)
- `connect`
- `disconnect`
- `configureDI`
- `configureDIParameters`
- `createContainer`
- `dropContainer`
- `configureContainer`
- `configureContainerParameters`
- `listLibraries`
- `configureLibraries`
- `listConfiguredLibraries`
- `status`
- `read`
- `listDeployed`
- `readDeployed`
- `write`
- `delete`
- `make`
- `makeAsync`
- `grantContainerApiPrivileges`
- `grantContainerApiPrivilegesWithGrantOption`
- `revokeContainerApiPrivileges`
- `grantContainerSchemaPrivileges`
- `revokeContainerSchemaPrivileges`
- `grantContainerSchemaRoles`
- `revokeContainerSchemaRoles`
## General things
After installing the module via npm, an application needs to create an instance of the client:
Assuming that your **npm registry** is correctly configured and has access to SAP packages, simply running `npm install --save @sap/hdi` will install the package and add it as a dependency to your **package.json**.
`hdi = new HDI(container, logger, credentials);`
We recommend using version 2.0.0 or higher. V2 of the API brings access to the Container Group API, major refactoring of the HDI and Container API into separate components and lots of pre-defined classes to make working with the API easier.
where `container` is the name of an existing container, `logger` is a callback function used to write logging information, and `credentials` is an object containing the host name, port, user and password that shall be used for the DB connection:
Note that V2 is not backwards compatible to V1, code written with the old API will ***NOT*** run with new API. This documentation is for the V2 API.
All APIs require that the connected user has EXECUTE privileges for the corresponding SQL procedures and SELECT for all table types in SYS_DI (TT*).
Almost all methods are asynchronous and require a standard node-style callback, where the first parameter is any errors that occured and the second is the result.
**This document only provides a really high-level and shallow overview of the API. For a more detailed, technical documentation, refer to the JSDoc. To generate the documentation, run `npm install jsdoc`,`npm install ink-docstrap` and then `npm run documentation`. The documentation can then be found in the `docs` folder.**
## Using the HDI API
Access to the _SYS_DI API is provided by the `HDI` class. Access to this API requires HANA server version: 1.00.120 or newer. To work with the API, simply construct a new object, as can be seen in the following (ES6-based) example:
```javascript
const { HDI } = require('@sap/hdi');
#This credentials object will be directly passed to the hdb client. Any options accepted by the hdb client can be passed.
const credentials = {
host : <host>,
port : <port>,
user : <user>,
password: <password>
};
const hdi = new HDI(credentials, parameterSchema);
hdi.connect((error,result) => {
if(error){
throw error;
}
hdi.listLibraries(null,(error,result) => {
if(error){
throw error;
}
console.log(result);
})
})
```
{ host : 'hostname',
port : 30015,
user : 'user',
password : 'secret' }
```
The connection to the database is established with the `connect` method, which takes only a callback function as parameter.
When the application finishes, it should call
`hdi.disconnect();`
To construct an access object, you need the credentials for the HANA system and the `parameterSchema`. This schema will be used to create temporary tables to supply data to the underlying sql procedures.
**configureDI**
(Deprecated)
Configures HDI with the given parameters.
- `call_params`: an object with key/value pairs configuring HDI and controlling the HDI behaviour
- `externCB`: a callback function used to return errors or results
## Using the Container Group API
The Container Group API provides access to an **existing** container group. In order to use the API, you might need to first grant the correct rights by using `grantContainerGroupAPIPrivileges` of the HDI class.
**configureDIParameters**
Configures HDI with the given configuration parameters and the given parameters.
- `di_params`: an object with key/value pairs configuring HDI
- `call_params`: an object with key/value pairs controlling the HDI behaviour
- `externCB`: a callback function used to return errors or results
To construct an access object, you need the credentials for the HANA system, the `parameterSchema` and the name of the container group.
**createContainer**
Creates a container with the given container id.
- `container`: the container id/name
- `call_params`: an object with key/value pairs controlling the HDI behaviour
- `externCB`: a callback function used to return errors or results
## Using the Container API
The Container API provides access to an **existing** container. In order to use the API, you might need to first grant the correct rights by using `grantContainerAPIPrivileges` of the ContainerGroup class.
**dropContainer**
Drops the container with the given container id, incl. all corresponding technical users, schemata, tables, etc.
- `container`: the container id/name
- `call_params`: an object with key/value pairs controlling the HDI behaviour
- `externCB`: a callback function used to return errors or results
To construct an access object, you need the credentials for the HANA system, the `parameterSchema` and the name of the container.
**configureContainer**
(Deprecated) Configures the container with the given parameters.
- `call_params`: an object with key/value pairs configuring the container and controlling the HDI behaviour
- `externCB`: a callback function used to return errors or results
Example: Deploying files to a container
**configureContainerParameters**
Configures the container with the given configuration parameters and the given parameters.
- `container_params`: an object with key/value pairs configuring the container
- `call_params`: an object with key/value pairs controlling the HDI behaviour
- `externCB`: a callback function used to return errors or results
```javascript
'use strict';
**listLibraries**
List all available plugin libraries that can be installed into a container.
- `call_params`: an object with key/value pairs controlling the HDI behaviour
- `externCB`: a callback function used to return errors or results
const fs = require('fs');
const async = require('async');
const path = require('path');
**configureLibraries**
(Re)configures the set of plugin libraries which are installed in the given container.
- `libconfig`: an array of ``[action, library_name]`` tuples. `action` could be `ADD` or `REMOVE`
- `call_params`: an object with key/value pairs controlling the HDI behaviour
- `externCB`: a callback function used to return errors or results
const {Container, HDI, FileWithContent, FolderWithContent, File, Parameter} = require('@sap/hdi');
**listConfiguredLibraries**
List the set of plugin libraries which are installed in the given container.
- `call_params`: an object with key/value pairs controlling the HDI behaviour
- `externCB`: a callback function used to return errors or results
// This credentials object will be directly passed to the hdb client. Any options accepted by the hdb client can be passed.
const credentials = {
host: 'host',
port: 'port',
user: 'user',
password: 'password'
};
**status**
Shows the status of files and folders in the container. It takes the following parameters:
- `paths`: an array of path names (strings)
- `call_params`: an object with key/value pairs controlling the HDI behaviour
- `externCB`: a callback function used to return errors or results
const containerUserCredentials = {
host: 'host',
port: 'port',
user: 'user',
password: 'password'
};
**read**
Reads files/folders from the containers `work file system`. It takes the same parameters as `status`
const containerName = 'container_name';
**readDeployed**
Like `read`, but reads files/folders from the containers `deployed file system`.
const hdi = new HDI(credentials, // Credentials to use for the HANA system.
credentials.user // Schema where the user used for the connection has privileges to create temporary tables, for example the user's own schema.
);
**listDeployed**
Like `readDeployed`, but reads only metadata for files/folders from the containers `deployed file system`.
const containerUser = new Container(containerName, // Name of the container. Does not have to exist yet but has to exist before calling any methods.
containerUserCredentials, // Credentials to use for the HANA system.
containerUserCredentials.user // Schema where the user used for the connection has privileges to create temporary tables, for example the user's own schema.
);
**write**
Writes files/folders to the containers `work file system`. It takes the following parameters:
- `paths_content`: an array of arrays, containing the path names and the corresponding file content
- `call_params`: an object with key/value pairs controlling the HDI behaviour
- `externCB`: a callback function used to return errors or results
const fPath = 'folder/';
**delete**
Deletes files/folders from the containers `work file system`. It takes the same parameters as `read`.
const cPath = 'folder/.hdiconfig';
const cContent = fs.createReadStream(`${__dirname}${path.sep}testdata${path.sep}.hdiconfig`);
**make**/**makeAsync**
Triggers a synchronous resp. asynchronous make with the given sets of files/folders.
- `deploy_paths`: an array of path names, listing the files/folders to deploy
- `undeploy_paths`: an array of path names, listing the files/folders to undeploy
- `path_parameters`: an object with path names as keys and file specific parameters (like call_params) for each such path
- `call_params`: an object with key/value pairs controlling the HDI behaviour
- `externCB`: a callback function used to return errors or results
const tPath = 'folder/table1.hdbtable';
const tContent = fs.createReadStream(`${__dirname}${path.sep}testdata${path.sep}table1.hdbtable`);
**grantContainerApiPrivileges**/**grantContainerApiPrivilegesWithGrantOption**
Grants the given privileges on the containers API objects to the given users.
- `privileges`: an array of arrays (4-tuples: privilege name, object name, principal schema name, principal name)
- `call_params`: an object with key/value pairs controlling the HDI behaviour
- `externCB`: a callback function used to return errors or results
const rContent = fs.createReadStream(`${__dirname}${path.sep}testdata${path.sep}role.hdbrole`);
const rPath = 'folder/role.hdbrole';
**revokeContainerApiPrivileges**
Revokes the given privileges on the containers API objects from the given users.
It takes the same parameters as grantContainerApiPrivileges.
const filesFoldersContent = [
new FolderWithContent(fPath),
new FileWithContent(cPath, cContent),
new FileWithContent(tPath, tContent),
new FileWithContent(rPath, rContent)
];
**grantContainerSchemaPrivileges**
Grants the given privileges on the containers target schema to the given users.
- `privileges`: array of arrays (3-tuples: privilege name, principal schema name, principal name)
- `call_params`: an object with key/value pairs controlling the HDI behaviour
- `externCB`: a callback function used to return errors or results
const files = [new File(rPath), new File(cPath), new File(tPath)];
const params = [new Parameter('ignore_work', 'TRUE'), new Parameter('ignore_deployed', 'TRUE')];
/**
* Get the default privileges to work with a container and grant them to the container user.
*/
const handlePrivileges = (cb) => {
hdi.getDefaultContainerUserPrivileges('', containerUserCredentials.user, (e, privileges) => {
if (e) {
return cb(e);
}
hdi.grantContainerApiPrivileges(containerName, privileges, null, cb);
});
};
/**
* Get the default libraries and allow them for the container.
*/
const handleLibraries = (cb) => {
hdi.getDefaultLibraries((e, libraries) => {
if (e) {
return cb(e);
}
hdi.configureLibraries(containerName, libraries, null, cb);
});
};
const tasks = [
(cb) => hdi.connect(cb),
(cb) => hdi.createContainer(containerName, null, cb),
handleLibraries,
handlePrivileges,
(cb) => containerUser.connect(cb),
(cb) => containerUser.lock(0, null, cb),
(cb) => containerUser.write(filesFoldersContent, null, cb),
(cb) => containerUser.status(null, null, cb),
(cb) => containerUser.list(null, null, cb),
(cb) => containerUser.make(files, null, null, null, cb),
(cb) => containerUser.unlock(cb),
(cb) => {
containerUser.disconnect(); cb(null, 'OK: disconnected.');
},
(cb) => hdi.dropContainer(containerName, params, cb)
];
**revokeContainerSchemaPrivileges**
Revokes the given privileges on the containers target schema from the given users.
It takes the same parameters as grantContainerSchemaPrivileges.
async.series(tasks, (e, results) => {
/*
*Check for errors
*Check if all results have return code (rc) equal 0
*If all rc are 0 and there are no errors, everything was successful.
*/
});
```
**grantContainerSchemaRoles**
Grants the given roles (which are deployed inside the container) to the given users.
- `roles`: array of arrays (3-tuples: role name, principal schema name, principal name)
- `call_params`: an object with key/value pairs controlling the HDI behaviour
- `externCB`: a callback function used to return errors or results
## Using the API with xsjs
Since most of the methods of the HDI, ContainerGroup and Container class are asynchronous, you need to use the provided `sync` functionality to use them in xsjs code.
Be aware that this requires a version of xsjs that uses at least `"@sap/fibrous": "0.5.0-0"` as a dependency. This fixes issues with `sync` in combination with class methods.
**revokeContainerSchemaRoles**
Revokes the given roles (which are deployed inside the container) from the given users.
It takes the same parameters as grantContainerSchemaRoles.
If your version of xsjs is up to date in that regard, simply add `sync` before your method calls. This
```javascript
const { HDI } = require('@sap/hdi');
#This credentials object will be directly passed to the hdb client. Any options accepted by the hdb client can be passed.
const credentials = {
host : <host>,
port : <port>,
user : <user>,
password: <password>
};
const hdi = new HDI(credentials, parameterSchema);
hdi.connect((error,result) => {
if(error){
throw error;
}
hdi.listLibraries(null,(error,result) => {
if(error){
throw error;
}
console.log(result);
})
})
```
turns into this:
```javascript
var { HDI } = $.require('@sap/hdi');
#This credentials object will be directly passed to the hdb client. Any options accepted by the hdb client can be passed.
var credentials = {
host : <host>,
port : <port>,
user : <user>,
password: <password>
};
var hdi = new HDI(credentials, parameterSchema);
hdi.sync.connect();
var libraries = hdi.sync.listLibraries(null);
console.log(libraries);
```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc