@live-change/dao 0.8.37 → 0.8.38
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/ReactiveServerConnection.js +11 -8
- package/lib/utils.js +5 -0
- package/package.json +2 -2
|
@@ -118,7 +118,7 @@ class PushObservableTrigger {
|
|
|
118
118
|
added.filter(pointer => this.pointers.get(pointer))
|
|
119
119
|
for(let [pointer, count] of this.pointers.entries()) {
|
|
120
120
|
if(count < 0) throw new Error("deleted not existing pointer: "+ pointer)
|
|
121
|
-
if(count
|
|
121
|
+
if(count === 0) removed.push(pointer)
|
|
122
122
|
}
|
|
123
123
|
for(let rm of removed) this.pointers.delete(rm)
|
|
124
124
|
this.commitPointersUpdate(added, removed)
|
|
@@ -264,7 +264,7 @@ class PushObservable extends ObservableList {
|
|
|
264
264
|
const trigger = this.triggers.get(key)
|
|
265
265
|
if(!trigger) throw new Error("could not remove not existing trigger")
|
|
266
266
|
trigger.uses --
|
|
267
|
-
if(trigger.uses
|
|
267
|
+
if(trigger.uses === 0) {
|
|
268
268
|
trigger.dispose()
|
|
269
269
|
this.triggers.delete(key)
|
|
270
270
|
}
|
|
@@ -288,7 +288,7 @@ class PushObservable extends ObservableList {
|
|
|
288
288
|
let observationInfo = this.observations.get(whatId)
|
|
289
289
|
if(!observationInfo) throw new Error("could not unpush not existing observation")
|
|
290
290
|
observationInfo.uses--
|
|
291
|
-
if(observationInfo.uses
|
|
291
|
+
if(observationInfo.uses === 0) {
|
|
292
292
|
this.observations.delete(whatId)
|
|
293
293
|
observationInfo.observation.unpush()
|
|
294
294
|
this.remove(what)
|
|
@@ -320,6 +320,9 @@ class Observation {
|
|
|
320
320
|
if(!observed) this.push()
|
|
321
321
|
|
|
322
322
|
this.observer = (signal, ...args) => {
|
|
323
|
+
if(signal === 'error' && args[0]) {
|
|
324
|
+
args[0] = utils.errorToJSON(args[0])
|
|
325
|
+
}
|
|
323
326
|
this.connection.send({
|
|
324
327
|
type: "notify",
|
|
325
328
|
what, signal, args
|
|
@@ -343,7 +346,7 @@ class Observation {
|
|
|
343
346
|
if(!this.observed) throw new Error("Unobserve of not observed "+JSON.stringify(this.what)+
|
|
344
347
|
" pushed "+this.pushCount)
|
|
345
348
|
this.observed = false
|
|
346
|
-
if(this.pushCount
|
|
349
|
+
if(this.pushCount === 0) {
|
|
347
350
|
this.dispose()
|
|
348
351
|
} else if(!pushed) { // distributed race condition - client removed observation before received push
|
|
349
352
|
/// Refresh observation - send fresh value
|
|
@@ -353,7 +356,7 @@ class Observation {
|
|
|
353
356
|
}
|
|
354
357
|
unpush() {
|
|
355
358
|
this.pushCount--
|
|
356
|
-
if(this.pushCount
|
|
359
|
+
if(this.pushCount === 0) {
|
|
357
360
|
this.connection.send({
|
|
358
361
|
type: "unpush",
|
|
359
362
|
what: this.what
|
|
@@ -364,7 +367,7 @@ class Observation {
|
|
|
364
367
|
}
|
|
365
368
|
push() {
|
|
366
369
|
this.pushCount++
|
|
367
|
-
if(this.pushCount
|
|
370
|
+
if(this.pushCount === 1) {
|
|
368
371
|
this.connection.send({
|
|
369
372
|
type: "push",
|
|
370
373
|
what: this.what
|
|
@@ -438,7 +441,7 @@ class ReactiveServerConnection extends EventEmitter {
|
|
|
438
441
|
try {
|
|
439
442
|
const serialized = JSON.stringify(message)
|
|
440
443
|
this.connection.write(serialized)
|
|
441
|
-
if(message.signal
|
|
444
|
+
if(message.signal === 'error') {
|
|
442
445
|
debug("sending error", JSON.stringify(message, null, 2))
|
|
443
446
|
}
|
|
444
447
|
} catch (error) {
|
|
@@ -608,7 +611,7 @@ class ReactiveServerConnection extends EventEmitter {
|
|
|
608
611
|
moreDeps.push(dep)
|
|
609
612
|
return undefined
|
|
610
613
|
})
|
|
611
|
-
if(moreDeps.length
|
|
614
|
+
if(moreDeps.length === 0) return Promise.resolve(pointers)
|
|
612
615
|
return Promise.all(moreDeps.map(dep => {
|
|
613
616
|
const result = fetch({ what: dep }).catch(error => {
|
|
614
617
|
error.stack += `\nWhile fetching ${JSON.stringify(dep)} from source`
|
package/lib/utils.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
export function errorToJSON(error) {
|
|
2
2
|
if(typeof error == 'object') {
|
|
3
|
+
if(error instanceof Error && error.stack) return error.stack.toString()
|
|
4
|
+
if(error instanceof Error && error.message) return error.message.toString()
|
|
3
5
|
let obj = {}
|
|
6
|
+
//obj.string = error.toString()
|
|
4
7
|
Object.getOwnPropertyNames(error).forEach(function (key) {
|
|
5
8
|
obj[key] = error[key]
|
|
6
9
|
})
|
|
10
|
+
if(error.message) obj.message = error.message.toString()
|
|
11
|
+
if(error.stack) obj.stack = error.stack.toString()
|
|
7
12
|
return obj
|
|
8
13
|
}
|
|
9
14
|
return error
|
package/package.json
CHANGED