@roeehrl/tinode-sdk 0.25.1-sqlite.11 → 0.25.1-sqlite.13

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 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.11",
4
+ "version": "0.25.1-sqlite.13",
5
5
  "types": "./types/index.d.ts",
6
6
  "scripts": {
7
7
  "format": "js-beautify -r src/*.js",
package/src/comm-error.js CHANGED
@@ -1,14 +1,15 @@
1
1
  /**
2
- * @file Throwable error with numeric error code.
2
+ * @file Throwable error with numeric error code and optional params.
3
3
  *
4
4
  * @copyright 2015-2023 Tinode LLC.
5
5
  */
6
6
  'use strict';
7
7
 
8
8
  export default class CommError extends Error {
9
- constructor(message, code) {
9
+ constructor(message, code, params) {
10
10
  super(`${message} (${code})`);
11
11
  this.name = 'CommError';
12
12
  this.code = code;
13
+ this.params = params;
13
14
  }
14
15
  }
@@ -114,7 +114,12 @@ export default class LargeFileHelperNative {
114
114
 
115
115
  // Log upload details
116
116
  this._tinode.logger("Starting upload to:", url);
117
- this._tinode.logger("Upload file:", { uri, filename, mimetype, size });
117
+ this._tinode.logger("Upload file:", {
118
+ uri,
119
+ filename,
120
+ mimetype,
121
+ size
122
+ });
118
123
 
119
124
  // Create AbortController for cancellation
120
125
  const abortController = new AbortController();
package/src/tinode.js CHANGED
@@ -495,6 +495,7 @@ export class Tinode {
495
495
 
496
496
  // Resolve or reject a pending promise.
497
497
  // Unresolved promises are stored in _pendingPromises.
498
+ // onOK is the full ctrl object, which contains params for error responses.
498
499
  #execPromise(id, code, onOK, errorText) {
499
500
  const callbacks = this._pendingPromises[id];
500
501
  if (callbacks) {
@@ -504,7 +505,14 @@ export class Tinode {
504
505
  callbacks.resolve(onOK);
505
506
  }
506
507
  } else if (callbacks.reject) {
507
- callbacks.reject(new CommError(errorText, code));
508
+ console.log("[Tinode/execPromise] Rejecting:", JSON.stringify({
509
+ code: code,
510
+ errorText: errorText,
511
+ hasOnOK: !!onOK,
512
+ params: onOK ? onOK.params : undefined,
513
+ onOKKeys: onOK ? Object.keys(onOK) : undefined,
514
+ }));
515
+ callbacks.reject(new CommError(errorText, code, onOK ? onOK.params : undefined));
508
516
  }
509
517
  }
510
518
  }
package/src/topic.js CHANGED
@@ -381,12 +381,19 @@ export default class Topic {
381
381
  this._routeData(pub);
382
382
  return ctrl;
383
383
  }).catch(err => {
384
+ console.log("[Tinode/publishMessage] Error caught:", JSON.stringify({
385
+ code: err.code,
386
+ message: err.message,
387
+ params: err.params,
388
+ name: err.name,
389
+ }));
384
390
  this._tinode.logger("WARNING: Message rejected by the server", err);
385
391
  pub._sending = false;
386
392
  pub._failed = true;
387
393
  if (this.onData) {
388
394
  this.onData();
389
395
  }
396
+ throw err;
390
397
  });
391
398
  }
392
399
 
package/umd/tinode.dev.js CHANGED
@@ -360,10 +360,11 @@ __webpack_require__.r(__webpack_exports__);
360
360
 
361
361
 
362
362
  class CommError extends Error {
363
- constructor(message, code) {
363
+ constructor(message, code, params) {
364
364
  super(`${message} (${code})`);
365
365
  this.name = 'CommError';
366
366
  this.code = code;
367
+ this.params = params;
367
368
  }
368
369
  }
369
370
 
@@ -852,15 +853,9 @@ class DB {
852
853
  });
853
854
  }
854
855
  initDatabase() {
855
- console.log('[DB] initDatabase CALLED, shouldDelegate:', this.#shouldDelegate(), 'delegateStorage:', !!this.#delegateStorage);
856
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
- });
857
+ return this.#delegateStorage.initDatabase();
862
858
  }
863
- console.log('[DB] initDatabase using IndexedDB');
864
859
  return new Promise((resolve, reject) => {
865
860
  const req = IDBProvider.open(DB_NAME, DB_VERSION);
866
861
  req.onsuccess = event => {
@@ -955,10 +950,8 @@ class DB {
955
950
  }
956
951
  updTopic(topic) {
957
952
  if (topic?._new) {
958
- console.log('[DB] updTopic DEFERRED - topic not yet confirmed by server:', topic.name);
959
953
  return Promise.resolve();
960
954
  }
961
- console.log('[DB] updTopic CALLED:', topic?.name, 'shouldDelegate:', this.#shouldDelegate());
962
955
  if (this.#shouldDelegate()) {
963
956
  return this.#delegateStorage.updTopic(topic);
964
957
  }
@@ -1031,15 +1024,9 @@ class DB {
1031
1024
  });
1032
1025
  }
1033
1026
  mapTopics(callback, context) {
1034
- console.log('[DB] mapTopics CALLED, shouldDelegate:', this.#shouldDelegate());
1035
1027
  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
- });
1028
+ return this.#delegateStorage.mapTopics(callback, context);
1041
1029
  }
1042
- console.log('[DB] mapTopics using IndexedDB');
1043
1030
  return this.#mapObjects('topic', callback, context);
1044
1031
  }
1045
1032
  deserializeTopic(topic, src) {
@@ -1246,12 +1233,9 @@ class DB {
1246
1233
  });
1247
1234
  }
