@gibme/mikrotik 2.0.1 → 2.0.3
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/index.d.ts +4 -3
- package/dist/index.js +45 -5
- package/dist/types.d.ts +10 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import SSH from '@gibme/ssh';
|
|
1
|
+
import SSH, { AbortController, AbortSignal } from '@gibme/ssh';
|
|
2
2
|
import { BandwidthTest, Response } from './types';
|
|
3
3
|
import Cache from '@gibme/cache/memory';
|
|
4
|
+
export { AbortController, AbortSignal };
|
|
4
5
|
export type { ConnectConfig } from '@gibme/ssh';
|
|
5
6
|
export type Direction = BandwidthTest.Direction;
|
|
6
7
|
export type Protocol = BandwidthTest.Protocol;
|
|
@@ -108,12 +109,12 @@ export default class Mikrotik extends SSH {
|
|
|
108
109
|
* @param command
|
|
109
110
|
* @protected
|
|
110
111
|
*/
|
|
111
|
-
|
|
112
|
+
terse<Type extends object = any>(command: string): Promise<Type[]>;
|
|
112
113
|
/**
|
|
113
114
|
* Executes a command that expects the result as a 'table' of key-value pairs separated by a colon (:)
|
|
114
115
|
*
|
|
115
116
|
* @param command
|
|
116
117
|
* @protected
|
|
117
118
|
*/
|
|
118
|
-
|
|
119
|
+
kvs<Type extends object = any>(command: string): Promise<Type>;
|
|
119
120
|
}
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,29 @@
|
|
|
18
18
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
19
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
20
|
// SOFTWARE.
|
|
21
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
24
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
25
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
26
|
+
}
|
|
27
|
+
Object.defineProperty(o, k2, desc);
|
|
28
|
+
}) : (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
o[k2] = m[k];
|
|
31
|
+
}));
|
|
32
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
33
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
34
|
+
}) : function(o, v) {
|
|
35
|
+
o["default"] = v;
|
|
36
|
+
});
|
|
37
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
38
|
+
if (mod && mod.__esModule) return mod;
|
|
39
|
+
var result = {};
|
|
40
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
41
|
+
__setModuleDefault(result, mod);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
21
44
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
45
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
46
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -31,7 +54,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
31
54
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
55
|
};
|
|
33
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
|
|
57
|
+
exports.AbortSignal = exports.AbortController = void 0;
|
|
58
|
+
const ssh_1 = __importStar(require("@gibme/ssh"));
|
|
59
|
+
Object.defineProperty(exports, "AbortController", { enumerable: true, get: function () { return ssh_1.AbortController; } });
|
|
60
|
+
Object.defineProperty(exports, "AbortSignal", { enumerable: true, get: function () { return ssh_1.AbortSignal; } });
|
|
35
61
|
const types_1 = require("./types");
|
|
36
62
|
const ip_address_1 = require("ip-address");
|
|
37
63
|
const memory_1 = __importDefault(require("@gibme/cache/memory"));
|
|
@@ -265,9 +291,12 @@ class Mikrotik extends ssh_1.default {
|
|
|
265
291
|
*/
|
|
266
292
|
bandwidth_test(target_1, username_1, password_1) {
|
|
267
293
|
return __awaiter(this, arguments, void 0, function* (target, username, password, options = {}) {
|
|
294
|
+
var _a;
|
|
268
295
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
269
296
|
const $ = this;
|
|
270
297
|
const sleep = (timeout) => __awaiter(this, void 0, void 0, function* () { return new Promise(resolve => setTimeout(resolve, timeout)); });
|
|
298
|
+
const controller = new ssh_1.AbortController();
|
|
299
|
+
(_a = options.signal) !== null && _a !== void 0 ? _a : (options.signal = controller.signal);
|
|
271
300
|
// eslint-disable-next-line no-async-promise-executor
|
|
272
301
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
273
302
|
var _a, _b, _c, _d, _e;
|
|
@@ -380,11 +409,19 @@ class Mikrotik extends ssh_1.default {
|
|
|
380
409
|
yield Mikrotik.cache.del(target);
|
|
381
410
|
});
|
|
382
411
|
yield Mikrotik.cache.set(target, target, options.duration); // set our mutex
|
|
383
|
-
|
|
412
|
+
let command = `/tool bandwidth-test protocol=${options.protocol} ` +
|
|
384
413
|
`user=${username} password=${password} ` +
|
|
385
414
|
`duration=${options.duration}s direction=${options.direction} ` +
|
|
386
|
-
`address=${target} random-data=${options.random_data ? 'yes' : 'no'} interval=1s
|
|
387
|
-
|
|
415
|
+
`address=${target} random-data=${options.random_data ? 'yes' : 'no'} interval=1s`;
|
|
416
|
+
if (options.local_tx_speed) {
|
|
417
|
+
command += ` local-tx-speed=${options.local_tx_speed}M`;
|
|
418
|
+
}
|
|
419
|
+
if (options.remote_tx_speed) {
|
|
420
|
+
command += ` remote-tx-speed=${options.remote_tx_speed}M`;
|
|
421
|
+
}
|
|
422
|
+
yield this.stream(command, {
|
|
423
|
+
separator: '\r\n\r\n',
|
|
424
|
+
signal: options.signal
|
|
388
425
|
});
|
|
389
426
|
this.once('stream_complete', () => __awaiter(this, void 0, void 0, function* () {
|
|
390
427
|
yield cleanup();
|
|
@@ -394,7 +431,10 @@ class Mikrotik extends ssh_1.default {
|
|
|
394
431
|
return reject(new Error('Bandwidth Test Cancelled'));
|
|
395
432
|
}));
|
|
396
433
|
if (options.timeout) {
|
|
397
|
-
setTimeout(
|
|
434
|
+
setTimeout(() => {
|
|
435
|
+
var _a;
|
|
436
|
+
(_a = options.signal) === null || _a === void 0 ? void 0 : _a.dispatchEvent(new Event('abort'));
|
|
437
|
+
}, options.timeout);
|
|
398
438
|
}
|
|
399
439
|
}));
|
|
400
440
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AbortSignal } from 'abort-controller';
|
|
1
2
|
export declare namespace BandwidthTest {
|
|
2
3
|
export type Direction = 'both' | 'transmit' | 'receive';
|
|
3
4
|
export type Protocol = 'udp' | 'tcp';
|
|
@@ -36,6 +37,15 @@ export declare namespace BandwidthTest {
|
|
|
36
37
|
random_data: boolean;
|
|
37
38
|
callback: (frame: Update) => void;
|
|
38
39
|
timeout: number;
|
|
40
|
+
signal: AbortSignal;
|
|
41
|
+
/**
|
|
42
|
+
* In Megabits
|
|
43
|
+
*/
|
|
44
|
+
local_tx_speed: number;
|
|
45
|
+
/**
|
|
46
|
+
* In Megabits
|
|
47
|
+
*/
|
|
48
|
+
remote_tx_speed: number;
|
|
39
49
|
}
|
|
40
50
|
export {};
|
|
41
51
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gibme/mikrotik",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "A simple mikrotik helper/wrapper",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@gibme/cache": "^1.1.5",
|
|
59
|
-
"@gibme/ssh": "^
|
|
59
|
+
"@gibme/ssh": "^2.0.0",
|
|
60
60
|
"@types/jsbn": "^1.2.33",
|
|
61
61
|
"ip-address": "^9.0.5",
|
|
62
62
|
"semver": "^7.6.2"
|