@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,220 @@
1
+ 'use strict';
2
+
3
+ var _ = require('lodash');
4
+ var zipLib = require('yazl');
5
+ var unzipLib = require('yauzl');
6
+ var VError = require('verror');
7
+ var ctypes = require('../../ctypes');
8
+ var ResultSet = require('../db/dbapi/ResultSet');
9
+ var bufferUtils = require('../../utils/buffer-utils');
10
+ var compressionUtils = require('../../utils/compression-utils');
11
+
12
+ module.exports = Zip;
13
+
14
+ function Zip(source, index, settings) {
15
+ if (!(this instanceof Zip)) { // if the constructor is used without the "new" keyword
16
+ return new Zip(source, index, settings);
17
+ }
18
+
19
+ if (arguments.length > 3) {
20
+ throw new VError('Zip.constructor: expects at most 3 arguments, got %d', arguments.length);
21
+ }
22
+
23
+ var argsCount = Array.prototype.slice.call(arguments).reduce(function (prev, current) {
24
+ return prev + !!current;
25
+ }, 0);
26
+
27
+ if (argsCount && !_.isObject(source)) {
28
+ throw new Error('Zip.constructor: Expected one of the following as first argument: ArrayBuffer, Body object, ResultSet object or JS object');
29
+ }
30
+
31
+ Object.defineProperty(this, '_metadata_', {
32
+ enumerable: false,
33
+ get: async function () {
34
+ await updateZipContent(this);
35
+ return await readZip(this, false);
36
+ }
37
+ });
38
+ defineZipProperty(this, '_zipAsBuffer', null);
39
+ defineZipProperty(this, '_uncompressedSizeRestriction', Infinity);
40
+
41
+ switch (argsCount) {
42
+ case 1: // case: (ArrayBuffer or Body) or Settings object
43
+ if (compressionUtils.isWebBodyOrArrayBuffer(source)) {
44
+ this._zipAsBuffer = compressionUtils.extractBuffer(source);
45
+ } else {
46
+ this._uncompressedSizeRestriction = extractZipSettingsFromJsObject(source, argsCount);
47
+ }
48
+ break;
49
+ case 2:
50
+ if (compressionUtils.isWebBodyOrArrayBuffer(source)) { // case: (ArrayBuffer or Body) and Settings object
51
+ this._zipAsBuffer = compressionUtils.extractBuffer(source);
52
+ this._uncompressedSizeRestriction = extractZipSettingsFromJsObject(index, argsCount);
53
+ } else if (source instanceof ResultSet) { // case: ResultSet and index
54
+ this._zipAsBuffer = extractBufferFromResultSet(source, index);
55
+ } else {
56
+ throw new Error('Zip.constructor: Expected ArrayBuffer, Body object, ResultSet object or JS object as first argument');
57
+ }
58
+ break;
59
+ case 3: // case: ResultSet, index and settings
60
+ if (source instanceof ResultSet) {
61
+ this._zipAsBuffer = extractBufferFromResultSet(source, index);
62
+ this._uncompressedSizeRestriction = extractZipSettingsFromJsObject(settings, argsCount);
63
+ } else {
64
+ throw new Error('Zip.constructor: Expected ResultSet as first argument and Number as a second argument');
65
+ }
66
+ break;
67
+ }
68
+
69
+ var self = this;
70
+ return new Promise((resolve, reject) => {
71
+ if (this._zipAsBuffer) {
72
+ __readZip(this, true, ()=>{resolve(self);}, reject);
73
+ } else {
74
+ resolve(self);
75
+ }
76
+ });
77
+ }
78
+
79
+ defineZipProperty(Zip.prototype, 'asArrayBuffer', async function () {
80
+ await updateZipContent(this);
81
+ return bufferUtils.toArrayBuffer(this._zipAsBuffer);
82
+ });
83
+
84
+ function updateZipContent(zipInstance) {
85
+ var zipFileChunks = [];
86
+ var zipFileSize = 0;
87
+
88
+ return new Promise((resolve, reject) => {
89
+ var zip = new zipLib.ZipFile();
90
+ zip.outputStream.on('data', function (data) {
91
+ zipFileChunks.push(data);
92
+ zipFileSize += data.length;
93
+ });
94
+ zip.outputStream.on('end', function () {
95
+ zipInstance._zipAsBuffer = bufferUtils.toBuffer(constructFileFromFileChunks(zipFileChunks, zipFileSize));
96
+ resolve();
97
+ });
98
+ zip.outputStream.on('error', reject);
99
+ for (var entry in zipInstance) {
100
+ var content = zipInstance[entry];
101
+ zip.addBuffer(_.isString(content) ? Buffer.from(content, 'utf8') : bufferUtils.toBuffer(content), entry);
102
+ }
103
+ zip.end();
104
+ });
105
+ }
106
+
107
+ function defineZipProperty(zipInstance, key, value) {
108
+ Object.defineProperty(zipInstance, key, { value: value, writable: true, enumerable: false });
109
+ }
110
+
111
+ // loads the entries and the metadata for the zip
112
+ function readZip(zipInstance, checkZipSize) {
113
+ return new Promise((resolve, reject)=>{
114
+ __readZip(zipInstance, checkZipSize, resolve, reject);
115
+ });
116
+ }
117
+
118
+ // loads the entries and the metadata for the zip
119
+ function __readZip(zipInstance, checkZipSize, resolve, reject) {
120
+ unzipLib.fromBuffer(zipInstance._zipAsBuffer, { lazyEntries: true }, function (err, zipfile) {
121
+ if (err) {
122
+ return reject(err);
123
+ }
124
+
125
+ var currentCompressedSizeInBytes = 0;
126
+ var currentUncompressedSizeInBytes = 0;
127
+ zipfile.readEntry();
128
+
129
+ zipfile.on('entry', function (entry) {
130
+ currentCompressedSizeInBytes += entry.compressedSize;
131
+ currentUncompressedSizeInBytes += entry.uncompressedSize;
132
+ if (checkZipSize && currentUncompressedSizeInBytes > zipInstance._uncompressedSizeRestriction) { // zip bomb prevention
133
+ return reject(new VError(
134
+ 'The uncompressed size of the given zip exceeds the maximum allowed size of %d bytes. The zip will not be loaded.',
135
+ zipInstance._uncompressedSizeRestriction
136
+ ));
137
+ }
138
+
139
+ var fileChunks = [];
140
+ var fileSize = 0;
141
+ zipfile.openReadStream(entry, function (err, readStream) {
142
+ if (err) {
143
+ return reject(err);
144
+ }
145
+
146
+ readStream.on('data', function (chunk) {
147
+ fileChunks.push(chunk);
148
+ fileSize += chunk.length;
149
+ });
150
+
151
+ readStream.on('end', function () {
152
+ var fileContent = constructFileFromFileChunks(fileChunks, fileSize);
153
+ zipInstance[entry.fileName] = fileContent;
154
+ zipfile.readEntry();
155
+ });
156
+ });
157
+ });
158
+
159
+ zipfile.on('error', function (err) {
160
+ if (err) {
161
+ return reject(err);
162
+ }
163
+ });
164
+
165
+ zipfile.once('end', function () {
166
+ resolve({
167
+ compressedSizeInBytes: currentCompressedSizeInBytes,
168
+ uncompressedSizeInBytes: currentUncompressedSizeInBytes
169
+ });
170
+ });
171
+ });
172
+ }
173
+
174
+ function extractBufferFromResultSet(resultSet, index) {
175
+ if (!Number.isInteger(index)) {
176
+ throw new Error('Zip.constructor: second argument expected to be a positive integer');
177
+ }
178
+
179
+ try {
180
+ var rez = bufferUtils.toBuffer(resultSet.getBlob(index));
181
+ return rez;
182
+ } catch (exception) {
183
+ throw new VError.WError(exception, 'Zip.constructor: Failed to create a zip out of a ResultSet with index %d', index);
184
+ }
185
+ }
186
+
187
+ function extractZipSettingsFromJsObject(settings, argumentPosition) {
188
+ if (!_.isObject(settings)) {
189
+ throw new VError('Zip.constructor: expected argument %d to be a JS object', argumentPosition);
190
+ }
191
+
192
+ if (settings.hasOwnProperty('password')) {
193
+ throw new Error('Feature not supported: Creating zip with password encryption');
194
+ }
195
+
196
+ var sizeSetting = getUncompressedSizeRestriction(settings);
197
+ if (sizeSetting && !_.isNumber(sizeSetting)) {
198
+ throw new Error('Zip.constructor: value of property maxUncompressedSizeInBytes got to be a safe JS Number or ctypes.Int64.');
199
+ }
200
+ return sizeSetting;
201
+ }
202
+
203
+ function getUncompressedSizeRestriction(settings) {
204
+ if (settings.maxUncompressedSizeInBytes instanceof ctypes.Int64) {
205
+ return settings.maxUncompressedSizeInBytes.toJSON();
206
+ }
207
+ return settings.maxUncompressedSizeInBytes || Infinity;
208
+ }
209
+
210
+ function constructFileFromFileChunks(fileChunks, fileSize) {
211
+ var fileContent = new Uint8Array(fileSize);
212
+ var offset = 0;
213
+
214
+ fileChunks.forEach(function (chunk) {
215
+ fileContent.set(chunk, offset);
216
+ offset += chunk.length;
217
+ });
218
+
219
+ return fileContent.buffer;
220
+ }
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ var _ = require('lodash');
4
+ var buffUtils = require('../../utils/buffer-utils');
5
+
6
+ module.exports.decodeBase64 = function decodeBase64(base64Data) {
7
+ checkIsString(base64Data);
8
+ return buffUtils.toArrayBuffer(Buffer.from(base64Data, 'base64'));
9
+ };
10
+
11
+ module.exports.decodeHex = function decodeHex(hexData) {
12
+ checkIsString(hexData);
13
+ return buffUtils.toArrayBuffer(Buffer.from(hexData, 'hex'));
14
+ };
15
+
16
+ module.exports.encodeBase64 = function encodeBase64(data) {
17
+ return toBuffer(data).toString('base64');
18
+ };
19
+
20
+ module.exports.encodeHex = function encodeBase64(data) {
21
+ return toBuffer(data).toString('hex');
22
+ };
23
+
24
+ function checkIsString(data) {
25
+ if (!_.isString(data)) {
26
+ throw new Error('Input parameter must be String');
27
+ }
28
+ }
29
+
30
+ function toBuffer(data) {
31
+ data = buffUtils.getData(data);
32
+ return _.isString(data) ? Buffer.from(data) : data;
33
+ }
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ var _ = require('lodash');
4
+ var zlib = require('zlib');
5
+ var buffUtils = require('../../utils/buffer-utils');
6
+ var compressionUtils = require('../../utils/compression-utils');
7
+
8
+ module.exports = {
9
+ gunzip: function (source) {
10
+ if (!compressionUtils.isWebBodyOrArrayBuffer(source)) {
11
+ throw new Error('gunzip: expected either ArrayBuffer or Request/Response Body argument.');
12
+ }
13
+ var buffer = compressionUtils.extractBuffer(source);
14
+ return buffUtils.toArrayBuffer(zlib.gunzipSync(buffer));
15
+ },
16
+
17
+ gzip: function (source) {
18
+ if (!_.isString(source) && !compressionUtils.isWebBodyOrArrayBuffer(source)) {
19
+ throw new Error('gzip: expected either string, ArrayBuffer or Request/Response Body argument.');
20
+ }
21
+ var content = _.isString(source) ? source : compressionUtils.extractBuffer(source);
22
+ return buffUtils.toArrayBuffer(zlib.gzipSync(content));
23
+ }
24
+ };
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ var crypto = require('crypto');
4
+ var isArrayBuffer = require('../../utils/buffer-utils').isArrayBuffer;
5
+ var SAXParser = require('./SAXParser');
6
+
7
+ module.exports.Zip = require('./Zip');
8
+ module.exports.codec = require('./codec');
9
+ module.exports.compression = require('./compression');
10
+
11
+ module.exports.stringify = function stringify(buf) {
12
+ if (!isArrayBuffer(buf)) {
13
+ throw new Error('Input parameter must be ArrayBuffer');
14
+ }
15
+ return String.fromCharCode.apply(null, new Uint8Array(buf)); // eslint-disable-line no-undef
16
+ };
17
+
18
+ module.exports.createUuid = function createUuid() {
19
+ return crypto.randomBytes(16).toString('hex').toUpperCase();
20
+ };
21
+
22
+ module.exports.SAXParser = SAXParser;
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ var assert = require('assert');
4
+ var EntityList = require('./EntityList');
5
+ var HeadersTupelList = require('./TupelLists/HeadersTupelList');
6
+ var ResultSet = require('../db/dbapi/ResultSet');
7
+
8
+ module.exports = BasicWebEntity;
9
+
10
+ function BasicWebEntity(arg) {
11
+ this.headers = new HeadersTupelList();
12
+ this.entities = new EntityList();
13
+ this.setBody('');
14
+
15
+ if (arg) {
16
+ this.headers._addData(arg.headers);
17
+ }
18
+ }
19
+
20
+ BasicWebEntity.prototype.setBody = async function(bodyContent, indexOpt) {
21
+ if (indexOpt !== null && indexOpt !== undefined) {
22
+ assert(bodyContent.constructor === ResultSet, 'First argument should be a $.db.ResultSet');
23
+ assert(indexOpt > 0, 'Second argument should be greater than 0');
24
+ }
25
+ var WebBody = require('./WebBody');
26
+ var isZip = require('../../utils/xs-types').isZip;
27
+ bodyContent = isZip(bodyContent) ? await bodyContent.asArrayBuffer() : bodyContent;
28
+ this.body = new WebBody(this, bodyContent, indexOpt);
29
+ };
30
+
31
+ Object.defineProperties(BasicWebEntity.prototype, {
32
+ contentType: {
33
+ set: function(type) {
34
+ this.headers.set('content-type', type);
35
+ },
36
+ get: function() {
37
+ return this.headers.get('content-type');
38
+ },
39
+ enumerable: true
40
+ }
41
+ });
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ var util = require('util');
4
+
5
+ module.exports = EntityList;
6
+
7
+ function EntityList() {
8
+ Array.call(this);
9
+ }
10
+
11
+ util.inherits(EntityList, Array);
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var util = require('util');
4
+ var assert = require('assert');
5
+ var TupelListBase = require('./TupelListBase');
6
+
7
+ module.exports = CookiesTupelList;
8
+
9
+ function CookiesTupelList() {
10
+ TupelListBase.call(this, { lowerCaseNames: false });
11
+ }
12
+
13
+ util.inherits(CookiesTupelList, TupelListBase);
14
+
15
+ CookiesTupelList.prototype.set = function (name, value) {
16
+ assert(typeof name === 'string', 'Expected string as first argument');
17
+ assert(typeof value === 'string', 'Expected string as second argument');
18
+
19
+ this.push({ name: name, value: value });
20
+ return true;
21
+ };
22
+
23
+ CookiesTupelList.prototype.get = function (name) {
24
+ assert(typeof name === 'string', 'Expected string as argument');
25
+ var nameLowerCase = name.toLowerCase();
26
+
27
+ for (var i = 0; i < this.length; i++) {
28
+ if (this[i].name.toLowerCase() === nameLowerCase) {
29
+ return this[i].value;
30
+ }
31
+ }
32
+ return undefined;
33
+ };
34
+
35
+ CookiesTupelList.prototype.remove = function (name) {
36
+ assert(typeof name === 'string', 'Expected string as argument');
37
+
38
+ var idxCurrentTupel = 0;
39
+ while (idxCurrentTupel < this.length) {
40
+ if (this[idxCurrentTupel].name === name) {
41
+ this.splice(idxCurrentTupel, 1);
42
+ return;
43
+ } else {
44
+ ++idxCurrentTupel;
45
+ }
46
+ }
47
+ };
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ var util = require('util');
4
+ var assert = require('assert');
5
+ var TupelListBase = require('./TupelListBase');
6
+
7
+
8
+ module.exports = HeadersTupelList;
9
+
10
+ function HeadersTupelList() {
11
+ TupelListBase.call(this, { lowerCaseNames: true });
12
+ }
13
+
14
+ util.inherits(HeadersTupelList, TupelListBase);
15
+
16
+ HeadersTupelList.prototype.set = function (name, value) {
17
+ assert(typeof name === 'string', 'Expected string as first argument');
18
+ assert(typeof value === 'string', 'Expected string as second argument');
19
+
20
+ this.remove(name);
21
+ this.push({ name: name.toLowerCase(), value: value });
22
+ return true;
23
+ };
24
+
25
+ HeadersTupelList.prototype.get = function (name) {
26
+ assert(typeof name === 'string', 'Expected string as argument');
27
+ name = name.toLowerCase();
28
+
29
+ var filtered = this.filter(function (tupel) {
30
+ return tupel.name === name;
31
+ }).map(function (tupel) {
32
+ return tupel.value;
33
+ });
34
+ if (filtered.length > 1) {
35
+ return filtered;
36
+ }
37
+ if (filtered.length === 1) {
38
+ return filtered[0];
39
+ }
40
+ return undefined;
41
+ };
42
+
43
+ HeadersTupelList.prototype.remove = function (name) {
44
+ assert(typeof name === 'string', 'Expected string as argument');
45
+ name = name.toLowerCase();
46
+
47
+ var currentPairIndex = 0;
48
+ while (currentPairIndex < this.length) {
49
+ if (this[currentPairIndex].name === name) {
50
+ this.splice(currentPairIndex, 1);
51
+ } else {
52
+ ++currentPairIndex;
53
+ }
54
+ }
55
+ };
@@ -0,0 +1,83 @@
1
+ 'use strict';
2
+
3
+ var util = require('util');
4
+ var assert = require('assert');
5
+ var TupelListBase = require('./TupelListBase');
6
+
7
+ module.exports = ParametersTupelList;
8
+
9
+ function ParametersTupelList() {
10
+ TupelListBase.call(this, { lowerCaseNames: false });
11
+ }
12
+
13
+ util.inherits(ParametersTupelList, TupelListBase);
14
+
15
+ ParametersTupelList.prototype.set = function (name, value) {
16
+ assert(typeof name === 'string', 'Expected string as first argument');
17
+ assert(typeof value === 'string', 'Expected string as second argument');
18
+
19
+ caseSensitiveRemove(this, name);
20
+ this.push({ name: name, value: value });
21
+ return true;
22
+ };
23
+
24
+ ParametersTupelList.prototype.get = function (name) {
25
+ assert(typeof name === 'string', 'Expected string as argument');
26
+ var nameLowerCase = name.toLowerCase();
27
+ var searchFor;
28
+
29
+ var filtered = [];
30
+ for (var i = 0; i < this.length; i++) {
31
+ var tupel = this[i];
32
+ if (!searchFor && (tupel.name.toLowerCase() === nameLowerCase)) {
33
+ searchFor = tupel.name;
34
+ }
35
+ if (searchFor && tupel.name === searchFor) {
36
+ filtered.push(tupel.value);
37
+ }
38
+ }
39
+
40
+ if (filtered.length > 1) {
41
+ return filtered;
42
+ }
43
+ if (filtered.length === 1) {
44
+ return filtered[0];
45
+ }
46
+ return undefined;
47
+ };
48
+
49
+ ParametersTupelList.prototype.remove = function (name) {
50
+ assert(typeof name === 'string', 'Expected string as argument');
51
+ caseInsensitiveRemove(this, name);
52
+ };
53
+
54
+ function caseSensitiveRemove(tupelList, name) {
55
+ var idxCurrentTupel = 0;
56
+ while (idxCurrentTupel < tupelList.length) {
57
+ if (tupelList[idxCurrentTupel].name === name) {
58
+ tupelList.splice(idxCurrentTupel, 1);
59
+ return;
60
+ } else {
61
+ ++idxCurrentTupel;
62
+ }
63
+ }
64
+ }
65
+
66
+ function caseInsensitiveRemove(tupelList, name) {
67
+ var nameLowerCase = name.toLowerCase();
68
+ var searchFor;
69
+
70
+ var idxCurrentTupel = 0;
71
+ while (idxCurrentTupel < tupelList.length) {
72
+ var tupel = tupelList[idxCurrentTupel];
73
+ if (!searchFor && (tupel.name.toLowerCase() === nameLowerCase)) {
74
+ searchFor = tupel.name;
75
+ }
76
+ if (searchFor && tupel.name === searchFor) {
77
+ tupelList.splice(idxCurrentTupel, 1);
78
+ return;
79
+ } else {
80
+ ++idxCurrentTupel;
81
+ }
82
+ }
83
+ }
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ var util = require('util');
4
+
5
+ module.exports = TupelListBase;
6
+
7
+ function TupelListBase(options) {
8
+ Array.call(this);
9
+ Object.defineProperties(this, {
10
+ lowerCaseNames: {
11
+ value: options.lowerCaseNames
12
+ }
13
+ });
14
+ }
15
+
16
+ util.inherits(TupelListBase, Array);
17
+
18
+
19
+ TupelListBase.prototype._addData = function (data) {
20
+ if (typeof data !== 'object') {
21
+ return;
22
+ }
23
+ Object.keys(data).forEach(function (property) {
24
+ var value = data[property];
25
+ var name = (this.lowerCaseNames) ? property.toLowerCase() : property;
26
+
27
+ if (!Array.isArray(value)) {
28
+ addTupelPair(this, name, value);
29
+ } else {
30
+ value.forEach(function (arrayElement) {
31
+ addTupelPair(this, name, arrayElement);
32
+ }, this);
33
+ }
34
+ }, this);
35
+ };
36
+
37
+ function addTupelPair(tupelList, name, value) {
38
+ if (typeof value === 'string') {
39
+ tupelList.push({ name: name, value: value });
40
+ } else if (typeof value === 'number') {
41
+ tupelList.push({ name: name, value: '' + value });
42
+ } else {
43
+ throw new Error('Could not handle TupelList value: ' + JSON.stringify(value));
44
+ }
45
+ }