@cutos/core 3.2.0 → 3.2.1

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/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.0";
401
+ var version = "3.2.1";
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";
@@ -653,12 +653,12 @@ class Database {
653
653
  case "db.table.create":
654
654
  break;
655
655
  case "db.table.insert":
656
- body.id = dbResult.row;
657
- body.timestamp = dbResult.timestamp;
656
+ body.id = dbResult.msg.row;
657
+ body.timestamp = dbResult.msg.timestamp;
658
658
  break;
659
659
  case "db.table.insertById":
660
660
  case "db.table.insertByKey":
661
- body.timestamp = dbResult.timestamp;
661
+ body.timestamp = dbResult.msg.timestamp;
662
662
  break;
663
663
  }
664
664
  mirror.gwIPC.mirror(body, confirmCallback, {lwaName: mirror.lwaName});
@@ -803,6 +803,13 @@ class Heartbeat {
803
803
  }
804
804
 
805
805
  class Device {
806
+ /**
807
+ *
808
+ * @param name
809
+ * @param type
810
+ * @param callback(result, error)
811
+ * @param opts
812
+ */
806
813
  constructor(name = 'default-device-name', type = cutosAPI$1.DEVICE.DEFAULT, callback, opts) {
807
814
  this.name = name;
808
815
  this.type = type;
@@ -845,7 +852,13 @@ class Device {
845
852
 
846
853
  // response callback
847
854
  client.subscribe(this.topicResponse); // receive response from device
848
- listenerMap.set(this.topicResponse, callback);
855
+ listenerMap.set(this.topicResponse, ({status, msg}) => {
856
+ if (status) {
857
+ callback && callback(`Driver ${this.type} loaded`);
858
+ } else {
859
+ callback && callback(null, msg);
860
+ }
861
+ });
849
862
  }
850
863
 
851
864
  onStatus(listener) {
@@ -856,6 +869,11 @@ class Device {
856
869
  return this.msg;
857
870
  }
858
871
 
872
+ /**
873
+ *
874
+ * @param command
875
+ * @param callback(result)
876
+ */
859
877
  sendCommand(command, callback) {
860
878
  // exam: command = {cmd: "connect", args: ""}
861
879
  publishRequest(this.topicCommand, callback, command);
@@ -865,9 +883,9 @@ class Device {
865
883
  if (!listenerMap.has(this.topicData)) {
866
884
  client.subscribe(this.topicData); // receive data from device
867
885
  }
868
- let _this = this;
869
- listenerMap.set(this.topicData, function (data) {
870
- _this.data = data;
886
+
887
+ listenerMap.set(this.topicData, (data) => {
888
+ this.data = data;
871
889
  listener(data);
872
890
  });
873
891
  }
@@ -919,13 +937,17 @@ class Driver {
919
937
  client.publish(topic, JSON.stringify(data));
920
938
  }
921
939
 
940
+ /**
941
+ *
942
+ * @param listener(command, callback(result))
943
+ */
922
944
  onCommand(listener) {
923
945
  if (listener) {
924
946
  let cmdListener = (message) => {
925
947
  // process command callback
926
948
  // message.context
927
949
  // message.context.id
928
- // message.body
950
+ // message.body
929
951
  listener(message.body, result => {
930
952
  publishResponse(this.topicCommand, message, result);
931
953
  });
@@ -937,10 +959,10 @@ class Driver {
937
959
  }
938
960
  }
939
961
 
940
- class CutosError extends Error {
962
+ class CutosError {
941
963
  constructor(name, message) {
942
- super(message);
943
964
  this.name = name;
965
+ this.message = message;
944
966
  }
945
967
  }
946
968
 
@@ -977,7 +999,7 @@ const CoreAPI$2 = {
977
999
  client.subscribe(cutosAPI$1.CORE_APP[api]);
978
1000
  }
979
1001
 
980
- !coreApiInitialized && callback && callback('CUTOS CORE connected.');
1002
+ !coreApiInitialized && callback && callback('CoreAPI init success');
981
1003
  coreApiInitialized = true;
982
1004
  });
983
1005
 
@@ -1100,21 +1122,26 @@ const {CoreAPI: CoreAPI$1, CoreClass: CoreClass$1} = cutos;
1100
1122
 
1101
1123
  const CoreSimulator$1 = {
1102
1124
  start: function (driver, port = 1883) {
1103
- CoreAPI$1.init(`ws://localhost:${port}`, result => {
1125
+ CoreAPI$1.init(`ws://localhost:${port}`, (result, error) => {
1126
+ if (error) {
1127
+ console.log('CUTOS Simulator error', error.message);
1128
+ return;
1129
+ }
1130
+
1104
1131
  console.log('CUTOS Simulator started and listening on port ', port);
1105
1132
 
1106
1133
  let drvDefault = new CoreClass$1.Driver();
1107
1134
  drvDefault.onCommand((command) => {
1108
1135
  console.log('drvDefault onCommand', JSON.stringify(command));
1109
1136
  if (command.cmd === "init") {
1110
- let rsp = {result: true};
1137
+ let result = {status: true};
1111
1138
  try {
1112
1139
  driver.init(command.args);
1113
1140
  } catch (e) {
1114
- rsp.msg = e.message;
1115
- rsp.result = false;
1141
+ result.msg = e.message;
1142
+ result.status = false;
1116
1143
  }
1117
- drvDefault.sendResponse(rsp, command.topicResponse);
1144
+ drvDefault.sendResponse(result, command.topicResponse);
1118
1145
  }
1119
1146
  });
1120
1147
  });
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.0";
693
+ var version = "3.2.1";
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";
@@ -945,12 +945,12 @@ class Database {
945
945
  case "db.table.create":
946
946
  break;
947
947
  case "db.table.insert":
948
- body.id = dbResult.row;
949
- body.timestamp = dbResult.timestamp;
948
+ body.id = dbResult.msg.row;
949
+ body.timestamp = dbResult.msg.timestamp;
950
950
  break;
951
951
  case "db.table.insertById":
952
952
  case "db.table.insertByKey":
953
- body.timestamp = dbResult.timestamp;
953
+ body.timestamp = dbResult.msg.timestamp;
954
954
  break;
955
955
  }
956
956
  mirror.gwIPC.mirror(body, confirmCallback, {lwaName: mirror.lwaName});
@@ -1095,6 +1095,13 @@ class Heartbeat {
1095
1095
  }
1096
1096
 
1097
1097
  class Device {
1098
+ /**
1099
+ *
1100
+ * @param name
1101
+ * @param type
1102
+ * @param callback(result, error)
1103
+ * @param opts
1104
+ */
1098
1105
  constructor(name = 'default-device-name', type = cutosAPI$1.DEVICE.DEFAULT, callback, opts) {
1099
1106
  this.name = name;
1100
1107
  this.type = type;
@@ -1137,7 +1144,13 @@ class Device {
1137
1144
 
1138
1145
  // response callback
1139
1146
  client.subscribe(this.topicResponse); // receive response from device
1140
- listenerMap.set(this.topicResponse, callback);
1147
+ listenerMap.set(this.topicResponse, ({status, msg}) => {
1148
+ if (status) {
1149
+ callback && callback(`Driver ${this.type} loaded`);
1150
+ } else {
1151
+ callback && callback(null, msg);
1152
+ }
1153
+ });
1141
1154
  }
1142
1155
 
1143
1156
  onStatus(listener) {
@@ -1148,6 +1161,11 @@ class Device {
1148
1161
  return this.msg;
1149
1162
  }
1150
1163
 
1164
+ /**
1165
+ *
1166
+ * @param command
1167
+ * @param callback(result)
1168
+ */
1151
1169
  sendCommand(command, callback) {
1152
1170
  // exam: command = {cmd: "connect", args: ""}
1153
1171
  publishRequest(this.topicCommand, callback, command);
@@ -1157,9 +1175,9 @@ class Device {
1157
1175
  if (!listenerMap.has(this.topicData)) {
1158
1176
  client.subscribe(this.topicData); // receive data from device
1159
1177
  }
1160
- let _this = this;
1161
- listenerMap.set(this.topicData, function (data) {
1162
- _this.data = data;
1178
+
1179
+ listenerMap.set(this.topicData, (data) => {
1180
+ this.data = data;
1163
1181
  listener(data);
1164
1182
  });
1165
1183
  }
@@ -1211,13 +1229,17 @@ class Driver {
1211
1229
  client.publish(topic, JSON.stringify(data));
1212
1230
  }
1213
1231
 
1232
+ /**
1233
+ *
1234
+ * @param listener(command, callback(result))
1235
+ */
1214
1236
  onCommand(listener) {
1215
1237
  if (listener) {
1216
1238
  let cmdListener = (message) => {
1217
1239
  // process command callback
1218
1240
  // message.context
1219
1241
  // message.context.id
1220
- // message.body
1242
+ // message.body
1221
1243
  listener(message.body, result => {
1222
1244
  publishResponse(this.topicCommand, message, result);
1223
1245
  });
@@ -1229,10 +1251,10 @@ class Driver {
1229
1251
  }
1230
1252
  }
1231
1253
 
1232
- class CutosError extends Error {
1254
+ class CutosError {
1233
1255
  constructor(name, message) {
1234
- super(message);
1235
1256
  this.name = name;
1257
+ this.message = message;
1236
1258
  }
1237
1259
  }
1238
1260
 
@@ -1269,7 +1291,7 @@ const CoreAPI$2 = {
1269
1291
  client.subscribe(cutosAPI$1.CORE_APP[api]);
1270
1292
  }
1271
1293
 
1272
- !coreApiInitialized && callback && callback('CUTOS CORE connected.');
1294
+ !coreApiInitialized && callback && callback('CoreAPI init success');
1273
1295
  coreApiInitialized = true;
1274
1296
  });
1275
1297
 
@@ -1392,21 +1414,26 @@ const {CoreAPI: CoreAPI$1, CoreClass: CoreClass$1} = cutos;
1392
1414
 
1393
1415
  const CoreSimulator$1 = {
1394
1416
  start: function (driver, port = 1883) {
1395
- CoreAPI$1.init(`ws://localhost:${port}`, result => {
1417
+ CoreAPI$1.init(`ws://localhost:${port}`, (result, error) => {
1418
+ if (error) {
1419
+ console.log('CUTOS Simulator error', error.message);
1420
+ return;
1421
+ }
1422
+
1396
1423
  console.log('CUTOS Simulator started and listening on port ', port);
1397
1424
 
1398
1425
  let drvDefault = new CoreClass$1.Driver();
1399
1426
  drvDefault.onCommand((command) => {
1400
1427
  console.log('drvDefault onCommand', JSON.stringify(command));
1401
1428
  if (command.cmd === "init") {
1402
- let rsp = {result: true};
1429
+ let result = {status: true};
1403
1430
  try {
1404
1431
  driver.init(command.args);
1405
1432
  } catch (e) {
1406
- rsp.msg = e.message;
1407
- rsp.result = false;
1433
+ result.msg = e.message;
1434
+ result.status = false;
1408
1435
  }
1409
- drvDefault.sendResponse(rsp, command.topicResponse);
1436
+ drvDefault.sendResponse(result, command.topicResponse);
1410
1437
  }
1411
1438
  });
1412
1439
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cutos/core",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
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",