@roeehrl/tinode-sdk 0.25.1-sqlite.5 → 0.25.1-sqlite.6
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/package.json +1 -1
- package/types/index.d.ts +2 -1
- package/umd/tinode.dev.js +109 -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 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roeehrl/tinode-sdk",
|
|
3
3
|
"description": "Tinode SDK fork with Storage interface for SQLite persistence in React Native",
|
|
4
|
-
"version": "0.25.1-sqlite.
|
|
4
|
+
"version": "0.25.1-sqlite.6",
|
|
5
5
|
"types": "./types/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"format": "js-beautify -r src/*.js",
|
package/types/index.d.ts
CHANGED
|
@@ -206,7 +206,8 @@ declare module '@roeehrl/tinode-sdk' {
|
|
|
206
206
|
|
|
207
207
|
export interface SetDesc {
|
|
208
208
|
defacs?: DefAcs;
|
|
209
|
-
|
|
209
|
+
/** Public data. For fnd topic, can be a search query string. */
|
|
210
|
+
public?: Record<string, unknown> | string;
|
|
210
211
|
trusted?: Record<string, unknown>;
|
|
211
212
|
private?: Record<string, unknown>;
|
|
212
213
|
}
|
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;
|
|
@@ -799,14 +803,23 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
799
803
|
const DB_VERSION = 3;
|
|
800
804
|
const DB_NAME = 'tinode-web';
|
|
801
805
|
let IDBProvider;
|
|
806
|
+
let _storageProvider = null;
|
|
802
807
|
class DB {
|
|
803
808
|
#onError = _ => {};
|
|
804
809
|
#logger = _ => {};
|
|
805
810
|
db = null;
|
|
806
811
|
disabled = true;
|
|
812
|
+
#delegateStorage = null;
|
|
807
813
|
constructor(onError, logger) {
|
|
808
814
|
this.#onError = onError || this.#onError;
|
|
809
815
|
this.#logger = logger || this.#logger;
|
|
816
|
+
if (_storageProvider) {
|
|
817
|
+
this.#delegateStorage = _storageProvider;
|
|
818
|
+
this.disabled = false;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
#shouldDelegate() {
|
|
822
|
+
return this.#delegateStorage !== null;
|
|
810
823
|
}
|
|
811
824
|
#mapObjects(source, callback, context) {
|
|
812
825
|
if (!this.db) {
|
|
@@ -829,6 +842,15 @@ class DB {
|
|
|
829
842
|
});
|
|
830
843
|
}
|
|
831
844
|
initDatabase() {
|
|
845
|
+
console.log('[DB] initDatabase CALLED, shouldDelegate:', this.#shouldDelegate(), 'delegateStorage:', !!this.#delegateStorage);
|
|
846
|
+
if (this.#shouldDelegate()) {
|
|
847
|
+
console.log('[DB] initDatabase DELEGATING to SQLiteStorage');
|
|
848
|
+
return this.#delegateStorage.initDatabase().then(result => {
|
|
849
|
+
console.log('[DB] initDatabase: SQLiteStorage initialized successfully');
|
|
850
|
+
return result;
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
console.log('[DB] initDatabase using IndexedDB');
|
|
832
854
|
return new Promise((resolve, reject) => {
|
|
833
855
|
const req = IDBProvider.open(DB_NAME, DB_VERSION);
|
|
834
856
|
req.onsuccess = event => {
|
|
@@ -887,6 +909,9 @@ class DB {
|
|
|
887
909
|
});
|
|
888
910
|
}
|
|
889
911
|
deleteDatabase() {
|
|
912
|
+
if (this.#shouldDelegate()) {
|
|
913
|
+
return this.#delegateStorage.deleteDatabase();
|
|
914
|
+
}
|
|
890
915
|
if (this.db) {
|
|
891
916
|
this.db.close();
|
|
892
917
|
this.db = null;
|
|
@@ -913,9 +938,16 @@ class DB {
|
|
|
913
938
|
});
|
|
914
939
|
}
|
|
915
940
|
isReady() {
|
|
941
|
+
if (this.#shouldDelegate()) {
|
|
942
|
+
return this.#delegateStorage.isReady();
|
|
943
|
+
}
|
|
916
944
|
return !!this.db;
|
|
917
945
|
}
|
|
918
946
|
updTopic(topic) {
|
|
947
|
+
console.log('[DB] updTopic CALLED:', topic?.name, 'shouldDelegate:', this.#shouldDelegate());
|
|
948
|
+
if (this.#shouldDelegate()) {
|
|
949
|
+
return this.#delegateStorage.updTopic(topic);
|
|
950
|
+
}
|
|
919
951
|
if (!this.isReady()) {
|
|
920
952
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
921
953
|
}
|
|
@@ -936,6 +968,9 @@ class DB {
|
|
|
936
968
|
});
|
|
937
969
|
}
|
|
938
970
|
markTopicAsDeleted(name, deleted) {
|
|
971
|
+
if (this.#shouldDelegate()) {
|
|
972
|
+
return this.#delegateStorage.markTopicAsDeleted(name, deleted);
|
|
973
|
+
}
|
|
939
974
|
if (!this.isReady()) {
|
|
940
975
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
941
976
|
}
|
|
@@ -960,6 +995,9 @@ class DB {
|
|
|
960
995
|
});
|
|
961
996
|
}
|
|
962
997
|
remTopic(name) {
|
|
998
|
+
if (this.#shouldDelegate()) {
|
|
999
|
+
return this.#delegateStorage.remTopic(name);
|
|
1000
|
+
}
|
|
963
1001
|
if (!this.isReady()) {
|
|
964
1002
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
965
1003
|
}
|
|
@@ -979,12 +1017,27 @@ class DB {
|
|
|
979
1017
|
});
|
|
980
1018
|
}
|
|
981
1019
|
mapTopics(callback, context) {
|
|
1020
|
+
console.log('[DB] mapTopics CALLED, shouldDelegate:', this.#shouldDelegate());
|
|
1021
|
+
if (this.#shouldDelegate()) {
|
|
1022
|
+
console.log('[DB] mapTopics DELEGATING to SQLiteStorage');
|
|
1023
|
+
return this.#delegateStorage.mapTopics(callback, context).then(result => {
|
|
1024
|
+
console.log('[DB] mapTopics: SQLiteStorage returned', result ? result.length : 0, 'topics');
|
|
1025
|
+
return result;
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
console.log('[DB] mapTopics using IndexedDB');
|
|
982
1029
|
return this.#mapObjects('topic', callback, context);
|
|
983
1030
|
}
|
|
984
1031
|
deserializeTopic(topic, src) {
|
|
1032
|
+
if (this.#shouldDelegate()) {
|
|
1033
|
+
return this.#delegateStorage.deserializeTopic(topic, src);
|
|
1034
|
+
}
|
|
985
1035
|
DB.#deserializeTopic(topic, src);
|
|
986
1036
|
}
|
|
987
1037
|
updUser(uid, pub) {
|
|
1038
|
+
if (this.#shouldDelegate()) {
|
|
1039
|
+
return this.#delegateStorage.updUser(uid, pub);
|
|
1040
|
+
}
|
|
988
1041
|
if (arguments.length < 2 || pub === undefined) {
|
|
989
1042
|
return;
|
|
990
1043
|
}
|
|
@@ -1008,6 +1061,9 @@ class DB {
|
|
|
1008
1061
|
});
|
|
1009
1062
|
}
|
|
1010
1063
|
remUser(uid) {
|
|
1064
|
+
if (this.#shouldDelegate()) {
|
|
1065
|
+
return this.#delegateStorage.remUser(uid);
|
|
1066
|
+
}
|
|
1011
1067
|
if (!this.isReady()) {
|
|
1012
1068
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
1013
1069
|
}
|
|
@@ -1025,9 +1081,15 @@ class DB {
|
|
|
1025
1081
|
});
|
|
1026
1082
|
}
|
|
1027
1083
|
mapUsers(callback, context) {
|
|
1084
|
+
if (this.#shouldDelegate()) {
|
|
1085
|
+
return this.#delegateStorage.mapUsers(callback, context);
|
|
1086
|
+
}
|
|
1028
1087
|
return this.#mapObjects('user', callback, context);
|
|
1029
1088
|
}
|
|
1030
1089
|
getUser(uid) {
|
|
1090
|
+
if (this.#shouldDelegate()) {
|
|
1091
|
+
return this.#delegateStorage.getUser(uid);
|
|
1092
|
+
}
|
|
1031
1093
|
if (!this.isReady()) {
|
|
1032
1094
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
1033
1095
|
}
|
|
@@ -1048,6 +1110,9 @@ class DB {
|
|
|
1048
1110
|
});
|
|
1049
1111
|
}
|
|
1050
1112
|
updSubscription(topicName, uid, sub) {
|
|
1113
|
+
if (this.#shouldDelegate()) {
|
|
1114
|
+
return this.#delegateStorage.updSubscription(topicName, uid, sub);
|
|
1115
|
+
}
|
|
1051
1116
|
if (!this.isReady()) {
|
|
1052
1117
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
1053
1118
|
}
|
|
@@ -1067,6 +1132,9 @@ class DB {
|
|
|
1067
1132
|
});
|
|
1068
1133
|
}
|
|
1069
1134
|
mapSubscriptions(topicName, callback, context) {
|
|
1135
|
+
if (this.#shouldDelegate()) {
|
|
1136
|
+
return this.#delegateStorage.mapSubscriptions(topicName, callback, context);
|
|
1137
|
+
}
|
|
1070
1138
|
if (!this.isReady()) {
|
|
1071
1139
|
return this.disabled ? Promise.resolve([]) : Promise.reject(new Error("not initialized"));
|
|
1072
1140
|
}
|
|
@@ -1087,6 +1155,9 @@ class DB {
|
|
|
1087
1155
|
});
|
|
1088
1156
|
}
|
|
1089
1157
|
addMessage(msg) {
|
|
1158
|
+
if (this.#shouldDelegate()) {
|
|
1159
|
+
return this.#delegateStorage.addMessage(msg);
|
|
1160
|
+
}
|
|
1090
1161
|
if (!this.isReady()) {
|
|
1091
1162
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
1092
1163
|
}
|
|
@@ -1104,6 +1175,9 @@ class DB {
|
|
|
1104
1175
|
});
|
|
1105
1176
|
}
|
|
1106
1177
|
updMessageStatus(topicName, seq, status) {
|
|
1178
|
+
if (this.#shouldDelegate()) {
|
|
1179
|
+
return this.#delegateStorage.updMessageStatus(topicName, seq, status);
|
|
1180
|
+
}
|
|
1107
1181
|
if (!this.isReady()) {
|
|
1108
1182
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
1109
1183
|
}
|
|
@@ -1133,6 +1207,9 @@ class DB {
|
|
|
1133
1207
|
});
|
|
1134
1208
|
}
|
|
1135
1209
|
remMessages(topicName, from, to) {
|
|
1210
|
+
if (this.#shouldDelegate()) {
|
|
1211
|
+
return this.#delegateStorage.remMessages(topicName, from, to);
|
|
1212
|
+
}
|
|
1136
1213
|
if (!this.isReady()) {
|
|
1137
1214
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
1138
1215
|
}
|
|
@@ -1155,6 +1232,12 @@ class DB {
|
|
|
1155
1232
|
});
|
|
1156
1233
|
}
|
|
1157
1234
|
readMessages(topicName, query, callback, context) {
|
|
1235
|
+
console.log('[DB] readMessages CALLED:', topicName, 'shouldDelegate:', this.#shouldDelegate(), 'delegateStorage:', !!this.#delegateStorage);
|
|
1236
|
+
if (this.#shouldDelegate()) {
|
|
1237
|
+
console.log('[DB] readMessages DELEGATING to SQLiteStorage');
|
|
1238
|
+
return this.#delegateStorage.readMessages(topicName, query, callback, context);
|
|
1239
|
+
}
|
|
1240
|
+
console.log('[DB] readMessages NOT delegating, using IndexedDB');
|
|
1158
1241
|
query = query || {};
|
|
1159
1242
|
if (!this.isReady()) {
|
|
1160
1243
|
return this.disabled ? Promise.resolve([]) : Promise.reject(new Error("not initialized"));
|
|
@@ -1218,6 +1301,9 @@ class DB {
|
|
|
1218
1301
|
});
|
|
1219
1302
|
}
|
|
1220
1303
|
addDelLog(topicName, delId, ranges) {
|
|
1304
|
+
if (this.#shouldDelegate()) {
|
|
1305
|
+
return this.#delegateStorage.addDelLog(topicName, delId, ranges);
|
|
1306
|
+
}
|
|
1221
1307
|
if (!this.isReady()) {
|
|
1222
1308
|
return this.disabled ? Promise.resolve() : Promise.reject(new Error("not initialized"));
|
|
1223
1309
|
}
|
|
@@ -1240,6 +1326,9 @@ class DB {
|
|
|
1240
1326
|
});
|
|
1241
1327
|
}
|
|
1242
1328
|
readDelLog(topicName, query) {
|
|
1329
|
+
if (this.#shouldDelegate()) {
|
|
1330
|
+
return this.#delegateStorage.readDelLog(topicName, query);
|
|
1331
|
+
}
|
|
1243
1332
|
query = query || {};
|
|
1244
1333
|
if (!this.isReady()) {
|
|
1245
1334
|
return this.disabled ? Promise.resolve([]) : Promise.reject(new Error("not initialized"));
|
|
@@ -1312,6 +1401,9 @@ class DB {
|
|
|
1312
1401
|
});
|
|
1313
1402
|
}
|
|
1314
1403
|
maxDelId(topicName) {
|
|
1404
|
+
if (this.#shouldDelegate()) {
|
|
1405
|
+
return this.#delegateStorage.maxDelId(topicName);
|
|
1406
|
+
}
|
|
1315
1407
|
if (!this.isReady()) {
|
|
1316
1408
|
return this.disabled ? Promise.resolve(0) : Promise.reject(new Error("not initialized"));
|
|
1317
1409
|
}
|
|
@@ -1389,6 +1481,12 @@ class DB {
|
|
|
1389
1481
|
static setDatabaseProvider(idbProvider) {
|
|
1390
1482
|
IDBProvider = idbProvider;
|
|
1391
1483
|
}
|
|
1484
|
+
static setStorageProvider(storage) {
|
|
1485
|
+
_storageProvider = storage;
|
|
1486
|
+
}
|
|
1487
|
+
static getStorageProvider() {
|
|
1488
|
+
return _storageProvider;
|
|
1489
|
+
}
|
|
1392
1490
|
}
|
|
1393
1491
|
|
|
1394
1492
|
/***/ }),
|
|
@@ -5155,10 +5253,13 @@ class Topic {
|
|
|
5155
5253
|
return this._queuedSeqId++;
|
|
5156
5254
|
}
|
|
5157
5255
|
_loadMessages(db, query) {
|
|
5256
|
+
console.log('[Topic] _loadMessages CALLED:', this.name, 'query:', JSON.stringify(query), 'db:', !!db);
|
|
5158
5257
|
query = query || {};
|
|
5159
5258
|
query.limit = query.limit || _config_js__WEBPACK_IMPORTED_MODULE_3__.DEFAULT_MESSAGES_PAGE;
|
|
5160
5259
|
let count = 0;
|
|
5260
|
+
console.log('[Topic] _loadMessages: calling db.readMessages');
|
|
5161
5261
|
return db.readMessages(this.name, query).then(msgs => {
|
|
5262
|
+
console.log('[Topic] _loadMessages: db.readMessages returned', msgs ? msgs.length : 0, 'messages');
|
|
5162
5263
|
msgs.forEach(data => {
|
|
5163
5264
|
if (data.seq > this._maxSeq) {
|
|
5164
5265
|
this._maxSeq = data.seq;
|
|
@@ -5170,6 +5271,7 @@ class Topic {
|
|
|
5170
5271
|
this._maybeUpdateMessageVersionsCache(data);
|
|
5171
5272
|
});
|
|
5172
5273
|
count = msgs.length;
|
|
5274
|
+
console.log('[Topic] _loadMessages: processed', count, 'messages, _maxSeq:', this._maxSeq, '_minSeq:', this._minSeq);
|
|
5173
5275
|
}).then(_ => db.readDelLog(this.name, query)).then(dellog => {
|
|
5174
5276
|
return dellog.forEach(rec => {
|
|
5175
5277
|
this._messages.put({
|
|
@@ -5449,7 +5551,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
5449
5551
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
5450
5552
|
/* harmony export */ PACKAGE_VERSION: function() { return /* binding */ PACKAGE_VERSION; }
|
|
5451
5553
|
/* harmony export */ });
|
|
5452
|
-
const PACKAGE_VERSION = "0.25.1";
|
|
5554
|
+
const PACKAGE_VERSION = "0.25.1-sqlite.6";
|
|
5453
5555
|
|
|
5454
5556
|
/***/ })
|
|
5455
5557
|
|
|
@@ -5548,6 +5650,7 @@ var __webpack_exports__ = {};
|
|
|
5548
5650
|
__webpack_require__.r(__webpack_exports__);
|
|
5549
5651
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
5550
5652
|
/* harmony export */ AccessMode: function() { return /* reexport safe */ _access_mode_js__WEBPACK_IMPORTED_MODULE_0__["default"]; },
|
|
5653
|
+
/* harmony export */ DB: function() { return /* reexport safe */ _db_js__WEBPACK_IMPORTED_MODULE_4__["default"]; },
|
|
5551
5654
|
/* harmony export */ Drafty: function() { return /* reexport default from dynamic */ _drafty_js__WEBPACK_IMPORTED_MODULE_5___default.a; },
|
|
5552
5655
|
/* harmony export */ Tinode: function() { return /* binding */ Tinode; }
|
|
5553
5656
|
/* harmony export */ });
|
|
@@ -6299,6 +6402,9 @@ class Tinode {
|
|
|
6299
6402
|
IndexedDBProvider = idbProvider;
|
|
6300
6403
|
_db_js__WEBPACK_IMPORTED_MODULE_4__["default"].setDatabaseProvider(IndexedDBProvider);
|
|
6301
6404
|
}
|
|
6405
|
+
static setStorageProvider(storage) {
|
|
6406
|
+
_db_js__WEBPACK_IMPORTED_MODULE_4__["default"].setStorageProvider(storage);
|
|
6407
|
+
}
|
|
6302
6408
|
static getLibrary() {
|
|
6303
6409
|
return _config_js__WEBPACK_IMPORTED_MODULE_1__.LIBRARY;
|
|
6304
6410
|
}
|