@sap/async-xsjs 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE +37 -0
  3. package/README.md +445 -0
  4. package/differences.md +162 -0
  5. package/docs/$.Application.html +262 -0
  6. package/docs/$.Session.html +674 -0
  7. package/docs/$.db.CallableStatement.html +2524 -0
  8. package/docs/$.db.Connection.html +511 -0
  9. package/docs/$.db.ParameterMetaData.html +805 -0
  10. package/docs/$.db.PreparedStatement.html +1796 -0
  11. package/docs/$.db.ResultSet.html +1308 -0
  12. package/docs/$.db.ResultSetMetaData.html +800 -0
  13. package/docs/$.db.SQLException.html +259 -0
  14. package/docs/$.db.html +773 -0
  15. package/docs/$.hdb.ColumnMetadata.html +438 -0
  16. package/docs/$.hdb.Connection.html +663 -0
  17. package/docs/$.hdb.ProcedureResult.html +280 -0
  18. package/docs/$.hdb.ResultSet.html +324 -0
  19. package/docs/$.hdb.ResultSetIterator.html +315 -0
  20. package/docs/$.hdb.ResultSetMetaData.html +259 -0
  21. package/docs/$.hdb.SQLException.html +259 -0
  22. package/docs/$.hdb.html +557 -0
  23. package/docs/$.html +471 -0
  24. package/docs/$.jobs.Job.html +783 -0
  25. package/docs/$.jobs.JobLog.html +380 -0
  26. package/docs/$.jobs.JobSchedules.html +852 -0
  27. package/docs/$.jobs.html +238 -0
  28. package/docs/$.net.Destination.html +304 -0
  29. package/docs/$.net.Mail.Part.html +510 -0
  30. package/docs/$.net.Mail.html +504 -0
  31. package/docs/$.net.SMTPConnection.html +347 -0
  32. package/docs/$.net.html +749 -0
  33. package/docs/$.net.http.Client.html +562 -0
  34. package/docs/$.net.http.Destination.html +237 -0
  35. package/docs/$.net.http.Request.html +567 -0
  36. package/docs/$.net.http.html +292 -0
  37. package/docs/$.security.AntiVirus.html +361 -0
  38. package/docs/$.security.Store.html +636 -0
  39. package/docs/$.security.crypto.html +414 -0
  40. package/docs/$.security.html +247 -0
  41. package/docs/$.security.x509.html +373 -0
  42. package/docs/$.text.analysis.Session.html +983 -0
  43. package/docs/$.text.analysis.html +242 -0
  44. package/docs/$.text.html +246 -0
  45. package/docs/$.text.mining.Session.html +2018 -0
  46. package/docs/$.text.mining.html +242 -0
  47. package/docs/$.trace.html +525 -0
  48. package/docs/$.util.SAXParser.html +955 -0
  49. package/docs/$.util.Zip.html +474 -0
  50. package/docs/$.util.codec.html +414 -0
  51. package/docs/$.util.compression.html +357 -0
  52. package/docs/$.util.html +325 -0
  53. package/docs/$.util.sql.html +290 -0
  54. package/docs/$.web.Body.html +333 -0
  55. package/docs/$.web.EntityList.html +296 -0
  56. package/docs/$.web.TupelList.html +496 -0
  57. package/docs/$.web.WebEntityRequest.html +393 -0
  58. package/docs/$.web.WebEntityResponse.html +392 -0
  59. package/docs/$.web.WebRequest.html +560 -0
  60. package/docs/$.web.WebResponse.html +609 -0
  61. package/docs/$.web.html +246 -0
  62. package/docs/Copyright-SAP.html +39 -0
  63. package/docs/Disclaimer-SAP.html +55 -0
  64. package/docs/index.html +232 -0
  65. package/docs/styles/jsdoc-default.css +382 -0
  66. package/lib/AppConfig.js +36 -0
  67. package/lib/AuditLogger.js +41 -0
  68. package/lib/cacert.js +26 -0
  69. package/lib/ctypes.js +153 -0
  70. package/lib/destinations/dest-provider.js +57 -0
  71. package/lib/index.js +235 -0
  72. package/lib/jobs/Action.js +40 -0
  73. package/lib/jobs/Job.js +100 -0
  74. package/lib/jobs/JobManager.js +150 -0
  75. package/lib/jobs/JobsRuntime.js +133 -0
  76. package/lib/jobs/SqlScriptJobRunner.js +36 -0
  77. package/lib/jobs/XsjsJobRunner.js +78 -0
  78. package/lib/jobs/index.js +11 -0
  79. package/lib/logging.js +16 -0
  80. package/lib/middleware.js +125 -0
  81. package/lib/odata/ODataService.js +125 -0
  82. package/lib/odata/index.js +7 -0
  83. package/lib/odata/service-factory.js +26 -0
  84. package/lib/passport-noauth.js +17 -0
  85. package/lib/routes.js +115 -0
  86. package/lib/runtime.js +740 -0
  87. package/lib/sandbox.js +40 -0
  88. package/lib/utils/XsJsFunctionRunner.js +57 -0
  89. package/lib/utils/XsJsLibFunctionRunner.js +57 -0
  90. package/lib/utils/buffer-utils.js +77 -0
  91. package/lib/utils/compression-utils.js +14 -0
  92. package/lib/utils/date-utils.js +104 -0
  93. package/lib/utils/errors/HttpError.js +20 -0
  94. package/lib/utils/errors/wrap-app-error.js +18 -0
  95. package/lib/utils/index.js +17 -0
  96. package/lib/utils/xs-function-runner.js +51 -0
  97. package/lib/utils/xs-types.js +21 -0
  98. package/lib/utils/xspath.js +36 -0
  99. package/lib/utils/xsstack.js +28 -0
  100. package/lib/views/error.html +28 -0
  101. package/lib/xsjs/Application.js +28 -0
  102. package/lib/xsjs/Locale.js +53 -0
  103. package/lib/xsjs/Session.js +31 -0
  104. package/lib/xsjs/constants.js +71 -0
  105. package/lib/xsjs/db/common/DbBase.js +85 -0
  106. package/lib/xsjs/db/common/DbOptions.js +163 -0
  107. package/lib/xsjs/db/common/arguments-validation.js +102 -0
  108. package/lib/xsjs/db/common/connection.js +12 -0
  109. package/lib/xsjs/db/common/enums.js +93 -0
  110. package/lib/xsjs/db/common/execute-batch.js +38 -0
  111. package/lib/xsjs/db/common/parse-time.js +139 -0
  112. package/lib/xsjs/db/dbapi/CallableStatement.js +192 -0
  113. package/lib/xsjs/db/dbapi/Connection.js +78 -0
  114. package/lib/xsjs/db/dbapi/DB.js +39 -0
  115. package/lib/xsjs/db/dbapi/ParameterMetaData.js +118 -0
  116. package/lib/xsjs/db/dbapi/PreparedStatement.js +78 -0
  117. package/lib/xsjs/db/dbapi/ResultSet.js +220 -0
  118. package/lib/xsjs/db/dbapi/ResultSetMetaData.js +116 -0
  119. package/lib/xsjs/db/dbapi/Statement.js +514 -0
  120. package/lib/xsjs/db/dbapi/conversions.js +113 -0
  121. package/lib/xsjs/db/dbapi/fetch-rows.js +32 -0
  122. package/lib/xsjs/db/hdbapi/Connection.js +525 -0
  123. package/lib/xsjs/db/hdbapi/HDB.js +32 -0
  124. package/lib/xsjs/db/hdbapi/ResultSetIterator.js +40 -0
  125. package/lib/xsjs/db/hdbapi/convert.js +77 -0
  126. package/lib/xsjs/db/hdbapi/table-string-parser.js +52 -0
  127. package/lib/xsjs/db/index.js +4 -0
  128. package/lib/xsjs/index.js +13 -0
  129. package/lib/xsjs/jobs/Job.js +228 -0
  130. package/lib/xsjs/jobs/Jobs.js +11 -0
  131. package/lib/xsjs/jobs/Logs.js +127 -0
  132. package/lib/xsjs/jobs/Schedule.js +110 -0
  133. package/lib/xsjs/jobs/Schedules.js +108 -0
  134. package/lib/xsjs/net/Destination.js +43 -0
  135. package/lib/xsjs/net/http/Client.js +220 -0
  136. package/lib/xsjs/net/http/HTTP.js +72 -0
  137. package/lib/xsjs/net/index.js +5 -0
  138. package/lib/xsjs/net/smtp/Mail.js +38 -0
  139. package/lib/xsjs/net/smtp/Part.js +30 -0
  140. package/lib/xsjs/net/smtp/SMTPConnection.js +39 -0
  141. package/lib/xsjs/net/smtp/index.js +18 -0
  142. package/lib/xsjs/net/smtp/nodemailer-util.js +77 -0
  143. package/lib/xsjs/require.js +39 -0
  144. package/lib/xsjs/security/AntiVirus.js +31 -0
  145. package/lib/xsjs/security/Store.js +119 -0
  146. package/lib/xsjs/security/crypto.js +23 -0
  147. package/lib/xsjs/security/index.js +5 -0
  148. package/lib/xsjs/security/x509.js +12 -0
  149. package/lib/xsjs/text/analysis/Session.js +128 -0
  150. package/lib/xsjs/text/index.js +30 -0
  151. package/lib/xsjs/text/mining/Session.js +82 -0
  152. package/lib/xsjs/trace/trace.js +41 -0
  153. package/lib/xsjs/util/SAXParser.js +174 -0
  154. package/lib/xsjs/util/Zip.js +220 -0
  155. package/lib/xsjs/util/codec.js +33 -0
  156. package/lib/xsjs/util/compression.js +24 -0
  157. package/lib/xsjs/util/index.js +22 -0
  158. package/lib/xsjs/web/BasicWebEntity.js +41 -0
  159. package/lib/xsjs/web/EntityList.js +11 -0
  160. package/lib/xsjs/web/TupelLists/CookiesTupelList.js +47 -0
  161. package/lib/xsjs/web/TupelLists/HeadersTupelList.js +55 -0
  162. package/lib/xsjs/web/TupelLists/ParametersTupelList.js +83 -0
  163. package/lib/xsjs/web/TupelLists/TupelListBase.js +45 -0
  164. package/lib/xsjs/web/WebBody.js +135 -0
  165. package/lib/xsjs/web/WebEntityRequest.js +40 -0
  166. package/lib/xsjs/web/WebEntityResponse.js +26 -0
  167. package/lib/xsjs/web/WebRequest.js +209 -0
  168. package/lib/xsjs/web/WebResponse.js +183 -0
  169. package/lib/xsjs/web/index.js +4 -0
  170. package/lib/xsjs/web/utils/HeadersParser.js +53 -0
  171. package/lib/xsjs/web/utils/HttpRequestParser.js +93 -0
  172. package/lib/xsjs/web/utils/MultipartParser.js +163 -0
  173. package/lib/xsjs/web/utils/MultipartResponseBuilder.js +73 -0
  174. package/lib/xsjs/web/utils/SetCookieParser.js +32 -0
  175. package/lib/xsjslib/TextBundleWrapper.js +46 -0
  176. package/lib/xsjslib/index.js +11 -0
  177. package/npm-shrinkwrap.json +11540 -0
  178. package/package.json +84 -0
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ var util = require('util');
4
+
5
+ module.exports = Session;
6
+
7
+ function Session(req, locale) {
8
+ this.user = req.user && req.user.id;
9
+ var language = locale && locale.sessionLanguage || '';
10
+ Object.defineProperty(this, 'language', {
11
+ value: language,
12
+ enumerable: true
13
+ });
14
+ this.securityContext = req.authInfo;
15
+ }
16
+
17
+ Session.prototype.getUsername = function () {
18
+ return this.user && this.user.toUpperCase();
19
+ };
20
+
21
+ Session.prototype.assertAppPrivilege = function (privilegeName) {
22
+ if (!this.hasAppPrivilege(privilegeName)) {
23
+ var err = new Error(util.format('User %s has no %s privilege.', this.user, privilegeName));
24
+ err.privilege = privilegeName;
25
+ throw err;
26
+ }
27
+ };
28
+
29
+ Session.prototype.hasAppPrivilege = function (privilegeName) {
30
+ return !!this.securityContext && this.securityContext.checkLocalScope(privilegeName);
31
+ };
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ exports.httpStatusCodes = {
4
+ CONTINUE: 100,
5
+ SWITCH_PROTOCOL: 101,
6
+
7
+ OK: 200,
8
+ CREATED: 201,
9
+ ACCEPTED: 202,
10
+ NON_AUTHORITATIVE: 203,
11
+ NO_CONTENT: 204,
12
+ RESET_CONTENT: 205,
13
+ PARTIAL_CONTENT: 206,
14
+
15
+ MULTIPLE_CHOICES: 300,
16
+ MOVED_PERMANENTLY: 301,
17
+ FOUND: 302,
18
+ SEE_OTHER: 303,
19
+ NOT_MODIFIED: 304,
20
+ USE_PROXY: 305,
21
+ TEMPORARY_REDIRECT: 307,
22
+
23
+ BAD_REQUEST: 400,
24
+ UNAUTHORIZED: 401,
25
+ PAYMENT_REQUIRED: 402,
26
+ FORBIDDEN: 403,
27
+ NOT_FOUND: 404,
28
+ METHOD_NOT_ALLOWED: 405,
29
+ NOT_ACCEPTABLE: 406,
30
+ PROXY_AUTH_REQUIRED: 407,
31
+ REQUEST_TIMEOUT: 408,
32
+ CONFLICT: 409,
33
+ GONE: 410,
34
+ LENGTH_REQUIRED: 411,
35
+ PRECONDITION_FAILED: 412,
36
+ REQUEST_ENTITY_TOO_LARGE: 413,
37
+ REQUEST_URI_TOO_LONG: 414,
38
+ UNSUPPORTED_MEDIA_TYPE: 415,
39
+ REQUESTED_RANGE_NOT_SATISFIABLE: 416,
40
+ EXPECTATION_FAILED: 417,
41
+
42
+ INTERNAL_SERVER_ERROR: 500,
43
+ NOT_YET_IMPLEMENTED: 501,
44
+ BAD_GATEWAY: 502,
45
+ SERVICE_UNAVAILABLE: 503,
46
+ GATEWAY_TIMEOUT: 504,
47
+ HTTP_VERSION_NOT_SUPPORTED: 505
48
+ };
49
+
50
+ exports.webTypes = {
51
+ INVALID: -1,
52
+ OPTIONS: 0,
53
+ GET: 1,
54
+ HEAD: 2,
55
+ POST: 3,
56
+ PUT: 4,
57
+ DEL: 5,
58
+ TRACE: 6,
59
+ CONNECT: 7,
60
+ PATCH: 8
61
+ };
62
+
63
+ exports.WEB = {
64
+ MESSAGES : {
65
+ LINE_BREAK : '\r\n'
66
+ },
67
+ MESSAGE_TYPE : {
68
+ REQUEST : 'request',
69
+ RESPONSE : 'response'
70
+ }
71
+ };
@@ -0,0 +1,85 @@
1
+ 'use strict';
2
+
3
+ var _ = require('lodash');
4
+ var connection = require('./connection');
5
+ var enums = require('./enums');
6
+
7
+ module.exports = DbBase;
8
+
9
+ function DbBase(dbReqOptions) {
10
+ this._dbReqOptions = dbReqOptions;
11
+ this._openConnections = new Set();
12
+ }
13
+
14
+ DbBase.prototype.isolation = enums.isolationLevel.XSC;
15
+ DbBase.prototype.types = enums.types.XSC;
16
+
17
+ DbBase.prototype._getClient = async function (userOptions) {
18
+ var sqlccName = getSqlccName(userOptions);
19
+ var hanaOptions = (sqlccName) ?
20
+ this._dbReqOptions.getSqlccOptions(sqlccName) :
21
+ await this._dbReqOptions.getInstanceOptionsPromise();
22
+
23
+ hanaOptions = mergeUserOptions(hanaOptions, userOptions);
24
+ this._options = hanaOptions; // used by $.text
25
+ var client = await connection.connect(hanaOptions);
26
+
27
+ var openConnections = this._openConnections;
28
+ openConnections.add(client);
29
+
30
+ var originalClose = client.close;
31
+
32
+ Object.defineProperty(client, 'close', {
33
+ writable: true,
34
+ value: function () {
35
+ openConnections.delete(client);
36
+ client.close = originalClose;
37
+ originalClose.apply(client, arguments);
38
+ }
39
+ });
40
+
41
+ return client;
42
+ };
43
+
44
+ DbBase.prototype._closeAllConnections = function () {
45
+ for (var client of this._openConnections) {
46
+ client.close(function() { }); // ignoring an error here
47
+ }
48
+ this._openConnections.clear();
49
+ };
50
+
51
+ function getSqlccName(userOptions) {
52
+ userOptions = userOptions || {};
53
+ if (!userOptions.sqlcc) {
54
+ return;
55
+ }
56
+
57
+ if (!_.isString(userOptions.sqlcc)) {
58
+ throw new TypeError('The provided SQLCC name is not a string');
59
+ }
60
+
61
+ var sqlccName = userOptions.sqlcc.trim();
62
+ if (!sqlccName) {
63
+ throw new TypeError('The provided SQLCC name is empty string or contains only whitespaces');
64
+ }
65
+ return sqlccName;
66
+ }
67
+
68
+ function extractUserOptions(userOptions) {
69
+ var acceptedProperties = ['sqlcc', 'isolationLevel', 'locale', 'treatDateAsUTC'];
70
+ var filtered = _.pick(userOptions, acceptedProperties);
71
+ if (filtered.isolationLevel) {
72
+ filtered.isolationLevel = enums.convert.toDriverIsolationLevel(filtered.isolationLevel);
73
+ }
74
+ if ('locale' in filtered && !filtered.locale) {
75
+ // falsy values for locale provided in xsjs code are ignored
76
+ delete filtered.locale;
77
+ }
78
+ return filtered;
79
+ }
80
+
81
+ function mergeUserOptions(options, userOptions) {
82
+ userOptions = extractUserOptions(userOptions);
83
+ var opt = _.extend({}, options, userOptions);
84
+ return opt;
85
+ }
@@ -0,0 +1,163 @@
1
+ 'use strict';
2
+
3
+ var _ = require('lodash');
4
+ var VError = require('verror');
5
+ var HttpError = require('../../../utils/errors/HttpError');
6
+ var connOptions = require('@sap/hdbext').connectionOptions;
7
+ var instanceManager = require('@sap/instance-manager');
8
+
9
+ var INSTANCE_MANAGER_OPTS = [
10
+ 'user', 'password',
11
+ 'post_managed_instance_url', 'delete_managed_instance_url',
12
+ 'get_managed_instance_url', 'get_all_managed_instances_url',
13
+ 'polling_interval_millis', 'polling_timeout_seconds',
14
+ 'cache_max_items', 'cache_item_expire_seconds'
15
+ ];
16
+
17
+ var SERVICE_MANAGER_OPTS = [
18
+ 'clientid', 'clientsecret',
19
+ 'sm_url', 'url','polling_interval_millis', 'polling_timeout_seconds',
20
+ 'cache_max_items', 'cache_item_expire_seconds'
21
+ ];
22
+
23
+ var DEFAULT_OPTIONS = {
24
+ pooling: true,
25
+ maxPoolSize: 10,
26
+ connectionLifetime: 30
27
+ };
28
+
29
+ module.exports = DbOptions;
30
+
31
+ function DbOptions(globalOptions, xsApplicationUser) {
32
+ this._globalOptions = _.extend({}, DEFAULT_OPTIONS, globalOptions);
33
+ this._xsApplicationUser = xsApplicationUser;
34
+ this._instManager = null;
35
+ }
36
+
37
+ DbOptions.prototype._getInstanceManager = function (cb) {
38
+ if (this._instManager) {
39
+ return cb(null, this._instManager);
40
+ }
41
+ var self = this;
42
+ instanceManager.create(this._globalOptions, function (err, instManager) {
43
+ if (err) {
44
+ return cb(err);
45
+ }
46
+ self._instManager = instManager;
47
+ cb(null, instManager);
48
+ });
49
+ };
50
+
51
+ DbOptions.prototype.forRequest = function (req, locale) {
52
+ return new DbRequestOptions(this, req, locale);
53
+ };
54
+
55
+ function DbRequestOptions(dbOptions, req, locale) {
56
+ this._dbOptions = dbOptions;
57
+ this._globalOptions = _.cloneDeep(dbOptions._globalOptions);
58
+ this._xsApplicationUser = dbOptions._xsApplicationUser;
59
+ this._req = req;
60
+ this._locale = locale;
61
+ }
62
+
63
+ DbRequestOptions.prototype.getSqlccOptions = function (sqlccName) {
64
+ let options;
65
+ if (isInstanceManagerOptions(this._globalOptions)) {
66
+ options = _.omit(this._globalOptions, INSTANCE_MANAGER_OPTS);
67
+ } else if (isServiceManagerOptions(this._globalOptions)) {
68
+ options = _.omit(this._globalOptions, SERVICE_MANAGER_OPTS);
69
+ } else {
70
+ options = this._globalOptions;
71
+ }
72
+ if (!options.sqlcc || !options.sqlcc[sqlccName]) {
73
+ throw new TypeError('SQLCC connection with name "' + sqlccName +
74
+ '" not found in the provided hana configurations');
75
+ }
76
+
77
+ options = _.merge({}, options, options.sqlcc[sqlccName]);
78
+ return addRequestOptions(this._req, this._locale, options, this._xsApplicationUser);
79
+ };
80
+
81
+ DbRequestOptions.prototype.getInstanceOptions = function (callback) {
82
+ if (!isInstanceManagerOptions(this._globalOptions) && !isServiceManagerOptions(this._globalOptions)) {
83
+ var options = addRequestOptions(this._req, this._locale, this._globalOptions, this._xsApplicationUser);
84
+ return callback(null, options);
85
+ }
86
+ var self = this;
87
+ this._dbOptions._getInstanceManager(function (err, instManager) {
88
+ if (err) {
89
+ return callback(err);
90
+ }
91
+ var tenant = getTenant(self._req.authInfo);
92
+ if (!tenant) {
93
+ return callback(new Error('Could not get HANA service instance as no tenant is available in current context.'));
94
+ }
95
+ instManager.get(tenant, function (err, instance) {
96
+ if (err) {
97
+ return callback(err);
98
+ }
99
+ if (!instance) {
100
+ return callback(new VError("No service instance for tenant '%s'", tenant));
101
+ }
102
+ if (instance.status !== 'CREATION_SUCCEEDED') {
103
+ return callback(new VError("Status of service instance for tenant '%s' is %s", tenant, instance.status));
104
+ }
105
+ var hanaOptions;
106
+ if (isInstanceManagerOptions(self._globalOptions)){
107
+ hanaOptions = _.merge(_.omit(self._globalOptions, INSTANCE_MANAGER_OPTS), instance.credentials);
108
+ } else {
109
+ hanaOptions = _.merge(_.omit(self._globalOptions, SERVICE_MANAGER_OPTS), instance.credentials);
110
+ }
111
+ callback(null, addRequestOptions(self._req, self._locale, hanaOptions, self._xsApplicationUser));
112
+ });
113
+ });
114
+ };
115
+
116
+ DbRequestOptions.prototype.getInstanceOptionsPromise = function () {
117
+ var self = this;
118
+ return new Promise ((resolve, reject) => {
119
+ self.getInstanceOptions((err, result) => {
120
+ if (err) { return reject(err); }
121
+ resolve(result);
122
+ });
123
+ });
124
+ };
125
+
126
+ function getTenant(authInfo) {
127
+ return authInfo && authInfo.getZoneId();
128
+ }
129
+
130
+ function getUserToken(authInfo) {
131
+ return authInfo && authInfo.getHdbToken();
132
+ }
133
+
134
+ function isInstanceManagerOptions(options) {
135
+ return !!options.get_managed_instance_url;
136
+ }
137
+
138
+ function isServiceManagerOptions(options) {
139
+ return !!options.sm_url;
140
+ }
141
+
142
+ function addRequestOptions(req, locale, hanaSettings, xsApplicationUser) {
143
+ var hana = _.merge({}, hanaSettings, connOptions.getRequestOptions(req));
144
+
145
+ if (locale && locale.dbLocale) {
146
+ hana.locale = locale.dbLocale;
147
+ }
148
+
149
+ if (xsApplicationUser === false) {
150
+ delete hana['sessionVariable:XS_APPLICATIONUSER'];
151
+ }
152
+
153
+ if (hana.connectWithLoggedUser) {
154
+ var userToken = getUserToken(req.authInfo);
155
+ if (!userToken) {
156
+ throw new HttpError(400, 'No user token in request');
157
+ }
158
+ hana.user = '';
159
+ hana.password = userToken;
160
+ }
161
+ delete hana.sqlcc;
162
+ return hana;
163
+ }
@@ -0,0 +1,102 @@
1
+ 'use strict';
2
+
3
+ var _ = require('lodash');
4
+ var VError = require('verror');
5
+
6
+ module.exports = {
7
+ validateSetterArgs: validateArgs,
8
+ validateGetterArgs: validateGetterArgs,
9
+ validateParsedInteger: validateParsedInteger,
10
+ validateNumber: validateNumber,
11
+ validateInteger: validateInteger,
12
+ numberToInteger: numberToInteger,
13
+ validateIntegerBoundaries: validateIntegerBoundaries,
14
+ validateDateValue: validateDateValue,
15
+ validateString: validateString,
16
+ validateDateTime: validateDateTime,
17
+ INTEGER_TYPE: {
18
+ TINY_INT: { min: 0, max: 255 },
19
+ SMALL_INT: { min: -32768, max: 32767 },
20
+ INTEGER: { min: -2147483648, max: 2147483647 },
21
+ BIG_INT: { min: Number.MIN_SAFE_INTEGER, max: Number.MAX_SAFE_INTEGER } // or using ctypes.INT64 for larger values
22
+ }
23
+ };
24
+
25
+ function validateArgs(args, minNumArgs) {
26
+ if (args.length < minNumArgs) {
27
+ throw new VError('Expected %d arguments', minNumArgs);
28
+ }
29
+ var columnIndex = args[0];
30
+ if (!_.isInteger(columnIndex) || columnIndex > module.exports.INTEGER_TYPE.INTEGER.max) {
31
+ throw new VError('Expected integer for first argument');
32
+ }
33
+ if (columnIndex < 1) {
34
+ throw new VError('Column index should be bigger than zero');
35
+ }
36
+ if (minNumArgs === 2 && Number.isNaN(args[1])) {
37
+ throw new VError('Second argument is NaN (not a number)');
38
+ }
39
+ }
40
+
41
+ function validateGetterArgs(args, minNumArgs, resultSetRow) {
42
+ validateArgs(args, minNumArgs);
43
+
44
+ if (_.isNull(resultSetRow)) {
45
+ throw new Error('next() is not called for this result set');
46
+ }
47
+ if (_.isUndefined(resultSetRow)) {
48
+ throw new Error('next() returned false - no results');
49
+ }
50
+ }
51
+
52
+ function validateParsedInteger(parsedValue, rawValue) {
53
+ if (_.isNaN(parsedValue) || (_.isString(rawValue) && rawValue.indexOf('.') > -1)) {
54
+ throw new VError('Unsupported type conversion from %s to number. Not a valid number value: "%s"', typeof rawValue, rawValue);
55
+ }
56
+ }
57
+
58
+ function validateNumber(value) {
59
+ if (!_.isNumber(value)) {
60
+ throw new VError('Expected a number as second argument');
61
+ }
62
+ }
63
+
64
+ function validateInteger(value) {
65
+ if (!_.isInteger(value)) {
66
+ throw new VError('Expected an integer as second argument');
67
+ }
68
+ }
69
+
70
+ function numberToInteger(num) {
71
+ if (_.isInteger(num)) {
72
+ return num;
73
+ }
74
+ return (num < 0) ? Math.ceil(num) : Math.floor(num);
75
+ }
76
+
77
+ function validateIntegerBoundaries(type, value) {
78
+ if (value < type.min || value > type.max) {
79
+ if (type === module.exports.INTEGER_TYPE.BIG_INT) {
80
+ throw new Error('Number values are only accurate between -2^53+1 and 2^53-1. Please use ctypes.int64 objects for larger numbers');
81
+ }
82
+ throw new VError('Expected integer between %d and %d as second argument', type.min, type.max);
83
+ }
84
+ }
85
+
86
+ function validateDateValue(value) {
87
+ if (!_.isString(value)) {
88
+ throw new VError('Unsupported type conversion from %s to a valid date object', typeof value);
89
+ }
90
+ }
91
+
92
+ function validateString(value) {
93
+ if (!_.isString(value)) {
94
+ throw new VError('Expected a string as second argument');
95
+ }
96
+ }
97
+
98
+ function validateDateTime(value) {
99
+ if (!_.isDate(value) && !_.isString(value)) {
100
+ throw new Error('Expected either a Date object or a string as second argument');
101
+ }
102
+ }
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ var hdbext = require('@sap/hdbext');
4
+
5
+ exports = module.exports;
6
+ exports.connect = connect;
7
+
8
+ async function connect (hanaOptions) {
9
+ var conn = await hdbext.createConnectionPromise(hanaOptions);
10
+ conn.setAutoCommit(false);
11
+ return conn;
12
+ }
@@ -0,0 +1,93 @@
1
+ 'use strict';
2
+
3
+ var _ = require('lodash');
4
+ var VError = require('verror');
5
+ var driverEnum = require('@sap/hana-client/extension/Enums');
6
+ var types = require('@sap/hana-client/extension/TypeCode');
7
+
8
+ var XSC_ISOLATION = {
9
+ READ_COMMITTED: 2,
10
+ REPEATABLE_READ: 4,
11
+ SERIALIZABLE: 8
12
+ };
13
+
14
+ var XSC_TO_DRIVER_ISOLATION = {};
15
+ XSC_TO_DRIVER_ISOLATION[XSC_ISOLATION.READ_COMMITTED] = driverEnum.READ_COMMITTED;
16
+ XSC_TO_DRIVER_ISOLATION[XSC_ISOLATION.REPEATABLE_READ] = driverEnum.REPEATABLE_READ;
17
+ XSC_TO_DRIVER_ISOLATION[XSC_ISOLATION.SERIALIZABLE] = driverEnum.SERIALIZABLE;
18
+
19
+ var XSC_PARAM_MODE = {
20
+ IN: 1,
21
+ INOUT: 2,
22
+ OUT: 4
23
+ };
24
+
25
+ var DRIVER_TO_XSC_PARAM_MODE = {};
26
+ DRIVER_TO_XSC_PARAM_MODE[driverEnum.DD_INPUT] = XSC_PARAM_MODE.IN;
27
+ DRIVER_TO_XSC_PARAM_MODE[driverEnum.DD_INPUT_OUTPUT] = XSC_PARAM_MODE.INOUT;
28
+ DRIVER_TO_XSC_PARAM_MODE[driverEnum.DD_OUTPUT] = XSC_PARAM_MODE.OUT;
29
+
30
+
31
+ function findCorresponding(map, key) {
32
+ var value = map[key];
33
+ if (_.isNil(value)) {
34
+ throw new VError('Cannot find property %s in %j', key, map);
35
+ }
36
+ return value;
37
+ }
38
+
39
+ function createXscTypesConst() {
40
+ var xscTypes = _.clone(types);
41
+ xscTypes.INTEGER = xscTypes.INT;
42
+ xscTypes.VARCHAR = xscTypes.VARCHAR1;
43
+ xscTypes.SMALLDECIMAL = 47;
44
+ return xscTypes;
45
+ }
46
+
47
+ function toXscType(type) {
48
+ if (type === types.DAYDATE) {
49
+ return types.DATE;
50
+ }
51
+ if (type === types.SECONDTIME) {
52
+ return types.TIME;
53
+ }
54
+ if (type === types.LONGDATE) {
55
+ return types.TIMESTAMP;
56
+ }
57
+ return type;
58
+ }
59
+
60
+ function toXscTypeName(typeName) {
61
+ if (typeName === 'INT') {
62
+ return 'INTEGER';
63
+ }
64
+ if (typeName === 'VARCHAR1') {
65
+ return 'VARCHAR';
66
+ }
67
+ if (typeName === 'DAYDATE') {
68
+ return 'DATE';
69
+ }
70
+ if (typeName === 'SECONDTIME') {
71
+ return 'TIME';
72
+ }
73
+ if (typeName === 'LONGDATE') {
74
+ return 'TIMESTAMP';
75
+ }
76
+ return typeName;
77
+ }
78
+
79
+ module.exports = {
80
+ isolationLevel: {
81
+ XSC: XSC_ISOLATION
82
+ },
83
+ types: {
84
+ XSC: createXscTypesConst()
85
+ },
86
+
87
+ convert: {
88
+ toDriverIsolationLevel: findCorresponding.bind(null, XSC_TO_DRIVER_ISOLATION),
89
+ toXscParameterMode: findCorresponding.bind(null, DRIVER_TO_XSC_PARAM_MODE),
90
+ toXscType,
91
+ toXscTypeName
92
+ }
93
+ };
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ var _ = require('lodash');
4
+
5
+ module.exports.executeBatchPromise = executeBatchPromise;
6
+
7
+ async function executeBatchPromise (stmt, args) {
8
+ var err = null;
9
+ try {
10
+ await stmt.executeBatch(args);
11
+ } catch (error) {
12
+ err = error;
13
+ }
14
+ var statuses = stmt.getRowStatus();
15
+
16
+ if (!err) {
17
+ return statuses;
18
+ }
19
+
20
+ var allFailed = statuses.every(function (value) {
21
+ return value < 0;
22
+ });
23
+
24
+ if (allFailed) {
25
+ throw err;
26
+ }
27
+
28
+ if (!_.isNumber(err.code)) {
29
+ throw err;
30
+ }
31
+
32
+ var code = -Math.abs(err.code);
33
+ statuses = statuses.map(function (value) {
34
+ return (value < 0) ? code : value;
35
+ });
36
+
37
+ return statuses;
38
+ }