@live-change/db 0.8.58 → 0.8.60

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.
@@ -18,10 +18,14 @@ class ObjectObserver {
18
18
  this.#valuePromiseReject = reject
19
19
  })
20
20
  }
21
- set(value) {
22
- if(this._queryReader.state == READER_DISPOSED) return
21
+ async set(value) {
22
+ if(this._queryReader.state === READER_DISPOSED) return
23
23
  const now = (''+Date.now()).padStart(16, '0')
24
- this.#callback(value, this.#oldValue, value ? value.id : this.#oldValue && this.#oldValue.id, now)
24
+ if(this._queryReader.state === READER_READING) {
25
+ await this.#callback(value, this.#oldValue, value ? value.id : this.#oldValue && this.#oldValue.id, now)
26
+ } else {
27
+ this.#callback(value, this.#oldValue, value ? value.id : this.#oldValue && this.#oldValue.id, now)
28
+ }
25
29
  this.#oldValue = value
26
30
  if(!this.#resolved) this.#valuePromiseResolve(value)
27
31
  }
@@ -46,9 +50,9 @@ class RangeObserver {
46
50
  })
47
51
  }
48
52
  async set(value) {
49
- if(this._queryReader.state == READER_DISPOSED) return
53
+ if(this._queryReader.state === READER_DISPOSED) return
50
54
  const now = (''+Date.now()).padStart(16, '0')
51
- if(this._queryReader.state == READER_READING) {
55
+ if(this._queryReader.state === READER_READING) {
52
56
  await Promise.all(value.map(obj => this.#callback(obj, null, obj.id, now)))
53
57
  } else {
54
58
  for(let obj of value) this.#callback(obj, null, obj.id, now)
@@ -56,13 +60,13 @@ class RangeObserver {
56
60
  if(!this.#resolved) this.#valuePromiseResolve(value)
57
61
  }
58
62
  putByField(field, id, object, reverse, oldObject) {
59
- if(this._queryReader.state == READER_DISPOSED) return
60
- if(field != 'id') throw new Error("incompatible range protocol")
63
+ if(this._queryReader.state === READER_DISPOSED) return
64
+ if(field !== 'id') throw new Error("incompatible range protocol")
61
65
  const now = (''+Date.now()).padStart(16, '0')
62
66
  this.#callback(object, oldObject, id, now)
63
67
  }
64
68
  removeByField(field, id, object) {
65
- if(this._queryReader.state == READER_DISPOSED) return
69
+ if(this._queryReader.state === READER_DISPOSED) return
66
70
  this.#callback(null, object)
67
71
  }
68
72
  readPromise() {
@@ -87,9 +91,9 @@ class Reader extends ChangeStream {
87
91
  this.#observers.push(observer)
88
92
  ;(await this.#observable).observe(observer)
89
93
  await observer.readPromise()
90
- observer.dispose = async function() {
94
+ observer.dispose = async () => {
91
95
  const observerIndex = this.#observers.indexOf(observer)
92
- if(observerIndex == -1) throw new Error('Observer double dispose')
96
+ if(observerIndex === -1) throw new Error('Observer double dispose')
93
97
  this.#observers.splice(observerIndex, 1)
94
98
  ;(await this.#observable).unobserve(observer)
95
99
  }
@@ -97,7 +101,7 @@ class Reader extends ChangeStream {
97
101
  }
98
102
  async unobserve(observer) {
99
103
  const index = this.#observers.indexOf(observer)
100
- if(index == -1) {
104
+ if(index === -1) {
101
105
  console.error("OBSERVER NOT FOUND", observer)
102
106
  throw new Error("observer not found")
103
107
  }
@@ -276,7 +280,7 @@ class QueryWriter {
276
280
  //if(!obj && !oldObj) throw new Error("empty change in observable query")
277
281
  if(this.#observationMode) {
278
282
  if(obj) {
279
- if(oldObj && oldObj.id != obj.id) {
283
+ if(oldObj && oldObj.id !== obj.id) {
280
284
  this.#observable.deleteObject(oldObj)
281
285
  this.#observable.putObject(obj, null, this.#reverse)
282
286
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/db",
3
- "version": "0.8.58",
3
+ "version": "0.8.60",
4
4
  "description": "Database with observable data for live queries",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,8 +22,8 @@
22
22
  "type": "module",
23
23
  "homepage": "https://github.com/live-change/live-change-stack",
24
24
  "devDependencies": {
25
- "@live-change/db-store-level": "^0.8.58",
26
- "@live-change/db-store-lmdb": "^0.8.58",
25
+ "@live-change/db-store-level": "^0.8.60",
26
+ "@live-change/db-store-lmdb": "^0.8.60",
27
27
  "minimist": ">=1.2.3",
28
28
  "next-tick": "^1.1.0",
29
29
  "rimraf": "^5.0.5",
@@ -32,9 +32,9 @@
32
32
  "websocket-extensions": ">=0.1.4"
33
33
  },
34
34
  "dependencies": {
35
- "@live-change/dao": "^0.8.58",
35
+ "@live-change/dao": "^0.8.60",
36
36
  "get-random-values": "^1.2.2",
37
37
  "node-interval-tree": "^1.3.3"
38
38
  },
39
- "gitHead": "bd44582e1eaa6396a4a24daabc945c0866ed8657"
39
+ "gitHead": "88bd85bdcd412560abb0aa13f9f3e9c30cbc5455"
40
40
  }