@cutos/core 3.2.5 → 3.2.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 CHANGED
@@ -112,7 +112,7 @@ CoreAPI.getVersion();
112
112
  - Return result example:
113
113
 
114
114
  ```
115
- "3.2.5"
115
+ "3.2.7"
116
116
  ```
117
117
 
118
118
  ### CoreAPI.getPlatform
@@ -398,7 +398,19 @@ let ipc = CoreAPI.getIPC([destAddress]);
398
398
 
399
399
  * destAddress: optional parameter, target IP address, used for inter-device process communication
400
400
 
401
- ![PNG](/img/IPC.png)
401
+ ![ipc](https://oss.cut-os.com/resources/developer/images/ipc.jpg)
402
+
403
+ ### ipc.sendTo
404
+
405
+ Send IPC information
406
+
407
+ ```js
408
+ ipc.sendTo(channel, args, callback = null);
409
+ ```
410
+
411
+ * channel: channel name
412
+ * args: information to send
413
+ * callback: callback function
402
414
 
403
415
  ### ipc.on
404
416
 
@@ -409,18 +421,19 @@ ipc.on(channel, listener);
409
421
  ```
410
422
 
411
423
  * channel: channel name
412
- * listener: listener function (data)
424
+ * listener: listener function (args, context)
413
425
 
414
- ### ipc.sendTo
426
+ ### ipc.sendResponse
415
427
 
416
- Send IPC information
428
+ The receiver replies to the message
417
429
 
418
430
  ```js
419
- ipc.sendTo(channel, data);
431
+ ipc.sendResponse(context, result, error = null);
420
432
  ```
421
433
 
422
- * channel: channel name
423
- * data: sent information
434
+ * context: context information
435
+ * result: reply message content
436
+ * error: error message
424
437
 
425
438
  ##### Local device communication example:
426
439
 
@@ -430,11 +443,10 @@ import {CoreAPI} from '@cutos/core';
430
443
  CoreAPI.init();
431
444
 
432
445
  let ipc = CoreAPI.getIPC();
433
- //Listen for IPC information
434
- let ipcListener = function (data) {
435
- console.log(data);
436
- };
437
- ipc.on("channel-1", ipcListener);
446
+ //Listen to IPC information
447
+ ipc.on("channel-1", function (args, context) {
448
+ console.log(args);
449
+ });
438
450
  //Send IPC information
439
451
  ipc.sendTo("channel-1", {event: "event-1", msg: "msg-1"});
440
452
  ```
@@ -450,29 +462,51 @@ ipc.sendTo("channel-1", {event: "event-1", msg: "msg-1"});
450
462
 
451
463
  ##### Example of inter-device process communication:
452
464
 
465
+ ##### Sender
466
+ IP:192.168.1.136
453
467
  ```js
454
468
  import {CoreAPI} from '@cutos/core';
455
469
 
456
470
  CoreAPI.init();
457
-
471
+ //Destination IP:192.168.1.149
458
472
  let ipc = CoreAPI.getIPC("192.168.1.149");
473
+ //Send IPC information
474
+ ipc.sendTo("channel-2", {event: "event-2", msg: "msg-2"}, (result, error) => {
475
+ if (!error) {
476
+ console.log(result)
477
+ }
478
+ });
479
+ ```
480
+ - Return result example:
481
+
482
+ ```json
483
+ "Received"
484
+ ```
485
+
486
+ ##### Receiver
487
+ IP:192.168.1.149
488
+ ```js
489
+ import {CoreAPI} from '@cutos/core';
490
+
491
+ CoreAPI.init();
492
+ //Target IP:192.168.1.136
493
+ let ipc = CoreAPI.getIPC("192.168.1.136");
459
494
  //Listen for IPC information
460
- let ipcListener = function (data) {
461
- console.log(data);
495
+ let ipcListener = function (args, context) {
496
+ console.log(args);
497
+ ipc.sendResponse(context, "Received");
462
498
  }
463
499
  ipc.on("channel-2", ipcListener);
464
- //Send IPC information
465
- ipc.sendTo("channel-2", {event: "event-2", msg: "msg-2"});
466
500
  ```
467
501
 
468
502
  - Return result example:
469
503
 
470
504
  ```json
471
505
  {
472
- "event": "event-2",
473
- "msg": "msg-2"
506
+ "event": "event-2",
507
+ "msg": "msg-2"
474
508
  }
475
- ```
509
+ ```
476
510
 
477
511
 
478
512
  # Database API
@@ -1012,15 +1046,15 @@ device.onData(listener)
1012
1046
 
1013
1047
  ##### 1. onData and sendData
1014
1048
 
1015
- ![ddr1.png](..%2Fimg%2Fddr1.png)
1049
+ ![ddr1.png](https://oss.cut-os.com/resources/developer/images/ddr1.png)
1016
1050
 
1017
1051
  ##### 2. sendCommand (without callback function) and onCommand
1018
1052
 
1019
- ![ddr2.png](..%2Fimg%2Fddr2.png)
1053
+ ![ddr2.png](https://oss.cut-os.com/resources/developer/images/ddr2.png)
1020
1054
 
1021
1055
  ##### 3. sendCommand (with callback function) and onCommand
1022
1056
 
1023
- ![ddr3.png](..%2Fimg%2Fddr3.png)
1057
+ ![ddr3.png](https://oss.cut-os.com/resources/developer/images/ddr3.png)
1024
1058
 
1025
1059
  ## Device driver management template
1026
1060
 
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 = "3.2.5";
401
+ var version = "3.2.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";
@@ -445,7 +445,7 @@ var require$$3 = {
445
445
  };
446
446
 
447
447
  /**
448
- * Copyright (C) 2010-2023 - SipTimes Technologies Corporation - All rights reserved.
448
+ * Copyright (C) 2010-2024 - SipTimes Technologies Corporation - All rights reserved.
449
449
  */
450
450
 
451
451
  const {v4: uuidv4} = require$$0;
@@ -527,18 +527,26 @@ function doCallback(id, body, err) {
527
527
  return true;
528
528
  }
529
529
 
530
+ /**
531
+ * @Database
532
+ * The basic table structure of CUTOS database is in Key-Value format, and Value can be any json object.
533
+ */
530
534
  class Database {
531
535
  KEY_TYPE_TEXT = "TEXT";
532
536
  KEY_TYPE_INTEGER = "INTEGER";
533
537
 
534
538
  /**
535
539
  * The constructor of Database
536
- * @param {string} db - name of database, can be null
540
+ * @param {String} [db] - name of database, can be null
537
541
  */
538
542
  constructor(db) {
539
543
  this.db = db;
540
544
  }
541
545
 
546
+ /**
547
+ * Connect to database
548
+ * @param {Function} callback
549
+ */
542
550
  connect(callback) {
543
551
  let body = {
544
552
  cmd: "db.connect", db: this.db
@@ -546,6 +554,11 @@ class Database {
546
554
  publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
547
555
  }
548
556
 
557
+ /**
558
+ * Run sql
559
+ * @param {String} sql - execute sql statement
560
+ * @param {Function} callback
561
+ */
549
562
  run(sql, callback) {
550
563
  let body = {
551
564
  db: this.db, cmd: "db.run", sql: sql
@@ -559,6 +572,12 @@ class Database {
559
572
  }
560
573
 
561
574
  Database.Table = class {
575
+
576
+ /**
577
+ * @constructor The constructor of Table
578
+ * @param {String} name - name of table, can not be null
579
+ * @param {Object} database - database object, can not be null
580
+ */
562
581
  constructor(name, database) {
563
582
  this.name = name;
564
583
  this.database = database;
@@ -569,6 +588,11 @@ Database.Table = class {
569
588
  }
570
589
  }
571
590
 
591
+ /**
592
+ * Create a Table
593
+ * @param {Object} [opts]
594
+ * @param {Function} callback
595
+ */
572
596
  create(opts, callback) {
573
597
  if (typeof opts === "function") {
574
598
  callback = opts;
@@ -594,6 +618,12 @@ Database.Table = class {
594
618
  this.publishRequestMirror(cutosAPI$1.CORE.DATABASE, callback, body);
595
619
  }
596
620
 
621
+ /**
622
+ * Insert data
623
+ * @param {Object} value
624
+ * @param {Object} [opts]
625
+ * @param {Function} callback
626
+ */
597
627
  insert(value, opts, callback) {
598
628
  if (typeof opts === "function") {
599
629
  callback = opts;
@@ -618,6 +648,13 @@ Database.Table = class {
618
648
  this.publishRequestMirror(cutosAPI$1.CORE.DATABASE, callback, body);
619
649
  }
620
650
 
651
+ /**
652
+ * Insert data by key
653
+ * @param {String} key
654
+ * @param {Object} value
655
+ * @param {Object} [opts] - opts.tid - if exist it contains tid
656
+ * @param {Function} callback
657
+ */
621
658
  insertByKey(key, value, opts, callback) {
622
659
  if (typeof opts === "function") {
623
660
  callback = opts;
@@ -630,6 +667,12 @@ Database.Table = class {
630
667
  this.publishRequestMirror(cutosAPI$1.CORE.DATABASE, callback, body);
631
668
  }
632
669
 
670
+ /**
671
+ * Update data
672
+ * @param {Number} id
673
+ * @param {Object} value
674
+ * @param {Function} callback
675
+ */
633
676
  update(id, value, callback) {
634
677
  let body = {
635
678
  db: this.db, cmd: "db.table.update", name: this.name, id: id, value: value
@@ -644,6 +687,11 @@ Database.Table = class {
644
687
  publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
645
688
  }
646
689
 
690
+ /**
691
+ * delete data
692
+ * @param {Number} id
693
+ * @param {Function} callback
694
+ */
647
695
  delete(id, callback) {
648
696
  let body = {
649
697
  db: this.db, cmd: "db.table.delete", name: this.name, id: id
@@ -651,6 +699,11 @@ Database.Table = class {
651
699
  publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
652
700
  }
653
701
 
702
+ /**
703
+ * query data
704
+ * @param {Number} id
705
+ * @param {Function} callback
706
+ */
654
707
  query(id, callback) {
655
708
  let body = {
656
709
  db: this.db, cmd: "db.table.query", name: this.name, id: id
@@ -658,6 +711,11 @@ Database.Table = class {
658
711
  publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
659
712
  }
660
713
 
714
+ /**
715
+ * query data by key
716
+ * @param {String} key
717
+ * @param {Function} callback
718
+ */
661
719
  queryByKey(key, callback) {
662
720
  let body = {
663
721
  db: this.db, cmd: "db.table.queryByKey", name: this.name, key: key
@@ -665,6 +723,11 @@ Database.Table = class {
665
723
  publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
666
724
  }
667
725
 
726
+ /**
727
+ * query data by tid
728
+ * @param {Number} tid
729
+ * @param {Function} callback
730
+ */
668
731
  queryByTid(tid, callback) {
669
732
  let body = {
670
733
  db: this.db, cmd: "db.table.queryByTid", name: this.name, tid: tid
@@ -672,6 +735,11 @@ Database.Table = class {
672
735
  publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
673
736
  }
674
737
 
738
+ /**
739
+ * query unsynced data by tid
740
+ * @param {Number} tid
741
+ * @param {Function} callback
742
+ */
675
743
  queryUnsynced(opts, callback) {
676
744
  if (typeof opts === "function") {
677
745
  callback = opts;
@@ -686,6 +754,10 @@ Database.Table = class {
686
754
  publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
687
755
  }
688
756
 
757
+ /**
758
+ * query all data
759
+ * @param {Function} callback
760
+ */
689
761
  queryAll(callback) {
690
762
  let body = {
691
763
  db: this.db, cmd: "db.table.queryAll", name: this.name
@@ -693,6 +765,11 @@ Database.Table = class {
693
765
  publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
694
766
  }
695
767
 
768
+ /**
769
+ * sync data
770
+ * @param {Number} id
771
+ * @param {Function} callback
772
+ */
696
773
  sync(id, callback) {
697
774
  let body = {
698
775
  db: this.db, cmd: "db.table.sync", name: this.name, id: id
@@ -733,9 +810,19 @@ Database.Table = class {
733
810
  };
734
811
 
735
812
  class Logger {
813
+
814
+ /**
815
+ * The constructor of logger
816
+ */
736
817
  constructor() {
737
818
  }
738
819
 
820
+ /**
821
+ * Information
822
+ * @param {String} remark
823
+ * @param {String} content
824
+ * @param {String} type
825
+ */
739
826
  info(remark, content, type = "LWA") {
740
827
  let body = {
741
828
  type: type, level: "info", remark: remark, content: content
@@ -743,6 +830,12 @@ class Logger {
743
830
  return publishRequest(cutosAPI$1.CORE_NORESP.LOGGER, null, body);
744
831
  }
745
832
 
833
+ /**
834
+ * Warning
835
+ * @param {String} remark
836
+ * @param {String} content
837
+ * @param {String} type
838
+ */
746
839
  warning(remark, content, type = "LWA") {
747
840
  let body = {
748
841
  type: type, level: "warning", remark: remark, content: content
@@ -750,6 +843,12 @@ class Logger {
750
843
  return publishRequest(cutosAPI$1.CORE_NORESP.LOGGER, null, body);
751
844
  }
752
845
 
846
+ /**
847
+ * Error
848
+ * @param {String} remark
849
+ * @param {String} content
850
+ * @param {String} type
851
+ */
753
852
  error(remark, content, type = "LWA") {
754
853
  let body = {
755
854
  type: type, level: "error", remark: remark, content: content
@@ -757,6 +856,12 @@ class Logger {
757
856
  return publishRequest(cutosAPI$1.CORE_NORESP.LOGGER, null, body);
758
857
  }
759
858
 
859
+ /**
860
+ * Debug
861
+ * @param {String} remark
862
+ * @param {String} content
863
+ * @param {String} type
864
+ */
760
865
  debug(remark, content, type = "LWA") {
761
866
  let body = {
762
867
  type: type, level: "debug", remark: remark, content: content
@@ -776,13 +881,41 @@ class IPC {
776
881
  }
777
882
  }
778
883
 
779
- sendTo(channel, args) {
884
+ /**
885
+ * send message to channel
886
+ * @param channel
887
+ * @param args
888
+ * @param callback (result, error):void
889
+ * @returns {boolean}
890
+ */
891
+ sendTo(channel, args, callback = null) {
780
892
  let body = {};
781
893
  body.channel = channel;
782
894
  body.args = args;
783
- return publishRequest(cutosAPI$1.CORE_NORESP.IPC, null, body, this.destAddress);
895
+ return publishRequest(cutosAPI$1.CORE_NORESP.IPC, callback, body, this.destAddress);
784
896
  }
785
897
 
898
+ /**
899
+ * 发送需要callback的消息的响应
900
+ * @param context listener收到的context
901
+ * @param result
902
+ * @param error
903
+ */
904
+ sendResponse(context, result, error = null) {
905
+ let response = {};
906
+ response.context = {};
907
+ response.context.destAddress = context.sourceAddress;
908
+ response.id = context.id;
909
+ response.result = result;
910
+ response.err = error;
911
+ client.publish(cutosAPI$1.CORE_NORESP.IPC, JSON.stringify(response));
912
+ }
913
+
914
+ /**
915
+ * Listen IPC form channel
916
+ * @param channel
917
+ * @param listener (args, context) the context use when sendResponse
918
+ */
786
919
  on(channel, listener) {
787
920
  listenerMap.set(channel, listener);
788
921
  }
@@ -793,17 +926,33 @@ class IPC {
793
926
  }
794
927
 
795
928
  class Notification {
929
+
930
+ /**
931
+ * The constructor of Notification
932
+ */
796
933
  constructor() {
797
934
  }
798
935
 
936
+ /**
937
+ * Register notification listener function
938
+ * @param {Function} listener - listener function (data)
939
+ */
799
940
  register(listener) {
800
941
  listenerMap.set(cutosAPI$1.CORE_APP.NOTIFICATION, listener);
801
942
  }
802
943
 
944
+ /**
945
+ * Unregister, used to cancel the registration of notification
946
+ */
803
947
  unregister() {
804
948
  listenerMap.delete(cutosAPI$1.CORE_APP.NOTIFICATION);
805
949
  }
806
950
 
951
+ /**
952
+ * Cancel registration, used to cancel the registration of notification
953
+ * @param {String} event - event name
954
+ * @param {String} msg - event content
955
+ */
807
956
  emit(event, msg) {
808
957
  client.publish(cutosAPI$1.CORE_APP.NOTIFICATION, JSON.stringify({event: event, msg: msg}));
809
958
  return true;
@@ -844,7 +993,7 @@ class Heartbeat {
844
993
 
845
994
  class Device {
846
995
  /**
847
- *
996
+ * The constructor of Device
848
997
  * @param name
849
998
  * @param type
850
999
  */
@@ -880,7 +1029,7 @@ class Device {
880
1029
  }
881
1030
 
882
1031
  /**
883
- *
1032
+ * Device initialize
884
1033
  * @param callback(result, error)
885
1034
  * @param opts
886
1035
  */
@@ -908,10 +1057,18 @@ class Device {
908
1057
  });
909
1058
  }
910
1059
 
1060
+ /**
1061
+ * Get device status
1062
+ * @param {Function} listener
1063
+ */
911
1064
  onStatus(listener) {
912
1065
  this.statusListener = listener;
913
1066
  }
914
1067
 
1068
+ /**
1069
+ * Get device status
1070
+ * @param {Function} listener
1071
+ */
915
1072
  getCurrentStatus() {
916
1073
  return this.msg;
917
1074
  }
@@ -926,6 +1083,10 @@ class Device {
926
1083
  publishRequest(this.topicCommand, callback, command);
927
1084
  }
928
1085
 
1086
+ /**
1087
+ * Receive data sent by the driver
1088
+ * @param listener - listener(data)
1089
+ */
929
1090
  onData(listener) {
930
1091
  if (!listenerMap.has(this.topicData)) {
931
1092
  client.subscribe(this.topicData); // receive data from device
@@ -953,6 +1114,13 @@ class Device {
953
1114
  }
954
1115
 
955
1116
  class Driver {
1117
+
1118
+ /**
1119
+ * The constructor of Driver
1120
+ * @param name
1121
+ * @param type
1122
+ * @param counter
1123
+ */
956
1124
  constructor(name = 'default-driver-name', type = cutosAPI$1.DEVICE.DEFAULT, counter = 10) {
957
1125
  this.name = name;
958
1126
  this.type = type;
@@ -979,6 +1147,10 @@ class Driver {
979
1147
  this.statusInfo.info = info;
980
1148
  }
981
1149
 
1150
+ /**
1151
+ * Send data to the device
1152
+ * @param data
1153
+ */
982
1154
  sendData(data) {
983
1155
  client.publish(this.topicData, JSON.stringify(data));
984
1156
  }
@@ -988,7 +1160,7 @@ class Driver {
988
1160
  }
989
1161
 
990
1162
  /**
991
- *
1163
+ * Receive device commands
992
1164
  * @param listener(command, callback(result))
993
1165
  */
994
1166
  onCommand(listener) {
@@ -1017,6 +1189,11 @@ class CutosError {
1017
1189
  }
1018
1190
 
1019
1191
  const CoreAPI$2 = {
1192
+ /**
1193
+ * Initialization of CUTOS core
1194
+ * @param {string} host CUTOS address.When host is equal to null, it takes the value 'localhost'. During development, it can be changed to the target address (the device address where CUTOS is installed), such as: '192.168.1.11'
1195
+ * @param {Function} callback callback(result, error)
1196
+ */
1020
1197
  init(host = 'localhost', callback) {
1021
1198
  let brokerUrl;
1022
1199
  if (host && host.startsWith('ws://') && host.endsWith(':1883')) {
@@ -1058,6 +1235,11 @@ const CoreAPI$2 = {
1058
1235
  // console.debug(topic.toString() + message.toString());
1059
1236
  let _message = JSON.parse(message);
1060
1237
  if (topic === cutosAPI$1.CORE_NORESP.IPC + '-endpoint') { // ipc
1238
+ // process response message
1239
+ if (_message.id) {
1240
+ doCallback(_message.id, _message.result, _message.err);
1241
+ return
1242
+ }
1061
1243
  let listener = listenerMap.get(_message.body.channel);
1062
1244
  if (listener !== undefined) {
1063
1245
  listener(_message.body.args, _message.context);
@@ -1091,26 +1273,49 @@ const CoreAPI$2 = {
1091
1273
  return !!client && client.connected;
1092
1274
  },
1093
1275
 
1276
+ /**
1277
+ * Get platform version information
1278
+ */
1094
1279
  getVersion() {
1095
1280
  return packageJson.version ;
1096
1281
  },
1097
1282
 
1283
+ /**
1284
+ * Get platform information
1285
+ * @param {Function} callback - callback(result)
1286
+ */
1098
1287
  getPlatform(callback) {
1099
1288
  return publishRequest(cutosAPI$1.CORE.PLATFORM, callback);
1100
1289
  },
1101
1290
 
1291
+ /**
1292
+ * Get configuration information
1293
+ * @param {Function} callback - callback(result)
1294
+ */
1102
1295
  getConfig(callback) {
1103
1296
  return publishRequest(cutosAPI$1.CORE.CONFIG, callback);
1104
1297
  },
1105
1298
 
1299
+ /**
1300
+ * Get host information
1301
+ * @param {Function} callback - callback(result)
1302
+ */
1106
1303
  getBoxInfo(callback) {
1107
1304
  return publishRequest(cutosAPI$1.CORE.BOX_INFO, callback);
1108
1305
  },
1109
1306
 
1307
+ /**
1308
+ * Get sign information
1309
+ * @param {Function} callback - callback(result)
1310
+ */
1110
1311
  getSignInfo(callback) {
1111
1312
  return publishRequest(cutosAPI$1.CORE.SIGN_INFO, callback);
1112
1313
  },
1113
1314
 
1315
+ /**
1316
+ * Get device information
1317
+ * @param {Function} callback - callback(result)
1318
+ */
1114
1319
  getDeviceInfo(callback) {
1115
1320
  return publishRequest(cutosAPI$1.CORE.DEVICE_INFO, callback);
1116
1321
  },
@@ -1119,10 +1324,17 @@ const CoreAPI$2 = {
1119
1324
  return publishRequest(cutosAPI$1.CORE.SIGN_GROUP_INFO, callback);
1120
1325
  },
1121
1326
 
1327
+ /**
1328
+ * Get IPC instance object
1329
+ * @param {String} destAddress - optional parameter, target IP address, used for inter-device process communication
1330
+ */
1122
1331
  getIPC(destAddress) {
1123
1332
  return new IPC(destAddress);
1124
1333
  },
1125
1334
 
1335
+ /**
1336
+ * Get notification information instance object
1337
+ */
1126
1338
  getNotification() {
1127
1339
  if (!_notification) {
1128
1340
  _notification = new Notification();
@@ -1130,6 +1342,9 @@ const CoreAPI$2 = {
1130
1342
  return _notification;
1131
1343
  },
1132
1344
 
1345
+ /**
1346
+ * Get the log instance object
1347
+ */
1133
1348
  getLogger() {
1134
1349
  if (!_logger) {
1135
1350
  _logger = new Logger();
@@ -1137,18 +1352,38 @@ const CoreAPI$2 = {
1137
1352
  return _logger;
1138
1353
  },
1139
1354
 
1355
+ /**
1356
+ * Shell command execution
1357
+ * @param {String} command - command
1358
+ * @param {Function} callback - callback(result, error)
1359
+ */
1140
1360
  shell(command, callback) {
1141
1361
  return publishRequest(cutosAPI$1.CORE.SHELL, callback, command);
1142
1362
  },
1143
1363
 
1364
+ /**
1365
+ * Get the volume
1366
+ * @param {Function} callback - callback(result)
1367
+ */
1144
1368
  getVolume(callback) {
1145
1369
  return publishRequest(cutosAPI$1.CORE.GET_VOLUME, callback);
1146
1370
  },
1147
1371
 
1372
+ /**
1373
+ * Set the volume
1374
+ * @param {Number} vol - volume:[0-100]
1375
+ * @param {Function} callback - callback(result)
1376
+ */
1148
1377
  setVolume(vol, callback) {
1149
1378
  return publishRequest(cutosAPI$1.CORE.SET_VOLUME, callback, vol);
1150
1379
  },
1151
1380
 
1381
+ /**
1382
+ * Set proxy to solve LWA cross-domain problem
1383
+ * @param {String} api - interface name
1384
+ * @param {String} target - target address
1385
+ * @param {Function} callback - callback(result, error)
1386
+ */
1152
1387
  setHttpProxy(api, target, callback) {
1153
1388
  return publishRequest(cutosAPI$1.CORE.SET_HTTP_PROXY, callback, {api, target});
1154
1389
  }
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 = "3.2.5";
693
+ var version = "3.2.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";
@@ -737,7 +737,7 @@ var require$$3 = {
737
737
  };
738
738
 
739
739
  /**
740
- * Copyright (C) 2010-2023 - SipTimes Technologies Corporation - All rights reserved.
740
+ * Copyright (C) 2010-2024 - SipTimes Technologies Corporation - All rights reserved.
741
741
  */
742
742
 
743
743
  const {v4: uuidv4} = require$$0;
@@ -819,18 +819,26 @@ function doCallback(id, body, err) {
819
819
  return true;
820
820
  }
821
821
 
822
+ /**
823
+ * @Database
824
+ * The basic table structure of CUTOS database is in Key-Value format, and Value can be any json object.
825
+ */
822
826
  class Database {
823
827
  KEY_TYPE_TEXT = "TEXT";
824
828
  KEY_TYPE_INTEGER = "INTEGER";
825
829
 
826
830
  /**
827
831
  * The constructor of Database
828
- * @param {string} db - name of database, can be null
832
+ * @param {String} [db] - name of database, can be null
829
833
  */
830
834
  constructor(db) {
831
835
  this.db = db;
832
836
  }
833
837
 
838
+ /**
839
+ * Connect to database
840
+ * @param {Function} callback
841
+ */
834
842
  connect(callback) {
835
843
  let body = {
836
844
  cmd: "db.connect", db: this.db
@@ -838,6 +846,11 @@ class Database {
838
846
  publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
839
847
  }
840
848
 
849
+ /**
850
+ * Run sql
851
+ * @param {String} sql - execute sql statement
852
+ * @param {Function} callback
853
+ */
841
854
  run(sql, callback) {
842
855
  let body = {
843
856
  db: this.db, cmd: "db.run", sql: sql
@@ -851,6 +864,12 @@ class Database {
851
864
  }
852
865
 
853
866
  Database.Table = class {
867
+
868
+ /**
869
+ * @constructor The constructor of Table
870
+ * @param {String} name - name of table, can not be null
871
+ * @param {Object} database - database object, can not be null
872
+ */
854
873
  constructor(name, database) {
855
874
  this.name = name;
856
875
  this.database = database;
@@ -861,6 +880,11 @@ Database.Table = class {
861
880
  }
862
881
  }
863
882
 
883
+ /**
884
+ * Create a Table
885
+ * @param {Object} [opts]
886
+ * @param {Function} callback
887
+ */
864
888
  create(opts, callback) {
865
889
  if (typeof opts === "function") {
866
890
  callback = opts;
@@ -886,6 +910,12 @@ Database.Table = class {
886
910
  this.publishRequestMirror(cutosAPI$1.CORE.DATABASE, callback, body);
887
911
  }
888
912
 
913
+ /**
914
+ * Insert data
915
+ * @param {Object} value
916
+ * @param {Object} [opts]
917
+ * @param {Function} callback
918
+ */
889
919
  insert(value, opts, callback) {
890
920
  if (typeof opts === "function") {
891
921
  callback = opts;
@@ -910,6 +940,13 @@ Database.Table = class {
910
940
  this.publishRequestMirror(cutosAPI$1.CORE.DATABASE, callback, body);
911
941
  }
912
942
 
943
+ /**
944
+ * Insert data by key
945
+ * @param {String} key
946
+ * @param {Object} value
947
+ * @param {Object} [opts] - opts.tid - if exist it contains tid
948
+ * @param {Function} callback
949
+ */
913
950
  insertByKey(key, value, opts, callback) {
914
951
  if (typeof opts === "function") {
915
952
  callback = opts;
@@ -922,6 +959,12 @@ Database.Table = class {
922
959
  this.publishRequestMirror(cutosAPI$1.CORE.DATABASE, callback, body);
923
960
  }
924
961
 
962
+ /**
963
+ * Update data
964
+ * @param {Number} id
965
+ * @param {Object} value
966
+ * @param {Function} callback
967
+ */
925
968
  update(id, value, callback) {
926
969
  let body = {
927
970
  db: this.db, cmd: "db.table.update", name: this.name, id: id, value: value
@@ -936,6 +979,11 @@ Database.Table = class {
936
979
  publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
937
980
  }
938
981
 
982
+ /**
983
+ * delete data
984
+ * @param {Number} id
985
+ * @param {Function} callback
986
+ */
939
987
  delete(id, callback) {
940
988
  let body = {
941
989
  db: this.db, cmd: "db.table.delete", name: this.name, id: id
@@ -943,6 +991,11 @@ Database.Table = class {
943
991
  publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
944
992
  }
945
993
 
994
+ /**
995
+ * query data
996
+ * @param {Number} id
997
+ * @param {Function} callback
998
+ */
946
999
  query(id, callback) {
947
1000
  let body = {
948
1001
  db: this.db, cmd: "db.table.query", name: this.name, id: id
@@ -950,6 +1003,11 @@ Database.Table = class {
950
1003
  publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
951
1004
  }
952
1005
 
1006
+ /**
1007
+ * query data by key
1008
+ * @param {String} key
1009
+ * @param {Function} callback
1010
+ */
953
1011
  queryByKey(key, callback) {
954
1012
  let body = {
955
1013
  db: this.db, cmd: "db.table.queryByKey", name: this.name, key: key
@@ -957,6 +1015,11 @@ Database.Table = class {
957
1015
  publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
958
1016
  }
959
1017
 
1018
+ /**
1019
+ * query data by tid
1020
+ * @param {Number} tid
1021
+ * @param {Function} callback
1022
+ */
960
1023
  queryByTid(tid, callback) {
961
1024
  let body = {
962
1025
  db: this.db, cmd: "db.table.queryByTid", name: this.name, tid: tid
@@ -964,6 +1027,11 @@ Database.Table = class {
964
1027
  publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
965
1028
  }
966
1029
 
1030
+ /**
1031
+ * query unsynced data by tid
1032
+ * @param {Number} tid
1033
+ * @param {Function} callback
1034
+ */
967
1035
  queryUnsynced(opts, callback) {
968
1036
  if (typeof opts === "function") {
969
1037
  callback = opts;
@@ -978,6 +1046,10 @@ Database.Table = class {
978
1046
  publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
979
1047
  }
980
1048
 
1049
+ /**
1050
+ * query all data
1051
+ * @param {Function} callback
1052
+ */
981
1053
  queryAll(callback) {
982
1054
  let body = {
983
1055
  db: this.db, cmd: "db.table.queryAll", name: this.name
@@ -985,6 +1057,11 @@ Database.Table = class {
985
1057
  publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
986
1058
  }
987
1059
 
1060
+ /**
1061
+ * sync data
1062
+ * @param {Number} id
1063
+ * @param {Function} callback
1064
+ */
988
1065
  sync(id, callback) {
989
1066
  let body = {
990
1067
  db: this.db, cmd: "db.table.sync", name: this.name, id: id
@@ -1025,9 +1102,19 @@ Database.Table = class {
1025
1102
  };
1026
1103
 
1027
1104
  class Logger {
1105
+
1106
+ /**
1107
+ * The constructor of logger
1108
+ */
1028
1109
  constructor() {
1029
1110
  }
1030
1111
 
1112
+ /**
1113
+ * Information
1114
+ * @param {String} remark
1115
+ * @param {String} content
1116
+ * @param {String} type
1117
+ */
1031
1118
  info(remark, content, type = "LWA") {
1032
1119
  let body = {
1033
1120
  type: type, level: "info", remark: remark, content: content
@@ -1035,6 +1122,12 @@ class Logger {
1035
1122
  return publishRequest(cutosAPI$1.CORE_NORESP.LOGGER, null, body);
1036
1123
  }
1037
1124
 
1125
+ /**
1126
+ * Warning
1127
+ * @param {String} remark
1128
+ * @param {String} content
1129
+ * @param {String} type
1130
+ */
1038
1131
  warning(remark, content, type = "LWA") {
1039
1132
  let body = {
1040
1133
  type: type, level: "warning", remark: remark, content: content
@@ -1042,6 +1135,12 @@ class Logger {
1042
1135
  return publishRequest(cutosAPI$1.CORE_NORESP.LOGGER, null, body);
1043
1136
  }
1044
1137
 
1138
+ /**
1139
+ * Error
1140
+ * @param {String} remark
1141
+ * @param {String} content
1142
+ * @param {String} type
1143
+ */
1045
1144
  error(remark, content, type = "LWA") {
1046
1145
  let body = {
1047
1146
  type: type, level: "error", remark: remark, content: content
@@ -1049,6 +1148,12 @@ class Logger {
1049
1148
  return publishRequest(cutosAPI$1.CORE_NORESP.LOGGER, null, body);
1050
1149
  }
1051
1150
 
1151
+ /**
1152
+ * Debug
1153
+ * @param {String} remark
1154
+ * @param {String} content
1155
+ * @param {String} type
1156
+ */
1052
1157
  debug(remark, content, type = "LWA") {
1053
1158
  let body = {
1054
1159
  type: type, level: "debug", remark: remark, content: content
@@ -1068,13 +1173,41 @@ class IPC {
1068
1173
  }
1069
1174
  }
1070
1175
 
1071
- sendTo(channel, args) {
1176
+ /**
1177
+ * send message to channel
1178
+ * @param channel
1179
+ * @param args
1180
+ * @param callback (result, error):void
1181
+ * @returns {boolean}
1182
+ */
1183
+ sendTo(channel, args, callback = null) {
1072
1184
  let body = {};
1073
1185
  body.channel = channel;
1074
1186
  body.args = args;
1075
- return publishRequest(cutosAPI$1.CORE_NORESP.IPC, null, body, this.destAddress);
1187
+ return publishRequest(cutosAPI$1.CORE_NORESP.IPC, callback, body, this.destAddress);
1076
1188
  }
1077
1189
 
1190
+ /**
1191
+ * 发送需要callback的消息的响应
1192
+ * @param context listener收到的context
1193
+ * @param result
1194
+ * @param error
1195
+ */
1196
+ sendResponse(context, result, error = null) {
1197
+ let response = {};
1198
+ response.context = {};
1199
+ response.context.destAddress = context.sourceAddress;
1200
+ response.id = context.id;
1201
+ response.result = result;
1202
+ response.err = error;
1203
+ client.publish(cutosAPI$1.CORE_NORESP.IPC, JSON.stringify(response));
1204
+ }
1205
+
1206
+ /**
1207
+ * Listen IPC form channel
1208
+ * @param channel
1209
+ * @param listener (args, context) the context use when sendResponse
1210
+ */
1078
1211
  on(channel, listener) {
1079
1212
  listenerMap.set(channel, listener);
1080
1213
  }
@@ -1085,17 +1218,33 @@ class IPC {
1085
1218
  }
1086
1219
 
1087
1220
  class Notification {
1221
+
1222
+ /**
1223
+ * The constructor of Notification
1224
+ */
1088
1225
  constructor() {
1089
1226
  }
1090
1227
 
1228
+ /**
1229
+ * Register notification listener function
1230
+ * @param {Function} listener - listener function (data)
1231
+ */
1091
1232
  register(listener) {
1092
1233
  listenerMap.set(cutosAPI$1.CORE_APP.NOTIFICATION, listener);
1093
1234
  }
1094
1235
 
1236
+ /**
1237
+ * Unregister, used to cancel the registration of notification
1238
+ */
1095
1239
  unregister() {
1096
1240
  listenerMap.delete(cutosAPI$1.CORE_APP.NOTIFICATION);
1097
1241
  }
1098
1242
 
1243
+ /**
1244
+ * Cancel registration, used to cancel the registration of notification
1245
+ * @param {String} event - event name
1246
+ * @param {String} msg - event content
1247
+ */
1099
1248
  emit(event, msg) {
1100
1249
  client.publish(cutosAPI$1.CORE_APP.NOTIFICATION, JSON.stringify({event: event, msg: msg}));
1101
1250
  return true;
@@ -1136,7 +1285,7 @@ class Heartbeat {
1136
1285
 
1137
1286
  class Device {
1138
1287
  /**
1139
- *
1288
+ * The constructor of Device
1140
1289
  * @param name
1141
1290
  * @param type
1142
1291
  */
@@ -1172,7 +1321,7 @@ class Device {
1172
1321
  }
1173
1322
 
1174
1323
  /**
1175
- *
1324
+ * Device initialize
1176
1325
  * @param callback(result, error)
1177
1326
  * @param opts
1178
1327
  */
@@ -1200,10 +1349,18 @@ class Device {
1200
1349
  });
1201
1350
  }
1202
1351
 
1352
+ /**
1353
+ * Get device status
1354
+ * @param {Function} listener
1355
+ */
1203
1356
  onStatus(listener) {
1204
1357
  this.statusListener = listener;
1205
1358
  }
1206
1359
 
1360
+ /**
1361
+ * Get device status
1362
+ * @param {Function} listener
1363
+ */
1207
1364
  getCurrentStatus() {
1208
1365
  return this.msg;
1209
1366
  }
@@ -1218,6 +1375,10 @@ class Device {
1218
1375
  publishRequest(this.topicCommand, callback, command);
1219
1376
  }
1220
1377
 
1378
+ /**
1379
+ * Receive data sent by the driver
1380
+ * @param listener - listener(data)
1381
+ */
1221
1382
  onData(listener) {
1222
1383
  if (!listenerMap.has(this.topicData)) {
1223
1384
  client.subscribe(this.topicData); // receive data from device
@@ -1245,6 +1406,13 @@ class Device {
1245
1406
  }
1246
1407
 
1247
1408
  class Driver {
1409
+
1410
+ /**
1411
+ * The constructor of Driver
1412
+ * @param name
1413
+ * @param type
1414
+ * @param counter
1415
+ */
1248
1416
  constructor(name = 'default-driver-name', type = cutosAPI$1.DEVICE.DEFAULT, counter = 10) {
1249
1417
  this.name = name;
1250
1418
  this.type = type;
@@ -1271,6 +1439,10 @@ class Driver {
1271
1439
  this.statusInfo.info = info;
1272
1440
  }
1273
1441
 
1442
+ /**
1443
+ * Send data to the device
1444
+ * @param data
1445
+ */
1274
1446
  sendData(data) {
1275
1447
  client.publish(this.topicData, JSON.stringify(data));
1276
1448
  }
@@ -1280,7 +1452,7 @@ class Driver {
1280
1452
  }
1281
1453
 
1282
1454
  /**
1283
- *
1455
+ * Receive device commands
1284
1456
  * @param listener(command, callback(result))
1285
1457
  */
1286
1458
  onCommand(listener) {
@@ -1309,6 +1481,11 @@ class CutosError {
1309
1481
  }
1310
1482
 
1311
1483
  const CoreAPI$2 = {
1484
+ /**
1485
+ * Initialization of CUTOS core
1486
+ * @param {string} host CUTOS address.When host is equal to null, it takes the value 'localhost'. During development, it can be changed to the target address (the device address where CUTOS is installed), such as: '192.168.1.11'
1487
+ * @param {Function} callback callback(result, error)
1488
+ */
1312
1489
  init(host = 'localhost', callback) {
1313
1490
  let brokerUrl;
1314
1491
  if (host && host.startsWith('ws://') && host.endsWith(':1883')) {
@@ -1350,6 +1527,11 @@ const CoreAPI$2 = {
1350
1527
  // console.debug(topic.toString() + message.toString());
1351
1528
  let _message = JSON.parse(message);
1352
1529
  if (topic === cutosAPI$1.CORE_NORESP.IPC + '-endpoint') { // ipc
1530
+ // process response message
1531
+ if (_message.id) {
1532
+ doCallback(_message.id, _message.result, _message.err);
1533
+ return
1534
+ }
1353
1535
  let listener = listenerMap.get(_message.body.channel);
1354
1536
  if (listener !== undefined) {
1355
1537
  listener(_message.body.args, _message.context);
@@ -1383,26 +1565,49 @@ const CoreAPI$2 = {
1383
1565
  return !!client && client.connected;
1384
1566
  },
1385
1567
 
1568
+ /**
1569
+ * Get platform version information
1570
+ */
1386
1571
  getVersion() {
1387
1572
  return packageJson.version ;
1388
1573
  },
1389
1574
 
1575
+ /**
1576
+ * Get platform information
1577
+ * @param {Function} callback - callback(result)
1578
+ */
1390
1579
  getPlatform(callback) {
1391
1580
  return publishRequest(cutosAPI$1.CORE.PLATFORM, callback);
1392
1581
  },
1393
1582
 
1583
+ /**
1584
+ * Get configuration information
1585
+ * @param {Function} callback - callback(result)
1586
+ */
1394
1587
  getConfig(callback) {
1395
1588
  return publishRequest(cutosAPI$1.CORE.CONFIG, callback);
1396
1589
  },
1397
1590
 
1591
+ /**
1592
+ * Get host information
1593
+ * @param {Function} callback - callback(result)
1594
+ */
1398
1595
  getBoxInfo(callback) {
1399
1596
  return publishRequest(cutosAPI$1.CORE.BOX_INFO, callback);
1400
1597
  },
1401
1598
 
1599
+ /**
1600
+ * Get sign information
1601
+ * @param {Function} callback - callback(result)
1602
+ */
1402
1603
  getSignInfo(callback) {
1403
1604
  return publishRequest(cutosAPI$1.CORE.SIGN_INFO, callback);
1404
1605
  },
1405
1606
 
1607
+ /**
1608
+ * Get device information
1609
+ * @param {Function} callback - callback(result)
1610
+ */
1406
1611
  getDeviceInfo(callback) {
1407
1612
  return publishRequest(cutosAPI$1.CORE.DEVICE_INFO, callback);
1408
1613
  },
@@ -1411,10 +1616,17 @@ const CoreAPI$2 = {
1411
1616
  return publishRequest(cutosAPI$1.CORE.SIGN_GROUP_INFO, callback);
1412
1617
  },
1413
1618
 
1619
+ /**
1620
+ * Get IPC instance object
1621
+ * @param {String} destAddress - optional parameter, target IP address, used for inter-device process communication
1622
+ */
1414
1623
  getIPC(destAddress) {
1415
1624
  return new IPC(destAddress);
1416
1625
  },
1417
1626
 
1627
+ /**
1628
+ * Get notification information instance object
1629
+ */
1418
1630
  getNotification() {
1419
1631
  if (!_notification) {
1420
1632
  _notification = new Notification();
@@ -1422,6 +1634,9 @@ const CoreAPI$2 = {
1422
1634
  return _notification;
1423
1635
  },
1424
1636
 
1637
+ /**
1638
+ * Get the log instance object
1639
+ */
1425
1640
  getLogger() {
1426
1641
  if (!_logger) {
1427
1642
  _logger = new Logger();
@@ -1429,18 +1644,38 @@ const CoreAPI$2 = {
1429
1644
  return _logger;
1430
1645
  },
1431
1646
 
1647
+ /**
1648
+ * Shell command execution
1649
+ * @param {String} command - command
1650
+ * @param {Function} callback - callback(result, error)
1651
+ */
1432
1652
  shell(command, callback) {
1433
1653
  return publishRequest(cutosAPI$1.CORE.SHELL, callback, command);
1434
1654
  },
1435
1655
 
1656
+ /**
1657
+ * Get the volume
1658
+ * @param {Function} callback - callback(result)
1659
+ */
1436
1660
  getVolume(callback) {
1437
1661
  return publishRequest(cutosAPI$1.CORE.GET_VOLUME, callback);
1438
1662
  },
1439
1663
 
1664
+ /**
1665
+ * Set the volume
1666
+ * @param {Number} vol - volume:[0-100]
1667
+ * @param {Function} callback - callback(result)
1668
+ */
1440
1669
  setVolume(vol, callback) {
1441
1670
  return publishRequest(cutosAPI$1.CORE.SET_VOLUME, callback, vol);
1442
1671
  },
1443
1672
 
1673
+ /**
1674
+ * Set proxy to solve LWA cross-domain problem
1675
+ * @param {String} api - interface name
1676
+ * @param {String} target - target address
1677
+ * @param {Function} callback - callback(result, error)
1678
+ */
1444
1679
  setHttpProxy(api, target, callback) {
1445
1680
  return publishRequest(cutosAPI$1.CORE.SET_HTTP_PROXY, callback, {api, target});
1446
1681
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cutos/core",
3
- "version": "3.2.5",
3
+ "version": "3.2.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",