@live-change/db 0.8.2 → 0.8.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.
@@ -289,6 +289,7 @@ class AtomicWriter {
289
289
 
290
290
  async put(object) {
291
291
  const id = object.id
292
+ if(!id) throw new Error(`ID is empty ${JSON.stringify(object)}`)
292
293
  let queue = this.writes.get(id)
293
294
  if(!queue) {
294
295
  queue = new WriteQueue(this, this.store, id)
package/lib/Database.js CHANGED
@@ -278,12 +278,17 @@ class Database {
278
278
  return queryObservable.single(this, code)
279
279
  }
280
280
 
281
- handleUnhandledRejectionInIndex(name, reason, promise) {
281
+ handleUnhandledRejectionInIndex(name, reason) {
282
282
  const config = this.config.indexes[name]
283
283
  console.error("INDEX", name, "unhandledRejection", reason, "CODE:\n", config?.code)
284
284
  console.error("DELETING INDEX", name)
285
+ const index = this.indexes.get(name)
286
+ if(index) {
287
+ index.deleteIndex()
288
+ this.indexes.delete(name)
289
+ }
285
290
  nextTick(() => {
286
- if(!config) {
291
+ if(!this.config.indexes[name]) {
287
292
  console.error("INDEX", name, "IS ALREADY DELETED")
288
293
  console.trace("ALREADY DELETED")
289
294
  return;
package/lib/Index.js CHANGED
@@ -135,7 +135,6 @@ class TableReader extends ChangeStream {
135
135
  for(const rangeReader of rangeReaders) {
136
136
  rangeReader.change(obj, oldObj, id, timestamp)
137
137
  }
138
- //console.log("TR change", this.callbacks[0])
139
138
  for(const callback of this.callbacks) await callback(obj, oldObj, id, timestamp)
140
139
  if(profileOp) await profileLog.end(profileOp)
141
140
  }
@@ -372,16 +371,20 @@ class OpLogReader {
372
371
  //console.log("CKN", this.currentKey, '=>', next.key)
373
372
  this.currentKey = next.key
374
373
  //console.log("READ TO", readEnd)
375
- const readKey = await next.reader.readTo(readEnd)
376
- //console.log("READED")
377
- if(readKey) {
378
- if((readKey||'') < this.currentKey) {
379
- //debugger
380
- console.error("time travel", readKey, this.currentKey)
381
- //process.exit(1) /// TODO: do something about it!
374
+ try {
375
+ const readKey = await next.reader.readTo(readEnd)
376
+ //console.log("READED")
377
+ if(readKey) {
378
+ if((readKey||'') < this.currentKey) {
379
+ //debugger
380
+ console.error("time travel", readKey, this.currentKey)
381
+ //process.exit(1) /// TODO: do something about it!
382
+ }
383
+ //console.log("CKR", this.currentKey, '=>', readKey)
384
+ this.currentKey = readKey
382
385
  }
383
- //console.log("CKR", this.currentKey, '=>', readKey)
384
- this.currentKey = readKey
386
+ } catch(error) {
387
+ this.database.handleUnhandledRejectionInIndex(this.indexName, error)
385
388
  }
386
389
  }
387
390
  } while(this.gotSignals)
@@ -400,9 +403,13 @@ class IndexWriter {
400
403
  this.index = index
401
404
  }
402
405
  put(object) {
406
+ const id = object.id
407
+ if(!id) throw new Error(`ID is empty ${JSON.stringify(object)}`)
403
408
  this.index.put(object)
404
409
  }
405
410
  delete(object) {
411
+ const id = object.id
412
+ if(!id) throw new Error(`ID is empty ${JSON.stringify(object)}`)
406
413
  this.index.delete(object.id)
407
414
  }
408
415
  update(id, ops) {
package/lib/Table.js CHANGED
@@ -61,6 +61,8 @@ class Table {
61
61
  }
62
62
 
63
63
  async put(object) {
64
+ const id = object.id
65
+ if(!id) throw new Error(`ID is empty ${JSON.stringify(object)}`)
64
66
  try {
65
67
  return await this.atomicWriter.put(object)
66
68
  } catch(e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/db",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
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-db",
24
24
  "devDependencies": {
25
- "@live-change/db-store-level": "^0.8.2",
26
- "@live-change/db-store-lmdb": "^0.8.2",
25
+ "@live-change/db-store-level": "^0.8.4",
26
+ "@live-change/db-store-lmdb": "^0.8.4",
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.6.0",
35
+ "@live-change/dao": "^0.8.4",
36
36
  "get-random-values": "^1.2.2",
37
37
  "node-interval-tree": "^1.3.3"
38
38
  },
39
- "gitHead": "53b8efc8ec7f5c1c4af33077d8fb4a8a5580f1d9"
39
+ "gitHead": "cdc66924576866cd3b476e5a0e8956de54c6d8d9"
40
40
  }