@live-change/db 0.9.156 → 0.9.158
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 +2 -1
- package/lib/Index.js +11 -3
- package/lib/ScriptContext.js +1 -0
- package/package.json +6 -6
package/lib/Database.js
CHANGED
|
@@ -266,7 +266,8 @@ class Database {
|
|
|
266
266
|
try {
|
|
267
267
|
await index.startIndex()
|
|
268
268
|
} catch(error) {
|
|
269
|
-
console.error("INDEX", name, "ERROR", error
|
|
269
|
+
if(config.sourceName) console.error("INDEX", name, "ERROR", error)
|
|
270
|
+
else console.error("INDEX", name, "ERROR", error, "CODE:\n", code)
|
|
270
271
|
console.error("DELETINGww INDEX", name)
|
|
271
272
|
delete this.config.indexes[name]
|
|
272
273
|
this.indexesListObservable.remove(name)
|
package/lib/Index.js
CHANGED
|
@@ -6,7 +6,7 @@ import queryGet from './queryGet.js'
|
|
|
6
6
|
import profileLog from './profileLog.js'
|
|
7
7
|
import nextTick from 'next-tick'
|
|
8
8
|
import { ChangeStream } from './ChangeStream.js'
|
|
9
|
-
import { rangeIntersection } from './utils.js'
|
|
9
|
+
import { unitRange,rangeIntersection } from './utils.js'
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
import Debug from 'debug'
|
|
@@ -97,6 +97,7 @@ class RangeReader extends ChangeStream {
|
|
|
97
97
|
async count(range = {}) {
|
|
98
98
|
return await (await this.tableReader.table).countGet(rangeIntersection(this.range, range))
|
|
99
99
|
}
|
|
100
|
+
dispose() {}
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
class TableReader extends ChangeStream {
|
|
@@ -151,6 +152,13 @@ class TableReader extends ChangeStream {
|
|
|
151
152
|
}
|
|
152
153
|
async onChange(cb) {
|
|
153
154
|
this.callbacks.push(cb)
|
|
155
|
+
return {
|
|
156
|
+
dispose() {
|
|
157
|
+
const callbackIndex = this.callbacks.indexOf(cb)
|
|
158
|
+
if(callbackIndex === -1) throw new Error('Observer double dispose')
|
|
159
|
+
this.callbacks.splice(callbackIndex, 1)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
154
162
|
}
|
|
155
163
|
async change(obj, oldObj, id, timestamp) {
|
|
156
164
|
if(!(obj || oldObj)) return
|
|
@@ -181,7 +189,6 @@ class TableReader extends ChangeStream {
|
|
|
181
189
|
this.rangeReaders.set(key, reader)
|
|
182
190
|
}
|
|
183
191
|
return reader
|
|
184
|
-
return new RangeReader(this, range)
|
|
185
192
|
}
|
|
186
193
|
async objectGet(id) {
|
|
187
194
|
return await (await this.table).objectGet(id)
|
|
@@ -537,7 +544,8 @@ class Index extends Table {
|
|
|
537
544
|
/// TODO: script available routines
|
|
538
545
|
})
|
|
539
546
|
debug("COMPILE INDEX CODE", this.code)
|
|
540
|
-
const
|
|
547
|
+
const config = this.configObservable.getValue()
|
|
548
|
+
const queryFunction = this.scriptContext.getOrCreateFunction(this.code, config?.sourceName ??
|
|
541
549
|
`userCode:${this.database.name}/indexes/${this.name}`)
|
|
542
550
|
if(typeof queryFunction != 'function') {
|
|
543
551
|
console.error("INDEX CODE", this.code)
|
package/lib/ScriptContext.js
CHANGED
|
@@ -113,6 +113,7 @@ class ScriptContext {
|
|
|
113
113
|
const queryFunction = this.run(code, filename)
|
|
114
114
|
if(typeof queryFunction != 'function') {
|
|
115
115
|
console.error("compiled query function is not a function!", cleanCode)
|
|
116
|
+
console.trace('compiled function trace', code)
|
|
116
117
|
process.exit(21)
|
|
117
118
|
}
|
|
118
119
|
globalThis.compiledFunctions[cleanCode] = queryFunction
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/db",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.158",
|
|
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.9.
|
|
26
|
-
"@live-change/db-store-lmdb": "^0.9.
|
|
25
|
+
"@live-change/db-store-level": "^0.9.158",
|
|
26
|
+
"@live-change/db-store-lmdb": "^0.9.158",
|
|
27
27
|
"minimist": ">=1.2.3",
|
|
28
28
|
"next-tick": "^1.1.0",
|
|
29
29
|
"rimraf": "^5.0.5",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"websocket-extensions": ">=0.1.4"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@live-change/dao": "^0.9.
|
|
36
|
-
"@live-change/serialization": "^0.9.
|
|
35
|
+
"@live-change/dao": "^0.9.158",
|
|
36
|
+
"@live-change/serialization": "^0.9.158",
|
|
37
37
|
"get-random-values": "^1.2.2",
|
|
38
38
|
"node-interval-tree": "^1.3.3"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "bd30de9030c65b93fbb26b6879f574d5f93baea3"
|
|
41
41
|
}
|