@ya-modbus/transport 0.7.3 → 0.8.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.
- package/CHANGELOG.md +10 -0
- package/README.md +27 -0
- package/dist/cjs/src/client-config.d.ts +15 -0
- package/dist/cjs/src/client-config.d.ts.map +1 -0
- package/dist/cjs/src/client-config.js +21 -0
- package/dist/cjs/src/client-config.js.map +1 -0
- package/dist/cjs/src/index.d.ts +1 -0
- package/dist/cjs/src/index.d.ts.map +1 -1
- package/dist/cjs/src/index.js +3 -1
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/manager.d.ts.map +1 -1
- package/dist/cjs/src/manager.js +3 -2
- package/dist/cjs/src/manager.js.map +1 -1
- package/dist/cjs/src/normalize-error.d.ts +28 -0
- package/dist/cjs/src/normalize-error.d.ts.map +1 -0
- package/dist/cjs/src/normalize-error.js +47 -0
- package/dist/cjs/src/normalize-error.js.map +1 -0
- package/dist/cjs/src/retry.d.ts +4 -2
- package/dist/cjs/src/retry.d.ts.map +1 -1
- package/dist/cjs/src/retry.js +4 -2
- package/dist/cjs/src/retry.js.map +1 -1
- package/dist/cjs/src/rtu-transport.d.ts.map +1 -1
- package/dist/cjs/src/rtu-transport.js +2 -4
- package/dist/cjs/src/rtu-transport.js.map +1 -1
- package/dist/cjs/src/tcp-transport.d.ts.map +1 -1
- package/dist/cjs/src/tcp-transport.js +2 -4
- package/dist/cjs/src/tcp-transport.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/client-config.d.ts +15 -0
- package/dist/esm/src/client-config.d.ts.map +1 -0
- package/dist/esm/src/client-config.js +17 -0
- package/dist/esm/src/client-config.js.map +1 -0
- package/dist/esm/src/index.d.ts +1 -0
- package/dist/esm/src/index.d.ts.map +1 -1
- package/dist/esm/src/index.js +1 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/manager.d.ts.map +1 -1
- package/dist/esm/src/manager.js +3 -2
- package/dist/esm/src/manager.js.map +1 -1
- package/dist/esm/src/normalize-error.d.ts +28 -0
- package/dist/esm/src/normalize-error.d.ts.map +1 -0
- package/dist/esm/src/normalize-error.js +44 -0
- package/dist/esm/src/normalize-error.js.map +1 -0
- package/dist/esm/src/retry.d.ts +4 -2
- package/dist/esm/src/retry.d.ts.map +1 -1
- package/dist/esm/src/retry.js +4 -2
- package/dist/esm/src/retry.js.map +1 -1
- package/dist/esm/src/rtu-transport.d.ts.map +1 -1
- package/dist/esm/src/rtu-transport.js +2 -4
- package/dist/esm/src/rtu-transport.js.map +1 -1
- package/dist/esm/src/tcp-transport.d.ts.map +1 -1
- package/dist/esm/src/tcp-transport.js +2 -4
- package/dist/esm/src/tcp-transport.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.8.1](https://github.com/groupsky/ya-modbus/compare/@ya-modbus/transport@0.8.0...@ya-modbus/transport@0.8.1) (2026-10-12)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @ya-modbus/transport
|
|
9
|
+
|
|
10
|
+
# [0.8.0](https://github.com/groupsky/ya-modbus/compare/@ya-modbus/transport@0.7.3...@ya-modbus/transport@0.8.0) (2026-10-12)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- **transport:** keep details of modbus-serial errors instead of "[object Object]" ([#512](https://github.com/groupsky/ya-modbus/issues/512)) ([343dd50](https://github.com/groupsky/ya-modbus/commit/343dd50d011c7e06e86e31701e25a8d5b9e861dc)), closes [#177](https://github.com/groupsky/ya-modbus/issues/177)
|
|
15
|
+
|
|
6
16
|
## [0.7.3](https://github.com/groupsky/ya-modbus/compare/@ya-modbus/transport@0.7.2...@ya-modbus/transport@0.7.3) (2026-10-12)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @ya-modbus/transport
|
package/README.md
CHANGED
|
@@ -42,6 +42,33 @@ const tcpTransport = await createTransport({
|
|
|
42
42
|
await rtuTransport.readHoldingRegisters(0, 10)
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
## Error handling
|
|
46
|
+
|
|
47
|
+
Some `modbus-serial` failures (response timeouts, closed port) are plain objects instead of `Error`
|
|
48
|
+
instances. Transport read and write methods reject with an `Error` that keeps the diagnostic
|
|
49
|
+
properties of the original (the `ModbusError` type). The original value is available as `cause`:
|
|
50
|
+
|
|
51
|
+
| Property | Example | Meaning |
|
|
52
|
+
| ------------ | -------------------------- | --------------------------------------------- |
|
|
53
|
+
| `name` | `TransactionTimedOutError` | Error type reported by `modbus-serial` |
|
|
54
|
+
| `errno` | `ETIMEDOUT`, `-111` | Error name or number (timeout, refused, etc.) |
|
|
55
|
+
| `code` | `ECONNREFUSED` | Node.js error code (TCP socket errors) |
|
|
56
|
+
| `modbusCode` | `2` | Exception code returned by the device |
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import type { ModbusError } from '@ya-modbus/transport'
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
await transport.readHoldingRegisters(0, 10)
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if ((error as ModbusError).errno === 'ETIMEDOUT') {
|
|
65
|
+
// device did not answer
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`normalizeModbusError(error)` applies the same conversion to any caught value.
|
|
71
|
+
|
|
45
72
|
## License
|
|
46
73
|
|
|
47
74
|
GPL-3.0-or-later
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings shared by the modbus-serial clients that the transports create
|
|
3
|
+
*/
|
|
4
|
+
import type ModbusRTU from 'modbus-serial';
|
|
5
|
+
/** Default response timeout for Modbus operations in milliseconds */
|
|
6
|
+
export declare const DEFAULT_TIMEOUT_MS = 1000;
|
|
7
|
+
/**
|
|
8
|
+
* Apply the slave ID and response timeout to a modbus-serial client
|
|
9
|
+
*
|
|
10
|
+
* @param client - ModbusRTU client instance
|
|
11
|
+
* @param slaveId - Modbus slave ID
|
|
12
|
+
* @param timeout - Response timeout in milliseconds (default: DEFAULT_TIMEOUT_MS)
|
|
13
|
+
*/
|
|
14
|
+
export declare function configureClient(client: ModbusRTU, slaveId: number, timeout?: number): void;
|
|
15
|
+
//# sourceMappingURL=client-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-config.d.ts","sourceRoot":"","sources":["../../../src/client-config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,SAAS,MAAM,eAAe,CAAA;AAE1C,qEAAqE;AACrE,eAAO,MAAM,kBAAkB,OAAO,CAAA;AAEtC;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAG1F"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Settings shared by the modbus-serial clients that the transports create
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_TIMEOUT_MS = void 0;
|
|
7
|
+
exports.configureClient = configureClient;
|
|
8
|
+
/** Default response timeout for Modbus operations in milliseconds */
|
|
9
|
+
exports.DEFAULT_TIMEOUT_MS = 1000;
|
|
10
|
+
/**
|
|
11
|
+
* Apply the slave ID and response timeout to a modbus-serial client
|
|
12
|
+
*
|
|
13
|
+
* @param client - ModbusRTU client instance
|
|
14
|
+
* @param slaveId - Modbus slave ID
|
|
15
|
+
* @param timeout - Response timeout in milliseconds (default: DEFAULT_TIMEOUT_MS)
|
|
16
|
+
*/
|
|
17
|
+
function configureClient(client, slaveId, timeout) {
|
|
18
|
+
client.setID(slaveId);
|
|
19
|
+
client.setTimeout(timeout ?? exports.DEFAULT_TIMEOUT_MS);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=client-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-config.js","sourceRoot":"","sources":["../../../src/client-config.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAcH,0CAGC;AAbD,qEAAqE;AACxD,QAAA,kBAAkB,GAAG,IAAI,CAAA;AAEtC;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,MAAiB,EAAE,OAAe,EAAE,OAAgB;IAClF,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACrB,MAAM,CAAC,UAAU,CAAC,OAAO,IAAI,0BAAkB,CAAC,CAAA;AAClD,CAAC"}
|
package/dist/cjs/src/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { createRTUTransport, type RTUConfig } from './rtu-transport.js';
|
|
|
9
9
|
export { createTCPTransport, type TCPConfig } from './tcp-transport.js';
|
|
10
10
|
export { createModbusTransport } from './create-modbus-transport.js';
|
|
11
11
|
export { withRetry, MAX_RETRIES, RETRY_DELAY_MS, type RetryLogger } from './retry.js';
|
|
12
|
+
export { normalizeModbusError, type ModbusError } from './normalize-error.js';
|
|
12
13
|
export { TransportManager, type TransportStats } from './manager.js';
|
|
13
14
|
export { MutexTransport } from './mutex-transport.js';
|
|
14
15
|
export { SlaveTransport } from './slave-transport.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,kBAAkB,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAA;AACrF,OAAO,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,kBAAkB,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAA;AACrF,OAAO,EAAE,oBAAoB,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
|
package/dist/cjs/src/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* and transport pooling with mutex-based RTU bus serialization
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.SlaveTransport = exports.MutexTransport = exports.TransportManager = exports.RETRY_DELAY_MS = exports.MAX_RETRIES = exports.withRetry = exports.createModbusTransport = exports.createTCPTransport = exports.createRTUTransport = exports.createTransport = void 0;
|
|
9
|
+
exports.SlaveTransport = exports.MutexTransport = exports.TransportManager = exports.normalizeModbusError = exports.RETRY_DELAY_MS = exports.MAX_RETRIES = exports.withRetry = exports.createModbusTransport = exports.createTCPTransport = exports.createRTUTransport = exports.createTransport = void 0;
|
|
10
10
|
var factory_js_1 = require("./factory.js");
|
|
11
11
|
Object.defineProperty(exports, "createTransport", { enumerable: true, get: function () { return factory_js_1.createTransport; } });
|
|
12
12
|
var rtu_transport_js_1 = require("./rtu-transport.js");
|
|
@@ -19,6 +19,8 @@ var retry_js_1 = require("./retry.js");
|
|
|
19
19
|
Object.defineProperty(exports, "withRetry", { enumerable: true, get: function () { return retry_js_1.withRetry; } });
|
|
20
20
|
Object.defineProperty(exports, "MAX_RETRIES", { enumerable: true, get: function () { return retry_js_1.MAX_RETRIES; } });
|
|
21
21
|
Object.defineProperty(exports, "RETRY_DELAY_MS", { enumerable: true, get: function () { return retry_js_1.RETRY_DELAY_MS; } });
|
|
22
|
+
var normalize_error_js_1 = require("./normalize-error.js");
|
|
23
|
+
Object.defineProperty(exports, "normalizeModbusError", { enumerable: true, get: function () { return normalize_error_js_1.normalizeModbusError; } });
|
|
22
24
|
var manager_js_1 = require("./manager.js");
|
|
23
25
|
Object.defineProperty(exports, "TransportManager", { enumerable: true, get: function () { return manager_js_1.TransportManager; } });
|
|
24
26
|
var mutex_transport_js_1 = require("./mutex-transport.js");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2CAAoE;AAA3D,6GAAA,eAAe,OAAA;AACxB,uDAAuE;AAA9D,sHAAA,kBAAkB,OAAA;AAC3B,uDAAuE;AAA9D,sHAAA,kBAAkB,OAAA;AAC3B,2EAAoE;AAA3D,mIAAA,qBAAqB,OAAA;AAC9B,uCAAqF;AAA5E,qGAAA,SAAS,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,0GAAA,cAAc,OAAA;AAC/C,2CAAoE;AAA3D,8GAAA,gBAAgB,OAAA;AACzB,2DAAqD;AAA5C,oHAAA,cAAc,OAAA;AACvB,2DAAqD;AAA5C,oHAAA,cAAc,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2CAAoE;AAA3D,6GAAA,eAAe,OAAA;AACxB,uDAAuE;AAA9D,sHAAA,kBAAkB,OAAA;AAC3B,uDAAuE;AAA9D,sHAAA,kBAAkB,OAAA;AAC3B,2EAAoE;AAA3D,mIAAA,qBAAqB,OAAA;AAC9B,uCAAqF;AAA5E,qGAAA,SAAS,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,0GAAA,cAAc,OAAA;AAC/C,2DAA6E;AAApE,0HAAA,oBAAoB,OAAA;AAC7B,2CAAoE;AAA3D,8GAAA,gBAAgB,OAAA;AACzB,2DAAqD;AAA5C,oHAAA,cAAc,OAAA;AACvB,2DAAqD;AAA5C,oHAAA,cAAc,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAKxD,OAAO,KAAK,EAAwB,eAAe,EAAE,MAAM,cAAc,CAAA;AAazE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqC;IAEjE;;;;;;;OAOG;IACG,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC;IA6B/D;;;;OAIG;IACH,QAAQ,IAAI,cAAc;IAS1B;;;OAGG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB/B;;;;;;;;OAQG;IACH,OAAO,CAAC,wBAAwB;IAShC;;;;;;OAMG;YACW,eAAe;IAe7B;;;;;;OAMG;YACW,eAAe;IAU7B;;;;;OAKG;IACH,OAAO,CAAC,WAAW;CAGpB"}
|
package/dist/cjs/src/manager.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.TransportManager = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const async_mutex_1 = require("async-mutex");
|
|
6
6
|
const modbus_serial_1 = tslib_1.__importDefault(require("modbus-serial"));
|
|
7
|
+
const client_config_js_1 = require("./client-config.js");
|
|
7
8
|
const slave_transport_js_1 = require("./slave-transport.js");
|
|
8
9
|
/**
|
|
9
10
|
* TransportManager pools modbus-serial clients and provides slave-specific transports.
|
|
@@ -123,7 +124,7 @@ class TransportManager {
|
|
|
123
124
|
parity: config.parity,
|
|
124
125
|
stopBits: config.stopBits,
|
|
125
126
|
});
|
|
126
|
-
client.setTimeout(config.timeout ??
|
|
127
|
+
client.setTimeout(config.timeout ?? client_config_js_1.DEFAULT_TIMEOUT_MS);
|
|
127
128
|
return client;
|
|
128
129
|
}
|
|
129
130
|
/**
|
|
@@ -136,7 +137,7 @@ class TransportManager {
|
|
|
136
137
|
async createTCPClient(config) {
|
|
137
138
|
const client = new modbus_serial_1.default();
|
|
138
139
|
await client.connectTCP(config.host, { port: config.port ?? 502 });
|
|
139
|
-
client.setTimeout(config.timeout ??
|
|
140
|
+
client.setTimeout(config.timeout ?? client_config_js_1.DEFAULT_TIMEOUT_MS);
|
|
140
141
|
return client;
|
|
141
142
|
}
|
|
142
143
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../src/manager.ts"],"names":[],"mappings":";;;;AACA,6CAAmC;AACnC,0EAAqC;
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../src/manager.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error normalization for modbus-serial failures
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Error with the diagnostic properties that modbus-serial attaches to failures
|
|
6
|
+
*/
|
|
7
|
+
export interface ModbusError extends Error {
|
|
8
|
+
/** Node.js error code (e.g., 'ECONNREFUSED' from a TCP socket) */
|
|
9
|
+
code?: string | undefined;
|
|
10
|
+
/** Error number or name (e.g., 'ETIMEDOUT' for a response timeout, -111 from a TCP socket) */
|
|
11
|
+
errno?: string | number | undefined;
|
|
12
|
+
/** Modbus exception code returned by the device (e.g., 2 = illegal data address) */
|
|
13
|
+
modbusCode?: number | undefined;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Convert anything thrown by modbus-serial into an Error
|
|
17
|
+
*
|
|
18
|
+
* modbus-serial rejects with plain objects that do not extend Error
|
|
19
|
+
* (e.g., `{ name: 'TransactionTimedOutError', message: 'Timed out', errno: 'ETIMEDOUT' }`).
|
|
20
|
+
* Converting them with `String()` gives "[object Object]" and loses errno.
|
|
21
|
+
* This keeps message, name, errno, code and modbusCode, and sets the original
|
|
22
|
+
* value as `cause`. Error instances are returned unchanged.
|
|
23
|
+
*
|
|
24
|
+
* @param error - Value that was thrown or used to reject a promise
|
|
25
|
+
* @returns Error instance with the diagnostic properties of the original
|
|
26
|
+
*/
|
|
27
|
+
export declare function normalizeModbusError(error: unknown): ModbusError;
|
|
28
|
+
//# sourceMappingURL=normalize-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-error.d.ts","sourceRoot":"","sources":["../../../src/normalize-error.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,KAAK;IACxC,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,8FAA8F;IAC9F,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IACnC,oFAAoF;IACpF,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAChC;AAMD;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAkChE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error normalization for modbus-serial failures
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.normalizeModbusError = normalizeModbusError;
|
|
7
|
+
function nonEmptyString(value) {
|
|
8
|
+
return typeof value === 'string' && value !== '' ? value : undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Convert anything thrown by modbus-serial into an Error
|
|
12
|
+
*
|
|
13
|
+
* modbus-serial rejects with plain objects that do not extend Error
|
|
14
|
+
* (e.g., `{ name: 'TransactionTimedOutError', message: 'Timed out', errno: 'ETIMEDOUT' }`).
|
|
15
|
+
* Converting them with `String()` gives "[object Object]" and loses errno.
|
|
16
|
+
* This keeps message, name, errno, code and modbusCode, and sets the original
|
|
17
|
+
* value as `cause`. Error instances are returned unchanged.
|
|
18
|
+
*
|
|
19
|
+
* @param error - Value that was thrown or used to reject a promise
|
|
20
|
+
* @returns Error instance with the diagnostic properties of the original
|
|
21
|
+
*/
|
|
22
|
+
function normalizeModbusError(error) {
|
|
23
|
+
if (error instanceof Error) {
|
|
24
|
+
return error;
|
|
25
|
+
}
|
|
26
|
+
if (typeof error !== 'object' || error === null) {
|
|
27
|
+
return new Error(String(error), { cause: error });
|
|
28
|
+
}
|
|
29
|
+
const fields = error;
|
|
30
|
+
const name = nonEmptyString(fields.name);
|
|
31
|
+
const code = nonEmptyString(fields.code);
|
|
32
|
+
const errno = typeof fields.errno === 'string' || typeof fields.errno === 'number' ? fields.errno : undefined;
|
|
33
|
+
const modbusCode = typeof fields.modbusCode === 'number' ? fields.modbusCode : undefined;
|
|
34
|
+
const normalized = new Error(nonEmptyString(fields.message) ??
|
|
35
|
+
code ??
|
|
36
|
+
(errno === undefined ? 'Unknown error' : String(errno)), { cause: error });
|
|
37
|
+
if (name !== undefined)
|
|
38
|
+
normalized.name = name;
|
|
39
|
+
if (code !== undefined)
|
|
40
|
+
normalized.code = code;
|
|
41
|
+
if (errno !== undefined)
|
|
42
|
+
normalized.errno = errno;
|
|
43
|
+
if (modbusCode !== undefined)
|
|
44
|
+
normalized.modbusCode = modbusCode;
|
|
45
|
+
return normalized;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=normalize-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-error.js","sourceRoot":"","sources":["../../../src/normalize-error.ts"],"names":[],"mappings":";AAAA;;GAEG;;AA8BH,oDAkCC;AAlDD,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;AACtE,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,oBAAoB,CAAC,KAAc;IACjD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IACnD,CAAC;IAED,MAAM,MAAM,GAAG,KAMd,CAAA;IACD,MAAM,IAAI,GAAG,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACxC,MAAM,IAAI,GAAG,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACxC,MAAM,KAAK,GACT,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;IACjG,MAAM,UAAU,GAAG,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAA;IAExF,MAAM,UAAU,GAAgB,IAAI,KAAK,CACvC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC;QAC5B,IAAI;QACJ,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EACzD,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAA;IACD,IAAI,IAAI,KAAK,SAAS;QAAE,UAAU,CAAC,IAAI,GAAG,IAAI,CAAA;IAC9C,IAAI,IAAI,KAAK,SAAS;QAAE,UAAU,CAAC,IAAI,GAAG,IAAI,CAAA;IAC9C,IAAI,KAAK,KAAK,SAAS;QAAE,UAAU,CAAC,KAAK,GAAG,KAAK,CAAA;IACjD,IAAI,UAAU,KAAK,SAAS;QAAE,UAAU,CAAC,UAAU,GAAG,UAAU,CAAA;IAEhE,OAAO,UAAU,CAAA;AACnB,CAAC"}
|
package/dist/cjs/src/retry.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Retry configuration and utilities for Modbus transport operations
|
|
3
3
|
*/
|
|
4
|
+
import { type ModbusError } from './normalize-error.js';
|
|
4
5
|
/** Maximum number of retry attempts for failed operations */
|
|
5
6
|
export declare const MAX_RETRIES = 3;
|
|
6
7
|
/** Delay between retry attempts in milliseconds */
|
|
@@ -11,7 +12,7 @@ export declare const RETRY_DELAY_MS = 100;
|
|
|
11
12
|
* @param attempt - The attempt number (1-indexed)
|
|
12
13
|
* @param error - The error that caused the retry
|
|
13
14
|
*/
|
|
14
|
-
export type RetryLogger = (attempt: number, error:
|
|
15
|
+
export type RetryLogger = (attempt: number, error: ModbusError) => void;
|
|
15
16
|
/**
|
|
16
17
|
* Retry a function with fixed delay between attempts
|
|
17
18
|
*
|
|
@@ -19,7 +20,8 @@ export type RetryLogger = (attempt: number, error: Error) => void;
|
|
|
19
20
|
* @param maxRetries - Maximum number of attempts (default: MAX_RETRIES)
|
|
20
21
|
* @param logger - Optional callback to log retry attempts
|
|
21
22
|
* @returns Promise resolving to the function's return value
|
|
22
|
-
* @throws The last error encountered if all retries are exhausted
|
|
23
|
+
* @throws The last error encountered if all retries are exhausted, as an Error
|
|
24
|
+
* with the diagnostic properties of the original (see normalizeModbusError)
|
|
23
25
|
*/
|
|
24
26
|
export declare function withRetry<T>(fn: () => Promise<T>, maxRetries?: number, logger?: RetryLogger): Promise<T>;
|
|
25
27
|
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../src/retry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,6DAA6D;AAC7D,eAAO,MAAM,WAAW,IAAI,CAAA;AAE5B,mDAAmD;AACnD,eAAO,MAAM,cAAc,MAAM,CAAA;AAYjC;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../src/retry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAwB,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAE7E,6DAA6D;AAC7D,eAAO,MAAM,WAAW,IAAI,CAAA;AAE5B,mDAAmD;AACnD,eAAO,MAAM,cAAc,MAAM,CAAA;AAYjC;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,KAAK,IAAI,CAAA;AAEvE;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,UAAU,GAAE,MAAoB,EAChC,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,CAAC,CAAC,CAqBZ"}
|
package/dist/cjs/src/retry.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.RETRY_DELAY_MS = exports.MAX_RETRIES = void 0;
|
|
7
7
|
exports.withRetry = withRetry;
|
|
8
|
+
const normalize_error_js_1 = require("./normalize-error.js");
|
|
8
9
|
/** Maximum number of retry attempts for failed operations */
|
|
9
10
|
exports.MAX_RETRIES = 3;
|
|
10
11
|
/** Delay between retry attempts in milliseconds */
|
|
@@ -25,7 +26,8 @@ function sleep(ms) {
|
|
|
25
26
|
* @param maxRetries - Maximum number of attempts (default: MAX_RETRIES)
|
|
26
27
|
* @param logger - Optional callback to log retry attempts
|
|
27
28
|
* @returns Promise resolving to the function's return value
|
|
28
|
-
* @throws The last error encountered if all retries are exhausted
|
|
29
|
+
* @throws The last error encountered if all retries are exhausted, as an Error
|
|
30
|
+
* with the diagnostic properties of the original (see normalizeModbusError)
|
|
29
31
|
*/
|
|
30
32
|
async function withRetry(fn, maxRetries = exports.MAX_RETRIES, logger) {
|
|
31
33
|
let lastError = new Error('No retry attempts were made');
|
|
@@ -34,7 +36,7 @@ async function withRetry(fn, maxRetries = exports.MAX_RETRIES, logger) {
|
|
|
34
36
|
return await fn();
|
|
35
37
|
}
|
|
36
38
|
catch (error) {
|
|
37
|
-
lastError =
|
|
39
|
+
lastError = (0, normalize_error_js_1.normalizeModbusError)(error);
|
|
38
40
|
// Don't retry on the last attempt
|
|
39
41
|
if (attempt < maxRetries) {
|
|
40
42
|
// Log the retry attempt if logger is provided
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../../src/retry.ts"],"names":[],"mappings":";AAAA;;GAEG;;;
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../../src/retry.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAsCH,8BAyBC;AA7DD,6DAA6E;AAE7E,6DAA6D;AAChD,QAAA,WAAW,GAAG,CAAC,CAAA;AAE5B,mDAAmD;AACtC,QAAA,cAAc,GAAG,GAAG,CAAA;AAEjC;;;;;GAKG;AACH,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AAC1D,CAAC;AAUD;;;;;;;;;GASG;AACI,KAAK,UAAU,SAAS,CAC7B,EAAoB,EACpB,aAAqB,mBAAW,EAChC,MAAoB;IAEpB,IAAI,SAAS,GAAgB,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;IAErE,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;QACvD,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAA;QACnB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,SAAS,GAAG,IAAA,yCAAoB,EAAC,KAAK,CAAC,CAAA;YAEvC,kCAAkC;YAClC,IAAI,OAAO,GAAG,UAAU,EAAE,CAAC;gBACzB,8CAA8C;gBAC9C,IAAI,MAAM,EAAE,CAAC;oBACX,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;gBAC5B,CAAC;gBACD,MAAM,KAAK,CAAC,sBAAc,CAAC,CAAA;YAC7B,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,SAAS,CAAA;AACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rtu-transport.d.ts","sourceRoot":"","sources":["../../../src/rtu-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"rtu-transport.d.ts","sourceRoot":"","sources":["../../../src/rtu-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAK9F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAA;IACZ,gBAAgB;IAChB,QAAQ,EAAE,QAAQ,CAAA;IAClB,gBAAgB;IAChB,QAAQ,EAAE,QAAQ,CAAA;IAClB,aAAa;IACb,MAAM,EAAE,MAAM,CAAA;IACd,gBAAgB;IAChB,QAAQ,EAAE,QAAQ,CAAA;IAClB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,4DAA4D;IAC5D,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;CACjC;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAc9E"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createRTUTransport = createRTUTransport;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const modbus_serial_1 = tslib_1.__importDefault(require("modbus-serial"));
|
|
6
|
+
const client_config_js_1 = require("./client-config.js");
|
|
6
7
|
const create_modbus_transport_js_1 = require("./create-modbus-transport.js");
|
|
7
8
|
/**
|
|
8
9
|
* Create an RTU transport
|
|
@@ -19,10 +20,7 @@ async function createRTUTransport(config) {
|
|
|
19
20
|
parity: config.parity,
|
|
20
21
|
stopBits: config.stopBits,
|
|
21
22
|
});
|
|
22
|
-
|
|
23
|
-
client.setID(config.slaveId);
|
|
24
|
-
// Set timeout
|
|
25
|
-
client.setTimeout(config.timeout ?? 1000);
|
|
23
|
+
(0, client_config_js_1.configureClient)(client, config.slaveId, config.timeout);
|
|
26
24
|
return (0, create_modbus_transport_js_1.createModbusTransport)(client, config.maxRetries, config.logger);
|
|
27
25
|
}
|
|
28
26
|
//# sourceMappingURL=rtu-transport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rtu-transport.js","sourceRoot":"","sources":["../../../src/rtu-transport.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"rtu-transport.js","sourceRoot":"","sources":["../../../src/rtu-transport.ts"],"names":[],"mappings":";;AAqCA,gDAcC;;AAlDD,0EAAqC;AAErC,yDAAoD;AACpD,6EAAoE;AA2BpE;;;;;GAKG;AACI,KAAK,UAAU,kBAAkB,CAAC,MAAiB;IACxD,MAAM,MAAM,GAAG,IAAI,uBAAS,EAAE,CAAA;IAE9B,yBAAyB;IACzB,MAAM,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,EAAE;QAC3C,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;KAC1B,CAAC,CAAA;IAEF,IAAA,kCAAe,EAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;IAEvD,OAAO,IAAA,kDAAqB,EAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;AACxE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tcp-transport.d.ts","sourceRoot":"","sources":["../../../src/tcp-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"tcp-transport.d.ts","sourceRoot":"","sources":["../../../src/tcp-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAKxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAA;IACZ,8BAA8B;IAC9B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,4DAA4D;IAC5D,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;CACjC;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAS9E"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createTCPTransport = createTCPTransport;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const modbus_serial_1 = tslib_1.__importDefault(require("modbus-serial"));
|
|
6
|
+
const client_config_js_1 = require("./client-config.js");
|
|
6
7
|
const create_modbus_transport_js_1 = require("./create-modbus-transport.js");
|
|
7
8
|
/**
|
|
8
9
|
* Create a TCP transport
|
|
@@ -14,10 +15,7 @@ async function createTCPTransport(config) {
|
|
|
14
15
|
const client = new modbus_serial_1.default();
|
|
15
16
|
// Connect to TCP server
|
|
16
17
|
await client.connectTCP(config.host, { port: config.port ?? 502 });
|
|
17
|
-
|
|
18
|
-
client.setID(config.slaveId);
|
|
19
|
-
// Set timeout
|
|
20
|
-
client.setTimeout(config.timeout ?? 1000);
|
|
18
|
+
(0, client_config_js_1.configureClient)(client, config.slaveId, config.timeout);
|
|
21
19
|
return (0, create_modbus_transport_js_1.createModbusTransport)(client, config.maxRetries, config.logger);
|
|
22
20
|
}
|
|
23
21
|
//# sourceMappingURL=tcp-transport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tcp-transport.js","sourceRoot":"","sources":["../../../src/tcp-transport.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"tcp-transport.js","sourceRoot":"","sources":["../../../src/tcp-transport.ts"],"names":[],"mappings":";;AA+BA,gDASC;;AAvCD,0EAAqC;AAErC,yDAAoD;AACpD,6EAAoE;AAqBpE;;;;;GAKG;AACI,KAAK,UAAU,kBAAkB,CAAC,MAAiB;IACxD,MAAM,MAAM,GAAG,IAAI,uBAAS,EAAE,CAAA;IAE9B,wBAAwB;IACxB,MAAM,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC,CAAA;IAElE,IAAA,kCAAe,EAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;IAEvD,OAAO,IAAA,kDAAqB,EAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;AACxE,CAAC"}
|