@ya-modbus/driver-sdk 0.4.1-refactor-scope-driver-packages.0

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/errors.js ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Error formatting utilities for consistent validation error messages
3
+ */
4
+ export function formatRangeError(name, ...args) {
5
+ if (args.length === 2) {
6
+ const [min, max] = args;
7
+ return `Invalid ${name}: must be between ${min} and ${max}`;
8
+ }
9
+ const [value, min, max] = args;
10
+ return `Invalid ${name}: received ${String(value)}, must be between ${min} and ${max}`;
11
+ }
12
+ export function formatEnumError(name, ...args) {
13
+ if (args.length === 1) {
14
+ const [values] = args;
15
+ return `Invalid ${name}: must be one of ${values.join(', ')}`;
16
+ }
17
+ const [value, values] = args;
18
+ return `Invalid ${name}: received ${String(value)}, must be one of ${values.join(', ')}`;
19
+ }
20
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAiCH,MAAM,UAAU,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,MAAM,UAAU,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,31 @@
1
+ /**
2
+ * Runtime SDK for ya-modbus device drivers
3
+ *
4
+ * Provides utilities for common driver development tasks:
5
+ * - Buffer encoding/decoding for scaled register values
6
+ * - Configuration validation with type narrowing
7
+ * - Consistent error message formatting
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import {
12
+ * readScaledUInt16BE,
13
+ * createEnumValidator,
14
+ * formatEnumError,
15
+ * } from '@ya-modbus/driver-sdk'
16
+ *
17
+ * // Read scaled temperature value
18
+ * const buffer = await transport.readInputRegisters(1, 1)
19
+ * const temperature = readScaledUInt16BE(buffer, 0, 10)
20
+ *
21
+ * // Validate baud rate
22
+ * const isValidBaudRate = createEnumValidator([9600, 14400, 19200] as const)
23
+ * if (!isValidBaudRate(value)) {
24
+ * throw new Error(formatEnumError('baud rate', [9600, 14400, 19200]))
25
+ * }
26
+ * ```
27
+ */
28
+ export * from './codec.js';
29
+ export * from './validators.js';
30
+ export * from './errors.js';
31
+ //# sourceMappingURL=index.d.ts.map
@@ -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"}
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Runtime SDK for ya-modbus device drivers
3
+ *
4
+ * Provides utilities for common driver development tasks:
5
+ * - Buffer encoding/decoding for scaled register values
6
+ * - Configuration validation with type narrowing
7
+ * - Consistent error message formatting
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import {
12
+ * readScaledUInt16BE,
13
+ * createEnumValidator,
14
+ * formatEnumError,
15
+ * } from '@ya-modbus/driver-sdk'
16
+ *
17
+ * // Read scaled temperature value
18
+ * const buffer = await transport.readInputRegisters(1, 1)
19
+ * const temperature = readScaledUInt16BE(buffer, 0, 10)
20
+ *
21
+ * // Validate baud rate
22
+ * const isValidBaudRate = createEnumValidator([9600, 14400, 19200] as const)
23
+ * if (!isValidBaudRate(value)) {
24
+ * throw new Error(formatEnumError('baud rate', [9600, 14400, 19200]))
25
+ * }
26
+ * ```
27
+ */
28
+ // Re-export all utilities
29
+ export * from './codec.js';
30
+ export * from './validators.js';
31
+ export * from './errors.js';
32
+ //# 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,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Validation utilities for driver configuration values
3
+ *
4
+ * These utilities provide type-safe validation with proper TypeScript
5
+ * type narrowing for common configuration values like baud rates,
6
+ * device addresses, and numeric ranges.
7
+ */
8
+ /**
9
+ * Create a type-safe enum validator function
10
+ *
11
+ * Returns a type guard function that validates if a value is one of
12
+ * the allowed enum values. The returned function properly narrows
13
+ * TypeScript types.
14
+ *
15
+ * @param values - Readonly array of valid enum values
16
+ * @returns Type guard function that validates enum membership
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { createEnumValidator } from '@ya-modbus/driver-sdk'
21
+ *
22
+ * const VALID_BAUD_RATES = [9600, 14400, 19200] as const
23
+ * type ValidBaudRate = (typeof VALID_BAUD_RATES)[number]
24
+ *
25
+ * const isValidBaudRate = createEnumValidator(VALID_BAUD_RATES)
26
+ *
27
+ * if (isValidBaudRate(value)) {
28
+ * // value is now typed as ValidBaudRate
29
+ * const encoded = encodeBaudRate(value)
30
+ * }
31
+ * ```
32
+ */
33
+ export declare function createEnumValidator<T extends readonly unknown[]>(values: T): (value: unknown) => value is T[number];
34
+ /**
35
+ * Create a numeric range validator function
36
+ *
37
+ * Returns a function that validates if a value is a finite number
38
+ * within the specified range (inclusive).
39
+ *
40
+ * @param min - Minimum valid value (inclusive)
41
+ * @param max - Maximum valid value (inclusive)
42
+ * @returns Validator function that checks range membership
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * import { createRangeValidator } from '@ya-modbus/driver-sdk'
47
+ *
48
+ * const isValidAddress = createRangeValidator(1, 247)
49
+ *
50
+ * if (isValidAddress(value)) {
51
+ * // value is a finite number between 1 and 247
52
+ * await writeAddress(value)
53
+ * }
54
+ * ```
55
+ */
56
+ export declare function createRangeValidator(min: number, max: number): (value: unknown) => value is number;
57
+ /**
58
+ * Validate that a value is a finite integer
59
+ *
60
+ * Checks if a value is a number, finite, and has no fractional part.
61
+ *
62
+ * @param value - Value to validate
63
+ * @returns True if value is a finite integer
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * import { isValidInteger } from '@ya-modbus/driver-sdk'
68
+ *
69
+ * if (!isValidInteger(value)) {
70
+ * throw new Error('Device address must be an integer')
71
+ * }
72
+ * ```
73
+ */
74
+ export declare function isValidInteger(value: unknown): value is number;
75
+ //# sourceMappingURL=validators.d.ts.map
@@ -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,85 @@
1
+ /**
2
+ * Validation utilities for driver configuration values
3
+ *
4
+ * These utilities provide type-safe validation with proper TypeScript
5
+ * type narrowing for common configuration values like baud rates,
6
+ * device addresses, and numeric ranges.
7
+ */
8
+ /**
9
+ * Create a type-safe enum validator function
10
+ *
11
+ * Returns a type guard function that validates if a value is one of
12
+ * the allowed enum values. The returned function properly narrows
13
+ * TypeScript types.
14
+ *
15
+ * @param values - Readonly array of valid enum values
16
+ * @returns Type guard function that validates enum membership
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { createEnumValidator } from '@ya-modbus/driver-sdk'
21
+ *
22
+ * const VALID_BAUD_RATES = [9600, 14400, 19200] as const
23
+ * type ValidBaudRate = (typeof VALID_BAUD_RATES)[number]
24
+ *
25
+ * const isValidBaudRate = createEnumValidator(VALID_BAUD_RATES)
26
+ *
27
+ * if (isValidBaudRate(value)) {
28
+ * // value is now typed as ValidBaudRate
29
+ * const encoded = encodeBaudRate(value)
30
+ * }
31
+ * ```
32
+ */
33
+ export function createEnumValidator(values) {
34
+ return (value) => {
35
+ return values.includes(value);
36
+ };
37
+ }
38
+ /**
39
+ * Create a numeric range validator function
40
+ *
41
+ * Returns a function that validates if a value is a finite number
42
+ * within the specified range (inclusive).
43
+ *
44
+ * @param min - Minimum valid value (inclusive)
45
+ * @param max - Maximum valid value (inclusive)
46
+ * @returns Validator function that checks range membership
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * import { createRangeValidator } from '@ya-modbus/driver-sdk'
51
+ *
52
+ * const isValidAddress = createRangeValidator(1, 247)
53
+ *
54
+ * if (isValidAddress(value)) {
55
+ * // value is a finite number between 1 and 247
56
+ * await writeAddress(value)
57
+ * }
58
+ * ```
59
+ */
60
+ export function createRangeValidator(min, max) {
61
+ return (value) => {
62
+ return typeof value === 'number' && Number.isFinite(value) && value >= min && value <= max;
63
+ };
64
+ }
65
+ /**
66
+ * Validate that a value is a finite integer
67
+ *
68
+ * Checks if a value is a number, finite, and has no fractional part.
69
+ *
70
+ * @param value - Value to validate
71
+ * @returns True if value is a finite integer
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * import { isValidInteger } from '@ya-modbus/driver-sdk'
76
+ *
77
+ * if (!isValidInteger(value)) {
78
+ * throw new Error('Device address must be an integer')
79
+ * }
80
+ * ```
81
+ */
82
+ export function isValidInteger(value) {
83
+ return typeof value === 'number' && Number.isFinite(value) && Number.isInteger(value);
84
+ }
85
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,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,MAAM,UAAU,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,MAAM,UAAU,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"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@ya-modbus/driver-sdk",
3
+ "version": "0.4.1-refactor-scope-driver-packages.0",
4
+ "description": "Runtime SDK for ya-modbus device drivers with transformation utilities and helpers",
5
+ "keywords": [
6
+ "modbus",
7
+ "driver",
8
+ "sdk",
9
+ "runtime"
10
+ ],
11
+ "author": "Geno Roupsky <geno@roupsky.name>",
12
+ "license": "GPL-3.0-or-later",
13
+ "type": "module",
14
+ "main": "dist/index.js",
15
+ "types": "dist/index.d.ts",
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "CHANGELOG.md"
20
+ ],
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/groupsky/ya-modbus.git",
24
+ "directory": "packages/driver-sdk"
25
+ },
26
+ "homepage": "https://github.com/groupsky/ya-modbus/tree/main/packages/driver-sdk#readme",
27
+ "bugs": {
28
+ "url": "https://github.com/groupsky/ya-modbus/issues"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "scripts": {
34
+ "build": "tsc --build",
35
+ "clean": "rm -rf dist",
36
+ "test": "jest"
37
+ },
38
+ "dependencies": {
39
+ "@ya-modbus/driver-types": "^0.4.1-refactor-scope-driver-packages.0"
40
+ },
41
+ "gitHead": "b55d909d67dfff46fb79951e68a2d47ac3fab267"
42
+ }