@cutos/core 4.0.5 → 4.0.7
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 -9
- package/dist/cutos.cjs.js +30 -24
- package/dist/cutos.esm.js +30 -24
- package/package.json +1 -1
- package/types/index.d.ts +9 -12
package/README.md
CHANGED
|
@@ -186,15 +186,6 @@ Get registered CUTOS device identity information.
|
|
|
186
186
|
const deviceInfo = await CoreAPI.getDeviceInfo<Record<string, unknown>>()
|
|
187
187
|
```
|
|
188
188
|
|
|
189
|
-
## CoreAPI.getSignInfo / CoreAPI.getSignGroupInfo
|
|
190
|
-
|
|
191
|
-
Get sign and sign group metadata.
|
|
192
|
-
|
|
193
|
-
```ts
|
|
194
|
-
const signInfo = await CoreAPI.getSignInfo<Record<string, unknown>>()
|
|
195
|
-
const groupInfo = await CoreAPI.getSignGroupInfo<Record<string, unknown>>()
|
|
196
|
-
```
|
|
197
|
-
|
|
198
189
|
## CoreAPI.getVolume / CoreAPI.setVolume
|
|
199
190
|
|
|
200
191
|
```ts
|
|
@@ -427,8 +418,22 @@ logger.info("hello-provider", "started", "Provider")
|
|
|
427
418
|
|
|
428
419
|
`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
420
|
|
|
421
|
+
Device Base constructors expose only the raw device type. CUTOS derives the internal Capability identity and transport type:
|
|
422
|
+
|
|
423
|
+
```text
|
|
424
|
+
deviceType: printer
|
|
425
|
+
capabilityId: capability.device.printer
|
|
426
|
+
transport: device-channel-capability.device.printer-command
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
The legacy transport `name` and `type` are both set internally to the derived Capability id and cannot be overridden through Base options.
|
|
430
|
+
|
|
430
431
|
```ts
|
|
431
432
|
class PrinterProvider extends DeviceProviderBase {
|
|
433
|
+
constructor(options) {
|
|
434
|
+
super("printer", options)
|
|
435
|
+
}
|
|
436
|
+
|
|
432
437
|
connect(params) {
|
|
433
438
|
// Connect hardware.
|
|
434
439
|
}
|
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.7";
|
|
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));
|
|
@@ -1699,14 +1723,6 @@ const CoreAPI$3 = {
|
|
|
1699
1723
|
return maybePromise(callback, cb => publishRequest(cutosAPI$1.CORE.BOX_INFO, cb));
|
|
1700
1724
|
},
|
|
1701
1725
|
|
|
1702
|
-
/**
|
|
1703
|
-
* Get sign information
|
|
1704
|
-
* @param {Function} callback - callback(result)
|
|
1705
|
-
*/
|
|
1706
|
-
getSignInfo(callback) {
|
|
1707
|
-
return maybePromise(callback, cb => publishRequest(cutosAPI$1.CORE.SIGN_INFO, cb));
|
|
1708
|
-
},
|
|
1709
|
-
|
|
1710
1726
|
/**
|
|
1711
1727
|
* Get device information
|
|
1712
1728
|
* @param {Function} callback - callback(result)
|
|
@@ -1715,10 +1731,6 @@ const CoreAPI$3 = {
|
|
|
1715
1731
|
return maybePromise(callback, cb => publishRequest(cutosAPI$1.CORE.DEVICE_INFO, cb));
|
|
1716
1732
|
},
|
|
1717
1733
|
|
|
1718
|
-
getSignGroupInfo(callback) {
|
|
1719
|
-
return maybePromise(callback, cb => publishRequest(cutosAPI$1.CORE.SIGN_GROUP_INFO, cb));
|
|
1720
|
-
},
|
|
1721
|
-
|
|
1722
1734
|
/**
|
|
1723
1735
|
* Get IPC instance object
|
|
1724
1736
|
* @param {String} destAddress - optional parameter, target IP address, used for inter-device process communication
|
|
@@ -1839,9 +1851,7 @@ const original = {
|
|
|
1839
1851
|
getPlatform: CoreAPI$1.getPlatform,
|
|
1840
1852
|
getConfig: CoreAPI$1.getConfig,
|
|
1841
1853
|
getBoxInfo: CoreAPI$1.getBoxInfo,
|
|
1842
|
-
getSignInfo: CoreAPI$1.getSignInfo,
|
|
1843
1854
|
getDeviceInfo: CoreAPI$1.getDeviceInfo,
|
|
1844
|
-
getSignGroupInfo: CoreAPI$1.getSignGroupInfo,
|
|
1845
1855
|
shell: CoreAPI$1.shell,
|
|
1846
1856
|
getVolume: CoreAPI$1.getVolume,
|
|
1847
1857
|
setVolume: CoreAPI$1.setVolume,
|
|
@@ -1917,9 +1927,7 @@ function installCutosMock$1(options = {}) {
|
|
|
1917
1927
|
CoreAPI$1.getPlatform = callback => resolveCallback(callback, options.platform || {name: 'CUTOS Mock'});
|
|
1918
1928
|
CoreAPI$1.getConfig = callback => resolveCallback(callback, options.config || {});
|
|
1919
1929
|
CoreAPI$1.getBoxInfo = callback => resolveCallback(callback, options.boxInfo || {name: 'CUTOS Mock Node'});
|
|
1920
|
-
CoreAPI$1.
|
|
1921
|
-
CoreAPI$1.getDeviceInfo = callback => resolveCallback(callback, options.deviceInfo || []);
|
|
1922
|
-
CoreAPI$1.getSignGroupInfo = callback => resolveCallback(callback, options.signGroupInfo || {});
|
|
1930
|
+
CoreAPI$1.getDeviceInfo = callback => resolveCallback(callback, options.deviceInfo || {name: 'CUTOS Mock Device'});
|
|
1923
1931
|
CoreAPI$1.shell = (command, callback) => resolveCallback(callback, {command, stdout: '', stderr: '', code: 0});
|
|
1924
1932
|
CoreAPI$1.getVolume = callback => resolveCallback(callback, options.volume ?? 50);
|
|
1925
1933
|
CoreAPI$1.setVolume = (vol, callback) => {
|
|
@@ -1938,9 +1946,7 @@ function uninstallCutosMock$1() {
|
|
|
1938
1946
|
CoreAPI$1.getPlatform = original.getPlatform;
|
|
1939
1947
|
CoreAPI$1.getConfig = original.getConfig;
|
|
1940
1948
|
CoreAPI$1.getBoxInfo = original.getBoxInfo;
|
|
1941
|
-
CoreAPI$1.getSignInfo = original.getSignInfo;
|
|
1942
1949
|
CoreAPI$1.getDeviceInfo = original.getDeviceInfo;
|
|
1943
|
-
CoreAPI$1.getSignGroupInfo = original.getSignGroupInfo;
|
|
1944
1950
|
CoreAPI$1.shell = original.shell;
|
|
1945
1951
|
CoreAPI$1.getVolume = original.getVolume;
|
|
1946
1952
|
CoreAPI$1.setVolume = original.setVolume;
|
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.7";
|
|
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));
|
|
@@ -1991,14 +2015,6 @@ const CoreAPI$3 = {
|
|
|
1991
2015
|
return maybePromise(callback, cb => publishRequest(cutosAPI$1.CORE.BOX_INFO, cb));
|
|
1992
2016
|
},
|
|
1993
2017
|
|
|
1994
|
-
/**
|
|
1995
|
-
* Get sign information
|
|
1996
|
-
* @param {Function} callback - callback(result)
|
|
1997
|
-
*/
|
|
1998
|
-
getSignInfo(callback) {
|
|
1999
|
-
return maybePromise(callback, cb => publishRequest(cutosAPI$1.CORE.SIGN_INFO, cb));
|
|
2000
|
-
},
|
|
2001
|
-
|
|
2002
2018
|
/**
|
|
2003
2019
|
* Get device information
|
|
2004
2020
|
* @param {Function} callback - callback(result)
|
|
@@ -2007,10 +2023,6 @@ const CoreAPI$3 = {
|
|
|
2007
2023
|
return maybePromise(callback, cb => publishRequest(cutosAPI$1.CORE.DEVICE_INFO, cb));
|
|
2008
2024
|
},
|
|
2009
2025
|
|
|
2010
|
-
getSignGroupInfo(callback) {
|
|
2011
|
-
return maybePromise(callback, cb => publishRequest(cutosAPI$1.CORE.SIGN_GROUP_INFO, cb));
|
|
2012
|
-
},
|
|
2013
|
-
|
|
2014
2026
|
/**
|
|
2015
2027
|
* Get IPC instance object
|
|
2016
2028
|
* @param {String} destAddress - optional parameter, target IP address, used for inter-device process communication
|
|
@@ -2131,9 +2143,7 @@ const original = {
|
|
|
2131
2143
|
getPlatform: CoreAPI$1.getPlatform,
|
|
2132
2144
|
getConfig: CoreAPI$1.getConfig,
|
|
2133
2145
|
getBoxInfo: CoreAPI$1.getBoxInfo,
|
|
2134
|
-
getSignInfo: CoreAPI$1.getSignInfo,
|
|
2135
2146
|
getDeviceInfo: CoreAPI$1.getDeviceInfo,
|
|
2136
|
-
getSignGroupInfo: CoreAPI$1.getSignGroupInfo,
|
|
2137
2147
|
shell: CoreAPI$1.shell,
|
|
2138
2148
|
getVolume: CoreAPI$1.getVolume,
|
|
2139
2149
|
setVolume: CoreAPI$1.setVolume,
|
|
@@ -2209,9 +2219,7 @@ function installCutosMock$1(options = {}) {
|
|
|
2209
2219
|
CoreAPI$1.getPlatform = callback => resolveCallback(callback, options.platform || {name: 'CUTOS Mock'});
|
|
2210
2220
|
CoreAPI$1.getConfig = callback => resolveCallback(callback, options.config || {});
|
|
2211
2221
|
CoreAPI$1.getBoxInfo = callback => resolveCallback(callback, options.boxInfo || {name: 'CUTOS Mock Node'});
|
|
2212
|
-
CoreAPI$1.
|
|
2213
|
-
CoreAPI$1.getDeviceInfo = callback => resolveCallback(callback, options.deviceInfo || []);
|
|
2214
|
-
CoreAPI$1.getSignGroupInfo = callback => resolveCallback(callback, options.signGroupInfo || {});
|
|
2222
|
+
CoreAPI$1.getDeviceInfo = callback => resolveCallback(callback, options.deviceInfo || {name: 'CUTOS Mock Device'});
|
|
2215
2223
|
CoreAPI$1.shell = (command, callback) => resolveCallback(callback, {command, stdout: '', stderr: '', code: 0});
|
|
2216
2224
|
CoreAPI$1.getVolume = callback => resolveCallback(callback, options.volume ?? 50);
|
|
2217
2225
|
CoreAPI$1.setVolume = (vol, callback) => {
|
|
@@ -2230,9 +2238,7 @@ function uninstallCutosMock$1() {
|
|
|
2230
2238
|
CoreAPI$1.getPlatform = original.getPlatform;
|
|
2231
2239
|
CoreAPI$1.getConfig = original.getConfig;
|
|
2232
2240
|
CoreAPI$1.getBoxInfo = original.getBoxInfo;
|
|
2233
|
-
CoreAPI$1.getSignInfo = original.getSignInfo;
|
|
2234
2241
|
CoreAPI$1.getDeviceInfo = original.getDeviceInfo;
|
|
2235
|
-
CoreAPI$1.getSignGroupInfo = original.getSignGroupInfo;
|
|
2236
2242
|
CoreAPI$1.shell = original.shell;
|
|
2237
2243
|
CoreAPI$1.getVolume = original.getVolume;
|
|
2238
2244
|
CoreAPI$1.setVolume = original.setVolume;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cutos/core",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.7",
|
|
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>
|
|
@@ -341,12 +344,8 @@ export interface CoreAPI {
|
|
|
341
344
|
getConfig<TResult = unknown>(): Promise<TResult>;
|
|
342
345
|
getBoxInfo<TResult = unknown>(callback: CutosCallback<TResult>): boolean;
|
|
343
346
|
getBoxInfo<TResult = unknown>(): Promise<TResult>;
|
|
344
|
-
getSignInfo<TResult = unknown>(callback: CutosCallback<TResult>): boolean;
|
|
345
|
-
getSignInfo<TResult = unknown>(): Promise<TResult>;
|
|
346
347
|
getDeviceInfo<TResult = unknown>(callback: CutosCallback<TResult>): boolean;
|
|
347
348
|
getDeviceInfo<TResult = unknown>(): Promise<TResult>;
|
|
348
|
-
getSignGroupInfo<TResult = unknown>(callback: CutosCallback<TResult>): boolean;
|
|
349
|
-
getSignGroupInfo<TResult = unknown>(): Promise<TResult>;
|
|
350
349
|
getIPC(destAddress?: string): IPC;
|
|
351
350
|
getNotification(): Notification;
|
|
352
351
|
getLogger(): Logger;
|
|
@@ -389,9 +388,7 @@ export interface CutosMockOptions {
|
|
|
389
388
|
platform?: unknown;
|
|
390
389
|
config?: unknown;
|
|
391
390
|
boxInfo?: unknown;
|
|
392
|
-
signInfo?: unknown;
|
|
393
391
|
deviceInfo?: unknown;
|
|
394
|
-
signGroupInfo?: unknown;
|
|
395
392
|
volume?: number;
|
|
396
393
|
capabilities?: Record<string, CutosMockCapabilityDefinition>;
|
|
397
394
|
}
|