-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathproxy.js
56 lines (46 loc) · 979 Bytes
/
proxy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* @module proxy
* @license MIT
* @version 2017/11/09
*/
'use strict';
// Import lib
const spawn = require('./spawn');
/**
* @class Proxy
*/
class Proxy {
/**
* @constructor
* @param {string} engine
*/
constructor(engine) {
this.engine = engine;
}
/**
* @method exec
* @param {string} command
* @param {Object} params
* @returns {Promise}
*/
exec(command, params) {
const engine = this.engine;
// Params to string
params = JSON.stringify(params);
// Spawn args
const args = [Proxy.adodb, '//E:JScript', '//Nologo', '//U', '//B', command];
// Spawn
return spawn(engine, args, params, { encoding: 'utf16le' })
.then(data => JSON.parse(data))
.catch(error => {
if (error.process) {
error.process = JSON.parse(error.process);
}
throw error;
});
}
}
// ADODB actuator
Proxy.adodb = require.resolve('./adodb');
// Exports
module.exports = Proxy;