@roeehrl/tinode-sdk 0.25.1-sqlite.1 → 0.25.1-sqlite.10
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 +349 -32
- package/package.json +7 -3
- package/src/connection.js +24 -2
- package/src/db.js +9 -18
- package/src/index.native.js +9 -1
- package/src/large-file.native.js +365 -0
- package/src/storage-sqlite.js +105 -158
- package/src/topic.js +0 -4
- package/types/index.d.ts +90 -2
- package/umd/tinode.dev.js +123 -3
- package/umd/tinode.dev.js.map +1 -1
- package/umd/tinode.prod.js +1 -1
- package/umd/tinode.prod.js.map +1 -1
- package/version.js +1 -0
package/umd/tinode.dev.js
CHANGED
|
@@ -669,7 +669,9 @@ class Connection {
|
|
|
669
669
|
};
|
|
670
670
|
this.reconnect = force => {
|
|
671
671
|
this.#boffStop();
|
|
672
|
-
this.connect(null, force)
|
|
672
|
+
this.connect(null, force).catch(_ => {
|
|
673
|
+
Connection.#log('LP reconnect promise rejected, error handled via onDisconnect callback');
|
|
674
|
+
});
|
|
673
675
|
};
|
|
674
676
|
this.disconnect = _ => {
|
|
675
677
|
this.#boffClosed = true;
|
|
@@ -751,7 +753,9 @@ class Connection {
|
|
|
751
753
|
};
|
|
752
754
|
this.reconnect = force => {
|
|
753
755
|
this.#boffStop();
|
|
754
|
-
this.connect(null, force)
|
|
756
|
+
this.connect(null, force).catch(_ => {
|
|
757
|
+
Connection.#log('WS reconnect promise rejected, error handled via onDisconnect callback');
|
|
758
|
+
});
|
|
755
759
|
};
|
|
756
760
|
this.disconnect = _ => {
|
|
757
761
|
this.#boffClosed = true;
|
|
@@ -766,6 +770,16 @@ class Connection {
|
|
|
766
770
|
if (this.#socket && this.#socket.readyState == this.#socket.OPEN) {
|
|
767
771
|
this.#socket.send(msg);
|
|
768
772
|
} else {
|
|
773
|
+
if (this.onDisconnect) {
|
|
774
|
+
setTimeout(() => {
|
|
775
|
+
if (this.onDisconnect) {
|
|
776
|
+
this.onDisconnect(new _comm_error_js__WEBPACK_IMPORTED_MODULE_0__["default"](NETWORK_ERROR_TEXT, NETWORK_ERROR), NETWORK_ERROR);
|
|
777
|
+
}
|
|
778
|
+
}, 0);
|
|
779
|
+
}
|
|
780
|
+
if (this.#socket) {
|
|
781
|
+
this.#socket = null;
|
|
782
|
+
}
|
|
769
783
|
throw new Error("Websocket is not connected");
|
|
770
784
|
}
|
|
771
785
|
};
|
|
@@ -799,14 +813,23 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
799
813
|
const DB_VERSION = 3;
|
|
800
814
|
const DB_NAME = 'tinode-web';
|
|
801
815
|
let IDBProvider;
|
|
816
|
+
let _storageProvider = null;
|
|
802
817
|
class DB {
|
|
803
818
|
#onError = _ => {};
|
|
804
819
|
#logger = _ => {};
|
|
805
820
|
db = null;
|
|
806
821
|
disabled = true;
|
|
822
|
+
#delegateStorage = null;
|
|
807
823
|
constructor(onError, logger) {
|
|
808
824
|
this.#onError = onError || this.#onError;
|
|
809
825
|
this.#logger = logger || this.#logger;
|
|
826
|
+
if (_storageProvider) {
|
|
827
|
+
this.#delegateStorage = _storageProvider;
|
|
828
|
+
this.disabled = false;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
#shouldDelegate() {
|
|
832
|
+
return this.#delegateStorage !== null;
|
|
810
833
|
}
|
|
811
834
|
#mapObjects(source, callback, context) {
|
|
812
835
|
if (!this.db) {
|
|
@@ -829,6 +852,15 @@ class DB {
|
|
|
829
852
|
});
|
|
830
853
|
}
|
|
831
854
|
initDatabase() {
|
|
855
|
+
console.log('[DB] initDatabase CALLED, shouldDelegate:', this.#shouldDelegate(), 'delegateStorage:', !!this.#delegateStorage);
|
|
856
|
+
if (this.#shouldDelegate()) {
|
|
857
|
+
console.log('[DB] initDatabase DELEGATING to SQLiteStorage');
|
|
858
|
+
return this.#delegateStorage.initDatabase().then(result => {
|
|
859
|
+
console.log('[DB] initDatabase: SQLiteStorage initialized successfully');
|
|
860
|
+
return result;
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
console.log('[DB] initDatabase using IndexedDB');
|
|
832
864
|
return new Promise((resolve, reject) => {
|
|
833
865
|
const req = IDBProvider.open(DB_NAME, DB_VERSION);
|
|
834
866
|
req.onsuccess = event => {
|
|
@@ -887,6 +919,9 @@ class DB {
|
|
|
887
919
|
});
|
|
888
920
|
}
|
|
889
921
|
deleteDatabase() {
|
|
922
|
+
if (this.#shouldDelegate()) {
|
|
923
|
+
return this.#delegateStorage.deleteDatabase();
|
|
924
|
+
}
|
|
890
925
|
if (this.db) {
|
|
891
926
|
this.db.close();
|
|
892
927
|
this.db = null;
|
|
@@ -913,9 +948,20 @@ class DB {
|
|
|
913
948
|
});
|
|
914
949
|
}
|
|
915
950
|
isReady() {
|
|
951
|
+
if (this.#shouldDelegate()) {
|
|
952
|
+
return this.#delegateStorage.isReady();
|
|
953
|
+
}
|
|
916
954
|
return !!this.db;
|
|
917
955
|
}
|
|
918
956
|
updTopic(topic) {
|
|
957
|
+
if (topic?._new) {
|
|
958
|
+
console.log('[DB] updTopic DEFERRED - topic not yet confirmed by server:', topic.name);
|
|
959
|
+
return Promise.resolve();
|
|
960
|
+
}
|
|
961
|
+
console.log('[DB] updTopic CALLED:', topic?.name, 'shouldDelegate:', this.#shouldDelegate());
|
|
962
|
+
if (this.#shouldDelegate()) {
|
|
963
|
+
return this.#delegateStorage.updTopic(topic);
|
|
964
|
+
}
|
|
919
965
|
if (!this.isReady()) {
|
|
920
966
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
921
967
|
}
|
|
@@ -936,6 +982,9 @@ class DB {
|
|
|
936
982
|
});
|
|
937
983
|
}
|
|
938
984
|
markTopicAsDeleted(name, deleted) {
|
|
985
|
+
if (this.#shouldDelegate()) {
|
|
986
|
+
return this.#delegateStorage.markTopicAsDeleted(name, deleted);
|
|
987
|
+
}
|
|
939
988
|
if (!this.isReady()) {
|
|
940
989
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
941
990
|
}
|
|
@@ -960,6 +1009,9 @@ class DB {
|
|
|
960
1009
|
});
|
|
961
1010
|
}
|
|
962
1011
|
remTopic(name) {
|
|
1012
|
+
if (this.#shouldDelegate()) {
|
|
1013
|
+
return this.#delegateStorage.remTopic(name);
|
|
1014
|
+
}
|
|
963
1015
|
if (!this.isReady()) {
|
|
964
1016
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
965
1017
|
}
|
|
@@ -979,12 +1031,27 @@ class DB {
|
|
|
979
1031
|
});
|
|
980
1032
|
}
|
|
981
1033
|
mapTopics(callback, context) {
|
|
1034
|
+
console.log('[DB] mapTopics CALLED, shouldDelegate:', this.#shouldDelegate());
|
|
1035
|
+
if (this.#shouldDelegate()) {
|
|
1036
|
+
console.log('[DB] mapTopics DELEGATING to SQLiteStorage');
|
|
1037
|
+
return this.#delegateStorage.mapTopics(callback, context).then(result => {
|
|
1038
|
+
console.log('[DB] mapTopics: SQLiteStorage returned', result ? result.length : 0, 'topics');
|
|
1039
|
+
return result;
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
console.log('[DB] mapTopics using IndexedDB');
|
|
982
1043
|
return this.#mapObjects('topic', callback, context);
|
|
983
1044
|
}
|
|
984
1045
|
deserializeTopic(topic, src) {
|
|
1046
|
+
if (this.#shouldDelegate()) {
|
|
1047
|
+
return this.#delegateStorage.deserializeTopic(topic, src);
|
|
1048
|
+
}
|
|
985
1049
|
DB.#deserializeTopic(topic, src);
|
|
986
1050
|
}
|
|
987
1051
|
updUser(uid, pub) {
|
|
1052
|
+
if (this.#shouldDelegate()) {
|
|
1053
|
+
return this.#delegateStorage.updUser(uid, pub);
|
|
1054
|
+
}
|
|
988
1055
|
if (arguments.length < 2 || pub === undefined) {
|
|
989
1056
|
return;
|
|
990
1057
|
}
|
|
@@ -1008,6 +1075,9 @@ class DB {
|
|
|
1008
1075
|
});
|
|
1009
1076
|
}
|
|
1010
1077
|
remUser(uid) {
|
|
1078
|
+
if (this.#shouldDelegate()) {
|
|
1079
|
+
return this.#delegateStorage.remUser(uid);
|
|
1080
|
+
}
|
|
1011
1081
|
if (!this.isReady()) {
|
|
1012
1082
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
1013
1083
|
}
|
|
@@ -1025,9 +1095,15 @@ class DB {
|
|
|
1025
1095
|
});
|
|
1026
1096
|
}
|
|
1027
1097
|
mapUsers(callback, context) {
|
|
1098
|
+
if (this.#shouldDelegate()) {
|
|
1099
|
+
return this.#delegateStorage.mapUsers(callback, context);
|
|
1100
|
+
}
|
|
1028
1101
|
return this.#mapObjects('user', callback, context);
|
|
1029
1102
|
}
|
|
1030
1103
|
getUser(uid) {
|
|
1104
|
+
if (this.#shouldDelegate()) {
|
|
1105
|
+
return this.#delegateStorage.getUser(uid);
|
|
1106
|
+
}
|
|
1031
1107
|
if (!this.isReady()) {
|
|
1032
1108
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
1033
1109
|
}
|
|
@@ -1048,6 +1124,9 @@ class DB {
|
|
|
1048
1124
|
});
|
|
1049
1125
|
}
|
|
1050
1126
|
updSubscription(topicName, uid, sub) {
|
|
1127
|
+
if (this.#shouldDelegate()) {
|
|
1128
|
+
return this.#delegateStorage.updSubscription(topicName, uid, sub);
|
|
1129
|
+
}
|
|
1051
1130
|
if (!this.isReady()) {
|
|
1052
1131
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
1053
1132
|
}
|
|
@@ -1067,6 +1146,9 @@ class DB {
|
|
|
1067
1146
|
});
|
|
1068
1147
|
}
|
|
1069
1148
|
mapSubscriptions(topicName, callback, context) {
|
|
1149
|
+
if (this.#shouldDelegate()) {
|
|
1150
|
+
return this.#delegateStorage.mapSubscriptions(topicName, callback, context);
|
|
1151
|
+
}
|
|
1070
1152
|
if (!this.isReady()) {
|
|
1071
1153
|
return this.disabled ? Promise.resolve([]) : Promise.reject(new Error("not initialized"));
|
|
1072
1154
|
}
|
|
@@ -1087,6 +1169,9 @@ class DB {
|
|
|
1087
1169
|
});
|
|
1088
1170
|
}
|
|
1089
1171
|
addMessage(msg) {
|
|
1172
|
+
if (this.#shouldDelegate()) {
|
|
1173
|
+
return this.#delegateStorage.addMessage(msg);
|
|
1174
|
+
}
|
|
1090
1175
|
if (!this.isReady()) {
|
|
1091
1176
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
1092
1177
|
}
|
|
@@ -1104,6 +1189,9 @@ class DB {
|
|
|
1104
1189
|
});
|
|
1105
1190
|
}
|
|
1106
1191
|
updMessageStatus(topicName, seq, status) {
|
|
1192
|
+
if (this.#shouldDelegate()) {
|
|
1193
|
+
return this.#delegateStorage.updMessageStatus(topicName, seq, status);
|
|
1194
|
+
}
|
|
1107
1195
|
if (!this.isReady()) {
|
|
1108
1196
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
1109
1197
|
}
|
|
@@ -1133,6 +1221,9 @@ class DB {
|
|
|
1133
1221
|
});
|
|
1134
1222
|
}
|
|
1135
1223
|
remMessages(topicName, from, to) {
|
|
1224
|
+
if (this.#shouldDelegate()) {
|
|
1225
|
+
return this.#delegateStorage.remMessages(topicName, from, to);
|
|
1226
|
+
}
|
|
1136
1227
|
if (!this.isReady()) {
|
|
1137
1228
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
1138
1229
|
}
|
|
@@ -1155,6 +1246,12 @@ class DB {
|
|
|
1155
1246
|
});
|
|
1156
1247
|
}
|
|
1157
1248
|
readMessages(topicName, query, callback, context) {
|
|
1249
|
+
console.log('[DB] readMessages CALLED:', topicName, 'shouldDelegate:', this.#shouldDelegate(), 'delegateStorage:', !!this.#delegateStorage);
|
|
1250
|
+
if (this.#shouldDelegate()) {
|
|
1251
|
+
console.log('[DB] readMessages DELEGATING to SQLiteStorage');
|
|
1252
|
+
return this.#delegateStorage.readMessages(topicName, query, callback, context);
|
|
1253
|
+
}
|
|
1254
|
+
console.log('[DB] readMessages NOT delegating, using IndexedDB');
|
|
1158
1255
|
query = query || {};
|
|
1159
1256
|
if (!this.isReady()) {
|
|
1160
1257
|
return this.disabled ? Promise.resolve([]) : Promise.reject(new Error("not initialized"));
|
|
@@ -1218,6 +1315,9 @@ class DB {
|
|
|
1218
1315
|
});
|
|
1219
1316
|
}
|
|
1220
1317
|
addDelLog(topicName, delId, ranges) {
|
|
1318
|
+
if (this.#shouldDelegate()) {
|
|
1319
|
+
return this.#delegateStorage.addDelLog(topicName, delId, ranges);
|
|
1320
|
+
}
|
|
1221
1321
|
if (!this.isReady()) {
|
|
1222
1322
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
1223
1323
|
}
|
|
@@ -1240,6 +1340,9 @@ class DB {
|
|
|
1240
1340
|
});
|
|
1241
1341
|
}
|
|
1242
1342
|
readDelLog(topicName, query) {
|
|
1343
|
+
if (this.#shouldDelegate()) {
|
|
1344
|
+
return this.#delegateStorage.readDelLog(topicName, query);
|
|
1345
|
+
}
|
|
1243
1346
|
query = query || {};
|
|
1244
1347
|
if (!this.isReady()) {
|
|
1245
1348
|
return this.disabled ? Promise.resolve([]) : Promise.reject(new Error("not initialized"));
|
|
@@ -1312,6 +1415,9 @@ class DB {
|
|
|
1312
1415
|
});
|
|
1313
1416
|
}
|
|
1314
1417
|
maxDelId(topicName) {
|
|
1418
|
+
if (this.#shouldDelegate()) {
|
|
1419
|
+
return this.#delegateStorage.maxDelId(topicName);
|
|
1420
|
+
}
|
|
1315
1421
|
if (!this.isReady()) {
|
|
1316
1422
|
return this.disabled ? Promise.resolve(0) : Promise.reject(new Error("not initialized"));
|
|
1317
1423
|
}
|
|
@@ -1389,6 +1495,12 @@ class DB {
|
|
|
1389
1495
|
static setDatabaseProvider(idbProvider) {
|
|
1390
1496
|
IDBProvider = idbProvider;
|
|
1391
1497
|
}
|
|
1498
|
+
static setStorageProvider(storage) {
|
|
1499
|
+
_storageProvider = storage;
|
|
1500
|
+
}
|
|
1501
|
+
static getStorageProvider() {
|
|
1502
|
+
return _storageProvider;
|
|
1503
|
+
}
|
|
1392
1504
|
}
|
|
1393
1505
|
|
|
1394
1506
|
/***/ }),
|
|
@@ -5155,10 +5267,13 @@ class Topic {
|
|
|
5155
5267
|
return this._queuedSeqId++;
|
|
5156
5268
|
}
|
|
5157
5269
|
_loadMessages(db, query) {
|
|
5270
|
+
console.log('[Topic] _loadMessages CALLED:', this.name, 'query:', JSON.stringify(query), 'db:', !!db);
|
|
5158
5271
|
query = query || {};
|
|
5159
5272
|
query.limit = query.limit || _config_js__WEBPACK_IMPORTED_MODULE_3__.DEFAULT_MESSAGES_PAGE;
|
|
5160
5273
|
let count = 0;
|
|
5274
|
+
console.log('[Topic] _loadMessages: calling db.readMessages');
|
|
5161
5275
|
return db.readMessages(this.name, query).then(msgs => {
|
|
5276
|
+
console.log('[Topic] _loadMessages: db.readMessages returned', msgs ? msgs.length : 0, 'messages');
|
|
5162
5277
|
msgs.forEach(data => {
|
|
5163
5278
|
if (data.seq > this._maxSeq) {
|
|
5164
5279
|
this._maxSeq = data.seq;
|
|
@@ -5170,6 +5285,7 @@ class Topic {
|
|
|
5170
5285
|
this._maybeUpdateMessageVersionsCache(data);
|
|
5171
5286
|
});
|
|
5172
5287
|
count = msgs.length;
|
|
5288
|
+
console.log('[Topic] _loadMessages: processed', count, 'messages, _maxSeq:', this._maxSeq, '_minSeq:', this._minSeq);
|
|
5173
5289
|
}).then(_ => db.readDelLog(this.name, query)).then(dellog => {
|
|
5174
5290
|
return dellog.forEach(rec => {
|
|
5175
5291
|
this._messages.put({
|
|
@@ -5449,7 +5565,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
5449
5565
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
5450
5566
|
/* harmony export */ PACKAGE_VERSION: function() { return /* binding */ PACKAGE_VERSION; }
|
|
5451
5567
|
/* harmony export */ });
|
|
5452
|
-
const PACKAGE_VERSION = "0.25.1";
|
|
5568
|
+
const PACKAGE_VERSION = "0.25.1-sqlite.8";
|
|
5453
5569
|
|
|
5454
5570
|
/***/ })
|
|
5455
5571
|
|
|
@@ -5548,6 +5664,7 @@ var __webpack_exports__ = {};
|
|
|
5548
5664
|
__webpack_require__.r(__webpack_exports__);
|
|
5549
5665
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
5550
5666
|
/* harmony export */ AccessMode: function() { return /* reexport safe */ _access_mode_js__WEBPACK_IMPORTED_MODULE_0__["default"]; },
|
|
5667
|
+
/* harmony export */ DB: function() { return /* reexport safe */ _db_js__WEBPACK_IMPORTED_MODULE_4__["default"]; },
|
|
5551
5668
|
/* harmony export */ Drafty: function() { return /* reexport default from dynamic */ _drafty_js__WEBPACK_IMPORTED_MODULE_5___default.a; },
|
|
5552
5669
|
/* harmony export */ Tinode: function() { return /* binding */ Tinode; }
|
|
5553
5670
|
/* harmony export */ });
|
|
@@ -6299,6 +6416,9 @@ class Tinode {
|
|
|
6299
6416
|
IndexedDBProvider = idbProvider;
|
|
6300
6417
|
_db_js__WEBPACK_IMPORTED_MODULE_4__["default"].setDatabaseProvider(IndexedDBProvider);
|
|
6301
6418
|
}
|
|
6419
|
+
static setStorageProvider(storage) {
|
|
6420
|
+
_db_js__WEBPACK_IMPORTED_MODULE_4__["default"].setStorageProvider(storage);
|
|
6421
|
+
}
|
|
6302
6422
|
static getLibrary() {
|
|
6303
6423
|
return _config_js__WEBPACK_IMPORTED_MODULE_1__.LIBRARY;
|
|
6304
6424
|
}
|