@things-factory/integration-base 6.2.115 → 6.2.118
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.
- package/dist-server/engine/connector/oracle-connector.js +83 -21
- package/dist-server/engine/connector/oracle-connector.js.map +1 -1
- package/dist-server/engine/task/oracle-procedure.js +1 -15
- package/dist-server/engine/task/oracle-procedure.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/server/engine/connector/oracle-connector.ts +97 -23
- package/server/engine/task/oracle-procedure.ts +1 -16
@@ -4,7 +4,7 @@ exports.OracleConnector = void 0;
|
|
4
4
|
const env_1 = require("@things-factory/env");
|
5
5
|
const connection_manager_1 = require("../connection-manager");
|
6
6
|
try {
|
7
|
-
var
|
7
|
+
var oracledb = require('oracledb');
|
8
8
|
}
|
9
9
|
catch (err) {
|
10
10
|
env_1.logger.error('oracledb module loading failed');
|
@@ -14,13 +14,14 @@ class OracleConnector {
|
|
14
14
|
await Promise.all(connectionConfigs.map(this.connect));
|
15
15
|
connection_manager_1.ConnectionManager.logger.info('oracle-connector connections are ready');
|
16
16
|
}
|
17
|
-
async
|
17
|
+
async recreatePool(connection) {
|
18
18
|
const { name, endpoint, params: { user, password, database, poolMin, poolMax, poolIncrement }, domain } = connection;
|
19
|
-
if (!
|
19
|
+
if (!oracledb) {
|
20
20
|
throw new Error('oracledb module loading failed');
|
21
21
|
}
|
22
22
|
const poolAlias = `${domain.name}-${name}`;
|
23
|
-
|
23
|
+
await oracledb.getPool(poolAlias).close(10);
|
24
|
+
await oracledb.createPool({
|
24
25
|
user,
|
25
26
|
password,
|
26
27
|
// when oracle not using default port must add connection string with port like localhost:port
|
@@ -30,29 +31,90 @@ class OracleConnector {
|
|
30
31
|
poolIncrement,
|
31
32
|
poolAlias
|
32
33
|
});
|
34
|
+
connection_manager_1.ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} recreated.`);
|
35
|
+
}
|
36
|
+
async connect(connection) {
|
37
|
+
const { name, endpoint, params: { user, password, database, poolMin, poolMax, poolIncrement }, domain } = connection;
|
38
|
+
if (!oracledb) {
|
39
|
+
throw new Error('oracledb module loading failed');
|
40
|
+
}
|
41
|
+
const poolAlias = `${domain.name}-${name}`;
|
42
|
+
var enableStatistics = true;
|
43
|
+
const pool = await oracledb.createPool({
|
44
|
+
user,
|
45
|
+
password,
|
46
|
+
// when oracle not using default port must add connection string with port like localhost:port
|
47
|
+
connectString: `${endpoint.trim()}/${database}`,
|
48
|
+
poolMin,
|
49
|
+
poolMax,
|
50
|
+
poolIncrement,
|
51
|
+
poolAlias,
|
52
|
+
enableStatistics
|
53
|
+
});
|
33
54
|
connection_manager_1.ConnectionManager.addConnectionInstance(connection, {
|
34
55
|
query: async (query, params) => {
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
56
|
+
let dbConnection = {};
|
57
|
+
let taskResult = {};
|
58
|
+
try {
|
59
|
+
dbConnection = await oracledb.getConnection(poolAlias);
|
60
|
+
taskResult = (await dbConnection.execute(query, params, {
|
61
|
+
outFormat: oracledb.OBJECT
|
62
|
+
})).rows;
|
63
|
+
}
|
64
|
+
catch (e) {
|
65
|
+
if (e.name === 'Error' && e.message.includes('NJS-040')) {
|
66
|
+
await this.recreatePool(connection);
|
67
|
+
}
|
68
|
+
throw e;
|
69
|
+
}
|
70
|
+
finally {
|
71
|
+
await dbConnection.close();
|
72
|
+
}
|
73
|
+
return taskResult;
|
41
74
|
},
|
42
75
|
execute: async (procedure, params) => {
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
76
|
+
let dbConnection = {};
|
77
|
+
let taskResult = {};
|
78
|
+
try {
|
79
|
+
// TODO: need to check if this is available when procedure string is a common query.
|
80
|
+
procedure = `BEGIN
|
81
|
+
${procedure}
|
82
|
+
END;`;
|
83
|
+
dbConnection = await oracledb.getConnection(poolAlias);
|
84
|
+
// console.log('\n************* stat after get ****************')
|
85
|
+
// await oracledb.getPool(poolAlias).logStatistics()
|
86
|
+
const result = await dbConnection.execute(procedure, params, {
|
87
|
+
outFormat: oracledb.OBJECT
|
88
|
+
});
|
89
|
+
let paramKeys = Object.keys(params);
|
90
|
+
for (const paramKey of paramKeys) {
|
91
|
+
if (params[paramKey].dir === (oracledb === null || oracledb === void 0 ? void 0 : oracledb.BIND_OUT)) {
|
92
|
+
if (params[paramKey].type === (oracledb === null || oracledb === void 0 ? void 0 : oracledb.CURSOR)) {
|
93
|
+
const resultSetTemp = result.outBinds[paramKey];
|
94
|
+
taskResult[paramKey] = await resultSetTemp.getRows();
|
95
|
+
await resultSetTemp.close();
|
96
|
+
}
|
97
|
+
else {
|
98
|
+
taskResult[paramKey] = result.outBinds[paramKey];
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
catch (e) {
|
104
|
+
if (e.name === 'Error' && e.message.includes('NJS-040')) {
|
105
|
+
await this.recreatePool(connection);
|
106
|
+
}
|
107
|
+
throw e;
|
108
|
+
}
|
109
|
+
finally {
|
110
|
+
await dbConnection.close();
|
111
|
+
// console.log('\n************* stat after close ****************')
|
112
|
+
// await oracledb.getPool(poolAlias).logStatistics()
|
113
|
+
}
|
114
|
+
return taskResult;
|
53
115
|
},
|
54
116
|
close: async () => {
|
55
|
-
await
|
117
|
+
await oracledb.getPool(poolAlias).close(10);
|
56
118
|
}
|
57
119
|
});
|
58
120
|
connection_manager_1.ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} connected.`);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"oracle-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/oracle-connector.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE5C,8DAAyD;AAIzD,IAAI;IACF,IAAI,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;CACjC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,EAAE,QAAQ;gBACd,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,MAAM;aACd;YACD;gBACE,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,UAAU;aAClB;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,UAAU;gBAChB,WAAW,EAAE,KAAK;gBAClB,KAAK,EAAE,UAAU;aAClB;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,8BAA8B;gBAC3C,KAAK,EAAE,UAAU;gBACjB,KAAK,EAAE,CAAC;aACT;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,8BAA8B;gBAC3C,KAAK,EAAE,UAAU;gBACjB,KAAK,EAAE,CAAC;aACT;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,eAAe;gBACrB,WAAW,EAAE,6BAA6B;gBAC1C,KAAK,EAAE,gBAAgB;gBACvB,KAAK,EAAE,CAAC;aACT;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IAC/B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,wCAAwC,CAAA;IACjD,CAAC;CACF;AA9HD,0CA8HC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,kBAAkB,EAAE,IAAI,eAAe,EAAE,CAAC,CAAA;AAE9E,kBAAkB;AAClB,yHAAyH;AACzH,4DAA4D;AAE5D,2DAA2D","sourcesContent":["import { logger } from '@things-factory/env'\n\nimport { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { InputConnection } from '../../service/connection/connection-type'\n\ntry {\n var Client = require('oracledb')\n} catch (err) {\n logger.error('oracledb module loading failed')\n}\n\nexport class OracleConnector implements Connector {\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect))\n\n ConnectionManager.logger.info('oracle-connector connections are ready')\n }\n\n async connect(connection: InputConnection) {\n const {\n name,\n endpoint,\n params: { user, password, database, poolMin, poolMax, poolIncrement },\n domain\n } = connection\n\n if (!Client) {\n throw new Error('oracledb module loading failed')\n }\n\n const poolAlias = `${domain.name}-${name}`\n const client = await Client.createPool({\n user,\n password,\n // when oracle not using default port must add connection string with port like localhost:port\n connectString: `${endpoint.trim()}/${database}`,\n poolMin,\n poolMax,\n poolIncrement,\n poolAlias\n })\n\n \n ConnectionManager.addConnectionInstance(connection, {\n query: async (query, params) => {\n const connection = await Client.getConnection(poolAlias)\n const result = (\n await connection.execute(query, params, {\n outFormat: Client.OBJECT\n })\n ).rows\n await connection.close()\n return result\n \n },\n execute: async (procedure, params) => {\n // TODO: need to check if this is available when procedure string is a common query.\n procedure = `BEGIN\n ${procedure}\n END;`\n const connection = await Client.getConnection(poolAlias)\n const result = await connection.execute(procedure, params, {\n outFormat: Client.OBJECT\n })\n await connection.close()\n return result\n },\n close: async () => {\n await Client.getPool(poolAlias).close(10)\n }\n })\n\n ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} connected.`)\n }\n\n async disconnect(connection: InputConnection) {\n var client = ConnectionManager.getConnectionInstance(connection)\n\n try {\n await client.close()\n ConnectionManager.logger.info(`Oracle Database(${connection.name}) closed.`)\n } catch (e) {\n ConnectionManager.logger.error(e)\n }\n\n ConnectionManager.removeConnectionInstance(connection)\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'user',\n label: 'user'\n },\n {\n type: 'password',\n name: 'password',\n label: 'password'\n },\n {\n type: 'string',\n name: 'database',\n placeholder: 'SID',\n label: 'database'\n },\n {\n type: 'number',\n name: 'poolMin',\n placeholder: 'minimum connection-pool size',\n label: 'pool-min',\n value: 0\n },\n {\n type: 'number',\n name: 'poolMax',\n placeholder: 'maximum connection-pool size',\n label: 'pool-max',\n value: 4\n },\n {\n type: 'number',\n name: 'poolIncrement',\n placeholder: 'connection incremental size',\n label: 'pool-increment',\n value: 1\n }\n ]\n }\n\n get taskPrefixes() {\n return ['database', 'oracle']\n }\n\n get help() {\n return 'integration/connector/oracle-connector'\n }\n}\n\nConnectionManager.registerConnector('oracle-connector', new OracleConnector())\n\n// need reference:\n// https://download.oracle.com/otn_software/mac/instantclient/193000/instantclient-basiclite-macos.x64-19.3.0.0.0dbru.zip\n// https://node-oracledb.readthedocs.io/en/latest/index.html\n\n// docker pull store/oracle/database-instantclient:12.2.0.1\n"]}
|
1
|
+
{"version":3,"file":"oracle-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/oracle-connector.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE5C,8DAAyD;AAIzD,IAAI;IACF,IAAI,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;CACnC;AAAC,OAAO,GAAG,EAAE;IACZ,YAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAA;CAC/C;AAED,MAAa,eAAe;IAC1B,KAAK,CAAC,KAAK,CAAC,iBAAoC;QAC9C,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;QAEtD,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAA;IACzE,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,UAA2B;QAC5C,MAAM,EACJ,IAAI,EACJ,QAAQ,EACR,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,EACrE,MAAM,EACP,GAAG,UAAU,CAAA;QAEd,IAAI,CAAC,QAAQ,EAAE;YACb,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;SAClD;QAED,MAAM,SAAS,GAAG,GAAG,MAAM,CAAC,IAAI,IAAI,IAAI,EAAE,CAAA;QAC1C,MAAM,QAAQ,CAAC,OAAO,CAAC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;AACzH,4DAA4D;AAE5D,2DAA2D","sourcesContent":["import { logger } from '@things-factory/env'\n\nimport { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { InputConnection } from '../../service/connection/connection-type'\n\ntry {\n var oracledb = require('oracledb')\n} catch (err) {\n logger.error('oracledb module loading failed')\n}\n\nexport class OracleConnector implements Connector {\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect))\n\n ConnectionManager.logger.info('oracle-connector connections are ready')\n }\n\n async recreatePool(connection: InputConnection) {\n const {\n name,\n endpoint,\n params: { user, password, database, poolMin, poolMax, poolIncrement },\n domain\n } = connection\n\n if (!oracledb) {\n throw new Error('oracledb module loading failed')\n }\n\n const poolAlias = `${domain.name}-${name}`\n await oracledb.getPool(poolAlias).close(10)\n await oracledb.createPool({\n user,\n password,\n // when oracle not using default port must add connection string with port like localhost:port\n connectString: `${endpoint.trim()}/${database}`,\n poolMin,\n poolMax,\n poolIncrement,\n poolAlias\n })\n\n ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} recreated.`)\n }\n\n async connect(connection: InputConnection) {\n const {\n name,\n endpoint,\n params: { user, password, database, poolMin, poolMax, poolIncrement },\n domain\n } = connection\n\n if (!oracledb) {\n throw new Error('oracledb module loading failed')\n }\n\n const poolAlias = `${domain.name}-${name}`\n\n var enableStatistics = true\n const pool = await oracledb.createPool({\n user,\n password,\n // when oracle not using default port must add connection string with port like localhost:port\n connectString: `${endpoint.trim()}/${database}`,\n poolMin,\n poolMax,\n poolIncrement,\n poolAlias,\n enableStatistics\n })\n \n ConnectionManager.addConnectionInstance(connection, {\n query: async (query, params) => {\n let dbConnection: any = {}\n let taskResult: any = {}\n try {\n dbConnection = await oracledb.getConnection(poolAlias)\n\n taskResult = (\n await dbConnection.execute(query, params, {\n outFormat: oracledb.OBJECT\n })\n ).rows\n } catch (e) {\n if (e.name === 'Error' && e.message.includes('NJS-040')) {\n await this.recreatePool(connection)\n }\n throw e\n }\n finally {\n await dbConnection.close()\n }\n return taskResult\n \n },\n execute: async (procedure, params) => {\n let dbConnection: any = {}\n let taskResult: any = {}\n try {\n // TODO: need to check if this is available when procedure string is a common query.\n procedure = `BEGIN\n ${procedure}\n END;`\n dbConnection = await oracledb.getConnection(poolAlias)\n \n // console.log('\\n************* stat after get ****************')\n // await oracledb.getPool(poolAlias).logStatistics()\n\n const result = await dbConnection.execute(procedure, params, {\n outFormat: oracledb.OBJECT\n })\n\n let paramKeys = Object.keys(params)\n\n for (const paramKey of paramKeys) {\n if (params[paramKey].dir === oracledb?.BIND_OUT) {\n if (params[paramKey].type === oracledb?.CURSOR) {\n const resultSetTemp = result.outBinds[paramKey]\n taskResult[paramKey] = await resultSetTemp.getRows()\n await resultSetTemp.close()\n } else {\n taskResult[paramKey] = result.outBinds[paramKey]\n }\n }\n }\n } catch (e) {\n if (e.name === 'Error' && e.message.includes('NJS-040')) {\n await this.recreatePool(connection)\n }\n throw e\n }\n finally {\n await dbConnection.close()\n\n // console.log('\\n************* stat after close ****************')\n // await oracledb.getPool(poolAlias).logStatistics()\n }\n return taskResult\n },\n close: async () => {\n await oracledb.getPool(poolAlias).close(10)\n }\n })\n\n ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} connected.`)\n }\n\n async disconnect(connection: InputConnection) {\n var client = ConnectionManager.getConnectionInstance(connection)\n\n try {\n await client.close()\n ConnectionManager.logger.info(`Oracle Database(${connection.name}) closed.`)\n } catch (e) {\n ConnectionManager.logger.error(e)\n }\n\n ConnectionManager.removeConnectionInstance(connection)\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'user',\n label: 'user'\n },\n {\n type: 'password',\n name: 'password',\n label: 'password'\n },\n {\n type: 'string',\n name: 'database',\n placeholder: 'SID',\n label: 'database'\n },\n {\n type: 'number',\n name: 'poolMin',\n placeholder: 'minimum connection-pool size',\n label: 'pool-min',\n value: 0\n },\n {\n type: 'number',\n name: 'poolMax',\n placeholder: 'maximum connection-pool size',\n label: 'pool-max',\n value: 4\n },\n {\n type: 'number',\n name: 'poolIncrement',\n placeholder: 'connection incremental size',\n label: 'pool-increment',\n value: 1\n }\n ]\n }\n\n get taskPrefixes() {\n return ['database', 'oracle']\n }\n\n get help() {\n return 'integration/connector/oracle-connector'\n }\n}\n\nConnectionManager.registerConnector('oracle-connector', new OracleConnector())\n\n// need reference:\n// https://download.oracle.com/otn_software/mac/instantclient/193000/instantclient-basiclite-macos.x64-19.3.0.0.0dbru.zip\n// https://node-oracledb.readthedocs.io/en/latest/index.html\n\n// docker pull store/oracle/database-instantclient:12.2.0.1\n"]}
|
@@ -66,22 +66,8 @@ async function OracleProcedure(step, context) {
|
|
66
66
|
return sum;
|
67
67
|
}, {});
|
68
68
|
const result = await dbconnection.execute(code, procedureParameters);
|
69
|
-
var taskResult = {};
|
70
|
-
let paramKeys = Object.keys(procedureParameters);
|
71
|
-
for (const paramKey of paramKeys) {
|
72
|
-
if (procedureParameters[paramKey].dir === (oracledb === null || oracledb === void 0 ? void 0 : oracledb.BIND_OUT)) {
|
73
|
-
if (procedureParameters[paramKey].type === (oracledb === null || oracledb === void 0 ? void 0 : oracledb.CURSOR)) {
|
74
|
-
const resultSetTemp = result.outBinds[paramKey];
|
75
|
-
taskResult[paramKey] = await resultSetTemp.getRows();
|
76
|
-
await resultSetTemp.close();
|
77
|
-
}
|
78
|
-
else {
|
79
|
-
taskResult[paramKey] = result.outBinds[paramKey];
|
80
|
-
}
|
81
|
-
}
|
82
|
-
}
|
83
69
|
return {
|
84
|
-
data:
|
70
|
+
data: result
|
85
71
|
};
|
86
72
|
}
|
87
73
|
OracleProcedure.parameterSpec = [
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"oracle-procedure.js","sourceRoot":"","sources":["../../../server/engine/task/oracle-procedure.ts"],"names":[],"mappings":";;AAAA,6BAAwB;AACxB,6CAA4C;AAC5C,iDAA8C;AAC9C,8DAAyD;AACzD,oDAA+C;AAI/C,IAAI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AI,IAAI,QAAQ;4BAClB,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC;4BACpB,CAAC,CAAC,IAAI,IAAI,QAAQ;gCAClB,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC;gCACpB,CAAC,CAAC,UAAU,CAAA;aACjB;YAED,IAAI,OAAO,EAAE;gBACX,GAAG,CAAC,IAAI,CAAC,CAAC,OAAO,GAAG,OAAO,CAAA;aAC5B;YAED,OAAO,GAAG,CAAA;QACZ,CAAC,EAAE,EAAE,CAAC,CAAA;IAER,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAA;IAEpE,OAAO;QACL,IAAI,EAAE,MAAM;KACb,CAAA;AACH,CAAC;AAED,eAAe,CAAC,aAAa,GAAG;IAC9B;QACE,IAAI,EAAE,sBAAsB;QAC5B,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,EAAE;KACV;CACF,CAAA;AAED,eAAe,CAAC,IAAI,GAAG,mCAAmC,CAAA;AAE1D,4BAAY,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAA","sourcesContent":["import { VM } from 'vm2'\nimport { logger } from '@things-factory/env'\nimport { access } from '@things-factory/utils'\nimport { ConnectionManager } from '../connection-manager'\nimport { TaskRegistry } from '../task-registry'\nimport { InputStep } from '../../service/step/step-type'\nimport { Context } from '../types'\n\ntry {\n var oracledb = require('oracledb')\n} catch (err) {\n logger.error('oracledb module loading failed')\n}\n\ntype ProcedureParameterType = {\n name: string\n dir: string\n type: string\n val?: any\n accessor?: string\n maxSize?: number\n}\n\ntype ValueType = {\n code?: string\n procedure?: string\n parameters?: ProcedureParameterType[]\n}\n\nconst TYPES = {\n Number: oracledb?.NUMBER,\n String: oracledb?.STRING,\n Date: oracledb?.DATE,\n Buffer: oracledb?.BUFFER,\n Blob: oracledb?.BLOB,\n Clob: oracledb?.CLOB,\n Cursor: oracledb?.CURSOR\n}\n\nconst DIR = {\n In: oracledb?.BIND_IN,\n Inout: oracledb?.BIND_INOUT,\n Out: oracledb?.BIND_OUT\n}\n\nasync function OracleProcedure(step: InputStep, context: Context) {\n var { domain, user, data, variables, lng } = context\n var { connection: connectionName, params } = step\n\n var { code = '', parameters = [] } = params.parameters as ValueType\n\n var dbconnection = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n\n const vm = new VM({\n sandbox: {\n domain,\n user,\n lng,\n data,\n variables\n }\n })\n\n if (!code) {\n throw 'procedure code not defined'\n }\n\n code = vm.run('`' + code + '`')\n\n const procedureParameters =\n parameters &&\n parameters.reduce((sum, { name, val, dir, type, accessor, maxSize }) => {\n sum[name] = {\n dir: DIR[dir],\n type: TYPES[type]\n }\n\n const calculated = accessor ? access(accessor, data) || val : val\n\n if (calculated !== undefined) {\n sum[name].val =\n type == 'Date'\n ? new Date(calculated)\n : type == 'Number'\n ? Number(calculated)\n : type == 'String'\n ? String(calculated)\n : calculated\n }\n\n if (maxSize) {\n sum[name].maxSize = maxSize\n }\n\n return sum\n }, {})\n\n const result = await dbconnection.execute(code, procedureParameters)\n\n return {\n data: result\n }\n}\n\nOracleProcedure.parameterSpec = [\n {\n type: 'procedure-parameters',\n name: 'parameters',\n label: ''\n }\n]\n\nOracleProcedure.help = 'integration/task/oracle-procedure'\n\nTaskRegistry.registerTaskHandler('oracle-procedure', OracleProcedure)\n"]}
|