@cutos/core 0.0.8 → 0.0.9
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 +54 -10
- package/dist/cutos.esm.js +54 -10
- package/package.json +2 -1
package/dist/cutos.cjs.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var crypto = require('crypto');
|
|
6
6
|
var require$$1 = require('mqtt');
|
|
7
|
+
var require$$2 = require('lodash');
|
|
7
8
|
var require$$0$1 = require('qs');
|
|
8
9
|
|
|
9
10
|
function getAugmentedNamespace(n) {
|
|
@@ -409,7 +410,7 @@ if(typeof window !== 'undefined') {
|
|
|
409
410
|
var utils = config$1;
|
|
410
411
|
|
|
411
412
|
var name = "@cutos/core";
|
|
412
|
-
var version = "0.0.
|
|
413
|
+
var version = "0.0.9";
|
|
413
414
|
var description = "";
|
|
414
415
|
var main = "dist/cutos.cjs.js";
|
|
415
416
|
var module$1 = "dist/cutos.esm.js";
|
|
@@ -422,6 +423,7 @@ var keywords = [
|
|
|
422
423
|
var author = "";
|
|
423
424
|
var license = "ISC";
|
|
424
425
|
var dependencies = {
|
|
426
|
+
lodash: "4.17.21",
|
|
425
427
|
mqtt: "4.3.7",
|
|
426
428
|
qs: "6.11.2"
|
|
427
429
|
};
|
|
@@ -437,7 +439,7 @@ var files = [
|
|
|
437
439
|
"dist/cutos.esm.js",
|
|
438
440
|
"package.json"
|
|
439
441
|
];
|
|
440
|
-
var require$$
|
|
442
|
+
var require$$5 = {
|
|
441
443
|
name: name,
|
|
442
444
|
version: version,
|
|
443
445
|
description: description,
|
|
@@ -458,11 +460,12 @@ var require$$4 = {
|
|
|
458
460
|
|
|
459
461
|
const {v4: uuidv4} = require$$0;
|
|
460
462
|
const mqtt = require$$1;
|
|
463
|
+
const _ = require$$2;
|
|
461
464
|
const cutosAPI = cutosApi;
|
|
462
465
|
const config = utils;
|
|
463
466
|
const callbackMap = new Map();
|
|
464
467
|
const listenerMap = new Map();
|
|
465
|
-
const packageJson = require$$
|
|
468
|
+
const packageJson = require$$5;
|
|
466
469
|
|
|
467
470
|
const ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
468
471
|
|
|
@@ -488,12 +491,21 @@ class Database {
|
|
|
488
491
|
KEY_TYPE_TEXT = "TEXT";
|
|
489
492
|
KEY_TYPE_INTEGER = "INTEGER";
|
|
490
493
|
|
|
491
|
-
constructor(db, callback,
|
|
494
|
+
constructor(db, callback, opts = {
|
|
495
|
+
retentionTime: 48,
|
|
496
|
+
mirror: {
|
|
497
|
+
gwIPC: null,
|
|
498
|
+
lwaName: "lwa-default",
|
|
499
|
+
confirm: false
|
|
500
|
+
}
|
|
501
|
+
}) {
|
|
492
502
|
// sub class
|
|
503
|
+
let database = this;
|
|
493
504
|
this.Table = class {
|
|
494
505
|
constructor(db, name, callback, retentionTime, keyType, keyName) {
|
|
495
506
|
this.db = db;
|
|
496
507
|
this.name = name;
|
|
508
|
+
|
|
497
509
|
let body = {
|
|
498
510
|
db: this.db, cmd: "db.table.create", name: name
|
|
499
511
|
};
|
|
@@ -507,28 +519,28 @@ class Database {
|
|
|
507
519
|
throw new Error("keyType MUST be INTEGER or TEXT");
|
|
508
520
|
|
|
509
521
|
}
|
|
510
|
-
return
|
|
522
|
+
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
511
523
|
}
|
|
512
524
|
|
|
513
525
|
insert(value, callback, tid) {
|
|
514
526
|
let body = {
|
|
515
527
|
db: this.db, cmd: "db.table.insert", name: this.name, value: value, tid: tid
|
|
516
528
|
};
|
|
517
|
-
return
|
|
529
|
+
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
518
530
|
}
|
|
519
531
|
|
|
520
532
|
insertById(id, value, callback, tid) {
|
|
521
533
|
let body = {
|
|
522
534
|
db: this.db, cmd: "db.table.insertById", name: this.name, id: id, value: value, tid: tid
|
|
523
535
|
};
|
|
524
|
-
return
|
|
536
|
+
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
525
537
|
}
|
|
526
538
|
|
|
527
539
|
insertByKey(key, value, callback, tid) {
|
|
528
540
|
let body = {
|
|
529
541
|
db: this.db, cmd: "db.table.insertByKey", name: this.name, key: key, value: value, tid: tid
|
|
530
542
|
};
|
|
531
|
-
return
|
|
543
|
+
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
532
544
|
}
|
|
533
545
|
|
|
534
546
|
update(id, value, callback) {
|
|
@@ -593,9 +605,29 @@ class Database {
|
|
|
593
605
|
};
|
|
594
606
|
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
595
607
|
}
|
|
608
|
+
|
|
609
|
+
publishRequestMirror(topic, callback, body) {
|
|
610
|
+
let mirror = database.mirror;
|
|
611
|
+
let cb = callback;
|
|
612
|
+
if (mirror.gwIPC) { // mirror enabled
|
|
613
|
+
cb = (dbResult) => {
|
|
614
|
+
let confirmCallback = !mirror.confirm ? null : (gwResult) => {
|
|
615
|
+
if (gwResult.status === "success") {
|
|
616
|
+
this.sync(dbResult.row);
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
if (dbResult.status === true) {
|
|
620
|
+
mirror.gwIPC.mirror(body, confirmCallback, {lwa_name: mirror.lwaName});
|
|
621
|
+
}
|
|
622
|
+
callback && callback(dbResult);
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
return publishRequest(topic, cb, body);
|
|
626
|
+
};
|
|
596
627
|
};
|
|
597
628
|
this.db = db;
|
|
598
|
-
this.retentionTime = retentionTime
|
|
629
|
+
this.retentionTime = opts.retentionTime ? opts.retentionTime : 48;// default 48 hours
|
|
630
|
+
this.mirror = opts.mirror;
|
|
599
631
|
let body = {
|
|
600
632
|
cmd: "db.connect", db: this.db
|
|
601
633
|
};
|
|
@@ -936,7 +968,19 @@ const CoreAPI = {
|
|
|
936
968
|
},
|
|
937
969
|
|
|
938
970
|
getDatabase(db, callback) {
|
|
939
|
-
|
|
971
|
+
let opts = {
|
|
972
|
+
retentionTime: 48,
|
|
973
|
+
mirror: {
|
|
974
|
+
gwIPC: null,
|
|
975
|
+
lwaName: "lwa-default",
|
|
976
|
+
confirm: false
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
if (typeof db === 'object') {
|
|
980
|
+
_.merge(opts, db);
|
|
981
|
+
db = opts.db;
|
|
982
|
+
}
|
|
983
|
+
return new Database(db, callback, opts);
|
|
940
984
|
},
|
|
941
985
|
|
|
942
986
|
getVolume(callback) {
|
package/dist/cutos.esm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import require$$1 from 'mqtt/dist/mqtt';
|
|
2
|
+
import require$$2 from 'lodash';
|
|
2
3
|
import require$$0$1 from 'qs';
|
|
3
4
|
|
|
4
5
|
function getAugmentedNamespace(n) {
|
|
@@ -701,7 +702,7 @@ if(typeof window !== 'undefined') {
|
|
|
701
702
|
var utils = config$1;
|
|
702
703
|
|
|
703
704
|
var name = "@cutos/core";
|
|
704
|
-
var version = "0.0.
|
|
705
|
+
var version = "0.0.9";
|
|
705
706
|
var description = "";
|
|
706
707
|
var main = "dist/cutos.cjs.js";
|
|
707
708
|
var module = "dist/cutos.esm.js";
|
|
@@ -714,6 +715,7 @@ var keywords = [
|
|
|
714
715
|
var author = "";
|
|
715
716
|
var license = "ISC";
|
|
716
717
|
var dependencies = {
|
|
718
|
+
lodash: "4.17.21",
|
|
717
719
|
mqtt: "4.3.7",
|
|
718
720
|
qs: "6.11.2"
|
|
719
721
|
};
|
|
@@ -729,7 +731,7 @@ var files = [
|
|
|
729
731
|
"dist/cutos.esm.js",
|
|
730
732
|
"package.json"
|
|
731
733
|
];
|
|
732
|
-
var require$$
|
|
734
|
+
var require$$5 = {
|
|
733
735
|
name: name,
|
|
734
736
|
version: version,
|
|
735
737
|
description: description,
|
|
@@ -750,11 +752,12 @@ var require$$4 = {
|
|
|
750
752
|
|
|
751
753
|
const {v4: uuidv4} = require$$0;
|
|
752
754
|
const mqtt = require$$1;
|
|
755
|
+
const _ = require$$2;
|
|
753
756
|
const cutosAPI = cutosApi;
|
|
754
757
|
const config = utils;
|
|
755
758
|
const callbackMap = new Map();
|
|
756
759
|
const listenerMap = new Map();
|
|
757
|
-
const packageJson = require$$
|
|
760
|
+
const packageJson = require$$5;
|
|
758
761
|
|
|
759
762
|
const ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
760
763
|
|
|
@@ -780,12 +783,21 @@ class Database {
|
|
|
780
783
|
KEY_TYPE_TEXT = "TEXT";
|
|
781
784
|
KEY_TYPE_INTEGER = "INTEGER";
|
|
782
785
|
|
|
783
|
-
constructor(db, callback,
|
|
786
|
+
constructor(db, callback, opts = {
|
|
787
|
+
retentionTime: 48,
|
|
788
|
+
mirror: {
|
|
789
|
+
gwIPC: null,
|
|
790
|
+
lwaName: "lwa-default",
|
|
791
|
+
confirm: false
|
|
792
|
+
}
|
|
793
|
+
}) {
|
|
784
794
|
// sub class
|
|
795
|
+
let database = this;
|
|
785
796
|
this.Table = class {
|
|
786
797
|
constructor(db, name, callback, retentionTime, keyType, keyName) {
|
|
787
798
|
this.db = db;
|
|
788
799
|
this.name = name;
|
|
800
|
+
|
|
789
801
|
let body = {
|
|
790
802
|
db: this.db, cmd: "db.table.create", name: name
|
|
791
803
|
};
|
|
@@ -799,28 +811,28 @@ class Database {
|
|
|
799
811
|
throw new Error("keyType MUST be INTEGER or TEXT");
|
|
800
812
|
|
|
801
813
|
}
|
|
802
|
-
return
|
|
814
|
+
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
803
815
|
}
|
|
804
816
|
|
|
805
817
|
insert(value, callback, tid) {
|
|
806
818
|
let body = {
|
|
807
819
|
db: this.db, cmd: "db.table.insert", name: this.name, value: value, tid: tid
|
|
808
820
|
};
|
|
809
|
-
return
|
|
821
|
+
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
810
822
|
}
|
|
811
823
|
|
|
812
824
|
insertById(id, value, callback, tid) {
|
|
813
825
|
let body = {
|
|
814
826
|
db: this.db, cmd: "db.table.insertById", name: this.name, id: id, value: value, tid: tid
|
|
815
827
|
};
|
|
816
|
-
return
|
|
828
|
+
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
817
829
|
}
|
|
818
830
|
|
|
819
831
|
insertByKey(key, value, callback, tid) {
|
|
820
832
|
let body = {
|
|
821
833
|
db: this.db, cmd: "db.table.insertByKey", name: this.name, key: key, value: value, tid: tid
|
|
822
834
|
};
|
|
823
|
-
return
|
|
835
|
+
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
824
836
|
}
|
|
825
837
|
|
|
826
838
|
update(id, value, callback) {
|
|
@@ -885,9 +897,29 @@ class Database {
|
|
|
885
897
|
};
|
|
886
898
|
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
887
899
|
}
|
|
900
|
+
|
|
901
|
+
publishRequestMirror(topic, callback, body) {
|
|
902
|
+
let mirror = database.mirror;
|
|
903
|
+
let cb = callback;
|
|
904
|
+
if (mirror.gwIPC) { // mirror enabled
|
|
905
|
+
cb = (dbResult) => {
|
|
906
|
+
let confirmCallback = !mirror.confirm ? null : (gwResult) => {
|
|
907
|
+
if (gwResult.status === "success") {
|
|
908
|
+
this.sync(dbResult.row);
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
if (dbResult.status === true) {
|
|
912
|
+
mirror.gwIPC.mirror(body, confirmCallback, {lwa_name: mirror.lwaName});
|
|
913
|
+
}
|
|
914
|
+
callback && callback(dbResult);
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
return publishRequest(topic, cb, body);
|
|
918
|
+
};
|
|
888
919
|
};
|
|
889
920
|
this.db = db;
|
|
890
|
-
this.retentionTime = retentionTime
|
|
921
|
+
this.retentionTime = opts.retentionTime ? opts.retentionTime : 48;// default 48 hours
|
|
922
|
+
this.mirror = opts.mirror;
|
|
891
923
|
let body = {
|
|
892
924
|
cmd: "db.connect", db: this.db
|
|
893
925
|
};
|
|
@@ -1228,7 +1260,19 @@ const CoreAPI = {
|
|
|
1228
1260
|
},
|
|
1229
1261
|
|
|
1230
1262
|
getDatabase(db, callback) {
|
|
1231
|
-
|
|
1263
|
+
let opts = {
|
|
1264
|
+
retentionTime: 48,
|
|
1265
|
+
mirror: {
|
|
1266
|
+
gwIPC: null,
|
|
1267
|
+
lwaName: "lwa-default",
|
|
1268
|
+
confirm: false
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
if (typeof db === 'object') {
|
|
1272
|
+
_.merge(opts, db);
|
|
1273
|
+
db = opts.db;
|
|
1274
|
+
}
|
|
1275
|
+
return new Database(db, callback, opts);
|
|
1232
1276
|
},
|
|
1233
1277
|
|
|
1234
1278
|
getVolume(callback) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cutos/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/cutos.cjs.js",
|
|
6
6
|
"module": "dist/cutos.esm.js",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"author": "",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
|
+
"lodash": "4.17.21",
|
|
16
17
|
"mqtt": "4.3.7",
|
|
17
18
|
"qs": "6.11.2"
|
|
18
19
|
},
|