@ya-modbus/driver-loader 0.8.1 → 0.9.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/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
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.9.0](https://github.com/groupsky/ya-modbus/compare/@ya-modbus/driver-loader@0.8.1...@ya-modbus/driver-loader@0.9.0) (2026-10-12)
7
+
8
+ ### Features
9
+
10
+ - **driver-loader:** allow scoped third-party driver packages ([#573](https://github.com/groupsky/ya-modbus/issues/573)) ([63b2b83](https://github.com/groupsky/ya-modbus/commit/63b2b833dbb0b5198e8df7135f419793e32d95c3)), closes [#565](https://github.com/groupsky/ya-modbus/issues/565)
11
+
6
12
  ## [0.8.1](https://github.com/groupsky/ya-modbus/compare/@ya-modbus/driver-loader@0.8.0...@ya-modbus/driver-loader@0.8.1) (2026-10-12)
7
13
 
8
14
  ### Bug Fixes
package/README.md CHANGED
@@ -192,6 +192,29 @@ import { getCallerPackageInfo } from '@ya-modbus/driver-loader'
192
192
  program.version(getCallerPackageInfo().version)
193
193
  ```
194
194
 
195
+ ### `isValidDriverPackageName(name: unknown): boolean`
196
+
197
+ Checks a driver package name against the shared naming rule for applications that read the driver name from a configuration, such as the MQTT bridge. Allowed forms:
198
+
199
+ - `@ya-modbus/driver-<name>`
200
+ - `ya-modbus-driver-<name>`
201
+ - `@<scope>/ya-modbus-driver-<name>`
202
+
203
+ `<name>` and `<scope>` use only lowercase letters, numbers and hyphens. Paths (`../x`, `/opt/x`), sub paths, backslashes and any other package name are rejected. `loadDriver` does not check this rule. If your tool reads the driver name from a config file, call `assertValidDriverPackageName` before `loadDriver`.
204
+
205
+ ### `assertValidDriverPackageName(name: string): void`
206
+
207
+ Same check as `isValidDriverPackageName`. Throws a `ValidationError` (field `driverPackage`) that shows the rejected name and lists the allowed forms.
208
+
209
+ `DRIVER_PACKAGE_NAME_RULE` is the text of the rule ("must be ..."), for applications that build their own error message.
210
+
211
+ ```typescript
212
+ import { assertValidDriverPackageName, loadDriver } from '@ya-modbus/driver-loader'
213
+
214
+ assertValidDriverPackageName(config.driver)
215
+ await loadDriver({ driverPackage: config.driver })
216
+ ```
217
+
195
218
  ## Testing Utilities
196
219
 
197
220
  The package provides testing utilities for applications using driver-loader.
@@ -255,7 +278,7 @@ If you encounter `Driver package not found` errors:
255
278
 
256
279
  3. **Check the package name:**
257
280
  - Ensure the package name in your code matches the actual npm package name
258
- - Driver packages typically follow the naming convention: `ya-modbus-driver-<device>`
281
+ - Driver packages follow the naming rule described under `isValidDriverPackageName` (for example `ya-modbus-driver-<device>` or `@<scope>/ya-modbus-driver-<device>`)
259
282
 
260
283
  ### Module Resolution Issues
261
284
 
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Describes the allowed driver package names, for error messages.
3
+ * Written to follow "name must be ...", so callers can put their own words in front.
4
+ */
5
+ export declare const DRIVER_PACKAGE_NAME_RULE: string;
6
+ /**
7
+ * Check a driver package name against the shared naming rule for drivers that are loaded
8
+ * from a configured name, such as in the MQTT bridge.
9
+ *
10
+ * Allowed forms: `@ya-modbus/driver-<name>`, `ya-modbus-driver-<name>` and
11
+ * `@<scope>/ya-modbus-driver-<name>`.
12
+ *
13
+ * @param name - Value to check
14
+ * @returns true if the value is an allowed driver package name
15
+ */
16
+ export declare function isValidDriverPackageName(name: unknown): boolean;
17
+ /**
18
+ * Throw if a driver package name does not follow the naming rule.
19
+ *
20
+ * @param name - Driver package name to check
21
+ * @throws ValidationError (field `driverPackage`) listing the allowed forms
22
+ */
23
+ export declare function assertValidDriverPackageName(name: string): void;
24
+ //# sourceMappingURL=driver-package-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver-package-name.d.ts","sourceRoot":"","sources":["../../../src/driver-package-name.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,wBAAwB,QAEuC,CAAA;AAS5E;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAE/D;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAO/D"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DRIVER_PACKAGE_NAME_RULE = void 0;
4
+ exports.isValidDriverPackageName = isValidDriverPackageName;
5
+ exports.assertValidDriverPackageName = assertValidDriverPackageName;
6
+ const errors_js_1 = require("./errors.js");
7
+ /**
8
+ * Describes the allowed driver package names, for error messages.
9
+ * Written to follow "name must be ...", so callers can put their own words in front.
10
+ */
11
+ exports.DRIVER_PACKAGE_NAME_RULE = 'must be @ya-modbus/driver-<name>, ya-modbus-driver-<name> or @<scope>/ya-modbus-driver-<name>, ' +
12
+ 'where <name> and <scope> use only lowercase letters, numbers and hyphens';
13
+ /**
14
+ * The three allowed forms. Only lowercase letters, numbers and hyphens can follow the prefix,
15
+ * so a name can never contain a path separator, a dot, a backslash or a whitespace.
16
+ */
17
+ const DRIVER_PACKAGE_NAME_PATTERN = /^(?:@ya-modbus\/driver-|(?:@[a-z0-9][a-z0-9-]*\/)?ya-modbus-driver-)[a-z0-9-]+$/;
18
+ /**
19
+ * Check a driver package name against the shared naming rule for drivers that are loaded
20
+ * from a configured name, such as in the MQTT bridge.
21
+ *
22
+ * Allowed forms: `@ya-modbus/driver-<name>`, `ya-modbus-driver-<name>` and
23
+ * `@<scope>/ya-modbus-driver-<name>`.
24
+ *
25
+ * @param name - Value to check
26
+ * @returns true if the value is an allowed driver package name
27
+ */
28
+ function isValidDriverPackageName(name) {
29
+ return typeof name === 'string' && DRIVER_PACKAGE_NAME_PATTERN.test(name);
30
+ }
31
+ /**
32
+ * Throw if a driver package name does not follow the naming rule.
33
+ *
34
+ * @param name - Driver package name to check
35
+ * @throws ValidationError (field `driverPackage`) listing the allowed forms
36
+ */
37
+ function assertValidDriverPackageName(name) {
38
+ if (!isValidDriverPackageName(name)) {
39
+ throw new errors_js_1.ValidationError(`Invalid driver package name ${JSON.stringify(name)}: ${exports.DRIVER_PACKAGE_NAME_RULE}`, 'driverPackage');
40
+ }
41
+ }
42
+ //# sourceMappingURL=driver-package-name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver-package-name.js","sourceRoot":"","sources":["../../../src/driver-package-name.ts"],"names":[],"mappings":";;;AA2BA,4DAEC;AAQD,oEAOC;AA5CD,2CAA6C;AAE7C;;;GAGG;AACU,QAAA,wBAAwB,GACnC,iGAAiG;IACjG,0EAA0E,CAAA;AAE5E;;;GAGG;AACH,MAAM,2BAA2B,GAC/B,iFAAiF,CAAA;AAEnF;;;;;;;;;GASG;AACH,SAAgB,wBAAwB,CAAC,IAAa;IACpD,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC3E,CAAC;AAED;;;;;GAKG;AACH,SAAgB,4BAA4B,CAAC,IAAY;IACvD,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,2BAAe,CACvB,+BAA+B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,gCAAwB,EAAE,EAClF,eAAe,CAChB,CAAA;IACH,CAAC;AACH,CAAC"}
@@ -1,6 +1,7 @@
1
1
  export { loadDriver, clearDriverCache, getDriverCacheStats } from './loader.js';
2
2
  export type { LoadedDriver, LoadDriverOptions, SystemDependencies, DriverCacheStats, Logger, } from './loader.js';
3
3
  export { validateDefaultConfig, validateSupportedConfig, validateDevices, crossValidateConfigs, } from './config-validator.js';
4
+ export { DRIVER_PACKAGE_NAME_RULE, assertValidDriverPackageName, isValidDriverPackageName, } from './driver-package-name.js';
4
5
  export { ValidationError, DriverNotFoundError, PackageJsonError } from './errors.js';
5
6
  export { getCallerPackageInfo } from './package-info.js';
6
7
  export type { PackageInfo } from './package-info.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAC/E,YAAY,EACV,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,MAAM,GACP,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,eAAe,EACf,oBAAoB,GACrB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACxD,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAC/E,YAAY,EACV,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,MAAM,GACP,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,eAAe,EACf,oBAAoB,GACrB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACxD,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCallerPackageInfo = exports.PackageJsonError = exports.DriverNotFoundError = exports.ValidationError = exports.crossValidateConfigs = exports.validateDevices = exports.validateSupportedConfig = exports.validateDefaultConfig = exports.getDriverCacheStats = exports.clearDriverCache = exports.loadDriver = void 0;
3
+ exports.getCallerPackageInfo = exports.PackageJsonError = exports.DriverNotFoundError = exports.ValidationError = exports.isValidDriverPackageName = exports.assertValidDriverPackageName = exports.DRIVER_PACKAGE_NAME_RULE = exports.crossValidateConfigs = exports.validateDevices = exports.validateSupportedConfig = exports.validateDefaultConfig = exports.getDriverCacheStats = exports.clearDriverCache = exports.loadDriver = void 0;
4
4
  var loader_js_1 = require("./loader.js");
5
5
  Object.defineProperty(exports, "loadDriver", { enumerable: true, get: function () { return loader_js_1.loadDriver; } });
6
6
  Object.defineProperty(exports, "clearDriverCache", { enumerable: true, get: function () { return loader_js_1.clearDriverCache; } });
@@ -10,6 +10,10 @@ Object.defineProperty(exports, "validateDefaultConfig", { enumerable: true, get:
10
10
  Object.defineProperty(exports, "validateSupportedConfig", { enumerable: true, get: function () { return config_validator_js_1.validateSupportedConfig; } });
11
11
  Object.defineProperty(exports, "validateDevices", { enumerable: true, get: function () { return config_validator_js_1.validateDevices; } });
12
12
  Object.defineProperty(exports, "crossValidateConfigs", { enumerable: true, get: function () { return config_validator_js_1.crossValidateConfigs; } });
13
+ var driver_package_name_js_1 = require("./driver-package-name.js");
14
+ Object.defineProperty(exports, "DRIVER_PACKAGE_NAME_RULE", { enumerable: true, get: function () { return driver_package_name_js_1.DRIVER_PACKAGE_NAME_RULE; } });
15
+ Object.defineProperty(exports, "assertValidDriverPackageName", { enumerable: true, get: function () { return driver_package_name_js_1.assertValidDriverPackageName; } });
16
+ Object.defineProperty(exports, "isValidDriverPackageName", { enumerable: true, get: function () { return driver_package_name_js_1.isValidDriverPackageName; } });
13
17
  var errors_js_1 = require("./errors.js");
14
18
  Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_js_1.ValidationError; } });
15
19
  Object.defineProperty(exports, "DriverNotFoundError", { enumerable: true, get: function () { return errors_js_1.DriverNotFoundError; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA+E;AAAtE,uGAAA,UAAU,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAAE,gHAAA,mBAAmB,OAAA;AAQ1D,6DAK8B;AAJ5B,4HAAA,qBAAqB,OAAA;AACrB,8HAAA,uBAAuB,OAAA;AACvB,sHAAA,eAAe,OAAA;AACf,2HAAA,oBAAoB,OAAA;AAEtB,yCAAoF;AAA3E,4GAAA,eAAe,OAAA;AAAE,gHAAA,mBAAmB,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAC/D,qDAAwD;AAA/C,uHAAA,oBAAoB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA+E;AAAtE,uGAAA,UAAU,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAAE,gHAAA,mBAAmB,OAAA;AAQ1D,6DAK8B;AAJ5B,4HAAA,qBAAqB,OAAA;AACrB,8HAAA,uBAAuB,OAAA;AACvB,sHAAA,eAAe,OAAA;AACf,2HAAA,oBAAoB,OAAA;AAEtB,mEAIiC;AAH/B,kIAAA,wBAAwB,OAAA;AACxB,sIAAA,4BAA4B,OAAA;AAC5B,kIAAA,wBAAwB,OAAA;AAE1B,yCAAoF;AAA3E,4GAAA,eAAe,OAAA;AAAE,gHAAA,mBAAmB,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAC/D,qDAAwD;AAA/C,uHAAA,oBAAoB,OAAA"}
@@ -59,7 +59,7 @@ export interface Logger {
59
59
  export interface LoadDriverOptions {
60
60
  /**
61
61
  * Explicit driver package name
62
- * e.g., 'ya-modbus-driver-xymd1' or '@org/driver-pkg'
62
+ * e.g., 'ya-modbus-driver-xymd1' or '@org/ya-modbus-driver-xymd1'
63
63
  */
64
64
  driverPackage?: string;
65
65
  /**