@ya-modbus/transport 0.8.1 → 0.9.1

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.
@@ -1,33 +1,33 @@
1
1
  import { createRTUTransport } from './rtu-transport.js';
2
2
  import { createTCPTransport } from './tcp-transport.js';
3
3
  /**
4
- * Type guard to check if config is RTU
4
+ * Type guard to check if config is TCP
5
5
  */
6
- function isRTUConfig(config) {
7
- return 'port' in config && !('host' in config);
6
+ function isTCPConfig(config) {
7
+ return 'host' in config;
8
8
  }
9
9
  /**
10
10
  * Create a transport instance based on configuration
11
11
  *
12
12
  * Detects whether to create RTU or TCP transport based on the config:
13
- * - If `port` is provided → RTU transport
14
- * - If `host` is provided → TCP transport
13
+ * - If `host` is provided → TCP transport (`port` is the optional TCP port number)
14
+ * - Otherwise, if `port` is provided → RTU transport (`port` is the serial path)
15
15
  *
16
16
  * @param config - Transport configuration (RTU or TCP)
17
17
  * @returns Transport implementation
18
18
  * @throws Error if config is invalid
19
19
  */
20
20
  export async function createTransport(config) {
21
- // Validate that exactly one of port/host is provided
22
- if ('port' in config && 'host' in config) {
23
- throw new Error('Cannot specify both port (RTU) and host (TCP)');
21
+ if (isTCPConfig(config)) {
22
+ // A string `port` is a serial path, which cannot be combined with a TCP host
23
+ if (typeof config.port === 'string') {
24
+ throw new Error('Cannot specify both port (RTU) and host (TCP)');
25
+ }
26
+ return createTCPTransport(config);
24
27
  }
25
- if (isRTUConfig(config)) {
28
+ if ('port' in config) {
26
29
  return createRTUTransport(config);
27
30
  }
28
- if ('host' in config) {
29
- return createTCPTransport(config);
30
- }
31
31
  throw new Error('Either port (for RTU) or host (for TCP) must be specified');
32
32
  }
33
33
  //# sourceMappingURL=factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAA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