@live-change/db-store-observable-db 0.1.1 → 0.5.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/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/db-store-observable-db.iml +9 -0
- package/lib/Store.js +10 -3
- package/package.json +3 -2
- package/tests/store-non-reactive.js +8 -1
package/.idea/misc.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/db-store-observable-db.iml" filepath="$PROJECT_DIR$/db-store-observable-db.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
package/.idea/vcs.xml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
+
<exclude-output />
|
|
5
|
+
<content url="file://$MODULE_DIR$" />
|
|
6
|
+
<orderEntry type="inheritedJdk" />
|
|
7
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
+
</component>
|
|
9
|
+
</module>
|
package/lib/Store.js
CHANGED
|
@@ -52,7 +52,7 @@ const rangeFlags = {
|
|
|
52
52
|
|
|
53
53
|
const resultPutFlags = {
|
|
54
54
|
Found: 0x1,
|
|
55
|
-
Created:
|
|
55
|
+
Created: 0x2,
|
|
56
56
|
Last: 0x4
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -479,7 +479,7 @@ class DatabaseConnection {
|
|
|
479
479
|
packet.writeUInt16BE(keyBuffer.length, 1+4+4)
|
|
480
480
|
keyBuffer.copy(packet, 1+4+4+2)
|
|
481
481
|
if(debug) console.log("OBSERVE KEY", key)
|
|
482
|
-
|
|
482
|
+
const requestId = this.rawRequest(packet, (packet) => {
|
|
483
483
|
if(debug) console.log("HANDLE OBSERVE PACKET", packet)
|
|
484
484
|
const opcode = packet.readInt8(0)
|
|
485
485
|
if(opcode == opCodes.Result) {
|
|
@@ -489,12 +489,16 @@ class DatabaseConnection {
|
|
|
489
489
|
} else if(opcode == opCodes.Error) {
|
|
490
490
|
const error = packet.toString('utf8', 5)
|
|
491
491
|
onError(error)
|
|
492
|
+
return true
|
|
492
493
|
} else {
|
|
493
494
|
console.error("Unknown opcode", opCodeToString[opcode])
|
|
494
495
|
onError("Unknown opcode: " + opCodeToString[opcode])
|
|
495
496
|
}
|
|
497
|
+
process.exit(1)
|
|
496
498
|
return false// finish waiting
|
|
497
499
|
})
|
|
500
|
+
//console.log("OBSERVE", key, "=>", requestId)
|
|
501
|
+
return requestId
|
|
498
502
|
}
|
|
499
503
|
|
|
500
504
|
async observeRange(databaseName, storeName, range, onResultPut, onChanges, onError) {
|
|
@@ -551,6 +555,7 @@ class DatabaseConnection {
|
|
|
551
555
|
}
|
|
552
556
|
|
|
553
557
|
async unobserve(requestId) {
|
|
558
|
+
//console.log("UNOBSERVE", requestId)
|
|
554
559
|
if(!this.waitingRequests.get(requestId)) {
|
|
555
560
|
throw new Error("unobserve of not observed! "+requestId)
|
|
556
561
|
}
|
|
@@ -599,7 +604,9 @@ class Store {
|
|
|
599
604
|
const oldDispose = observableValue.dispose
|
|
600
605
|
const oldRespawn = observableValue.respawn
|
|
601
606
|
observableValue.dispose = () => {
|
|
602
|
-
|
|
607
|
+
//console.trace("DISPOSE!")
|
|
608
|
+
//console.log("DISPOSE", observableValue.requestId, this.disposed)
|
|
609
|
+
//if(!this.disposed) this.connection.unobserve(observableValue.requestId)
|
|
603
610
|
oldDispose.apply(this)
|
|
604
611
|
}
|
|
605
612
|
observableValue.respawn = async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/db-store-observable-db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Database backend protocol",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,5 +28,6 @@
|
|
|
28
28
|
"bufferutil": "^4.0.3",
|
|
29
29
|
"utf-8-validate": "^5.0.4",
|
|
30
30
|
"ws": "^7.4.5"
|
|
31
|
-
}
|
|
31
|
+
},
|
|
32
|
+
"gitHead": "d92fb65e55f55e246e7a4615cff609cafdc32eba"
|
|
32
33
|
}
|
|
@@ -23,7 +23,7 @@ test("store non-reactive properties", t => {
|
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
t.test("non reactive operations", async t => {
|
|
26
|
-
t.plan(
|
|
26
|
+
t.plan(25)
|
|
27
27
|
|
|
28
28
|
t.test("put value", async t => {
|
|
29
29
|
t.plan(1)
|
|
@@ -78,6 +78,13 @@ test("store non-reactive properties", t => {
|
|
|
78
78
|
t.deepEqual(values, 3, 'range count' )
|
|
79
79
|
})
|
|
80
80
|
|
|
81
|
+
t.test("count all", async t => {
|
|
82
|
+
t.plan(1)
|
|
83
|
+
let values = await store.countGet({ })
|
|
84
|
+
t.deepEqual(values, 3, 'full count' )
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
|
|
81
88
|
t.test("get reverse range [c,a]", async t => {
|
|
82
89
|
t.plan(1)
|
|
83
90
|
let values = await store.rangeGet({ gte: 'a', lte: 'c', reverse: true })
|