stimulsoft-data-adapter 2022.1.4 → 2022.2.1

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.
@@ -1,14 +1,14 @@
1
1
  /*
2
2
  Stimulsoft.Reports.JS
3
- Version: 2022.1.4
4
- Build date: 2022.01.14
3
+ Version: 2022.2.1
4
+ Build date: 2022.03.21
5
5
  License: https://www.stimulsoft.com/en/licensing/reports
6
6
  */
7
7
  exports.process = function (command, onResult) {
8
8
  var end = function (result) {
9
9
  try {
10
10
  if (db) db.detach();
11
- result.adapterVersion = "2022.1.4";
11
+ result.adapterVersion = "2022.2.1";
12
12
  onResult(result);
13
13
  }
14
14
  catch (e) {
package/MSSQLAdapter.js CHANGED
@@ -1,14 +1,14 @@
1
1
  /*
2
2
  Stimulsoft.Reports.JS
3
- Version: 2022.1.4
4
- Build date: 2022.01.14
3
+ Version: 2022.2.1
4
+ Build date: 2022.03.21
5
5
  License: https://www.stimulsoft.com/en/licensing/reports
6
6
  */
7
7
  exports.process = function (command, onResult) {
8
8
  var end = function (result) {
9
9
  try {
10
10
  if (connection) connection.close();
11
- result.adapterVersion = "2022.1.4";
11
+ result.adapterVersion = "2022.2.1";
12
12
  onResult(result);
13
13
  }
14
14
  catch (e) {
package/MySQLAdapter.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  Stimulsoft.Reports.JS
3
- Version: 2022.1.4
4
- Build date: 2022.01.14
3
+ Version: 2022.2.1
4
+ Build date: 2022.03.21
5
5
  License: https://www.stimulsoft.com/en/licensing/reports
6
6
  */
7
7
  exports.process = function (command, onResult) {
@@ -10,7 +10,7 @@ exports.process = function (command, onResult) {
10
10
  if (connection) {
11
11
  connection.end();
12
12
  }
13
- result.adapterVersion = "2022.1.4";
13
+ result.adapterVersion = "2022.2.1";
14
14
  onResult(result);
15
15
  }
16
16
  catch (e) {
@@ -1,14 +1,14 @@
1
1
  /*
2
2
  Stimulsoft.Reports.JS
3
- Version: 2022.1.4
4
- Build date: 2022.01.14
3
+ Version: 2022.2.1
4
+ Build date: 2022.03.21
5
5
  License: https://www.stimulsoft.com/en/licensing/reports
6
6
  */
7
7
  exports.process = function (command, onResult) {
8
8
  var end = function (result) {
9
9
  try {
10
10
  if (client) client.end();
11
- result.adapterVersion = "2022.1.4";
11
+ result.adapterVersion = "2022.2.1";
12
12
  onResult(result);
13
13
  }
14
14
  catch (e) {
package/index.js ADDED
@@ -0,0 +1,138 @@
1
+ /*
2
+ Stimulsoft.Reports.JS
3
+ Version: 2022.2.1
4
+ Build date: 2022.03.21
5
+ License: https://www.stimulsoft.com/en/licensing/reports
6
+ */
7
+
8
+ function getCommand(data) {
9
+ var encryptResult = false;
10
+ if (typeof data === "string" && !data.startsWith("{")) {
11
+ data = Buffer.from(data.replace(/[A-Za-z]/g, function (c) {
12
+ return String.fromCharCode(c.charCodeAt(0) + (c.toUpperCase() <= "M" ? 13 : -13));
13
+ }), "base64").toString("ascii");
14
+ encryptResult = true;
15
+ }
16
+
17
+ var command = JSON.parse(data.toString());
18
+ command.encryptResult = encryptResult;
19
+ return command;
20
+ }
21
+
22
+ function process(command, onResult) {
23
+ if (typeof command !== "object") command = getCommand(command);
24
+
25
+ var onProcessHandler = onProcess.bind(null, onResult, command.encryptResult);
26
+
27
+ if (command.command === "GetSupportedAdapters") {
28
+ onProcessHandler({ success: true, types: ["MySQL", "MS SQL", "Firebird", "PostgreSQL"] });
29
+ } else {
30
+ command.queryString = applyQueryParameters(command.queryString, command.parameters, command.escapeQueryParameters);
31
+
32
+ if (command.database == "MySQL") {
33
+ var MySQLAdapter = require('./MySQLAdapter');
34
+ MySQLAdapter.process(command, onProcessHandler);
35
+ }
36
+ else if (command.database == "Firebird") {
37
+ var FirebirdAdapter = require('./FirebirdAdapter');
38
+ FirebirdAdapter.process(command, onProcessHandler);
39
+ }
40
+ else if (command.database == "MS SQL") {
41
+ var MSSQLAdapter = require('./MSSQLAdapter');
42
+ MSSQLAdapter.process(command, onProcessHandler);
43
+ }
44
+ else if (command.database == "PostgreSQL") {
45
+ var PostgreSQLAdapter = require('./PostgreSQLAdapter');
46
+ PostgreSQLAdapter.process(command, onProcessHandler);
47
+ }
48
+ else onProcessHandler({ success: false, notice: "Database '" + command.database + "' not supported!" });
49
+ }
50
+ }
51
+
52
+ function applyQueryParameters(baseSqlCommand, parameters, escapeQueryParameters) {
53
+ if (baseSqlCommand == null || baseSqlCommand.indexOf("@") < 0) return baseSqlCommand;
54
+
55
+ var result = "";
56
+ while (baseSqlCommand.indexOf("@") >= 0 && parameters != null && parameters.length > 0) {
57
+ result += baseSqlCommand.substring(0, baseSqlCommand.indexOf("@"));
58
+ baseSqlCommand = baseSqlCommand.substring(baseSqlCommand.indexOf("@") + 1);
59
+
60
+ var parameterName = "";
61
+
62
+ while (baseSqlCommand.length > 0) {
63
+ var char = baseSqlCommand.charAt(0);
64
+ if (char.length === 1 && char.match(/[a-zA-Z0-9_-]/i)) {
65
+ parameterName += char;
66
+ baseSqlCommand = baseSqlCommand.substring(1);
67
+ }
68
+ else break;
69
+ }
70
+
71
+ var parameter = parameters.find(parameter => parameter.name.toLowerCase() == parameterName.toLowerCase());
72
+ if (parameter) {
73
+ if (parameter.typeGroup != "number") {
74
+ if (escapeQueryParameters)
75
+ result += "'" + parameter.value.toString().replace(/\\/gi, "\\\\").replace(/\'/gi, "\\\'").replace(/\"/gi, "\\\"") + "'";
76
+ else
77
+ result += "'" + parameter.value.toString() + "'";
78
+ }
79
+ else
80
+ result += parameter.value.toString();
81
+ }
82
+ else
83
+ result += "@" + parameterName;
84
+ }
85
+
86
+ return result + baseSqlCommand;
87
+ }
88
+
89
+ function getResponse(result) {
90
+ let encryptData = result.encryptData;
91
+ delete result.encryptData;
92
+
93
+ result = JSON.stringify(result);
94
+ if (encryptData) {
95
+ result = Buffer.from(result).toString("base64").replace(/[A-Za-z]/g, function (c) {
96
+ return String.fromCharCode(c.charCodeAt(0) + (c.toUpperCase() <= "M" ? 13 : -13));
97
+ });
98
+ }
99
+
100
+ return result
101
+ }
102
+ function onProcess(onResult, encryptData, result) {
103
+ result.handlerVersion = "2022.2.1";
104
+ result.checkVersion = true;
105
+ result.encryptData = encryptData;
106
+ onResult(result);
107
+ }
108
+
109
+ module.exports = { getCommand, process };
110
+
111
+ if (require.main === module) {
112
+ var http = require('http');
113
+ var accept = function (request, response) {
114
+ response.setHeader("Access-Control-Allow-Origin", "*");
115
+ response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
116
+ response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");
117
+ response.setHeader("Cache-Control", "no-cache");
118
+
119
+ var data = "";
120
+ request.on('data', function (buffer) {
121
+ data += buffer;
122
+ });
123
+
124
+ request.on('end', function () {
125
+ var command = getCommand(data);
126
+ process(command, function (result) {
127
+ var responseData = getResponse(result);
128
+ response.end(responseData);
129
+ });
130
+ });
131
+ }
132
+
133
+ console.log("The DataAdapter run on port 9615");
134
+ console.log("To use, on the client side, you need to specify the URL of this host that handles requests:");
135
+ console.log("StiOptions.WebServer.url = \"http://localhost:9615\"");
136
+ http.createServer(accept).listen(9615);
137
+ }
138
+
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "stimulsoft-data-adapter",
3
- "version": "2022.1.4",
3
+ "version": "2022.2.1",
4
4
  "description": "Nodejs data adapter for Stimulsoft Reports.JS",
5
- "main": "app.js",
5
+ "main": "index.js",
6
6
  "scripts": {
7
- "start": "node app.js"
7
+ "start": "node index.js"
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
@@ -20,11 +20,10 @@
20
20
  "files": [
21
21
  "package.json",
22
22
  "README.md",
23
- "app.js",
23
+ "index.js",
24
24
  "FirebirdAdapter.js",
25
25
  "MSSQLAdapter.js",
26
26
  "MySQLAdapter.js",
27
- "OracleAdapter.js",
28
27
  "PostgreSQLAdapter.js"
29
28
  ],
30
29
  "author": {
@@ -47,4 +46,4 @@
47
46
  ],
48
47
  "license": "Closed Source",
49
48
  "homepage": "https://github.com/stimulsoft/DataAdapters.JS/tree/main/NodejsDataAdapters"
50
- }
49
+ }
package/app.js DELETED
@@ -1,89 +0,0 @@
1
- /*
2
- Stimulsoft.Reports.JS
3
- Version: 2022.1.4
4
- Build date: 2022.01.14
5
- License: https://www.stimulsoft.com/en/licensing/reports
6
- */
7
- var http = require('http');
8
- var MySQLAdapter = require('./MySQLAdapter');
9
- var FirebirdAdapter = require('./FirebirdAdapter');
10
- var MSSQLAdapter = require('./MSSQLAdapter');
11
- var PostgreSQLAdapter = require('./PostgreSQLAdapter');
12
-
13
- var connectionStringBuilder;
14
- var response;
15
- function accept(req, res) {
16
- response = res;
17
- response.setHeader("Access-Control-Allow-Origin", "*");
18
- response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
19
- response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");
20
- response.setHeader("Cache-Control", "no-cache");
21
-
22
- var data = "";
23
- req.on('data', function (buffer) {
24
- data += buffer;
25
- });
26
-
27
- req.on('end', function () {
28
- if (data.indexOf("{") != 0) {
29
- data = Buffer.from(data.replace(/[A-Za-z]/g, function (c) {
30
- return String.fromCharCode(c.charCodeAt(0) + (c.toUpperCase() <= "M" ? 13 : -13));
31
- }), "base64").toString("ascii");
32
-
33
- }
34
-
35
- command = JSON.parse(data.toString());
36
-
37
- command.queryString = applyQueryParameters(command.queryString, command.parameters, command.escapeQueryParameters);
38
-
39
- if (command.database == "MySQL") MySQLAdapter.process(command, onProcess);
40
- else if (command.database == "Firebird") FirebirdAdapter.process(command, onProcess);
41
- else if (command.database == "MS SQL") MSSQLAdapter.process(command, onProcess);
42
- else if (command.database == "PostgreSQL") PostgreSQLAdapter.process(command, onProcess);
43
- else onResult({ success: false, notice: "Database '" + command.database + "' not supported!" });
44
- });
45
- }
46
-
47
- var applyQueryParameters = function (baseSqlCommand, parameters, escapeQueryParameters) {
48
- if (baseSqlCommand == null || baseSqlCommand.indexOf("@") < 0) return baseSqlCommand;
49
-
50
- var result = "";
51
- while (baseSqlCommand.indexOf("@") >= 0 && parameters != null && parameters.length > 0) {
52
- result += baseSqlCommand.substring(0, baseSqlCommand.indexOf("@"));
53
- baseSqlCommand = baseSqlCommand.substring(baseSqlCommand.indexOf("@") + 1);
54
-
55
- var parameterName = "";
56
-
57
- while (baseSqlCommand.length > 0) {
58
- var char = baseSqlCommand.charAt(0);
59
- if (char.length === 1 && char.match(/[a-zA-Z0-9_-]/i)) {
60
- parameterName += char;
61
- baseSqlCommand = baseSqlCommand.substring(1);
62
- }
63
- else break;
64
- }
65
-
66
- var parameter = parameters.find(parameter => parameter.name.toLowerCase() == parameterName.toLowerCase());
67
- if (parameter) {
68
- if (parameter.typeGroup != "number") {
69
- if (escapeQueryParameters)
70
- result += "'" + parameter.value.toString().replace(/\\/gi, "\\\\").replace(/\'/gi, "\\\'").replace(/\"/gi, "\\\"") + "'";
71
- else
72
- result += "'" + parameter.value.toString() + "'";
73
- }
74
- else
75
- result += parameter.value.toString();
76
- }
77
- else
78
- result += "@" + parameterName;
79
- }
80
-
81
- return result + baseSqlCommand;
82
- }
83
-
84
- var onProcess = function (result) {
85
- result.handlerVersion = "2022.1.4";
86
- response.end(JSON.stringify(result));
87
- }
88
-
89
- http.createServer(accept).listen(9615);