@cutos/core 4.0.5 → 4.0.6
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 +14 -0
- package/dist/cutos.cjs.js +29 -5
- package/dist/cutos.esm.js +29 -5
- package/package.json +1 -1
- package/types/index.d.ts +9 -6
package/README.md
CHANGED
|
@@ -427,8 +427,22 @@ logger.info("hello-provider", "started", "Provider")
|
|
|
427
427
|
|
|
428
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
429
|
|
|
430
|
+
Device Base constructors expose only the raw device type. CUTOS derives the internal Capability identity and transport type:
|
|
431
|
+
|
|
432
|
+
```text
|
|
433
|
+
deviceType: printer
|
|
434
|
+
capabilityId: capability.device.printer
|
|
435
|
+
transport: device-channel-capability.device.printer-command
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
The legacy transport `name` and `type` are both set internally to the derived Capability id and cannot be overridden through Base options.
|
|
439
|
+
|
|
430
440
|
```ts
|
|
431
441
|
class PrinterProvider extends DeviceProviderBase {
|
|
442
|
+
constructor(options) {
|
|
443
|
+
super("printer", options)
|
|
444
|
+
}
|
|
445
|
+
|
|
432
446
|
connect(params) {
|
|
433
447
|
// Connect hardware.
|
|
434
448
|
}
|
package/dist/cutos.cjs.js
CHANGED
|
@@ -398,7 +398,7 @@ const cutosAPI$2 = {
|
|
|
398
398
|
var cutosApi = cutosAPI$2;
|
|
399
399
|
|
|
400
400
|
var name = "@cutos/core";
|
|
401
|
-
var version = "4.0.
|
|
401
|
+
var version = "4.0.6";
|
|
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";
|
|
@@ -505,6 +505,20 @@ function createErrorResult(error, fallbackCode = 'CUTOS_ERROR') {
|
|
|
505
505
|
return {status: false, msg: normalizeError(error, fallbackCode)};
|
|
506
506
|
}
|
|
507
507
|
|
|
508
|
+
function resolveDeviceCapabilityId(deviceType) {
|
|
509
|
+
if (typeof deviceType !== "string" || !deviceType.trim()) {
|
|
510
|
+
throw new CutosError$2("INVALID_DEVICE_TYPE", "deviceType cannot be empty.");
|
|
511
|
+
}
|
|
512
|
+
const normalizedDeviceType = deviceType.trim();
|
|
513
|
+
if (normalizedDeviceType.startsWith("capability.")) {
|
|
514
|
+
throw new CutosError$2(
|
|
515
|
+
"INVALID_DEVICE_TYPE",
|
|
516
|
+
"deviceType must not include a capability prefix."
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
return `capability.device.${normalizedDeviceType}`;
|
|
520
|
+
}
|
|
521
|
+
|
|
508
522
|
function normalizeResult(result, error) {
|
|
509
523
|
if (error) {
|
|
510
524
|
throw normalizeError(error);
|
|
@@ -1460,8 +1474,13 @@ class Provider {
|
|
|
1460
1474
|
}
|
|
1461
1475
|
|
|
1462
1476
|
let DeviceCapabilityBase$1 = class DeviceCapabilityBase extends Capability {
|
|
1463
|
-
constructor(
|
|
1464
|
-
|
|
1477
|
+
constructor(deviceType, opts = {}) {
|
|
1478
|
+
const capabilityId = resolveDeviceCapabilityId(deviceType);
|
|
1479
|
+
const baseOptions = {...opts};
|
|
1480
|
+
delete baseOptions.name;
|
|
1481
|
+
delete baseOptions.type;
|
|
1482
|
+
super(capabilityId, {...baseOptions, type: capabilityId});
|
|
1483
|
+
this.deviceType = deviceType.trim();
|
|
1465
1484
|
}
|
|
1466
1485
|
|
|
1467
1486
|
init(opts = null, callback) {
|
|
@@ -1511,8 +1530,13 @@ let DeviceCapabilityBase$1 = class DeviceCapabilityBase extends Capability {
|
|
|
1511
1530
|
};
|
|
1512
1531
|
|
|
1513
1532
|
let DeviceProviderBase$1 = class DeviceProviderBase extends Provider {
|
|
1514
|
-
constructor(
|
|
1515
|
-
|
|
1533
|
+
constructor(deviceType, opts = {}) {
|
|
1534
|
+
const capabilityId = resolveDeviceCapabilityId(deviceType);
|
|
1535
|
+
const baseOptions = {...opts};
|
|
1536
|
+
delete baseOptions.name;
|
|
1537
|
+
delete baseOptions.type;
|
|
1538
|
+
super(capabilityId, {...baseOptions, type: capabilityId});
|
|
1539
|
+
this.deviceType = deviceType.trim();
|
|
1516
1540
|
|
|
1517
1541
|
this.method("connect", (params, context) => this.connect(params, context));
|
|
1518
1542
|
this.method("disconnect", (params, context) => this.disconnect(params, context));
|
package/dist/cutos.esm.js
CHANGED
|
@@ -690,7 +690,7 @@ const cutosAPI$2 = {
|
|
|
690
690
|
var cutosApi = cutosAPI$2;
|
|
691
691
|
|
|
692
692
|
var name = "@cutos/core";
|
|
693
|
-
var version = "4.0.
|
|
693
|
+
var version = "4.0.6";
|
|
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";
|
|
@@ -797,6 +797,20 @@ function createErrorResult(error, fallbackCode = 'CUTOS_ERROR') {
|
|
|
797
797
|
return {status: false, msg: normalizeError(error, fallbackCode)};
|
|
798
798
|
}
|
|
799
799
|
|
|
800
|
+
function resolveDeviceCapabilityId(deviceType) {
|
|
801
|
+
if (typeof deviceType !== "string" || !deviceType.trim()) {
|
|
802
|
+
throw new CutosError$2("INVALID_DEVICE_TYPE", "deviceType cannot be empty.");
|
|
803
|
+
}
|
|
804
|
+
const normalizedDeviceType = deviceType.trim();
|
|
805
|
+
if (normalizedDeviceType.startsWith("capability.")) {
|
|
806
|
+
throw new CutosError$2(
|
|
807
|
+
"INVALID_DEVICE_TYPE",
|
|
808
|
+
"deviceType must not include a capability prefix."
|
|
809
|
+
);
|
|
810
|
+
}
|
|
811
|
+
return `capability.device.${normalizedDeviceType}`;
|
|
812
|
+
}
|
|
813
|
+
|
|
800
814
|
function normalizeResult(result, error) {
|
|
801
815
|
if (error) {
|
|
802
816
|
throw normalizeError(error);
|
|
@@ -1752,8 +1766,13 @@ class Provider {
|
|
|
1752
1766
|
}
|
|
1753
1767
|
|
|
1754
1768
|
let DeviceCapabilityBase$1 = class DeviceCapabilityBase extends Capability {
|
|
1755
|
-
constructor(
|
|
1756
|
-
|
|
1769
|
+
constructor(deviceType, opts = {}) {
|
|
1770
|
+
const capabilityId = resolveDeviceCapabilityId(deviceType);
|
|
1771
|
+
const baseOptions = {...opts};
|
|
1772
|
+
delete baseOptions.name;
|
|
1773
|
+
delete baseOptions.type;
|
|
1774
|
+
super(capabilityId, {...baseOptions, type: capabilityId});
|
|
1775
|
+
this.deviceType = deviceType.trim();
|
|
1757
1776
|
}
|
|
1758
1777
|
|
|
1759
1778
|
init(opts = null, callback) {
|
|
@@ -1803,8 +1822,13 @@ let DeviceCapabilityBase$1 = class DeviceCapabilityBase extends Capability {
|
|
|
1803
1822
|
};
|
|
1804
1823
|
|
|
1805
1824
|
let DeviceProviderBase$1 = class DeviceProviderBase extends Provider {
|
|
1806
|
-
constructor(
|
|
1807
|
-
|
|
1825
|
+
constructor(deviceType, opts = {}) {
|
|
1826
|
+
const capabilityId = resolveDeviceCapabilityId(deviceType);
|
|
1827
|
+
const baseOptions = {...opts};
|
|
1828
|
+
delete baseOptions.name;
|
|
1829
|
+
delete baseOptions.type;
|
|
1830
|
+
super(capabilityId, {...baseOptions, type: capabilityId});
|
|
1831
|
+
this.deviceType = deviceType.trim();
|
|
1808
1832
|
|
|
1809
1833
|
this.method("connect", (params, context) => this.connect(params, context));
|
|
1810
1834
|
this.method("disconnect", (params, context) => this.disconnect(params, context));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cutos/core",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.6",
|
|
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",
|
package/types/index.d.ts
CHANGED
|
@@ -47,12 +47,13 @@ export interface ProviderOptions {
|
|
|
47
47
|
[key: string]: unknown;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
export interface DeviceCapabilityBaseOptions
|
|
51
|
-
|
|
50
|
+
export interface DeviceCapabilityBaseOptions {
|
|
51
|
+
device?: Device;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
export interface DeviceProviderBaseOptions
|
|
55
|
-
|
|
54
|
+
export interface DeviceProviderBaseOptions {
|
|
55
|
+
driver?: Driver;
|
|
56
|
+
counter?: number;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
export interface CallOptions {
|
|
@@ -215,7 +216,8 @@ export class DeviceCapabilityBase<
|
|
|
215
216
|
TStatus = DeviceStatus,
|
|
216
217
|
TError = CutosError
|
|
217
218
|
> extends Capability {
|
|
218
|
-
constructor(
|
|
219
|
+
constructor(deviceType: string, opts?: DeviceCapabilityBaseOptions);
|
|
220
|
+
readonly deviceType: string;
|
|
219
221
|
init<TResult = string>(callback: CutosCallback<TResult>): boolean;
|
|
220
222
|
init<TResult = string>(opts?: DeviceInitOptions | null): Promise<TResult>;
|
|
221
223
|
init<TResult = string>(opts: DeviceInitOptions | null, callback: CutosCallback<TResult>): boolean;
|
|
@@ -252,7 +254,8 @@ export class DeviceProviderBase<
|
|
|
252
254
|
TDisconnectResult = unknown,
|
|
253
255
|
TDeviceInfo = unknown
|
|
254
256
|
> extends Provider {
|
|
255
|
-
constructor(
|
|
257
|
+
constructor(deviceType: string, opts?: DeviceProviderBaseOptions);
|
|
258
|
+
readonly deviceType: string;
|
|
256
259
|
connect(
|
|
257
260
|
params: TConnectParams,
|
|
258
261
|
context?: ProviderContext<TConnectParams>
|