@live-change/db-store-rbtree 0.6.1 → 0.6.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/lib/Store.js +14 -8
- package/package.json +3 -3
package/lib/Store.js
CHANGED
|
@@ -293,8 +293,14 @@ class CountObservable extends ReactiveDao.ObservableValue {
|
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
class Store {
|
|
296
|
-
constructor() {
|
|
296
|
+
constructor(options = {}) {
|
|
297
297
|
this.tree = createTree()
|
|
298
|
+
|
|
299
|
+
const {
|
|
300
|
+
serialization = JSON
|
|
301
|
+
} = options
|
|
302
|
+
this.serialization = serialization
|
|
303
|
+
|
|
298
304
|
this.objectObservables = new Map()
|
|
299
305
|
this.rangeObservables = new Map()
|
|
300
306
|
this.countObservables = new Map()
|
|
@@ -306,7 +312,7 @@ class Store {
|
|
|
306
312
|
const json = this.tree.get(key)
|
|
307
313
|
if(!json) return Promise.resolve(null)
|
|
308
314
|
try {
|
|
309
|
-
const obj =
|
|
315
|
+
const obj = this.serialization.parse(json)
|
|
310
316
|
return Promise.resolve(obj)
|
|
311
317
|
} catch(e) {
|
|
312
318
|
return Promise.reject(e)
|
|
@@ -338,7 +344,7 @@ class Store {
|
|
|
338
344
|
if(range.gte && cursor.key < range.gte) break;
|
|
339
345
|
if((!range.lt || cursor.key < range.lt) && (!range.lte || cursor.key <= range.lte)) {
|
|
340
346
|
// key in range, skip keys outside range
|
|
341
|
-
data.push(
|
|
347
|
+
data.push(this.serialization.parse(cursor.value))
|
|
342
348
|
}
|
|
343
349
|
cursor.prev()
|
|
344
350
|
}
|
|
@@ -353,7 +359,7 @@ class Store {
|
|
|
353
359
|
if(range.lte && cursor.key > range.lte) break;
|
|
354
360
|
if((!range.gt || cursor.key > range.gt) && (!range.gte || cursor.key >= range.gte)) {
|
|
355
361
|
// key in range, skip keys outside range
|
|
356
|
-
data.push(
|
|
362
|
+
data.push(this.serialization.parse(cursor.value))
|
|
357
363
|
}
|
|
358
364
|
cursor.next()
|
|
359
365
|
}
|
|
@@ -470,7 +476,7 @@ class Store {
|
|
|
470
476
|
const key = keys[i]
|
|
471
477
|
const json = tree.get(key)
|
|
472
478
|
try {
|
|
473
|
-
const obj =
|
|
479
|
+
const obj = this.serialization.parse(json)
|
|
474
480
|
this.tree = this.tree.remove(key)
|
|
475
481
|
const rangeObservables = this.rangeObservablesTree.search([key, key])
|
|
476
482
|
for (const rangeObservable of rangeObservables) {
|
|
@@ -488,11 +494,11 @@ class Store {
|
|
|
488
494
|
const id = object.id
|
|
489
495
|
if(typeof id != 'string') throw new Error(`ID is not string: ${JSON.stringify(id)}`)
|
|
490
496
|
const oldObjectJson = this.tree.get(id)
|
|
491
|
-
const oldObject = oldObjectJson &&
|
|
497
|
+
const oldObject = oldObjectJson && this.serialization.parse(oldObjectJson)
|
|
492
498
|
if(oldObjectJson) {
|
|
493
499
|
this.tree = this.tree.remove(id)
|
|
494
500
|
}
|
|
495
|
-
this.tree = this.tree.insert(id,
|
|
501
|
+
this.tree = this.tree.insert(id, this.serialization.stringify(object))
|
|
496
502
|
const objectObservable = this.objectObservables.get(id)
|
|
497
503
|
if (objectObservable) objectObservable.set(object, oldObject)
|
|
498
504
|
const rangeObservables = this.rangeObservablesTree.search([id, id])
|
|
@@ -518,7 +524,7 @@ class Store {
|
|
|
518
524
|
let object = null
|
|
519
525
|
try {
|
|
520
526
|
const json = this.tree.get(id)
|
|
521
|
-
object = json ?
|
|
527
|
+
object = json ? this.serialization.parse(json) : null
|
|
522
528
|
this.tree = this.tree.remove(id)
|
|
523
529
|
} catch(e) {
|
|
524
530
|
console.error("FAILED REMOVE OF", id, e)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/db-store-rbtree",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "Database with observable data for live queries",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"tape": "^5.3.2"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@live-change/dao": "0.5.
|
|
27
|
+
"@live-change/dao": "0.5.15",
|
|
28
28
|
"@live-change/interval-tree": "^1.0.12",
|
|
29
29
|
"functional-red-black-tree": "^1.0.1"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "8dc4ac726243970c9f1431bf67b4390f7845ce76"
|
|
32
32
|
}
|