@ya-modbus/driver-sdk 0.6.0 → 0.7.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/cjs/package.json +1 -0
  3. package/dist/{codec.d.ts → cjs/src/codec.d.ts} +30 -0
  4. package/dist/cjs/src/codec.d.ts.map +1 -0
  5. package/dist/cjs/src/codec.js +224 -0
  6. package/dist/cjs/src/codec.js.map +1 -0
  7. package/dist/cjs/src/errors.d.ts.map +1 -0
  8. package/dist/cjs/src/errors.js +24 -0
  9. package/dist/cjs/src/errors.js.map +1 -0
  10. package/dist/cjs/src/index.d.ts.map +1 -0
  11. package/dist/cjs/src/index.js +35 -0
  12. package/dist/cjs/src/index.js.map +1 -0
  13. package/dist/cjs/src/validators.d.ts.map +1 -0
  14. package/dist/cjs/src/validators.js +90 -0
  15. package/dist/cjs/src/validators.js.map +1 -0
  16. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
  17. package/dist/esm/package.json +1 -0
  18. package/dist/esm/src/codec.d.ts +120 -0
  19. package/dist/esm/src/codec.d.ts.map +1 -0
  20. package/dist/{codec.js → esm/src/codec.js} +38 -0
  21. package/dist/esm/src/codec.js.map +1 -0
  22. package/dist/esm/src/errors.d.ts +64 -0
  23. package/dist/esm/src/errors.d.ts.map +1 -0
  24. package/dist/esm/src/errors.js.map +1 -0
  25. package/dist/esm/src/index.d.ts +31 -0
  26. package/dist/esm/src/index.d.ts.map +1 -0
  27. package/dist/esm/src/index.js.map +1 -0
  28. package/dist/esm/src/validators.d.ts +75 -0
  29. package/dist/esm/src/validators.d.ts.map +1 -0
  30. package/dist/esm/src/validators.js.map +1 -0
  31. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
  32. package/package.json +24 -7
  33. package/dist/codec.d.ts.map +0 -1
  34. package/dist/codec.js.map +0 -1
  35. package/dist/errors.d.ts.map +0 -1
  36. package/dist/errors.js.map +0 -1
  37. package/dist/index.d.ts.map +0 -1
  38. package/dist/index.js.map +0 -1
  39. package/dist/validators.d.ts.map +0 -1
  40. package/dist/validators.js.map +0 -1
  41. /package/dist/{errors.d.ts → cjs/src/errors.d.ts} +0 -0
  42. /package/dist/{index.d.ts → cjs/src/index.d.ts} +0 -0
  43. /package/dist/{validators.d.ts → cjs/src/validators.d.ts} +0 -0
  44. /package/dist/{errors.js → esm/src/errors.js} +0 -0
  45. /package/dist/{index.js → esm/src/index.js} +0 -0
  46. /package/dist/{validators.js → esm/src/validators.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
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.7.1](https://github.com/groupsky/ya-modbus/compare/@ya-modbus/driver-sdk@0.7.0...@ya-modbus/driver-sdk@0.7.1) (2026-02-06)
7
+
8
+ **Note:** Version bump only for package @ya-modbus/driver-sdk
9
+
10
+ # [0.7.0](https://github.com/groupsky/ya-modbus/compare/@ya-modbus/driver-sdk@0.6.0...@ya-modbus/driver-sdk@0.7.0) (2026-01-11)
11
+
12
+ ### Features
13
+
14
+ - **build:** add dual CommonJS/ESM package support ([#187](https://github.com/groupsky/ya-modbus/issues/187)) ([3d78130](https://github.com/groupsky/ya-modbus/commit/3d781304d42edba335cdc320ba25275f3b4ea6c9))
15
+ - **driver:** add ORNO OR-WE-516 3-phase energy meter driver ([#162](https://github.com/groupsky/ya-modbus/issues/162)) ([8d63837](https://github.com/groupsky/ya-modbus/commit/8d63837d7816791f5ce76cf3dcbf70dc61502037))
16
+
6
17
  # 0.6.0 (2026-01-04)
7
18
 
8
19
  ### Bug Fixes
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -87,4 +87,34 @@ export declare function writeScaledUInt16BE(value: number, scale: number): Buffe
87
87
  * ```
88
88
  */
89
89
  export declare function writeScaledInt16BE(value: number, scale: number): Buffer;
90
+ /**
91
+ * Read an IEEE 754 single-precision float (32-bit) from a buffer
92
+ *
93
+ * @param buffer - Buffer containing the register data (2 consecutive registers)
94
+ * @param offset - Byte offset to start reading from
95
+ * @returns Float value
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * // Device stores voltage as IEEE 754 float
100
+ * const buffer = await transport.readHoldingRegisters(0x000E, 2)
101
+ * const voltage = readFloatBE(buffer, 0)
102
+ * ```
103
+ */
104
+ export declare function readFloatBE(buffer: Buffer, offset: number): number;
105
+ /**
106
+ * Encode a float value to an IEEE 754 single-precision (32-bit) buffer
107
+ *
108
+ * @param value - Value to encode
109
+ * @returns 4-byte buffer containing the float value
110
+ * @throws Error if value is not finite
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * // Write S0 output rate as IEEE 754 float
115
+ * const buffer = writeFloatBE(1000.0)
116
+ * await transport.writeMultipleRegisters(0x0009, buffer)
117
+ * ```
118
+ */
119
+ export declare function writeFloatBE(value: number): Buffer;
90
120
  //# sourceMappingURL=codec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../../src/codec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsEH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKxF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKvF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKxF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAUxE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAWvE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAGlE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMlD"}
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ /**
3
+ * Buffer encoding/decoding utilities for Modbus register values
4
+ *
5
+ * These utilities handle common patterns in Modbus drivers like reading
6
+ * scaled integers (×10, ×100, ×1000) from register buffers.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.readScaledUInt16BE = readScaledUInt16BE;
10
+ exports.readScaledInt16BE = readScaledInt16BE;
11
+ exports.readScaledUInt32BE = readScaledUInt32BE;
12
+ exports.writeScaledUInt16BE = writeScaledUInt16BE;
13
+ exports.writeScaledInt16BE = writeScaledInt16BE;
14
+ exports.readFloatBE = readFloatBE;
15
+ exports.writeFloatBE = writeFloatBE;
16
+ /**
17
+ * Validate that a scale parameter is valid
18
+ *
19
+ * @param scale - Scale factor to validate
20
+ * @throws Error if scale is not finite or is not positive
21
+ */
22
+ function validateScale(scale) {
23
+ if (!Number.isFinite(scale)) {
24
+ throw new Error('Invalid scale: must be a finite number');
25
+ }
26
+ if (scale <= 0) {
27
+ throw new Error('Invalid scale: must be greater than 0');
28
+ }
29
+ }
30
+ /**
31
+ * Validate that a value for writing is valid
32
+ *
33
+ * @param value - Value to validate
34
+ * @throws Error if value is not finite
35
+ */
36
+ function validateWriteValue(value) {
37
+ if (!Number.isFinite(value)) {
38
+ throw new Error('Invalid value: must be a finite number');
39
+ }
40
+ }
41
+ /**
42
+ * Validate that a scaled value fits within the target integer range
43
+ *
44
+ * @param scaledValue - Scaled value to validate
45
+ * @param min - Minimum allowed value (inclusive)
46
+ * @param max - Maximum allowed value (inclusive)
47
+ * @param typeName - Name of the target type for error messages
48
+ * @throws Error if scaled value is outside the valid range
49
+ */
50
+ function validateRange(scaledValue, min, max, typeName) {
51
+ if (scaledValue < min || scaledValue > max) {
52
+ throw new Error(`Invalid scaled value: ${scaledValue} is outside ${typeName} range (${min} to ${max})`);
53
+ }
54
+ }
55
+ /**
56
+ * Validate that buffer has sufficient bytes for reading at the given offset
57
+ *
58
+ * @param buffer - Buffer to validate
59
+ * @param offset - Byte offset to start reading from
60
+ * @param bytesNeeded - Number of bytes required
61
+ * @param typeName - Name of the type being read for error messages
62
+ * @throws Error if buffer doesn't have enough bytes
63
+ */
64
+ function validateBufferBounds(buffer, offset, bytesNeeded, typeName) {
65
+ const available = buffer.length - offset;
66
+ if (available < bytesNeeded) {
67
+ throw new Error(`Insufficient buffer size for ${typeName}: need ${bytesNeeded} bytes at offset ${offset}, ` +
68
+ `but only ${available} bytes available (buffer length: ${buffer.length})`);
69
+ }
70
+ }
71
+ /**
72
+ * Read and scale an unsigned 16-bit integer from a buffer
73
+ *
74
+ * @param buffer - Buffer containing the register data
75
+ * @param offset - Byte offset to start reading from
76
+ * @param scale - Scale factor (e.g., 10 for ×10 values)
77
+ * @returns Scaled floating-point value
78
+ * @throws Error if scale is not a finite positive number
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // Device stores temperature as integer ×10 (235 = 23.5°C)
83
+ * const buffer = await transport.readInputRegisters(0, 1)
84
+ * const temperature = readScaledUInt16BE(buffer, 0, 10)
85
+ * ```
86
+ */
87
+ function readScaledUInt16BE(buffer, offset, scale) {
88
+ validateScale(scale);
89
+ validateBufferBounds(buffer, offset, 2, 'uint16');
90
+ const rawValue = buffer.readUInt16BE(offset);
91
+ return rawValue / scale;
92
+ }
93
+ /**
94
+ * Read and scale a signed 16-bit integer from a buffer
95
+ *
96
+ * @param buffer - Buffer containing the register data
97
+ * @param offset - Byte offset to start reading from
98
+ * @param scale - Scale factor (e.g., 10 for ×10 values)
99
+ * @returns Scaled floating-point value
100
+ * @throws Error if scale is not a finite positive number
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * // Device stores correction offset as signed integer ×10 (-50 = -5.0°C)
105
+ * const buffer = await transport.readHoldingRegisters(0x103, 1)
106
+ * const correction = readScaledInt16BE(buffer, 0, 10)
107
+ * ```
108
+ */
109
+ function readScaledInt16BE(buffer, offset, scale) {
110
+ validateScale(scale);
111
+ validateBufferBounds(buffer, offset, 2, 'int16');
112
+ const rawValue = buffer.readInt16BE(offset);
113
+ return rawValue / scale;
114
+ }
115
+ /**
116
+ * Read and scale an unsigned 32-bit integer from a buffer
117
+ *
118
+ * @param buffer - Buffer containing the register data (2 consecutive registers)
119
+ * @param offset - Byte offset to start reading from
120
+ * @param scale - Scale factor (e.g., 100 for ×100 values)
121
+ * @returns Scaled floating-point value
122
+ * @throws Error if scale is not a finite positive number
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * // Device stores total energy as 32-bit integer ×100 (1000000 = 10000.00 kWh)
127
+ * const buffer = await transport.readHoldingRegisters(0x0007, 2)
128
+ * const totalEnergy = readScaledUInt32BE(buffer, 0, 100)
129
+ * ```
130
+ */
131
+ function readScaledUInt32BE(buffer, offset, scale) {
132
+ validateScale(scale);
133
+ validateBufferBounds(buffer, offset, 4, 'uint32');
134
+ const rawValue = buffer.readUInt32BE(offset);
135
+ return rawValue / scale;
136
+ }
137
+ /**
138
+ * Encode and scale a value to an unsigned 16-bit integer buffer
139
+ *
140
+ * @param value - Value to encode
141
+ * @param scale - Scale factor (e.g., 10 for ×10 values)
142
+ * @returns 2-byte buffer containing the scaled value
143
+ * @throws Error if value is not finite, scale is invalid, or scaled value exceeds uint16 range
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * // Write humidity correction of 5.5% (stored as 55)
148
+ * const buffer = writeScaledUInt16BE(5.5, 10)
149
+ * await transport.writeMultipleRegisters(0x104, buffer)
150
+ * ```
151
+ */
152
+ function writeScaledUInt16BE(value, scale) {
153
+ validateWriteValue(value);
154
+ validateScale(scale);
155
+ const scaledValue = Math.trunc(value * scale);
156
+ validateRange(scaledValue, 0, 0xffff, 'uint16');
157
+ const buffer = Buffer.allocUnsafe(2);
158
+ buffer.writeUInt16BE(scaledValue, 0);
159
+ return buffer;
160
+ }
161
+ /**
162
+ * Encode and scale a value to a signed 16-bit integer buffer
163
+ *
164
+ * @param value - Value to encode
165
+ * @param scale - Scale factor (e.g., 10 for ×10 values)
166
+ * @returns 2-byte buffer containing the scaled value
167
+ * @throws Error if value is not finite, scale is invalid, or scaled value exceeds int16 range
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * // Write temperature correction of -3.5°C (stored as -35)
172
+ * const buffer = writeScaledInt16BE(-3.5, 10)
173
+ * await transport.writeMultipleRegisters(0x103, buffer)
174
+ * ```
175
+ */
176
+ function writeScaledInt16BE(value, scale) {
177
+ validateWriteValue(value);
178
+ validateScale(scale);
179
+ // Use Math.trunc for predictable rounding toward zero (avoids floating-point precision issues)
180
+ const scaledValue = Math.trunc(value * scale);
181
+ validateRange(scaledValue, -0x8000, 0x7fff, 'int16');
182
+ const buffer = Buffer.allocUnsafe(2);
183
+ buffer.writeInt16BE(scaledValue, 0);
184
+ return buffer;
185
+ }
186
+ /**
187
+ * Read an IEEE 754 single-precision float (32-bit) from a buffer
188
+ *
189
+ * @param buffer - Buffer containing the register data (2 consecutive registers)
190
+ * @param offset - Byte offset to start reading from
191
+ * @returns Float value
192
+ *
193
+ * @example
194
+ * ```typescript
195
+ * // Device stores voltage as IEEE 754 float
196
+ * const buffer = await transport.readHoldingRegisters(0x000E, 2)
197
+ * const voltage = readFloatBE(buffer, 0)
198
+ * ```
199
+ */
200
+ function readFloatBE(buffer, offset) {
201
+ validateBufferBounds(buffer, offset, 4, 'float32');
202
+ return buffer.readFloatBE(offset);
203
+ }
204
+ /**
205
+ * Encode a float value to an IEEE 754 single-precision (32-bit) buffer
206
+ *
207
+ * @param value - Value to encode
208
+ * @returns 4-byte buffer containing the float value
209
+ * @throws Error if value is not finite
210
+ *
211
+ * @example
212
+ * ```typescript
213
+ * // Write S0 output rate as IEEE 754 float
214
+ * const buffer = writeFloatBE(1000.0)
215
+ * await transport.writeMultipleRegisters(0x0009, buffer)
216
+ * ```
217
+ */
218
+ function writeFloatBE(value) {
219
+ validateWriteValue(value);
220
+ const buffer = Buffer.allocUnsafe(4);
221
+ buffer.writeFloatBE(value, 0);
222
+ return buffer;
223
+ }
224
+ //# sourceMappingURL=codec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.js","sourceRoot":"","sources":["../../../src/codec.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAsFH,gDAKC;AAkBD,8CAKC;AAkBD,gDAKC;AAiBD,kDAUC;AAiBD,gDAWC;AAgBD,kCAGC;AAgBD,oCAMC;AAvOD;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;IAC3D,CAAC;IACD,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAA;IAC1D,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,KAAa;IACvC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;IAC3D,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,aAAa,CAAC,WAAmB,EAAE,GAAW,EAAE,GAAW,EAAE,QAAgB;IACpF,IAAI,WAAW,GAAG,GAAG,IAAI,WAAW,GAAG,GAAG,EAAE,CAAC;QAC3C,MAAM,IAAI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AC,EAAE,SAAS,CAAC,CAAA;IAClD,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;AACnC,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,YAAY,CAAC,KAAa;IACxC,kBAAkB,CAAC,KAAK,CAAC,CAAA;IAEzB,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;IACpC,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAC7B,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;AAChF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;AAahG;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CAAA;AACjF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CAAA"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /**
3
+ * Error formatting utilities for consistent validation error messages
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.formatRangeError = formatRangeError;
7
+ exports.formatEnumError = formatEnumError;
8
+ function formatRangeError(name, ...args) {
9
+ if (args.length === 2) {
10
+ const [min, max] = args;
11
+ return `Invalid ${name}: must be between ${min} and ${max}`;
12
+ }
13
+ const [value, min, max] = args;
14
+ return `Invalid ${name}: received ${String(value)}, must be between ${min} and ${max}`;
15
+ }
16
+ function formatEnumError(name, ...args) {
17
+ if (args.length === 1) {
18
+ const [values] = args;
19
+ return `Invalid ${name}: must be one of ${values.join(', ')}`;
20
+ }
21
+ const [value, values] = args;
22
+ return `Invalid ${name}: received ${String(value)}, must be one of ${values.join(', ')}`;
23
+ }
24
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/errors.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAiCH,4CAUC;AA+BD,0CAUC;AAnDD,SAAgB,gBAAgB,CAC9B,IAAY,EACZ,GAAG,IAAkD;IAErD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;QACvB,OAAO,WAAW,IAAI,qBAAqB,GAAG,QAAQ,GAAG,EAAE,CAAA;IAC7D,CAAC;IACD,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;IAC9B,OAAO,WAAW,IAAI,cAAc,MAAM,CAAC,KAAK,CAAC,qBAAqB,GAAG,QAAQ,GAAG,EAAE,CAAA;AACxF,CAAC;AA+BD,SAAgB,eAAe,CAC7B,IAAY,EACZ,GAAG,IAA0D;IAE7D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAA;QACrB,OAAO,WAAW,IAAI,oBAAoB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;IAC/D,CAAC;IACD,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,CAAA;IAC5B,OAAO,WAAW,IAAI,cAAc,MAAM,CAAC,KAAK,CAAC,oBAAoB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;AAC1F,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ /**
3
+ * Runtime SDK for ya-modbus device drivers
4
+ *
5
+ * Provides utilities for common driver development tasks:
6
+ * - Buffer encoding/decoding for scaled register values
7
+ * - Configuration validation with type narrowing
8
+ * - Consistent error message formatting
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import {
13
+ * readScaledUInt16BE,
14
+ * createEnumValidator,
15
+ * formatEnumError,
16
+ * } from '@ya-modbus/driver-sdk'
17
+ *
18
+ * // Read scaled temperature value
19
+ * const buffer = await transport.readInputRegisters(1, 1)
20
+ * const temperature = readScaledUInt16BE(buffer, 0, 10)
21
+ *
22
+ * // Validate baud rate
23
+ * const isValidBaudRate = createEnumValidator([9600, 14400, 19200] as const)
24
+ * if (!isValidBaudRate(value)) {
25
+ * throw new Error(formatEnumError('baud rate', [9600, 14400, 19200]))
26
+ * }
27
+ * ```
28
+ */
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ const tslib_1 = require("tslib");
31
+ // Re-export all utilities
32
+ tslib_1.__exportStar(require("./codec.js"), exports);
33
+ tslib_1.__exportStar(require("./validators.js"), exports);
34
+ tslib_1.__exportStar(require("./errors.js"), exports);
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;;AAEH,0BAA0B;AAC1B,qDAA0B;AAC1B,0DAA+B;AAC/B,sDAA2B"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../src/validators.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,EAC9D,MAAM,EAAE,CAAC,GACR,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC,CAIxC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,GACV,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,MAAM,CAIrC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE9D"}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ /**
3
+ * Validation utilities for driver configuration values
4
+ *
5
+ * These utilities provide type-safe validation with proper TypeScript
6
+ * type narrowing for common configuration values like baud rates,
7
+ * device addresses, and numeric ranges.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.createEnumValidator = createEnumValidator;
11
+ exports.createRangeValidator = createRangeValidator;
12
+ exports.isValidInteger = isValidInteger;
13
+ /**
14
+ * Create a type-safe enum validator function
15
+ *
16
+ * Returns a type guard function that validates if a value is one of
17
+ * the allowed enum values. The returned function properly narrows
18
+ * TypeScript types.
19
+ *
20
+ * @param values - Readonly array of valid enum values
21
+ * @returns Type guard function that validates enum membership
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * import { createEnumValidator } from '@ya-modbus/driver-sdk'
26
+ *
27
+ * const VALID_BAUD_RATES = [9600, 14400, 19200] as const
28
+ * type ValidBaudRate = (typeof VALID_BAUD_RATES)[number]
29
+ *
30
+ * const isValidBaudRate = createEnumValidator(VALID_BAUD_RATES)
31
+ *
32
+ * if (isValidBaudRate(value)) {
33
+ * // value is now typed as ValidBaudRate
34
+ * const encoded = encodeBaudRate(value)
35
+ * }
36
+ * ```
37
+ */
38
+ function createEnumValidator(values) {
39
+ return (value) => {
40
+ return values.includes(value);
41
+ };
42
+ }
43
+ /**
44
+ * Create a numeric range validator function
45
+ *
46
+ * Returns a function that validates if a value is a finite number
47
+ * within the specified range (inclusive).
48
+ *
49
+ * @param min - Minimum valid value (inclusive)
50
+ * @param max - Maximum valid value (inclusive)
51
+ * @returns Validator function that checks range membership
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * import { createRangeValidator } from '@ya-modbus/driver-sdk'
56
+ *
57
+ * const isValidAddress = createRangeValidator(1, 247)
58
+ *
59
+ * if (isValidAddress(value)) {
60
+ * // value is a finite number between 1 and 247
61
+ * await writeAddress(value)
62
+ * }
63
+ * ```
64
+ */
65
+ function createRangeValidator(min, max) {
66
+ return (value) => {
67
+ return typeof value === 'number' && Number.isFinite(value) && value >= min && value <= max;
68
+ };
69
+ }
70
+ /**
71
+ * Validate that a value is a finite integer
72
+ *
73
+ * Checks if a value is a number, finite, and has no fractional part.
74
+ *
75
+ * @param value - Value to validate
76
+ * @returns True if value is a finite integer
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * import { isValidInteger } from '@ya-modbus/driver-sdk'
81
+ *
82
+ * if (!isValidInteger(value)) {
83
+ * throw new Error('Device address must be an integer')
84
+ * }
85
+ * ```
86
+ */
87
+ function isValidInteger(value) {
88
+ return typeof value === 'number' && Number.isFinite(value) && Number.isInteger(value);
89
+ }
90
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/validators.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AA2BH,kDAMC;AAwBD,oDAOC;AAmBD,wCAEC;AAnFD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAgB,mBAAmB,CACjC,MAAS;IAET,OAAO,CAAC,KAAc,EAAsB,EAAE;QAC5C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAkB,CAAC,CAAA;IAC5C,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,oBAAoB,CAClC,GAAW,EACX,GAAW;IAEX,OAAO,CAAC,KAAc,EAAmB,EAAE;QACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,CAAA;IAC5F,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AACvF,CAAC"}