@live-change/db 0.9.84 → 0.9.86

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.
@@ -125,6 +125,7 @@ class ChangeStream {
125
125
  if(typeof range === 'string') {
126
126
  range = { gte: range, lte: range + '\xFF\xFF\xFF\xFF' }
127
127
  }
128
+ range.limit = 1
128
129
  const count = await this.count(range)
129
130
  if(count) {
130
131
  await pipe.change(existingObj, null, id, timestamp)
package/lib/Index.js CHANGED
@@ -530,15 +530,18 @@ class Index extends Table {
530
530
  return this.startPromise
531
531
  }
532
532
  async startIndexInternal() {
533
- console.error("STARTING INDEX", this.name, "IN DATABASE", this.database.name)
533
+ debug("STARTING INDEX", this.name, "IN DATABASE", this.database.name)
534
534
  debug("EXECUTING INDEX CODE", this.name)
535
535
  this.scriptContext = this.database.createScriptContext({
536
536
  /// TODO: script available routines
537
537
  })
538
+ debug("COMPILE INDEX CODE", this.code)
538
539
  const queryFunction = this.scriptContext.getOrCreateFunction(this.code,
539
540
  `userCode:${this.database.name}/indexes/${this.name}`)
540
541
  if(typeof queryFunction != 'function') {
541
542
  console.error("INDEX CODE", this.code)
543
+ console.error("QUERY FUNCTION", typeof queryFunction, queryFunction)
544
+ process.exit(1)
542
545
  throw new Error("Index code is not a function")
543
546
  }
544
547
  this.codeFunction = (input, output) => queryFunction(input, output, this.params)
@@ -90,16 +90,22 @@ class ScriptContext {
90
90
 
91
91
  getOrCreateFunction(code, filename) {
92
92
  const cleanCode = code.replace(/\n +/g, "\n")
93
- //console.log("COMPILED FUNCTIONS", `\n[\n ${Object.keys(globalThis.compiledFunctions).join(',\n ')},\n]`)
94
- /*if(!(globalThis.compiledFunctions = globalThis.compiledFunctions || {})[cleanCode]) {
95
- console.log("############# compiled function not found: ", code)
96
- for(const key of Object.keys(globalThis.compiledFunctions)) {
97
- console.log(`compiled func |${cleanCode}| == |${key}| => ${cleanCode == key}`)
93
+ if(!globalThis.compiledFunctions) globalThis.compiledFunctions = {}
94
+ const compiledFunction = globalThis.compiledFunctions[cleanCode]
95
+ if(compiledFunction) {
96
+ /* console.log("found compiled function!", cleanCode) */
97
+ if(typeof compiledFunction != 'function') {
98
+ console.error("compiled function is not a function!", cleanCode)
99
+ process.exit(1)
98
100
  }
99
- }*/
100
- const queryFunction = (globalThis.compiledFunctions = globalThis.compiledFunctions || {})[cleanCode]
101
- ?? this.run(code, filename)
102
- ;(globalThis.compiledFunctions = globalThis.compiledFunctions || {})[cleanCode] = queryFunction
101
+ return compiledFunction
102
+ }
103
+ const queryFunction = this.run(code, filename)
104
+ if(typeof queryFunction != 'function') {
105
+ console.error("compiled query function is not a function!", cleanCode)
106
+ process.exit(1)
107
+ }
108
+ globalThis.compiledFunctions[cleanCode] = queryFunction
103
109
  return queryFunction
104
110
  }
105
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/db",
3
- "version": "0.9.84",
3
+ "version": "0.9.86",
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.84",
26
- "@live-change/db-store-lmdb": "^0.9.84",
25
+ "@live-change/db-store-level": "^0.9.86",
26
+ "@live-change/db-store-lmdb": "^0.9.86",
27
27
  "minimist": ">=1.2.3",
28
28
  "next-tick": "^1.1.0",
29
29
  "rimraf": "^5.0.5",
@@ -32,9 +32,9 @@
32
32
  "websocket-extensions": ">=0.1.4"
33
33
  },
34
34
  "dependencies": {
35
- "@live-change/dao": "^0.9.84",
35
+ "@live-change/dao": "^0.9.86",
36
36
  "get-random-values": "^1.2.2",
37
37
  "node-interval-tree": "^1.3.3"
38
38
  },
39
- "gitHead": "5881a5406e3a39e673034f172266409ddb306f2e"
39
+ "gitHead": "7b0013ef101d9033402eeec45fd1be60e151aada"
40
40
  }