1248
1235
  readMessages(topicName, query, callback, context) {
1249
- console.log('[DB] readMessages CALLED:', topicName, 'shouldDelegate:', this.#shouldDelegate(), 'delegateStorage:', !!this.#delegateStorage);
1250
1236
  if (this.#shouldDelegate()) {
1251
- console.log('[DB] readMessages DELEGATING to SQLiteStorage');
1252
1237
  return this.#delegateStorage.readMessages(topicName, query, callback, context);
1253
1238
  }
1254
- console.log('[DB] readMessages NOT delegating, using IndexedDB');
1255
1239
  query = query || {};
1256
1240
  if (!this.isReady()) {
1257
1241
  return this.disabled ? Promise.resolve([]) : Promise.reject(new Error("not initialized"));
@@ -4234,12 +4218,19 @@ class Topic {
4234
4218
  this._routeData(pub);
4235
4219
  return ctrl;
4236
4220
  }).catch(err => {
4221
+ console.log("[Tinode/publishMessage] Error caught:", JSON.stringify({
4222
+ code: err.code,
4223
+ message: err.message,
4224
+ params: err.params,
4225
+ name: err.name
4226
+ }));
4237
4227
  this._tinode.logger("WARNING: Message rejected by the server", err);
4238
4228
  pub._sending = false;
4239
4229
  pub._failed = true;
4240
4230
  if (this.onData) {
4241
4231
  this.onData();
4242
4232
  }
4233
+ throw err;
4243
4234
  });
4244
4235
  }
4245
4236
  publishDraft(pub, prom) {
@@ -5267,13 +5258,10 @@ class Topic {
5267
5258
  return this._queuedSeqId++;
5268
5259
  }
5269
5260
  _loadMessages(db, query) {
5270
- console.log('[Topic] _loadMessages CALLED:', this.name, 'query:', JSON.stringify(query), 'db:', !!db);
5271
5261
  query = query || {};
5272
5262
  query.limit = query.limit || _config_js__WEBPACK_IMPORTED_MODULE_3__.DEFAULT_MESSAGES_PAGE;
5273
5263
  let count = 0;
5274
- console.log('[Topic] _loadMessages: calling db.readMessages');
5275
5264
  return db.readMessages(this.name, query).then(msgs => {
5276
- console.log('[Topic] _loadMessages: db.readMessages returned', msgs ? msgs.length : 0, 'messages');
5277
5265
  msgs.forEach(data => {
5278
5266
  if (data.seq > this._maxSeq) {
5279
5267
  this._maxSeq = data.seq;
@@ -5285,7 +5273,6 @@ class Topic {
5285
5273
  this._maybeUpdateMessageVersionsCache(data);
5286
5274
  });
5287
5275
  count = msgs.length;
5288
- console.log('[Topic] _loadMessages: processed', count, 'messages, _maxSeq:', this._maxSeq, '_minSeq:', this._minSeq);
5289
5276
  }).then(_ => db.readDelLog(this.name, query)).then(dellog => {
5290
5277
  return dellog.forEach(rec => {
5291
5278
  this._messages.put({
@@ -5565,7 +5552,7 @@ __webpack_require__.r(__webpack_exports__);
5565
5552
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
5566
5553
  /* harmony export */ PACKAGE_VERSION: function() { return /* binding */ PACKAGE_VERSION; }
5567
5554
  /* harmony export */ });
5568
- const PACKAGE_VERSION = "0.25.1-sqlite.8";
5555
+ const PACKAGE_VERSION = "0.25.1-sqlite.13";
5569
5556
 
5570
5557
  /***/ })
5571
5558
 
@@ -6027,7 +6014,14 @@ class Tinode {
6027
6014
  callbacks.resolve(onOK);
6028
6015
  }
6029
6016
  } else if (callbacks.reject) {
6030
- callbacks.reject(new _comm_error_js__WEBPACK_IMPORTED_MODULE_2__["default"](errorText, code));
6017
+ console.log("[Tinode/execPromise] Rejecting:", JSON.stringify({
6018
+ code: code,
6019
+ errorText: errorText,
6020
+ hasOnOK: !!onOK,
6021
+ params: onOK ? onOK.params : undefined,
6022
+ onOKKeys: onOK ? Object.keys(onOK) : undefined
6023
+ }));
6024
+ callbacks.reject(new _comm_error_js__WEBPACK_IMPORTED_MODULE_2__["default"](errorText, code, onOK ? onOK.params : undefined));
6031
6025
  }
6032
6026
  }
6033
6027
  }