unping 0.0.1 → 0.0.2

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.
@@ -4,46 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  module.exports = hybridDriver;
7
- function hybridDriver(options = {}) {
7
+ function hybridDriver(options) {
8
8
  const {
9
- drivers: customDrivers
9
+ drivers
10
10
  } = options;
11
- const defaultDrivers = getDefaultDrivers();
12
- const drivers = customDrivers || defaultDrivers;
13
11
  const ping = async (host, opts) => {
14
- const lastError = new Error("All drivers failed");
15
12
  for (const driver of drivers) {
16
13
  try {
17
14
  const result = await driver.ping(host, opts);
18
15
  return result;
19
- } catch (error) {
20
- lastError.cause = error;
16
+ } catch {
21
17
  continue;
22
18
  }
23
19
  }
24
- throw lastError;
20
+ throw new Error("All drivers failed");
25
21
  };
26
22
  return {
27
23
  name: "hybrid",
28
24
  options,
29
25
  ping
30
26
  };
31
- }
32
- function getDefaultDrivers() {
33
- const {
34
- default: tcpDriver
35
- } = require("./tcp.cjs");
36
- const {
37
- default: httpDriver
38
- } = require("./http.cjs");
39
- const {
40
- default: dnsDriver
41
- } = require("./dns.cjs");
42
- return [tcpDriver({
43
- port: 80
44
- }), httpDriver({
45
- method: "HEAD"
46
- }), dnsDriver({
47
- type: "A"
48
- })];
49
27
  }
@@ -1,6 +1,5 @@
1
1
  import type { Driver, DriverOptions } from "../types";
2
2
  export interface HybridDriverOptions extends DriverOptions {
3
- /** Array of drivers to try in order (default: [tcp, http, dns]) */
4
- drivers?: Driver[];
3
+ drivers: Driver[];
5
4
  }
6
- export default function hybridDriver(options?: HybridDriverOptions): Driver;
5
+ export default function hybridDriver(options: HybridDriverOptions): Driver<HybridDriverOptions>;
@@ -1,19 +1,15 @@
1
- export default function hybridDriver(options = {}) {
2
- const { drivers: customDrivers } = options;
3
- const defaultDrivers = getDefaultDrivers();
4
- const drivers = customDrivers || defaultDrivers;
1
+ export default function hybridDriver(options) {
2
+ const { drivers } = options;
5
3
  const ping = async (host, opts) => {
6
- const lastError = new Error("All drivers failed");
7
4
  for (const driver of drivers) {
8
5
  try {
9
6
  const result = await driver.ping(host, opts);
10
7
  return result;
11
- } catch (error) {
12
- lastError.cause = error;
8
+ } catch {
13
9
  continue;
14
10
  }
15
11
  }
16
- throw lastError;
12
+ throw new Error("All drivers failed");
17
13
  };
18
14
  return {
19
15
  name: "hybrid",
@@ -21,13 +17,3 @@ export default function hybridDriver(options = {}) {
21
17
  ping
22
18
  };
23
19
  }
24
- function getDefaultDrivers() {
25
- const { default: tcpDriver } = require("./tcp");
26
- const { default: httpDriver } = require("./http");
27
- const { default: dnsDriver } = require("./dns");
28
- return [
29
- tcpDriver({ port: 80 }),
30
- httpDriver({ method: "HEAD" }),
31
- dnsDriver({ type: "A" })
32
- ];
33
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unping",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Unified network ping library with multi-driver support",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",