@cutos/core 4.0.4 → 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 +36 -0
- package/dist/cutos.cjs.js +56 -14
- package/dist/cutos.esm.js +56 -14
- package/package.json +3 -2
- package/types/index.d.ts +21 -17
package/README.md
CHANGED
|
@@ -423,6 +423,42 @@ 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
|
+
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
|
+
|
|
440
|
+
```ts
|
|
441
|
+
class PrinterProvider extends DeviceProviderBase {
|
|
442
|
+
constructor(options) {
|
|
443
|
+
super("printer", options)
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
connect(params) {
|
|
447
|
+
// Connect hardware.
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
disconnect() {
|
|
451
|
+
// Disconnect hardware.
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
readDeviceInfo() {
|
|
455
|
+
return { manufacturer: "CUTOS", model: "printer" }
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
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.
|
|
461
|
+
|
|
426
462
|
# Error Model
|
|
427
463
|
|
|
428
464
|
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.
|
|
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";
|
|
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",
|
|
@@ -504,6 +505,20 @@ function createErrorResult(error, fallbackCode = 'CUTOS_ERROR') {
|
|
|
504
505
|
return {status: false, msg: normalizeError(error, fallbackCode)};
|
|
505
506
|
}
|
|
506
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
|
+
|
|
507
522
|
function normalizeResult(result, error) {
|
|
508
523
|
if (error) {
|
|
509
524
|
throw normalizeError(error);
|
|
@@ -1459,8 +1474,13 @@ class Provider {
|
|
|
1459
1474
|
}
|
|
1460
1475
|
|
|
1461
1476
|
let DeviceCapabilityBase$1 = class DeviceCapabilityBase extends Capability {
|
|
1462
|
-
constructor(
|
|
1463
|
-
|
|
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();
|
|
1464
1484
|
}
|
|
1465
1485
|
|
|
1466
1486
|
init(opts = null, callback) {
|
|
@@ -1510,16 +1530,38 @@ let DeviceCapabilityBase$1 = class DeviceCapabilityBase extends Capability {
|
|
|
1510
1530
|
};
|
|
1511
1531
|
|
|
1512
1532
|
let DeviceProviderBase$1 = class DeviceProviderBase extends Provider {
|
|
1513
|
-
constructor(
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
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();
|
|
1540
|
+
|
|
1541
|
+
this.method("connect", (params, context) => this.connect(params, context));
|
|
1542
|
+
this.method("disconnect", (params, context) => this.disconnect(params, context));
|
|
1543
|
+
this.method("readDeviceInfo", (params, context) => this.readDeviceInfo(params, context));
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
connect(params, context) {
|
|
1547
|
+
throw new CutosError$2(
|
|
1548
|
+
"DEVICE_CONNECT_NOT_IMPLEMENTED",
|
|
1549
|
+
"connect() is not implemented."
|
|
1550
|
+
);
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
disconnect(params, context) {
|
|
1554
|
+
throw new CutosError$2(
|
|
1555
|
+
"DEVICE_DISCONNECT_NOT_IMPLEMENTED",
|
|
1556
|
+
"disconnect() is not implemented."
|
|
1557
|
+
);
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
readDeviceInfo(params, context) {
|
|
1561
|
+
throw new CutosError$2(
|
|
1562
|
+
"DEVICE_INFO_NOT_IMPLEMENTED",
|
|
1563
|
+
"readDeviceInfo() is not implemented."
|
|
1564
|
+
);
|
|
1523
1565
|
}
|
|
1524
1566
|
|
|
1525
1567
|
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.
|
|
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";
|
|
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",
|
|
@@ -796,6 +797,20 @@ function createErrorResult(error, fallbackCode = 'CUTOS_ERROR') {
|
|
|
796
797
|
return {status: false, msg: normalizeError(error, fallbackCode)};
|
|
797
798
|
}
|
|
798
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
|
+
|
|
799
814
|
function normalizeResult(result, error) {
|
|
800
815
|
if (error) {
|
|
801
816
|
throw normalizeError(error);
|
|
@@ -1751,8 +1766,13 @@ class Provider {
|
|
|
1751
1766
|
}
|
|
1752
1767
|
|
|
1753
1768
|
let DeviceCapabilityBase$1 = class DeviceCapabilityBase extends Capability {
|
|
1754
|
-
constructor(
|
|
1755
|
-
|
|
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();
|
|
1756
1776
|
}
|
|
1757
1777
|
|
|
1758
1778
|
init(opts = null, callback) {
|
|
@@ -1802,16 +1822,38 @@ let DeviceCapabilityBase$1 = class DeviceCapabilityBase extends Capability {
|
|
|
1802
1822
|
};
|
|
1803
1823
|
|
|
1804
1824
|
let DeviceProviderBase$1 = class DeviceProviderBase extends Provider {
|
|
1805
|
-
constructor(
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
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();
|
|
1832
|
+
|
|
1833
|
+
this.method("connect", (params, context) => this.connect(params, context));
|
|
1834
|
+
this.method("disconnect", (params, context) => this.disconnect(params, context));
|
|
1835
|
+
this.method("readDeviceInfo", (params, context) => this.readDeviceInfo(params, context));
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
connect(params, context) {
|
|
1839
|
+
throw new CutosError$2(
|
|
1840
|
+
"DEVICE_CONNECT_NOT_IMPLEMENTED",
|
|
1841
|
+
"connect() is not implemented."
|
|
1842
|
+
);
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
disconnect(params, context) {
|
|
1846
|
+
throw new CutosError$2(
|
|
1847
|
+
"DEVICE_DISCONNECT_NOT_IMPLEMENTED",
|
|
1848
|
+
"disconnect() is not implemented."
|
|
1849
|
+
);
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
readDeviceInfo(params, context) {
|
|
1853
|
+
throw new CutosError$2(
|
|
1854
|
+
"DEVICE_INFO_NOT_IMPLEMENTED",
|
|
1855
|
+
"readDeviceInfo() is not implemented."
|
|
1856
|
+
);
|
|
1815
1857
|
}
|
|
1816
1858
|
|
|
1817
1859
|
startBeat() {
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
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",
|
|
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
|
@@ -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;
|
|
@@ -249,21 +251,23 @@ export class DeviceProviderBase<
|
|
|
249
251
|
TConnectParams = unknown,
|
|
250
252
|
TConnectResult = unknown,
|
|
251
253
|
TDisconnectParams = Record<string, never>,
|
|
252
|
-
TDisconnectResult = unknown
|
|
254
|
+
TDisconnectResult = unknown,
|
|
255
|
+
TDeviceInfo = unknown
|
|
253
256
|
> extends Provider {
|
|
254
|
-
constructor(
|
|
257
|
+
constructor(deviceType: string, opts?: DeviceProviderBaseOptions);
|
|
258
|
+
readonly deviceType: string;
|
|
255
259
|
connect(
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
) => TConnectResult | Promise<TConnectResult>
|
|
260
|
-
): this;
|
|
260
|
+
params: TConnectParams,
|
|
261
|
+
context?: ProviderContext<TConnectParams>
|
|
262
|
+
): TConnectResult | Promise<TConnectResult>;
|
|
261
263
|
disconnect(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
264
|
+
params: TDisconnectParams,
|
|
265
|
+
context?: ProviderContext<TDisconnectParams>
|
|
266
|
+
): TDisconnectResult | Promise<TDisconnectResult>;
|
|
267
|
+
readDeviceInfo(
|
|
268
|
+
params: Record<string, never>,
|
|
269
|
+
context?: ProviderContext<Record<string, never>>
|
|
270
|
+
): TDeviceInfo | Promise<TDeviceInfo>;
|
|
267
271
|
startBeat(): void;
|
|
268
272
|
setBeatInterval(interval: number): this;
|
|
269
273
|
setStatus(status?: string, info?: unknown): this;
|