@live-change/db 0.7.3 → 0.8.3

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/LICENSE.md ADDED
@@ -0,0 +1,11 @@
1
+ Copyright 2019-2024 Michał Łaszczewski
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -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.7.3",
3
+ "version": "0.8.3",
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.7.3",
26
- "@live-change/db-store-lmdb": "^0.7.3",
25
+ "@live-change/db-store-level": "^0.8.3",
26
+ "@live-change/db-store-lmdb": "^0.8.3",
27
27
  "minimist": ">=1.2.3",
28
28
  "next-tick": "^1.1.0",
29
29
  "rimraf": "^5.0.5",
@@ -36,5 +36,5 @@
36
36
  "get-random-values": "^1.2.2",
37
37
  "node-interval-tree": "^1.3.3"
38
38
  },
39
- "gitHead": "447f57db32c3b49d53a76ea3f94d725c25ae2791"
39
+ "gitHead": "81b4ac5a36ab1abdf9d521e3c4fbea6d194bb892"
40
40
  }