@telestack/db-sdk 1.0.1 → 1.0.3
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/index.js +15 -24
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Transaction = exports.DocumentSnapshot = exports.WriteBatch = exports.DocumentReference = exports.CollectionReference = exports.Query = exports.TelestackClient = exports.TelestackError = exports.IndexedDBPersistence = void 0;
|
|
4
|
-
const centrifuge_1 = require("centrifuge");
|
|
1
|
+
import { Centrifuge } from 'centrifuge';
|
|
5
2
|
/**
|
|
6
3
|
* IndexedDB implementation of PersistenceEngine
|
|
7
4
|
*/
|
|
8
|
-
class IndexedDBPersistence {
|
|
5
|
+
export class IndexedDBPersistence {
|
|
9
6
|
db = null;
|
|
10
7
|
dbName = 'TelestackDB_Cache';
|
|
11
8
|
async init() {
|
|
@@ -80,9 +77,8 @@ class IndexedDBPersistence {
|
|
|
80
77
|
});
|
|
81
78
|
}
|
|
82
79
|
}
|
|
83
|
-
exports.IndexedDBPersistence = IndexedDBPersistence;
|
|
84
80
|
/** Custom Error class for Telestack operations */
|
|
85
|
-
class TelestackError extends Error {
|
|
81
|
+
export class TelestackError extends Error {
|
|
86
82
|
message;
|
|
87
83
|
code;
|
|
88
84
|
constructor(message, code) {
|
|
@@ -92,11 +88,10 @@ class TelestackError extends Error {
|
|
|
92
88
|
this.name = 'TelestackError';
|
|
93
89
|
}
|
|
94
90
|
}
|
|
95
|
-
exports.TelestackError = TelestackError;
|
|
96
91
|
/**
|
|
97
92
|
* Main Telestack Client
|
|
98
93
|
*/
|
|
99
|
-
class TelestackClient {
|
|
94
|
+
export class TelestackClient {
|
|
100
95
|
config;
|
|
101
96
|
centrifuge = null;
|
|
102
97
|
isProcessingQueue = false;
|
|
@@ -113,7 +108,7 @@ class TelestackClient {
|
|
|
113
108
|
this.persistence = new IndexedDBPersistence();
|
|
114
109
|
}
|
|
115
110
|
if (config.centrifugoUrl) {
|
|
116
|
-
this.centrifuge = new
|
|
111
|
+
this.centrifuge = new Centrifuge(config.centrifugoUrl, {
|
|
117
112
|
getToken: () => this.getToken()
|
|
118
113
|
});
|
|
119
114
|
this.centrifuge.on('connected', () => {
|
|
@@ -284,11 +279,10 @@ class TelestackClient {
|
|
|
284
279
|
setInterval(() => this.processQueue(), 5000); // Process queue every 5s
|
|
285
280
|
}
|
|
286
281
|
}
|
|
287
|
-
exports.TelestackClient = TelestackClient;
|
|
288
282
|
/**
|
|
289
283
|
* Query class for collection-level queries
|
|
290
284
|
*/
|
|
291
|
-
class Query {
|
|
285
|
+
export class Query {
|
|
292
286
|
client;
|
|
293
287
|
path;
|
|
294
288
|
filters = [];
|
|
@@ -434,7 +428,10 @@ class Query {
|
|
|
434
428
|
if (!centrifuge)
|
|
435
429
|
return () => { };
|
|
436
430
|
const channel = `collection:${this.path.replace(/\//g, '_')}`;
|
|
437
|
-
|
|
431
|
+
let sub = centrifuge.getSubscription(channel);
|
|
432
|
+
if (!sub) {
|
|
433
|
+
sub = centrifuge.newSubscription(channel);
|
|
434
|
+
}
|
|
438
435
|
const debouncedCallback = () => {
|
|
439
436
|
if (this.debounceTimer)
|
|
440
437
|
clearTimeout(this.debounceTimer);
|
|
@@ -518,11 +515,10 @@ class Query {
|
|
|
518
515
|
};
|
|
519
516
|
}
|
|
520
517
|
}
|
|
521
|
-
exports.Query = Query;
|
|
522
518
|
/**
|
|
523
519
|
* CollectionReference extends Query with add() and doc() methods
|
|
524
520
|
*/
|
|
525
|
-
class CollectionReference extends Query {
|
|
521
|
+
export class CollectionReference extends Query {
|
|
526
522
|
doc(id) {
|
|
527
523
|
return new DocumentReference(this.client, this.path, id);
|
|
528
524
|
}
|
|
@@ -547,11 +543,10 @@ class CollectionReference extends Query {
|
|
|
547
543
|
return result;
|
|
548
544
|
}
|
|
549
545
|
}
|
|
550
|
-
exports.CollectionReference = CollectionReference;
|
|
551
546
|
/**
|
|
552
547
|
* DocumentReference allows CRUD operations and realtime subscription on a single document
|
|
553
548
|
*/
|
|
554
|
-
class DocumentReference {
|
|
549
|
+
export class DocumentReference {
|
|
555
550
|
client;
|
|
556
551
|
collectionPath;
|
|
557
552
|
id;
|
|
@@ -731,11 +726,10 @@ class DocumentReference {
|
|
|
731
726
|
};
|
|
732
727
|
}
|
|
733
728
|
}
|
|
734
|
-
exports.DocumentReference = DocumentReference;
|
|
735
729
|
/**
|
|
736
730
|
* WriteBatch allows multiple write operations to be committed atomically
|
|
737
731
|
*/
|
|
738
|
-
class WriteBatch {
|
|
732
|
+
export class WriteBatch {
|
|
739
733
|
client;
|
|
740
734
|
operations = [];
|
|
741
735
|
constructor(client) {
|
|
@@ -767,11 +761,10 @@ class WriteBatch {
|
|
|
767
761
|
this.client.updateLastVersion(result.version);
|
|
768
762
|
}
|
|
769
763
|
}
|
|
770
|
-
exports.WriteBatch = WriteBatch;
|
|
771
764
|
/**
|
|
772
765
|
* DocumentSnapshot contains document data and its database version
|
|
773
766
|
*/
|
|
774
|
-
class DocumentSnapshot {
|
|
767
|
+
export class DocumentSnapshot {
|
|
775
768
|
id;
|
|
776
769
|
path;
|
|
777
770
|
_data;
|
|
@@ -787,11 +780,10 @@ class DocumentSnapshot {
|
|
|
787
780
|
exists() { return this._data !== null; }
|
|
788
781
|
data() { return this._data; }
|
|
789
782
|
}
|
|
790
|
-
exports.DocumentSnapshot = DocumentSnapshot;
|
|
791
783
|
/**
|
|
792
784
|
* Transaction allows read-modify-write operations with OCC
|
|
793
785
|
*/
|
|
794
|
-
class Transaction {
|
|
786
|
+
export class Transaction {
|
|
795
787
|
client;
|
|
796
788
|
operations = [];
|
|
797
789
|
constructor(client) {
|
|
@@ -845,4 +837,3 @@ class Transaction {
|
|
|
845
837
|
this.client.updateLastVersion(result.version);
|
|
846
838
|
}
|
|
847
839
|
}
|
|
848
|
-
exports.Transaction = Transaction;
|
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telestack/db-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Fluent, real-time SDK for Telestack DB",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
6
8
|
"types": "dist/index.d.ts",
|
|
7
9
|
"files": [
|
|
8
10
|
"dist",
|