@live-change/db 0.3.64 → 0.5.2
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/Database.js +5 -3
- package/lib/Index.js +7 -5
- package/package.json +5 -12
package/lib/Database.js
CHANGED
|
@@ -7,6 +7,8 @@ const getRandomValues = require('get-random-values')
|
|
|
7
7
|
|
|
8
8
|
const ReactiveDao = require("@live-change/dao")
|
|
9
9
|
|
|
10
|
+
const debug = require('debug')('db')
|
|
11
|
+
|
|
10
12
|
class Database {
|
|
11
13
|
constructor(config, storeFactory, saveConfig, deleteStore, name, createScriptContext) {
|
|
12
14
|
this.name = name
|
|
@@ -230,7 +232,7 @@ class Database {
|
|
|
230
232
|
async openIndex(name) {
|
|
231
233
|
let config = this.config.indexes[name]
|
|
232
234
|
if(!config) {
|
|
233
|
-
|
|
235
|
+
debug("INDEX", name, "NOT EXISTS - WAITING!")
|
|
234
236
|
await new Promise(r => setTimeout(r, 500))
|
|
235
237
|
config = this.config.indexes[name]
|
|
236
238
|
}
|
|
@@ -240,9 +242,9 @@ class Database {
|
|
|
240
242
|
const params = config.parameters
|
|
241
243
|
index = new Index(this, name, code, params, config)
|
|
242
244
|
try {
|
|
243
|
-
|
|
245
|
+
debug("STARTING INDEX", name)
|
|
244
246
|
await index.startIndex()
|
|
245
|
-
|
|
247
|
+
debug("STARTED INDEX", name)
|
|
246
248
|
} catch(error) {
|
|
247
249
|
console.error("INDEX", name, "ERROR", error, "CODE:\n", code)
|
|
248
250
|
console.error("DELETING INDEX", name)
|
package/lib/Index.js
CHANGED
|
@@ -6,6 +6,8 @@ const profileLog = require('./profileLog.js')
|
|
|
6
6
|
const queryObservable = require('./queryObservable.js')
|
|
7
7
|
const { ChangeStream } = require('./ChangeStream.js')
|
|
8
8
|
|
|
9
|
+
const debug = require('debug')('db')
|
|
10
|
+
|
|
9
11
|
const opLogBatchSize = 128 /// TODO: incrase after testing
|
|
10
12
|
|
|
11
13
|
class ObjectReader extends ChangeStream {
|
|
@@ -437,7 +439,7 @@ class Index extends Table {
|
|
|
437
439
|
this.code = code
|
|
438
440
|
}
|
|
439
441
|
async startIndex() {
|
|
440
|
-
|
|
442
|
+
debug("EXECUTING INDEX CODE", this.name)
|
|
441
443
|
this.scriptContext = this.database.createScriptContext({
|
|
442
444
|
/// TODO: script available routines
|
|
443
445
|
})
|
|
@@ -445,7 +447,7 @@ class Index extends Table {
|
|
|
445
447
|
this.codeFunction = (input, output) => queryFunction(input, output, this.params)
|
|
446
448
|
this.writer = new IndexWriter(this)
|
|
447
449
|
this.reader = null
|
|
448
|
-
|
|
450
|
+
debug("STARTING INDEX", this.name)
|
|
449
451
|
const lastIndexOperations = await this.opLog.rangeGet({ reverse: true, limit: 1 })
|
|
450
452
|
const lastIndexOperation = lastIndexOperations[0]
|
|
451
453
|
let lastUpdateTimestamp = 0
|
|
@@ -475,11 +477,11 @@ class Index extends Table {
|
|
|
475
477
|
codePromise = this.codeFunction(this.reader, this.writer)
|
|
476
478
|
//console.log("READING!")
|
|
477
479
|
await this.reader.readMore()
|
|
478
|
-
|
|
480
|
+
debug("WAITING FOR CODE!", this.name)
|
|
479
481
|
await codePromise
|
|
480
482
|
this.state = INDEX_READY
|
|
481
483
|
const startTime = Date.now()
|
|
482
|
-
|
|
484
|
+
debug("INDEX STARTED!", this.name)
|
|
483
485
|
await this.opLog.put({
|
|
484
486
|
id: ((''+startTime).padStart(16, '0'))+':000000',
|
|
485
487
|
timestamp: startTime,
|
|
@@ -499,7 +501,7 @@ class Index extends Table {
|
|
|
499
501
|
if(existingSourceInfo) return
|
|
500
502
|
const newSourceInfo = { type: sourceType, name: sourceName }
|
|
501
503
|
config.sources.push(newSourceInfo)
|
|
502
|
-
|
|
504
|
+
debug("NEW INDEX", this.name, "SOURCE DETECTED", sourceType, sourceName)
|
|
503
505
|
this.configObservable.set(config)
|
|
504
506
|
this.database.config.indexes[this.name] = config
|
|
505
507
|
this.database.handleConfigUpdated()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Database with observable data for live queries",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,19 +21,11 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/live-change/db",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@live-change/db-store-level": "^0.
|
|
25
|
-
"@live-change/db-store-lmdb": "^0.
|
|
26
|
-
"encoding-down": "^6.3.0",
|
|
27
|
-
"level-rocksdb": "^4.0.0",
|
|
28
|
-
"leveldown": "^5.6.0",
|
|
29
|
-
"levelup": "^4.4.0",
|
|
30
|
-
"memdown": "^5.1.0",
|
|
24
|
+
"@live-change/db-store-level": "^0.5.2",
|
|
25
|
+
"@live-change/db-store-lmdb": "^0.5.2",
|
|
31
26
|
"minimist": ">=1.2.3",
|
|
32
|
-
"node-lmdb": "^0.8.0",
|
|
33
27
|
"rimraf": "^3.0.2",
|
|
34
|
-
"rocksdb": "^4.1.0",
|
|
35
28
|
"sockjs": "^0.3.21",
|
|
36
|
-
"subleveldown": "^4.1.4",
|
|
37
29
|
"tape": "^4.13.3",
|
|
38
30
|
"websocket-extensions": ">=0.1.4"
|
|
39
31
|
},
|
|
@@ -41,5 +33,6 @@
|
|
|
41
33
|
"@live-change/dao": "^0.3.3",
|
|
42
34
|
"get-random-values": "^1.2.2",
|
|
43
35
|
"node-interval-tree": "^1.3.3"
|
|
44
|
-
}
|
|
36
|
+
},
|
|
37
|
+
"gitHead": "af756efb8db9ba90d79774786201cffe9c2162cf"
|
|
45
38
|
}
|