@live-change/db 0.6.3 → 0.6.4
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/Index.js +2 -1
- package/lib/ScriptContext.js +15 -0
- package/lib/WebScriptContext.js +15 -0
- package/package.json +4 -4
package/lib/Index.js
CHANGED
|
@@ -460,7 +460,8 @@ class Index extends Table {
|
|
|
460
460
|
this.scriptContext = this.database.createScriptContext({
|
|
461
461
|
/// TODO: script available routines
|
|
462
462
|
})
|
|
463
|
-
const queryFunction = this.scriptContext.
|
|
463
|
+
const queryFunction = this.scriptContext.getOrCreateFunction(this.code,
|
|
464
|
+
`userCode:${this.database.name}/indexes/${this.name}`)
|
|
464
465
|
this.codeFunction = (input, output) => queryFunction(input, output, this.params)
|
|
465
466
|
this.writer = new IndexWriter(this)
|
|
466
467
|
this.reader = null
|
package/lib/ScriptContext.js
CHANGED
|
@@ -86,6 +86,21 @@ class ScriptContext {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
+
|
|
90
|
+
getOrCreateFunction(code, filename) {
|
|
91
|
+
const cleanCode = code.replace(/\n +/g, "\n")
|
|
92
|
+
//console.log("COMPILED FUNCTIONS", `\n[\n ${Object.keys(globalThis.compiledFunctions).join(',\n ')},\n]`)
|
|
93
|
+
if(!(globalThis.compiledFunctions = globalThis.compiledFunctions || {})[cleanCode]) {
|
|
94
|
+
console.log("############# compiled function not found: ", code)
|
|
95
|
+
for(const key of Object.keys(globalThis.compiledFunctions)) {
|
|
96
|
+
console.log(`compiled func |${cleanCode}| == |${key}| => ${cleanCode == key}`)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const queryFunction = (globalThis.compiledFunctions = globalThis.compiledFunctions || {})[cleanCode]
|
|
100
|
+
?? this.run(code, filename)
|
|
101
|
+
;(globalThis.compiledFunctions = globalThis.compiledFunctions || {})[cleanCode] = queryFunction
|
|
102
|
+
return queryFunction
|
|
103
|
+
}
|
|
89
104
|
}
|
|
90
105
|
|
|
91
106
|
module.exports = ScriptContext
|
package/lib/WebScriptContext.js
CHANGED
|
@@ -42,6 +42,21 @@ class WebScriptContext {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
|
|
46
|
+
getOrCreateFunction(code, filename) {
|
|
47
|
+
const cleanCode = code.replace(/\n +/g, "\n")
|
|
48
|
+
//console.log("COMPILED FUNCTIONS", `\n[\n ${Object.keys(globalThis.compiledFunctions).join(',\n ')},\n]`)
|
|
49
|
+
if(!(globalThis.compiledFunctions = globalThis.compiledFunctions || {})[cleanCode]) {
|
|
50
|
+
console.log("############# compiled function not found: ", code)
|
|
51
|
+
for(const key of Object.keys(globalThis.compiledFunctions)) {
|
|
52
|
+
console.log(`compiled func |${cleanCode}| == |${key}| => ${cleanCode == key}`)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const queryFunction = (globalThis.compiledFunctions = globalThis.compiledFunctions || {})[cleanCode]
|
|
56
|
+
?? this.run(code, filename)
|
|
57
|
+
;(globalThis.compiledFunctions = globalThis.compiledFunctions || {})[cleanCode] = queryFunction
|
|
58
|
+
return queryFunction
|
|
59
|
+
}
|
|
45
60
|
}
|
|
46
61
|
|
|
47
62
|
module.exports = WebScriptContext
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/db",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "Database with observable data for live queries",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/live-change/live-change-db",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@live-change/db-store-level": "^0.6.
|
|
25
|
-
"@live-change/db-store-lmdb": "^0.6.
|
|
24
|
+
"@live-change/db-store-level": "^0.6.4",
|
|
25
|
+
"@live-change/db-store-lmdb": "^0.6.4",
|
|
26
26
|
"minimist": ">=1.2.3",
|
|
27
27
|
"next-tick": "^1.1.0",
|
|
28
28
|
"rimraf": "^3.0.2",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"get-random-values": "^1.2.2",
|
|
36
36
|
"node-interval-tree": "^1.3.3"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "2b63a796522f2a5bf7c4e0311331640b4152ba77"
|
|
39
39
|
}
|