pubo-node 1.0.144 → 1.0.145
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/pubo-node.js +1 -1
- package/es/child-process/index.js +12 -2
- package/lib/child-process/index.js +115 -329
- package/lib/file-system/index.js +45 -63
- package/lib/ftp-client/index.js +124 -252
- package/lib/grpc/index.js +94 -200
- package/lib/index.js +19 -112
- package/lib/pitch.js +9 -24
- package/lib/ros/topic.js +93 -111
- package/lib/storage/json.js +128 -272
- package/lib/utils/index.js +14 -17
- package/lib/utils/network.js +34 -60
- package/package.json +2 -2
package/lib/ros/topic.js
CHANGED
|
@@ -1,122 +1,104 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} : function
|
|
16
|
-
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
});
|
|
19
|
-
var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
|
|
20
|
-
Object.defineProperty(o, "default", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
value: v
|
|
23
|
-
});
|
|
24
|
-
} : function (o, v) {
|
|
25
|
-
o["default"] = v;
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
26
17
|
});
|
|
27
|
-
var __importStar = this && this.__importStar || function (mod) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
33
24
|
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", {
|
|
35
|
-
value: true
|
|
36
|
-
});
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
26
|
exports.RosTopicManager = exports.RosTopic = void 0;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
this.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.messageType = messageType;
|
|
56
|
-
this.subscribed = false;
|
|
57
|
-
this.emitter = new pubo_utils_1.Emitter();
|
|
58
|
-
}
|
|
59
|
-
var _proto = RosTopic.prototype;
|
|
60
|
-
_proto.onTimeout = function onTimeout() {
|
|
61
|
-
if (!this.subscribed) {
|
|
62
|
-
return;
|
|
27
|
+
const child_process_1 = require("child_process");
|
|
28
|
+
const pubo_utils_1 = require("pubo-utils");
|
|
29
|
+
const YAML = __importStar(require("yaml"));
|
|
30
|
+
const child_process_2 = require("../child-process");
|
|
31
|
+
class RosTopic {
|
|
32
|
+
topic;
|
|
33
|
+
messageType;
|
|
34
|
+
emitter = new pubo_utils_1.Emitter();
|
|
35
|
+
subscribed = false;
|
|
36
|
+
dog = new pubo_utils_1.WatchDog({ limit: 60, onTimeout: this.onTimeout.bind(this) });
|
|
37
|
+
strSplit = new pubo_utils_1.StringSplit('---');
|
|
38
|
+
subscribeChildProcess;
|
|
39
|
+
constructor(topic, messageType) {
|
|
40
|
+
this.topic = topic;
|
|
41
|
+
this.messageType = messageType;
|
|
42
|
+
this.subscribed = false;
|
|
43
|
+
this.emitter = new pubo_utils_1.Emitter();
|
|
63
44
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return;
|
|
45
|
+
onTimeout() {
|
|
46
|
+
if (!this.subscribed) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this.unsubscribe();
|
|
50
|
+
this.subscribe();
|
|
71
51
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
52
|
+
onData(data) {
|
|
53
|
+
const tmp = this.strSplit.split(data.toString()).slice(-1)[0];
|
|
54
|
+
if (!tmp) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const res = YAML.parse(tmp);
|
|
58
|
+
this.emitter.emit('message', res);
|
|
78
59
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
60
|
+
subscribe() {
|
|
61
|
+
if (this.subscribeChildProcess) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.subscribed = true;
|
|
65
|
+
this.subscribeChildProcess = (0, child_process_1.spawn)(`rostopic`, ['echo', this.topic]);
|
|
66
|
+
this.subscribeChildProcess.stdout.on('data', this.onData.bind(this));
|
|
67
|
+
this.dog.init();
|
|
87
68
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.subscribeChildProcess = null;
|
|
92
|
-
};
|
|
93
|
-
_proto.publish = function publish(payload) {
|
|
94
|
-
var _this = this;
|
|
95
|
-
var data = YAML.stringify(payload);
|
|
96
|
-
return new Promise(function (resolve, reject) {
|
|
97
|
-
(0, child_process_1.exec)("rostopic pub -1 " + _this.topic + " " + _this.messageType + " \"" + data + "\"", function (err, stdout) {
|
|
98
|
-
if (err) {
|
|
99
|
-
reject(err);
|
|
100
|
-
} else {
|
|
101
|
-
resolve(stdout);
|
|
69
|
+
unsubscribe() {
|
|
70
|
+
if (this.subscribeChildProcess) {
|
|
71
|
+
return;
|
|
102
72
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
73
|
+
this.dog.stop();
|
|
74
|
+
this.subscribed = false;
|
|
75
|
+
(0, child_process_2.SIGKILL)(this.subscribeChildProcess.pid);
|
|
76
|
+
this.subscribeChildProcess = null;
|
|
77
|
+
}
|
|
78
|
+
publish(payload) {
|
|
79
|
+
const data = YAML.stringify(payload);
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
(0, child_process_1.exec)(`rostopic pub -1 ${this.topic} ${this.messageType} "${data}"`, (err, stdout) => {
|
|
82
|
+
if (err) {
|
|
83
|
+
reject(err);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
resolve(stdout);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
108
92
|
exports.RosTopic = RosTopic;
|
|
109
93
|
exports.RosTopicManager = {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
};
|
|
94
|
+
cache: [],
|
|
95
|
+
getTopic: function (topic, messageType) {
|
|
96
|
+
const tmp = this.cache.find((item) => item.topic === topic);
|
|
97
|
+
if (tmp) {
|
|
98
|
+
return tmp;
|
|
99
|
+
}
|
|
100
|
+
const instance = new RosTopic(topic, messageType);
|
|
101
|
+
this.cache.push(instance);
|
|
102
|
+
return instance;
|
|
103
|
+
},
|
|
104
|
+
};
|
package/lib/storage/json.js
CHANGED
|
@@ -1,298 +1,154 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
function _await(value, then, direct) {
|
|
4
|
-
if (direct) {
|
|
5
|
-
return then ? then(value) : value;
|
|
6
|
-
}
|
|
7
|
-
if (!value || !value.then) {
|
|
8
|
-
value = Promise.resolve(value);
|
|
9
|
-
}
|
|
10
|
-
return then ? value.then(then) : value;
|
|
11
|
-
}
|
|
12
|
-
function _empty() {}
|
|
13
|
-
function _invokeIgnored(body) {
|
|
14
|
-
var result = body();
|
|
15
|
-
if (result && result.then) {
|
|
16
|
-
return result.then(_empty);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function _invoke(body, then) {
|
|
20
|
-
var result = body();
|
|
21
|
-
if (result && result.then) {
|
|
22
|
-
return result.then(then);
|
|
23
|
-
}
|
|
24
|
-
return then(result);
|
|
25
|
-
}
|
|
26
|
-
function _awaitIgnored(value, direct) {
|
|
27
|
-
if (!direct) {
|
|
28
|
-
return value && value.then ? value.then(_empty) : Promise.resolve();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
Object.defineProperty(exports, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
3
|
exports.JsonStorage = void 0;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const pubo_utils_1 = require("pubo-utils");
|
|
6
|
+
const uuid_1 = require("uuid");
|
|
7
|
+
const cluster = require('cluster');
|
|
39
8
|
// 主线程的实现
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
worker.on('message', function (message) {
|
|
53
|
-
return _this.onMessage(message, worker);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
this.restore();
|
|
57
|
-
}
|
|
58
|
-
var _proto = Manager.prototype;
|
|
59
|
-
_proto.onMessage = function onMessage(message, worker) {
|
|
60
|
-
try {
|
|
61
|
-
var _this2 = this;
|
|
62
|
-
if (message.key !== _this2.key) {
|
|
63
|
-
return _await();
|
|
64
|
-
}
|
|
65
|
-
var payload;
|
|
66
|
-
return _await(_invoke(function () {
|
|
67
|
-
if (message.type === 'get') {
|
|
68
|
-
return _await(_this2.getState(), function (_this2$getState) {
|
|
69
|
-
payload = _this2$getState;
|
|
70
|
-
});
|
|
71
|
-
} else return _invokeIgnored(function () {
|
|
72
|
-
if (message.type === 'set') {
|
|
73
|
-
return _await(_this2.setState(message.payload), function (_this2$setState) {
|
|
74
|
-
payload = _this2$setState;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
9
|
+
class Manager {
|
|
10
|
+
path;
|
|
11
|
+
_state = {};
|
|
12
|
+
queue = new pubo_utils_1.SyncQueue();
|
|
13
|
+
key;
|
|
14
|
+
defaultState;
|
|
15
|
+
constructor(path, defaultState) {
|
|
16
|
+
this.path = path;
|
|
17
|
+
this.defaultState = defaultState;
|
|
18
|
+
this.key = encodeURIComponent(path);
|
|
19
|
+
cluster.on('online', (worker) => {
|
|
20
|
+
worker.on('message', (message) => this.onMessage(message, worker));
|
|
77
21
|
});
|
|
78
|
-
|
|
79
|
-
worker.send({
|
|
80
|
-
uid: message.uid,
|
|
81
|
-
key: _this2.key,
|
|
82
|
-
payload: payload
|
|
83
|
-
});
|
|
84
|
-
}));
|
|
85
|
-
} catch (e) {
|
|
86
|
-
return Promise.reject(e);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
_proto.sync = function sync() {
|
|
90
|
-
try {
|
|
91
|
-
var _this3 = this;
|
|
92
|
-
if (_this3.queue.length > 0) {
|
|
93
|
-
return _await();
|
|
94
|
-
}
|
|
95
|
-
return _await(_awaitIgnored(_this3.queue.push(_this3._syncFile.bind(_this3))));
|
|
96
|
-
} catch (e) {
|
|
97
|
-
return Promise.reject(e);
|
|
22
|
+
this.restore();
|
|
98
23
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
});
|
|
111
|
-
}));
|
|
112
|
-
} catch (e) {
|
|
113
|
-
return Promise.reject(e);
|
|
24
|
+
async onMessage(message, worker) {
|
|
25
|
+
if (message.key !== this.key) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
let payload;
|
|
29
|
+
if (message.type === 'get') {
|
|
30
|
+
payload = await this.getState();
|
|
31
|
+
}
|
|
32
|
+
else if (message.type === 'set') {
|
|
33
|
+
payload = await this.setState(message.payload);
|
|
34
|
+
}
|
|
35
|
+
worker.send({ uid: message.uid, key: this.key, payload });
|
|
114
36
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
37
|
+
async sync() {
|
|
38
|
+
if (this.queue.length > 0) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
await this.queue.push(this._syncFile.bind(this));
|
|
42
|
+
}
|
|
43
|
+
async _syncFile() {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
(0, fs_1.writeFile)(this.path, JSON.stringify(this._state), (err) => {
|
|
46
|
+
if (err) {
|
|
47
|
+
reject(err);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
resolve('');
|
|
51
|
+
}
|
|
52
|
+
});
|
|
126
53
|
});
|
|
127
|
-
}
|
|
128
|
-
this.setState((_this$defaultState = this.defaultState) != null ? _this$defaultState : {});
|
|
129
54
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
55
|
+
restore() {
|
|
56
|
+
try {
|
|
57
|
+
const buf = (0, fs_1.readFileSync)(this.path);
|
|
58
|
+
this._state = JSON.parse(buf.toString());
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
const str = process.platform === 'win32' ? '\\' : '/';
|
|
62
|
+
if (str) {
|
|
63
|
+
(0, fs_1.mkdirSync)(this.path.split(str).slice(0, -1).join(str), { recursive: true });
|
|
64
|
+
}
|
|
65
|
+
this.setState(this.defaultState ?? {});
|
|
66
|
+
}
|
|
137
67
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
try {
|
|
141
|
-
var _this6 = this;
|
|
142
|
-
_this6._state = values;
|
|
143
|
-
return _await(_awaitIgnored(_this6.sync()));
|
|
144
|
-
} catch (e) {
|
|
145
|
-
return Promise.reject(e);
|
|
68
|
+
async getState() {
|
|
69
|
+
return this._state;
|
|
146
70
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
var Worker = /*#__PURE__*/function () {
|
|
151
|
-
function Worker(path) {
|
|
152
|
-
this.key = void 0;
|
|
153
|
-
this.callback = {};
|
|
154
|
-
this.key = encodeURIComponent(path);
|
|
155
|
-
process.on('message', this.onMessage.bind(this));
|
|
156
|
-
}
|
|
157
|
-
var _proto2 = Worker.prototype;
|
|
158
|
-
_proto2.onMessage = function onMessage(message) {
|
|
159
|
-
if (message.key !== this.key) {
|
|
160
|
-
return;
|
|
71
|
+
async setState(values) {
|
|
72
|
+
this._state = values;
|
|
73
|
+
await this.sync();
|
|
161
74
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
75
|
+
}
|
|
76
|
+
// work 线程的实现
|
|
77
|
+
class Worker {
|
|
78
|
+
key;
|
|
79
|
+
callback = {};
|
|
80
|
+
constructor(path) {
|
|
81
|
+
this.key = encodeURIComponent(path);
|
|
82
|
+
process.on('message', this.onMessage.bind(this));
|
|
83
|
+
}
|
|
84
|
+
onMessage(message) {
|
|
85
|
+
if (message.key !== this.key) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (typeof this.callback[message.uid] === 'function') {
|
|
89
|
+
this.callback[message.uid](message.payload);
|
|
90
|
+
delete this.callback[message.uid];
|
|
91
|
+
}
|
|
165
92
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return _await(new Promise(function (resolve) {
|
|
173
|
-
var uid = (0, uuid_1.v4)();
|
|
174
|
-
_this7.callback[uid] = function (data) {
|
|
175
|
-
return resolve(data);
|
|
176
|
-
};
|
|
177
|
-
// @ts-ignore
|
|
178
|
-
process.send({
|
|
179
|
-
uid: uid,
|
|
180
|
-
type: type,
|
|
181
|
-
payload: payload,
|
|
182
|
-
key: _this7.key
|
|
93
|
+
async call({ type, payload }) {
|
|
94
|
+
return new Promise((resolve) => {
|
|
95
|
+
const uid = (0, uuid_1.v4)();
|
|
96
|
+
this.callback[uid] = (data) => resolve(data);
|
|
97
|
+
// @ts-ignore
|
|
98
|
+
process.send({ uid, type, payload, key: this.key });
|
|
183
99
|
});
|
|
184
|
-
}));
|
|
185
|
-
} catch (e) {
|
|
186
|
-
return Promise.reject(e);
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
_proto2.getState = function getState() {
|
|
190
|
-
try {
|
|
191
|
-
var _this8 = this;
|
|
192
|
-
return _await(_this8.call({
|
|
193
|
-
type: 'get',
|
|
194
|
-
payload: {}
|
|
195
|
-
}));
|
|
196
|
-
} catch (e) {
|
|
197
|
-
return Promise.reject(e);
|
|
198
100
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
try {
|
|
202
|
-
var _this9 = this;
|
|
203
|
-
return _await(_this9.call({
|
|
204
|
-
type: 'set',
|
|
205
|
-
payload: payload
|
|
206
|
-
}));
|
|
207
|
-
} catch (e) {
|
|
208
|
-
return Promise.reject(e);
|
|
101
|
+
async getState() {
|
|
102
|
+
return this.call({ type: 'get', payload: {} });
|
|
209
103
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}();
|
|
213
|
-
var JsonStorage = /*#__PURE__*/function () {
|
|
214
|
-
function JsonStorage(path, options) {
|
|
215
|
-
var _options;
|
|
216
|
-
if (options === void 0) {
|
|
217
|
-
options = {};
|
|
104
|
+
async setState(payload) {
|
|
105
|
+
return this.call({ type: 'set', payload });
|
|
218
106
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
107
|
+
}
|
|
108
|
+
class JsonStorage {
|
|
109
|
+
instance;
|
|
110
|
+
constructor(path, options = {}) {
|
|
111
|
+
if (cluster.isPrimary) {
|
|
112
|
+
this.instance = new Manager(path, options.defaultState);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
this.instance = new Worker(path);
|
|
116
|
+
}
|
|
117
|
+
if (options?.initialState) {
|
|
118
|
+
this.merge(options.initialState);
|
|
119
|
+
}
|
|
227
120
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
_proto3.getState = function getState() {
|
|
231
|
-
try {
|
|
232
|
-
var _this10 = this;
|
|
233
|
-
return _await(_this10.instance.getState());
|
|
234
|
-
} catch (e) {
|
|
235
|
-
return Promise.reject(e);
|
|
121
|
+
async getState() {
|
|
122
|
+
return this.instance.getState();
|
|
236
123
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
try {
|
|
240
|
-
var _this11 = this;
|
|
241
|
-
return _await(_this11.instance.setState(state));
|
|
242
|
-
} catch (e) {
|
|
243
|
-
return Promise.reject(e);
|
|
124
|
+
async setState(state) {
|
|
125
|
+
return this.instance.setState(state);
|
|
244
126
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
return state[key];
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
} catch (e) {
|
|
257
|
-
return Promise.reject(e);
|
|
127
|
+
async get(key) {
|
|
128
|
+
if (!key) {
|
|
129
|
+
return this.getState();
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
const state = await this.getState();
|
|
133
|
+
return state[key];
|
|
134
|
+
}
|
|
258
135
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
try {
|
|
262
|
-
var _this13 = this;
|
|
263
|
-
return _await(_this13.getState(), function (state) {
|
|
136
|
+
async set(key, values) {
|
|
137
|
+
const state = await this.getState();
|
|
264
138
|
state[key] = values;
|
|
265
|
-
|
|
266
|
-
});
|
|
267
|
-
} catch (e) {
|
|
268
|
-
return Promise.reject(e);
|
|
139
|
+
await this.setState(state);
|
|
269
140
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
return _await(_this14.getState(), function (state) {
|
|
275
|
-
for (var _i = 0, _Object$keys = Object.keys(values); _i < _Object$keys.length; _i++) {
|
|
276
|
-
var key = _Object$keys[_i];
|
|
277
|
-
state[key] = values[key];
|
|
141
|
+
async merge(values) {
|
|
142
|
+
const state = await this.getState();
|
|
143
|
+
for (const key of Object.keys(values)) {
|
|
144
|
+
state[key] = values[key];
|
|
278
145
|
}
|
|
279
|
-
|
|
280
|
-
});
|
|
281
|
-
} catch (e) {
|
|
282
|
-
return Promise.reject(e);
|
|
146
|
+
await this.setState(state);
|
|
283
147
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
try {
|
|
287
|
-
var _this15 = this;
|
|
288
|
-
return _await(_this15.getState(), function (state) {
|
|
148
|
+
async remove(key) {
|
|
149
|
+
const state = await this.getState();
|
|
289
150
|
delete state[key];
|
|
290
|
-
|
|
291
|
-
});
|
|
292
|
-
} catch (e) {
|
|
293
|
-
return Promise.reject(e);
|
|
151
|
+
await this.setState(state);
|
|
294
152
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}();
|
|
298
|
-
exports.JsonStorage = JsonStorage;
|
|
153
|
+
}
|
|
154
|
+
exports.JsonStorage = JsonStorage;
|
package/lib/utils/index.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.isPortAvailable = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
const isPortAvailable = (port) => {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
const net = require('net');
|
|
7
|
+
const server = net.createServer();
|
|
8
|
+
server.listen(port, () => {
|
|
9
|
+
resolve(true);
|
|
10
|
+
server.close();
|
|
11
|
+
});
|
|
12
|
+
server.on('error', () => {
|
|
13
|
+
resolve(false);
|
|
14
|
+
server.close();
|
|
15
|
+
});
|
|
14
16
|
});
|
|
15
|
-
server.on('error', function () {
|
|
16
|
-
resolve(false);
|
|
17
|
-
server.close();
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
17
|
};
|
|
21
|
-
exports.isPortAvailable = isPortAvailable;
|
|
18
|
+
exports.isPortAvailable = isPortAvailable;
|