@cutos/core 4.0.4 → 4.0.5

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/README.md CHANGED
@@ -423,6 +423,28 @@ The third argument is optional and defaults to `LWA`.
423
423
  logger.info("hello-provider", "started", "Provider")
424
424
  ```
425
425
 
426
+ # Device Provider Base
427
+
428
+ `DeviceProviderBase` automatically registers the standard `connect`, `disconnect`, and `readDeviceInfo` Capability methods. A concrete device Provider overrides those methods and registers only its device-specific extensions:
429
+
430
+ ```ts
431
+ class PrinterProvider extends DeviceProviderBase {
432
+ connect(params) {
433
+ // Connect hardware.
434
+ }
435
+
436
+ disconnect() {
437
+ // Disconnect hardware.
438
+ }
439
+
440
+ readDeviceInfo() {
441
+ return { manufacturer: "CUTOS", model: "printer" }
442
+ }
443
+ }
444
+ ```
445
+
446
+ The Base implementations throw `DEVICE_CONNECT_NOT_IMPLEMENTED`, `DEVICE_DISCONNECT_NOT_IMPLEMENTED`, and `DEVICE_INFO_NOT_IMPLEMENTED`. This makes an incomplete Provider fail explicitly instead of leaving a standard method unregistered.
447
+
426
448
  # Error Model
427
449
 
428
450
  CUTOS 4.0 normalizes SDK errors to `CutosError`.
package/dist/cutos.cjs.js CHANGED
@@ -398,13 +398,14 @@ const cutosAPI$2 = {
398
398
  var cutosApi = cutosAPI$2;
399
399
 
400
400
  var name = "@cutos/core";
401
- var version = "4.0.4";
401
+ var version = "4.0.5";
402
402
  var description = "The CUTOS (CUT Operating System) Core API is a JavaScript library that provides essential functionalities for LWA (Local Web Application) edge computing and communication in the CUTOS ecosystem. ";
403
403
  var main = "dist/cutos.cjs.js";
404
404
  var module$1 = "dist/cutos.esm.js";
405
405
  var types = "types/index.d.ts";
406
406
  var scripts = {
407
- "build:rollup": "rollup -c rollup.config.cjs"
407
+ "build:rollup": "rollup -c rollup.config.cjs",
408
+ test: "node test/device-provider-base.mjs"
408
409
  };
409
410
  var keywords = [
410
411
  "CUTOS",
@@ -1512,14 +1513,31 @@ let DeviceCapabilityBase$1 = class DeviceCapabilityBase extends Capability {
1512
1513
  let DeviceProviderBase$1 = class DeviceProviderBase extends Provider {
1513
1514
  constructor(name, opts = {}) {
1514
1515
  super(name, {...opts, type: opts.type || name});
1516
+
1517
+ this.method("connect", (params, context) => this.connect(params, context));
1518
+ this.method("disconnect", (params, context) => this.disconnect(params, context));
1519
+ this.method("readDeviceInfo", (params, context) => this.readDeviceInfo(params, context));
1520
+ }
1521
+
1522
+ connect(params, context) {
1523
+ throw new CutosError$2(
1524
+ "DEVICE_CONNECT_NOT_IMPLEMENTED",
1525
+ "connect() is not implemented."
1526
+ );
1515
1527
  }
1516
1528
 
1517
- connect(handler) {
1518
- return this.method("connect", handler);
1529
+ disconnect(params, context) {
1530
+ throw new CutosError$2(
1531
+ "DEVICE_DISCONNECT_NOT_IMPLEMENTED",
1532
+ "disconnect() is not implemented."
1533
+ );
1519
1534
  }
1520
1535
 
1521
- disconnect(handler) {
1522
- return this.method("disconnect", handler);
1536
+ readDeviceInfo(params, context) {
1537
+ throw new CutosError$2(
1538
+ "DEVICE_INFO_NOT_IMPLEMENTED",
1539
+ "readDeviceInfo() is not implemented."
1540
+ );
1523
1541
  }
1524
1542
 
1525
1543
  startBeat() {
package/dist/cutos.esm.js CHANGED
@@ -690,13 +690,14 @@ const cutosAPI$2 = {
690
690
  var cutosApi = cutosAPI$2;
691
691
 
692
692
  var name = "@cutos/core";
693
- var version = "4.0.4";
693
+ var version = "4.0.5";
694
694
  var description = "The CUTOS (CUT Operating System) Core API is a JavaScript library that provides essential functionalities for LWA (Local Web Application) edge computing and communication in the CUTOS ecosystem. ";
695
695
  var main = "dist/cutos.cjs.js";
696
696
  var module = "dist/cutos.esm.js";
697
697
  var types = "types/index.d.ts";
698
698
  var scripts = {
699
- "build:rollup": "rollup -c rollup.config.cjs"
699
+ "build:rollup": "rollup -c rollup.config.cjs",
700
+ test: "node test/device-provider-base.mjs"
700
701
  };
701
702
  var keywords = [
702
703
  "CUTOS",
@@ -1804,14 +1805,31 @@ let DeviceCapabilityBase$1 = class DeviceCapabilityBase extends Capability {
1804
1805
  let DeviceProviderBase$1 = class DeviceProviderBase extends Provider {
1805
1806
  constructor(name, opts = {}) {
1806
1807
  super(name, {...opts, type: opts.type || name});
1808
+
1809
+ this.method("connect", (params, context) => this.connect(params, context));
1810
+ this.method("disconnect", (params, context) => this.disconnect(params, context));
1811
+ this.method("readDeviceInfo", (params, context) => this.readDeviceInfo(params, context));
1812
+ }
1813
+
1814
+ connect(params, context) {
1815
+ throw new CutosError$2(
1816
+ "DEVICE_CONNECT_NOT_IMPLEMENTED",
1817
+ "connect() is not implemented."
1818
+ );
1807
1819
  }
1808
1820
 
1809
- connect(handler) {
1810
- return this.method("connect", handler);
1821
+ disconnect(params, context) {
1822
+ throw new CutosError$2(
1823
+ "DEVICE_DISCONNECT_NOT_IMPLEMENTED",
1824
+ "disconnect() is not implemented."
1825
+ );
1811
1826
  }
1812
1827
 
1813
- disconnect(handler) {
1814
- return this.method("disconnect", handler);
1828
+ readDeviceInfo(params, context) {
1829
+ throw new CutosError$2(
1830
+ "DEVICE_INFO_NOT_IMPLEMENTED",
1831
+ "readDeviceInfo() is not implemented."
1832
+ );
1815
1833
  }
1816
1834
 
1817
1835
  startBeat() {
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@cutos/core",
3
- "version": "4.0.4",
3
+ "version": "4.0.5",
4
4
  "description": "The CUTOS (CUT Operating System) Core API is a JavaScript library that provides essential functionalities for LWA (Local Web Application) edge computing and communication in the CUTOS ecosystem. ",
5
5
  "main": "dist/cutos.cjs.js",
6
6
  "module": "dist/cutos.esm.js",
7
7
  "types": "types/index.d.ts",
8
8
  "scripts": {
9
- "build:rollup": "rollup -c rollup.config.cjs"
9
+ "build:rollup": "rollup -c rollup.config.cjs",
10
+ "test": "node test/device-provider-base.mjs"
10
11
  },
11
12
  "keywords": [
12
13
  "CUTOS", "core", "database", "IPC", "notification", "logging", "device&driver"
package/types/index.d.ts CHANGED
@@ -249,21 +249,22 @@ export class DeviceProviderBase<
249
249
  TConnectParams = unknown,
250
250
  TConnectResult = unknown,
251
251
  TDisconnectParams = Record<string, never>,
252
- TDisconnectResult = unknown
252
+ TDisconnectResult = unknown,
253
+ TDeviceInfo = unknown
253
254
  > extends Provider {
254
255
  constructor(name: string, opts?: DeviceProviderBaseOptions);
255
256
  connect(
256
- handler: (
257
- params: TConnectParams,
258
- context: ProviderContext<TConnectParams>
259
- ) => TConnectResult | Promise<TConnectResult>
260
- ): this;
257
+ params: TConnectParams,
258
+ context?: ProviderContext<TConnectParams>
259
+ ): TConnectResult | Promise<TConnectResult>;
261
260
  disconnect(
262
- handler: (
263
- params: TDisconnectParams,
264
- context: ProviderContext<TDisconnectParams>
265
- ) => TDisconnectResult | Promise<TDisconnectResult>
266
- ): this;
261
+ params: TDisconnectParams,
262
+ context?: ProviderContext<TDisconnectParams>
263
+ ): TDisconnectResult | Promise<TDisconnectResult>;
264
+ readDeviceInfo(
265
+ params: Record<string, never>,
266
+ context?: ProviderContext<Record<string, never>>
267
+ ): TDeviceInfo | Promise<TDeviceInfo>;
267
268
  startBeat(): void;
268
269
  setBeatInterval(interval: number): this;
269
270
  setStatus(status?: string, info?: unknown): this;