pubo-node 1.0.143 → 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 +3 -3
package/lib/ftp-client/index.js
CHANGED
|
@@ -1,268 +1,140 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var result = body();
|
|
16
|
-
if (result && result.then) {
|
|
17
|
-
return result.then(then);
|
|
18
|
-
}
|
|
19
|
-
return then(result);
|
|
20
|
-
}
|
|
21
|
-
function _empty() {}
|
|
22
|
-
function _awaitIgnored(value, direct) {
|
|
23
|
-
if (!direct) {
|
|
24
|
-
return value && value.then ? value.then(_empty) : Promise.resolve();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function _async(f) {
|
|
28
|
-
return function () {
|
|
29
|
-
for (var args = [], i = 0; i < arguments.length; i++) {
|
|
30
|
-
args[i] = arguments[i];
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FtpClientPool = exports.FtpClient = void 0;
|
|
4
|
+
const pubo_utils_1 = require("pubo-utils");
|
|
5
|
+
class FtpClient {
|
|
6
|
+
driver;
|
|
7
|
+
options;
|
|
8
|
+
state = { running: false, connected: false, destroyed: false, connecting: false };
|
|
9
|
+
client;
|
|
10
|
+
_len = 0;
|
|
11
|
+
id = (0, pubo_utils_1.random)();
|
|
12
|
+
constructor({ driver, ...options }) {
|
|
13
|
+
this.driver = driver;
|
|
14
|
+
this.options = options;
|
|
31
15
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} catch (e) {
|
|
35
|
-
return Promise.reject(e);
|
|
16
|
+
get len() {
|
|
17
|
+
return this._len;
|
|
36
18
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
42
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
43
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
44
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
45
|
-
Object.defineProperty(exports, "__esModule", {
|
|
46
|
-
value: true
|
|
47
|
-
});
|
|
48
|
-
exports.FtpClientPool = exports.FtpClient = void 0;
|
|
49
|
-
var pubo_utils_1 = require("pubo-utils");
|
|
50
|
-
var FtpClient = /*#__PURE__*/function () {
|
|
51
|
-
function FtpClient(_ref) {
|
|
52
|
-
var driver = _ref.driver,
|
|
53
|
-
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
54
|
-
this.driver = void 0;
|
|
55
|
-
this.options = void 0;
|
|
56
|
-
this.state = {
|
|
57
|
-
running: false,
|
|
58
|
-
connected: false,
|
|
59
|
-
destroyed: false,
|
|
60
|
-
connecting: false
|
|
61
|
-
};
|
|
62
|
-
this.client = void 0;
|
|
63
|
-
this._len = 0;
|
|
64
|
-
this.id = (0, pubo_utils_1.random)();
|
|
65
|
-
this.put = this.bind('put');
|
|
66
|
-
this["delete"] = this.bind('delete');
|
|
67
|
-
this.list = this.bind('list');
|
|
68
|
-
this.rename = this.bind('rename');
|
|
69
|
-
this.driver = driver;
|
|
70
|
-
this.options = options;
|
|
71
|
-
}
|
|
72
|
-
var _proto = FtpClient.prototype;
|
|
73
|
-
_proto.connect = function connect() {
|
|
74
|
-
try {
|
|
75
|
-
var _exit = false;
|
|
76
|
-
var _this = this;
|
|
77
|
-
if (!_this.client) {
|
|
78
|
-
_this.client = new _this.driver();
|
|
79
|
-
}
|
|
80
|
-
_this.state.destroyed = false;
|
|
81
|
-
return _await(_invoke(function () {
|
|
82
|
-
if (_this.state.connecting) {
|
|
83
|
-
return _await((0, pubo_utils_1.waitFor)(function () {
|
|
84
|
-
return _this.state.connected;
|
|
85
|
-
}, {
|
|
86
|
-
checkTime: 1000,
|
|
87
|
-
timeout: 10000
|
|
88
|
-
}), function () {
|
|
89
|
-
_exit = true;
|
|
90
|
-
return 'connected';
|
|
91
|
-
});
|
|
19
|
+
set len(n) {
|
|
20
|
+
this._len = n;
|
|
21
|
+
if (this._len < 1) {
|
|
22
|
+
this.close();
|
|
92
23
|
}
|
|
93
|
-
}, function (_result) {
|
|
94
|
-
if (_exit) return _result;
|
|
95
|
-
_this.state.connecting = true;
|
|
96
|
-
return new Promise(function (resolve, reject) {
|
|
97
|
-
_this.client.once('ready', function () {
|
|
98
|
-
_this.state.connected = true;
|
|
99
|
-
resolve('connected');
|
|
100
|
-
_this.state.connecting = false;
|
|
101
|
-
});
|
|
102
|
-
_this.client.once('error', function (err) {
|
|
103
|
-
reject(err);
|
|
104
|
-
_this.close();
|
|
105
|
-
});
|
|
106
|
-
_this.client.connect(_extends({}, _this.options));
|
|
107
|
-
});
|
|
108
|
-
}));
|
|
109
|
-
} catch (e) {
|
|
110
|
-
return Promise.reject(e);
|
|
111
24
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
this.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
};
|
|
120
|
-
_proto.run = function run(_ref2) {
|
|
121
|
-
var fn = _ref2.fn,
|
|
122
|
-
args = _ref2.args;
|
|
123
|
-
try {
|
|
124
|
-
var _this2 = this;
|
|
125
|
-
_this2.len += 1;
|
|
126
|
-
return _await(_invoke(function () {
|
|
127
|
-
if (!_this2.state.connected) {
|
|
128
|
-
return _awaitIgnored(_this2.connect());
|
|
25
|
+
put = this.bind('put');
|
|
26
|
+
delete = this.bind('delete');
|
|
27
|
+
list = this.bind('list');
|
|
28
|
+
rename = this.bind('rename');
|
|
29
|
+
async connect() {
|
|
30
|
+
if (!this.client) {
|
|
31
|
+
this.client = new this.driver();
|
|
129
32
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
var _this2$client;
|
|
144
|
-
(_this2$client = _this2.client)[fn].apply(_this2$client, args.concat([function (err, res) {
|
|
145
|
-
if (err) {
|
|
33
|
+
this.state.destroyed = false;
|
|
34
|
+
if (this.state.connecting) {
|
|
35
|
+
await (0, pubo_utils_1.waitFor)(() => this.state.connected, { checkTime: 1000, timeout: 10000 });
|
|
36
|
+
return 'connected';
|
|
37
|
+
}
|
|
38
|
+
this.state.connecting = true;
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
this.client.once('ready', () => {
|
|
41
|
+
this.state.connected = true;
|
|
42
|
+
resolve('connected');
|
|
43
|
+
this.state.connecting = false;
|
|
44
|
+
});
|
|
45
|
+
this.client.once('error', (err) => {
|
|
146
46
|
reject(err);
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}]));
|
|
151
|
-
});
|
|
47
|
+
this.close();
|
|
48
|
+
});
|
|
49
|
+
this.client.connect({ ...this.options });
|
|
152
50
|
});
|
|
153
|
-
}));
|
|
154
|
-
} catch (e) {
|
|
155
|
-
return Promise.reject(e);
|
|
156
51
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
fn: 'get',
|
|
183
|
-
args: args
|
|
184
|
-
}), function (stream) {
|
|
185
|
-
return new Promise(function (resolve) {
|
|
186
|
-
stream.on('data', function (chunk) {
|
|
187
|
-
res = Buffer.concat([res, chunk], res.byteLength + chunk.byteLength);
|
|
188
|
-
});
|
|
189
|
-
stream.on('end', function () {
|
|
190
|
-
resolve(res);
|
|
191
|
-
_this4.state.running = false;
|
|
192
|
-
_this4.len -= 1;
|
|
193
|
-
});
|
|
52
|
+
close() {
|
|
53
|
+
this.client.end();
|
|
54
|
+
this.state.connected = false;
|
|
55
|
+
this.state.destroyed = true;
|
|
56
|
+
this.state.connecting = false;
|
|
57
|
+
this.client = null;
|
|
58
|
+
}
|
|
59
|
+
async run({ fn, args }) {
|
|
60
|
+
this.len += 1;
|
|
61
|
+
if (!this.state.connected) {
|
|
62
|
+
await this.connect();
|
|
63
|
+
}
|
|
64
|
+
if (this.state.running) {
|
|
65
|
+
await (0, pubo_utils_1.waitFor)(() => !this.state.running, { checkTime: 1000, timeout: 6000000 });
|
|
66
|
+
}
|
|
67
|
+
this.state.running = true;
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
this.client[fn](...args, (err, res) => {
|
|
70
|
+
if (err) {
|
|
71
|
+
reject(err);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
resolve(res);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
194
77
|
});
|
|
195
|
-
});
|
|
196
|
-
} catch (e) {
|
|
197
|
-
return Promise.reject(e);
|
|
198
78
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
79
|
+
bind(fn) {
|
|
80
|
+
return async (...args) => {
|
|
81
|
+
const res = await this.run({ fn, args });
|
|
82
|
+
this.state.running = false;
|
|
83
|
+
this.len -= 1;
|
|
84
|
+
return res;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
async get(...args) {
|
|
88
|
+
let res = Buffer.alloc(0);
|
|
89
|
+
const stream = await this.run({ fn: 'get', args });
|
|
90
|
+
return new Promise((resolve) => {
|
|
91
|
+
stream.on('data', (chunk) => {
|
|
92
|
+
res = Buffer.concat([res, chunk], res.byteLength + chunk.byteLength);
|
|
93
|
+
});
|
|
94
|
+
stream.on('end', () => {
|
|
95
|
+
resolve(res);
|
|
96
|
+
this.state.running = false;
|
|
97
|
+
this.len -= 1;
|
|
98
|
+
});
|
|
99
|
+
});
|
|
210
100
|
}
|
|
211
|
-
|
|
212
|
-
return FtpClient;
|
|
213
|
-
}();
|
|
101
|
+
}
|
|
214
102
|
exports.FtpClient = FtpClient;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return _await(client[fn].apply(client, arguments), function (res) {
|
|
237
|
-
if (client.len < 1) {
|
|
238
|
-
var index = _this5.pool.findIndex(function (item) {
|
|
239
|
-
return item.id === client.id;
|
|
240
|
-
});
|
|
241
|
-
_this5.pool.splice(index, 1);
|
|
103
|
+
class FtpClientPool {
|
|
104
|
+
options;
|
|
105
|
+
maxConnection;
|
|
106
|
+
pool = [];
|
|
107
|
+
constructor({ maxConnection = 5, ...options }) {
|
|
108
|
+
this.options = options;
|
|
109
|
+
this.maxConnection = maxConnection;
|
|
110
|
+
}
|
|
111
|
+
get = this.bind('get');
|
|
112
|
+
put = this.bind('put');
|
|
113
|
+
delete = this.bind('delete');
|
|
114
|
+
list = this.bind('list');
|
|
115
|
+
rename = this.bind('rename');
|
|
116
|
+
get len() {
|
|
117
|
+
return this.pool.length;
|
|
118
|
+
}
|
|
119
|
+
get client() {
|
|
120
|
+
if (this.pool.length < this.maxConnection) {
|
|
121
|
+
const client = new FtpClient(this.options);
|
|
122
|
+
this.pool.push(client);
|
|
123
|
+
return client;
|
|
242
124
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
});
|
|
246
|
-
};
|
|
247
|
-
_createClass(FtpClientPool, [{
|
|
248
|
-
key: "len",
|
|
249
|
-
get: function get() {
|
|
250
|
-
return this.pool.length;
|
|
125
|
+
this.pool.sort((a, b) => a.len - b.len);
|
|
126
|
+
return this.pool[0];
|
|
251
127
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
});
|
|
263
|
-
return this.pool[0];
|
|
128
|
+
bind(fn) {
|
|
129
|
+
return async (...args) => {
|
|
130
|
+
const client = this.client;
|
|
131
|
+
const res = await client[fn](...args);
|
|
132
|
+
if (client.len < 1) {
|
|
133
|
+
const index = this.pool.findIndex((item) => item.id === client.id);
|
|
134
|
+
this.pool.splice(index, 1);
|
|
135
|
+
}
|
|
136
|
+
return res;
|
|
137
|
+
};
|
|
264
138
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}();
|
|
268
|
-
exports.FtpClientPool = FtpClientPool;
|
|
139
|
+
}
|
|
140
|
+
exports.FtpClientPool = FtpClientPool;
|