@cutos/core 0.0.12 → 0.0.14
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 +32 -32
- package/dist/cutos.esm.js +32 -32
- package/package.json +1 -1
package/dist/cutos.cjs.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var crypto = require('crypto');
|
|
6
6
|
var require$$1 = require('mqtt');
|
|
7
|
-
|
|
7
|
+
require('lodash');
|
|
8
8
|
var require$$0$1 = require('qs');
|
|
9
9
|
|
|
10
10
|
function getAugmentedNamespace(n) {
|
|
@@ -359,6 +359,7 @@ const CORE = Object.freeze({ // core level api
|
|
|
359
359
|
CONFIG: 'core-config',
|
|
360
360
|
BOX_INFO: 'core-box-info',
|
|
361
361
|
SIGN_INFO: 'core-sign-info',
|
|
362
|
+
DEVICE_INFO: 'core-device-info',
|
|
362
363
|
SIGN_GROUP_INFO: 'core-sign-group-info',
|
|
363
364
|
SHELL: 'core-shell',
|
|
364
365
|
DATABASE: 'core-database',
|
|
@@ -383,8 +384,7 @@ const DEVICE = Object.freeze({ // core level api
|
|
|
383
384
|
NFC: 'device-nfc',
|
|
384
385
|
FINGERPRINT: 'device-fingerprint',
|
|
385
386
|
QR_CODE_SCANNER: 'device-qr-code-scanner',
|
|
386
|
-
PRINTER: 'device-printer'
|
|
387
|
-
REFRIGERATOR: 'device-fridge'
|
|
387
|
+
PRINTER: 'device-printer'
|
|
388
388
|
});
|
|
389
389
|
|
|
390
390
|
const HEARTBEAT_STATUS = Object.freeze({
|
|
@@ -411,7 +411,7 @@ if(typeof window !== 'undefined') {
|
|
|
411
411
|
var utils = config$1;
|
|
412
412
|
|
|
413
413
|
var name = "@cutos/core";
|
|
414
|
-
var version = "0.0.
|
|
414
|
+
var version = "0.0.14";
|
|
415
415
|
var description = "";
|
|
416
416
|
var main = "dist/cutos.cjs.js";
|
|
417
417
|
var module$1 = "dist/cutos.esm.js";
|
|
@@ -461,7 +461,6 @@ var require$$5 = {
|
|
|
461
461
|
|
|
462
462
|
const {v4: uuidv4} = require$$0;
|
|
463
463
|
const mqtt = require$$1;
|
|
464
|
-
const _ = require$$2;
|
|
465
464
|
const cutosAPI = cutosApi;
|
|
466
465
|
const config = utils;
|
|
467
466
|
const callbackMap = new Map();
|
|
@@ -492,14 +491,7 @@ class Database {
|
|
|
492
491
|
KEY_TYPE_TEXT = "TEXT";
|
|
493
492
|
KEY_TYPE_INTEGER = "INTEGER";
|
|
494
493
|
|
|
495
|
-
constructor(db, callback
|
|
496
|
-
retentionTime: 48,
|
|
497
|
-
mirror: {
|
|
498
|
-
gwIPC: null,
|
|
499
|
-
lwaName: "lwa-default",
|
|
500
|
-
confirm: false
|
|
501
|
-
}
|
|
502
|
-
}) {
|
|
494
|
+
constructor(db, callback) {
|
|
503
495
|
// sub class
|
|
504
496
|
let database = this;
|
|
505
497
|
this.Table = class {
|
|
@@ -610,7 +602,7 @@ class Database {
|
|
|
610
602
|
publishRequestMirror(topic, callback, body) {
|
|
611
603
|
let mirror = database.mirror;
|
|
612
604
|
let cb = callback;
|
|
613
|
-
if (mirror.gwIPC) { // mirror enabled
|
|
605
|
+
if (mirror && mirror.gwIPC) { // mirror enabled
|
|
614
606
|
cb = (dbResult) => {
|
|
615
607
|
let confirmCallback = !mirror.confirm ? null : (gwResult) => {
|
|
616
608
|
if (gwResult.status === "success") {
|
|
@@ -639,8 +631,6 @@ class Database {
|
|
|
639
631
|
}
|
|
640
632
|
};
|
|
641
633
|
this.db = db;
|
|
642
|
-
this.retentionTime = opts.retentionTime ? opts.retentionTime : 48;// default 48 hours
|
|
643
|
-
this.mirror = opts.mirror;
|
|
644
634
|
let body = {
|
|
645
635
|
cmd: "db.connect", db: this.db
|
|
646
636
|
};
|
|
@@ -657,6 +647,10 @@ class Database {
|
|
|
657
647
|
createTable(name, callback, retentionTime, keyType = 'INTEGER', keyName = 'id') {
|
|
658
648
|
return new this.Table(null, name, callback, retentionTime, keyType, keyName);
|
|
659
649
|
}
|
|
650
|
+
|
|
651
|
+
setupMirror(gwIPC, lwaName, confirm = false) {
|
|
652
|
+
this.mirror = {gwIPC, lwaName, confirm};
|
|
653
|
+
}
|
|
660
654
|
}
|
|
661
655
|
|
|
662
656
|
class Logger {
|
|
@@ -883,13 +877,15 @@ class Driver {
|
|
|
883
877
|
}
|
|
884
878
|
|
|
885
879
|
onCommand(listener) {
|
|
886
|
-
|
|
887
|
-
|
|
880
|
+
if(listener) {
|
|
881
|
+
client.subscribe(this.topicCommand); // receive command from app
|
|
882
|
+
listenerMap.set(this.topicCommand, listener);
|
|
883
|
+
}
|
|
888
884
|
}
|
|
889
885
|
}
|
|
890
886
|
|
|
891
887
|
const CoreAPI = {
|
|
892
|
-
init(mqttHost = 'ws://localhost:1883') {
|
|
888
|
+
init(mqttHost = 'ws://localhost:1883', callback) {
|
|
893
889
|
client = mqtt.connect(mqttHost);
|
|
894
890
|
|
|
895
891
|
client.on('connect', function () {
|
|
@@ -903,6 +899,12 @@ const CoreAPI = {
|
|
|
903
899
|
for (let api in cutosAPI.CORE_APP) {
|
|
904
900
|
client.subscribe(cutosAPI.CORE_APP[api]);
|
|
905
901
|
}
|
|
902
|
+
if(typeof(callback) === 'function') {
|
|
903
|
+
callback({
|
|
904
|
+
status: true,
|
|
905
|
+
msg: 'CUTOS CORE connected.'
|
|
906
|
+
});
|
|
907
|
+
}
|
|
906
908
|
});
|
|
907
909
|
|
|
908
910
|
client.on('message', function (topic, message, context) {
|
|
@@ -933,6 +935,12 @@ const CoreAPI = {
|
|
|
933
935
|
});
|
|
934
936
|
|
|
935
937
|
client.on("error", (e) => {
|
|
938
|
+
if(typeof(callback) === 'function') {
|
|
939
|
+
callback({
|
|
940
|
+
status: false,
|
|
941
|
+
msg: e.message
|
|
942
|
+
});
|
|
943
|
+
}
|
|
936
944
|
console.error("CUTOS CORE error: ", e.message);
|
|
937
945
|
});
|
|
938
946
|
},
|
|
@@ -960,6 +968,10 @@ const CoreAPI = {
|
|
|
960
968
|
return publishRequest(cutosAPI.CORE.SIGN_INFO, callback);
|
|
961
969
|
},
|
|
962
970
|
|
|
971
|
+
getDeviceInfo(callback) {
|
|
972
|
+
return publishRequest(cutosAPI.CORE.DEVICE_INFO, callback);
|
|
973
|
+
},
|
|
974
|
+
|
|
963
975
|
getSignGroupInfo(callback) {
|
|
964
976
|
return publishRequest(cutosAPI.CORE.SIGN_GROUP_INFO, callback);
|
|
965
977
|
},
|
|
@@ -981,19 +993,7 @@ const CoreAPI = {
|
|
|
981
993
|
},
|
|
982
994
|
|
|
983
995
|
getDatabase(db, callback) {
|
|
984
|
-
|
|
985
|
-
retentionTime: 48,
|
|
986
|
-
mirror: {
|
|
987
|
-
gwIPC: null,
|
|
988
|
-
lwaName: "lwa-default",
|
|
989
|
-
confirm: false
|
|
990
|
-
}
|
|
991
|
-
};
|
|
992
|
-
if (typeof db === 'object') {
|
|
993
|
-
_.merge(opts, db);
|
|
994
|
-
db = opts.db;
|
|
995
|
-
}
|
|
996
|
-
return new Database(db, callback, opts);
|
|
996
|
+
return new Database(db, callback);
|
|
997
997
|
},
|
|
998
998
|
|
|
999
999
|
getVolume(callback) {
|
package/dist/cutos.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import require$$1 from 'mqtt/dist/mqtt';
|
|
2
|
-
import
|
|
2
|
+
import 'lodash';
|
|
3
3
|
import require$$0$1 from 'qs';
|
|
4
4
|
|
|
5
5
|
function getAugmentedNamespace(n) {
|
|
@@ -651,6 +651,7 @@ const CORE = Object.freeze({ // core level api
|
|
|
651
651
|
CONFIG: 'core-config',
|
|
652
652
|
BOX_INFO: 'core-box-info',
|
|
653
653
|
SIGN_INFO: 'core-sign-info',
|
|
654
|
+
DEVICE_INFO: 'core-device-info',
|
|
654
655
|
SIGN_GROUP_INFO: 'core-sign-group-info',
|
|
655
656
|
SHELL: 'core-shell',
|
|
656
657
|
DATABASE: 'core-database',
|
|
@@ -675,8 +676,7 @@ const DEVICE = Object.freeze({ // core level api
|
|
|
675
676
|
NFC: 'device-nfc',
|
|
676
677
|
FINGERPRINT: 'device-fingerprint',
|
|
677
678
|
QR_CODE_SCANNER: 'device-qr-code-scanner',
|
|
678
|
-
PRINTER: 'device-printer'
|
|
679
|
-
REFRIGERATOR: 'device-fridge'
|
|
679
|
+
PRINTER: 'device-printer'
|
|
680
680
|
});
|
|
681
681
|
|
|
682
682
|
const HEARTBEAT_STATUS = Object.freeze({
|
|
@@ -703,7 +703,7 @@ if(typeof window !== 'undefined') {
|
|
|
703
703
|
var utils = config$1;
|
|
704
704
|
|
|
705
705
|
var name = "@cutos/core";
|
|
706
|
-
var version = "0.0.
|
|
706
|
+
var version = "0.0.14";
|
|
707
707
|
var description = "";
|
|
708
708
|
var main = "dist/cutos.cjs.js";
|
|
709
709
|
var module = "dist/cutos.esm.js";
|
|
@@ -753,7 +753,6 @@ var require$$5 = {
|
|
|
753
753
|
|
|
754
754
|
const {v4: uuidv4} = require$$0;
|
|
755
755
|
const mqtt = require$$1;
|
|
756
|
-
const _ = require$$2;
|
|
757
756
|
const cutosAPI = cutosApi;
|
|
758
757
|
const config = utils;
|
|
759
758
|
const callbackMap = new Map();
|
|
@@ -784,14 +783,7 @@ class Database {
|
|
|
784
783
|
KEY_TYPE_TEXT = "TEXT";
|
|
785
784
|
KEY_TYPE_INTEGER = "INTEGER";
|
|
786
785
|
|
|
787
|
-
constructor(db, callback
|
|
788
|
-
retentionTime: 48,
|
|
789
|
-
mirror: {
|
|
790
|
-
gwIPC: null,
|
|
791
|
-
lwaName: "lwa-default",
|
|
792
|
-
confirm: false
|
|
793
|
-
}
|
|
794
|
-
}) {
|
|
786
|
+
constructor(db, callback) {
|
|
795
787
|
// sub class
|
|
796
788
|
let database = this;
|
|
797
789
|
this.Table = class {
|
|
@@ -902,7 +894,7 @@ class Database {
|
|
|
902
894
|
publishRequestMirror(topic, callback, body) {
|
|
903
895
|
let mirror = database.mirror;
|
|
904
896
|
let cb = callback;
|
|
905
|
-
if (mirror.gwIPC) { // mirror enabled
|
|
897
|
+
if (mirror && mirror.gwIPC) { // mirror enabled
|
|
906
898
|
cb = (dbResult) => {
|
|
907
899
|
let confirmCallback = !mirror.confirm ? null : (gwResult) => {
|
|
908
900
|
if (gwResult.status === "success") {
|
|
@@ -931,8 +923,6 @@ class Database {
|
|
|
931
923
|
}
|
|
932
924
|
};
|
|
933
925
|
this.db = db;
|
|
934
|
-
this.retentionTime = opts.retentionTime ? opts.retentionTime : 48;// default 48 hours
|
|
935
|
-
this.mirror = opts.mirror;
|
|
936
926
|
let body = {
|
|
937
927
|
cmd: "db.connect", db: this.db
|
|
938
928
|
};
|
|
@@ -949,6 +939,10 @@ class Database {
|
|
|
949
939
|
createTable(name, callback, retentionTime, keyType = 'INTEGER', keyName = 'id') {
|
|
950
940
|
return new this.Table(null, name, callback, retentionTime, keyType, keyName);
|
|
951
941
|
}
|
|
942
|
+
|
|
943
|
+
setupMirror(gwIPC, lwaName, confirm = false) {
|
|
944
|
+
this.mirror = {gwIPC, lwaName, confirm};
|
|
945
|
+
}
|
|
952
946
|
}
|
|
953
947
|
|
|
954
948
|
class Logger {
|
|
@@ -1175,13 +1169,15 @@ class Driver {
|
|
|
1175
1169
|
}
|
|
1176
1170
|
|
|
1177
1171
|
onCommand(listener) {
|
|
1178
|
-
|
|
1179
|
-
|
|
1172
|
+
if(listener) {
|
|
1173
|
+
client.subscribe(this.topicCommand); // receive command from app
|
|
1174
|
+
listenerMap.set(this.topicCommand, listener);
|
|
1175
|
+
}
|
|
1180
1176
|
}
|
|
1181
1177
|
}
|
|
1182
1178
|
|
|
1183
1179
|
const CoreAPI = {
|
|
1184
|
-
init(mqttHost = 'ws://localhost:1883') {
|
|
1180
|
+
init(mqttHost = 'ws://localhost:1883', callback) {
|
|
1185
1181
|
client = mqtt.connect(mqttHost);
|
|
1186
1182
|
|
|
1187
1183
|
client.on('connect', function () {
|
|
@@ -1195,6 +1191,12 @@ const CoreAPI = {
|
|
|
1195
1191
|
for (let api in cutosAPI.CORE_APP) {
|
|
1196
1192
|
client.subscribe(cutosAPI.CORE_APP[api]);
|
|
1197
1193
|
}
|
|
1194
|
+
if(typeof(callback) === 'function') {
|
|
1195
|
+
callback({
|
|
1196
|
+
status: true,
|
|
1197
|
+
msg: 'CUTOS CORE connected.'
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1198
1200
|
});
|
|
1199
1201
|
|
|
1200
1202
|
client.on('message', function (topic, message, context) {
|
|
@@ -1225,6 +1227,12 @@ const CoreAPI = {
|
|
|
1225
1227
|
});
|
|
1226
1228
|
|
|
1227
1229
|
client.on("error", (e) => {
|
|
1230
|
+
if(typeof(callback) === 'function') {
|
|
1231
|
+
callback({
|
|
1232
|
+
status: false,
|
|
1233
|
+
msg: e.message
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1228
1236
|
console.error("CUTOS CORE error: ", e.message);
|
|
1229
1237
|
});
|
|
1230
1238
|
},
|
|
@@ -1252,6 +1260,10 @@ const CoreAPI = {
|
|
|
1252
1260
|
return publishRequest(cutosAPI.CORE.SIGN_INFO, callback);
|
|
1253
1261
|
},
|
|
1254
1262
|
|
|
1263
|
+
getDeviceInfo(callback) {
|
|
1264
|
+
return publishRequest(cutosAPI.CORE.DEVICE_INFO, callback);
|
|
1265
|
+
},
|
|
1266
|
+
|
|
1255
1267
|
getSignGroupInfo(callback) {
|
|
1256
1268
|
return publishRequest(cutosAPI.CORE.SIGN_GROUP_INFO, callback);
|
|
1257
1269
|
},
|
|
@@ -1273,19 +1285,7 @@ const CoreAPI = {
|
|
|
1273
1285
|
},
|
|
1274
1286
|
|
|
1275
1287
|
getDatabase(db, callback) {
|
|
1276
|
-
|
|
1277
|
-
retentionTime: 48,
|
|
1278
|
-
mirror: {
|
|
1279
|
-
gwIPC: null,
|
|
1280
|
-
lwaName: "lwa-default",
|
|
1281
|
-
confirm: false
|
|
1282
|
-
}
|
|
1283
|
-
};
|
|
1284
|
-
if (typeof db === 'object') {
|
|
1285
|
-
_.merge(opts, db);
|
|
1286
|
-
db = opts.db;
|
|
1287
|
-
}
|
|
1288
|
-
return new Database(db, callback, opts);
|
|
1288
|
+
return new Database(db, callback);
|
|
1289
1289
|
},
|
|
1290
1290
|
|
|
1291
1291
|
getVolume(callback) {
|