@live-change/db-store-observable-db 0.8.88 → 0.8.90
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 +27 -27
- package/package.json +3 -3
package/lib/Store.js
CHANGED
|
@@ -85,9 +85,9 @@ class DatabaseConnection {
|
|
|
85
85
|
if(typeof message != 'string') { // Buffer
|
|
86
86
|
const opCode = message.readUInt8()
|
|
87
87
|
if(opCode < 2) {
|
|
88
|
-
if(opCode
|
|
88
|
+
if(opCode === opCodes.Ping) { // Ping - reply
|
|
89
89
|
message.writeUInt8(opCodes.Pong, 0)
|
|
90
|
-
if(this.websocket.readyState
|
|
90
|
+
if(this.websocket.readyState === 1) this.websocket.send(message)
|
|
91
91
|
} else {
|
|
92
92
|
// Pong - ignore
|
|
93
93
|
}
|
|
@@ -135,7 +135,7 @@ class DatabaseConnection {
|
|
|
135
135
|
addRequest(request) {
|
|
136
136
|
this.waitingRequests.set(request.id, request)
|
|
137
137
|
if(debug) console.log("ADD REQUEST", request.id,"AT STATE", this.websocket.readyState)
|
|
138
|
-
if(this.websocket.readyState
|
|
138
|
+
if(this.websocket.readyState === 1) { // 1 => open
|
|
139
139
|
this.websocket.send(request.requestPacket)
|
|
140
140
|
}
|
|
141
141
|
}
|
|
@@ -149,9 +149,9 @@ class DatabaseConnection {
|
|
|
149
149
|
requestPacket,
|
|
150
150
|
handlePacket: packet => {
|
|
151
151
|
const opcode = packet.readInt8(0)
|
|
152
|
-
if(opcode
|
|
152
|
+
if(opcode === opCodes.Ok) {
|
|
153
153
|
resolve()
|
|
154
|
-
} else if(opcode
|
|
154
|
+
} else if(opcode === opCodes.Error) {
|
|
155
155
|
const error = packet.toString('utf8', 5)
|
|
156
156
|
reject(error)
|
|
157
157
|
} else {
|
|
@@ -194,11 +194,11 @@ class DatabaseConnection {
|
|
|
194
194
|
return this.request(requestPacket, (packet, resolve, reject) => {
|
|
195
195
|
//console.log("HANDLE PACKET", packet)
|
|
196
196
|
const opcode = packet.readInt8(0)
|
|
197
|
-
if(opcode
|
|
197
|
+
if(opcode === opCodes.Result) {
|
|
198
198
|
resolve(packet.toString('utf8', 5))
|
|
199
|
-
} else if(opcode
|
|
199
|
+
} else if(opcode === opCodes.ResultNotFound) {
|
|
200
200
|
resolve(null)
|
|
201
|
-
} else if(opcode
|
|
201
|
+
} else if(opcode === opCodes.Error) {
|
|
202
202
|
const error = packet.toString('utf8', 5)
|
|
203
203
|
reject(error)
|
|
204
204
|
} else {
|
|
@@ -257,8 +257,8 @@ class DatabaseConnection {
|
|
|
257
257
|
async deleteStore(databaseName, storeName) {
|
|
258
258
|
if(debug) console.log("DELETE STORE", databaseName, storeName)
|
|
259
259
|
for(let i = 0; i < this.openStores.length; i++) {
|
|
260
|
-
if(this.openStores[i] && this.openStores[i].storeName
|
|
261
|
-
&& this.openStores[i].databaseName
|
|
260
|
+
if(this.openStores[i] && this.openStores[i].storeName === storeName
|
|
261
|
+
&& this.openStores[i].databaseName === databaseName) this.openStore[i] = null
|
|
262
262
|
}
|
|
263
263
|
const databaseNameBuffer = Buffer.from(databaseName)
|
|
264
264
|
const storeNameBuffer = Buffer.from(storeName)
|
|
@@ -273,8 +273,8 @@ class DatabaseConnection {
|
|
|
273
273
|
|
|
274
274
|
async openStore(databaseName, storeName) {
|
|
275
275
|
for(let i = 0; i < this.openStores.length; i++) {
|
|
276
|
-
if(this.openStores[i] && this.openStores[i].storeName
|
|
277
|
-
&& this.openStores[i].databaseName
|
|
276
|
+
if(this.openStores[i] && this.openStores[i].storeName === storeName
|
|
277
|
+
&& this.openStores[i].databaseName === databaseName) return i
|
|
278
278
|
}
|
|
279
279
|
const storeKey = JSON.stringify([databaseName, storeName])
|
|
280
280
|
console.log("OPEN STORE!", storeKey)
|
|
@@ -411,7 +411,7 @@ class DatabaseConnection {
|
|
|
411
411
|
return this.request(packet, (packet, resolve, reject) => {
|
|
412
412
|
//console.log("HANDLE PACKET", packet)
|
|
413
413
|
const opcode = packet.readInt8(0)
|
|
414
|
-
if(opcode
|
|
414
|
+
if(opcode === opCodes.ResultPut) {
|
|
415
415
|
const flags = packet.readUInt8(5) // ignore flags
|
|
416
416
|
const keySize = packet.readUInt16BE(6)
|
|
417
417
|
const key = packet.toString('utf8', 8, 8 + keySize)
|
|
@@ -419,9 +419,9 @@ class DatabaseConnection {
|
|
|
419
419
|
const value = packet.toString('utf8', 8 + keySize + 4, 8 + keySize + 4 + valueSize)
|
|
420
420
|
results.push({ key, value })
|
|
421
421
|
return true // need more data
|
|
422
|
-
} else if(opcode
|
|
422
|
+
} else if(opcode === opCodes.ResultsDone) {
|
|
423
423
|
resolve(results)
|
|
424
|
-
} else if(opcode
|
|
424
|
+
} else if(opcode === opCodes.Error) {
|
|
425
425
|
const error = packet.toString('utf8', 5)
|
|
426
426
|
reject(error)
|
|
427
427
|
} else {
|
|
@@ -438,9 +438,9 @@ class DatabaseConnection {
|
|
|
438
438
|
return this.request(packet, (packet, resolve, reject) => {
|
|
439
439
|
//console.log("HANDLE PACKET", packet)
|
|
440
440
|
const opcode = packet.readInt8(0)
|
|
441
|
-
if(opcode
|
|
441
|
+
if(opcode === opCodes.ResultCount) {
|
|
442
442
|
resolve(packet.readUInt32BE(5))
|
|
443
|
-
} else if(opcode
|
|
443
|
+
} else if(opcode === opCodes.Error) {
|
|
444
444
|
const error = packet.toString('utf8', 5)
|
|
445
445
|
reject(error)
|
|
446
446
|
} else {
|
|
@@ -457,9 +457,9 @@ class DatabaseConnection {
|
|
|
457
457
|
return this.request(packet, (packet, resolve, reject) => {
|
|
458
458
|
//console.log("HANDLE PACKET", packet)
|
|
459
459
|
const opcode = packet.readInt8(0)
|
|
460
|
-
if(opcode
|
|
460
|
+
if(opcode === opCodes.ResultCount) {
|
|
461
461
|
resolve(packet.readUInt32BE(5))
|
|
462
|
-
} else if(opcode
|
|
462
|
+
} else if(opcode === opCodes.Error) {
|
|
463
463
|
const error = packet.toString('utf8', 5)
|
|
464
464
|
reject(error)
|
|
465
465
|
} else {
|
|
@@ -482,11 +482,11 @@ class DatabaseConnection {
|
|
|
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
|
-
if(opcode
|
|
485
|
+
if(opcode === opCodes.Result) {
|
|
486
486
|
return onValue(packet.toString('utf8', 5))
|
|
487
|
-
} else if(opcode
|
|
487
|
+
} else if(opcode === opCodes.ResultNotFound) {
|
|
488
488
|
return onValue(null)
|
|
489
|
-
} else if(opcode
|
|
489
|
+
} else if(opcode === opCodes.Error) {
|
|
490
490
|
const error = packet.toString('utf8', 5)
|
|
491
491
|
onError(error)
|
|
492
492
|
return true
|
|
@@ -508,7 +508,7 @@ class DatabaseConnection {
|
|
|
508
508
|
return this.rawRequest(packet, (packet) => {
|
|
509
509
|
if(debug) console.log("OBSERVE RANGE HANDLE PACKET", packet)
|
|
510
510
|
const opcode = packet.readInt8(0)
|
|
511
|
-
if(opcode
|
|
511
|
+
if(opcode === opCodes.ResultPut) {
|
|
512
512
|
const flags = packet.readUInt8(5)
|
|
513
513
|
const found = !!(flags & resultPutFlags.Found)
|
|
514
514
|
const last = !!(flags & resultPutFlags.Last)
|
|
@@ -521,9 +521,9 @@ class DatabaseConnection {
|
|
|
521
521
|
} else {
|
|
522
522
|
return onResultPut(found, last, key, null)
|
|
523
523
|
}
|
|
524
|
-
} else if(opcode
|
|
524
|
+
} else if(opcode === opCodes.ResultsChanges) {
|
|
525
525
|
return onChanges()
|
|
526
|
-
} else if(opcode
|
|
526
|
+
} else if(opcode === opCodes.Error) {
|
|
527
527
|
const error = packet.toString('utf8', 5)
|
|
528
528
|
onError(error)
|
|
529
529
|
} else {
|
|
@@ -540,10 +540,10 @@ class DatabaseConnection {
|
|
|
540
540
|
return this.rawRequest(packet, (packet) => {
|
|
541
541
|
if(debug) console.log("OBSERVE RANGE HANDLE PACKET", packet)
|
|
542
542
|
const opcode = packet.readInt8(0)
|
|
543
|
-
if(opcode
|
|
543
|
+
if(opcode === opCodes.ResultCount) {
|
|
544
544
|
const count = packet.readUInt32BE(5)
|
|
545
545
|
return onCount(count)
|
|
546
|
-
} else if(opcode
|
|
546
|
+
} else if(opcode === opCodes.Error) {
|
|
547
547
|
const error = packet.toString('utf8', 5)
|
|
548
548
|
onError(error)
|
|
549
549
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/db-store-observable-db",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.90",
|
|
4
4
|
"description": "Database backend protocol",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"tape": "^5.7.4"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@live-change/dao": "^0.8.
|
|
27
|
+
"@live-change/dao": "^0.8.90",
|
|
28
28
|
"bufferutil": "^4.0.3",
|
|
29
29
|
"utf-8-validate": "^5.0.4",
|
|
30
30
|
"ws": "^7.4.5"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "745223326ab078f2155434fe684611fc1398df9d"
|
|
33
33
|
}
|