@gibme/mikrotik 2.0.2 → 2.0.4

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 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;
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
- const ssh_1 = __importDefault(require("@gibme/ssh"));
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;
@@ -390,8 +419,9 @@ class Mikrotik extends ssh_1.default {
390
419
  if (options.remote_tx_speed) {
391
420
  command += ` remote-tx-speed=${options.remote_tx_speed}M`;
392
421
  }
393
- const cancel = yield this.stream(command, {
394
- separator: '\r\n\r\n'
422
+ yield this.stream(command, {
423
+ separator: '\r\n\r\n',
424
+ signal: options.signal
395
425
  });
396
426
  this.once('stream_complete', () => __awaiter(this, void 0, void 0, function* () {
397
427
  yield cleanup();
@@ -401,7 +431,10 @@ class Mikrotik extends ssh_1.default {
401
431
  return reject(new Error('Bandwidth Test Cancelled'));
402
432
  }));
403
433
  if (options.timeout) {
404
- setTimeout(cancel, options.timeout);
434
+ setTimeout(() => {
435
+ var _a;
436
+ (_a = options.signal) === null || _a === void 0 ? void 0 : _a.dispatchEvent(new Event('abort'));
437
+ }, options.timeout);
405
438
  }
406
439
  }));
407
440
  });
@@ -674,6 +707,9 @@ class Mikrotik extends ssh_1.default {
674
707
  line.split(/\s+/)
675
708
  .map(col => col.trim())
676
709
  .forEach(col => {
710
+ if (!result.idx && !isNaN(parseInt(col))) {
711
+ result.idx = parseInt(col);
712
+ }
677
713
  if (col.includes('=')) {
678
714
  const [key, ...value] = col.split('=');
679
715
  result[key] = value.join('=');
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,7 @@ export declare namespace BandwidthTest {
36
37
  random_data: boolean;
37
38
  callback: (frame: Update) => void;
38
39
  timeout: number;
40
+ signal: AbortSignal;
39
41
  /**
40
42
  * In Megabits
41
43
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gibme/mikrotik",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
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": "^1.0.3",
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"