@live-change/db 0.5.2 → 0.5.5

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 CHANGED
@@ -229,39 +229,29 @@ class Database {
229
229
  return summary
230
230
  }
231
231
 
232
- async openIndex(name) {
233
- let config = this.config.indexes[name]
234
- if(!config) {
235
- debug("INDEX", name, "NOT EXISTS - WAITING!")
236
- await new Promise(r => setTimeout(r, 500))
237
- config = this.config.indexes[name]
238
- }
239
- let index, code
240
- if(!config) throw new Error(`Index ${name} not found`)
241
- code = config.code
242
- const params = config.parameters
243
- index = new Index(this, name, code, params, config)
244
- try {
245
- debug("STARTING INDEX", name)
246
- await index.startIndex()
247
- debug("STARTED INDEX", name)
248
- } catch(error) {
249
- console.error("INDEX", name, "ERROR", error, "CODE:\n", code)
250
- console.error("DELETING INDEX", name)
251
- delete this.config.indexes[name]
252
- this.indexesListObservable.remove(name)
253
- if(this.onAutoRemoveIndex && config) this.onAutoRemoveIndex(name, config.uid)
254
- await this.saveConfig(this.config)
255
- throw error
256
- }
257
- this.indexes.set(name, index)
258
- return index
259
- }
260
232
  async index(name) {
261
233
  let index = this.indexes.get(name)
262
234
  if(!index) {
263
- index = this.openIndex(name)
235
+ const config = this.config.indexes[name]
236
+ if(!config) throw new Error(`Index ${name} not found`)
237
+ let code = config.code
238
+ const params = config.parameters
239
+ index = new Index(this, name, code, params, config)
240
+ try {
241
+ debug("STARTING INDEX", name)
242
+ await index.startIndex()
243
+ debug("STARTED INDEX", name)
244
+ } catch(error) {
245
+ console.error("INDEX", name, "ERROR", error, "CODE:\n", code)
246
+ console.error("DELETING INDEX", name)
247
+ delete this.config.indexes[name]
248
+ this.indexesListObservable.remove(name)
249
+ if(this.onAutoRemoveIndex && config) this.onAutoRemoveIndex(name, config.uid)
250
+ await this.saveConfig(this.config)
251
+ throw error
252
+ }
264
253
  this.indexes.set(name, index)
254
+ return index
265
255
  }
266
256
  return index
267
257
  }
package/lib/Index.js CHANGED
@@ -38,7 +38,7 @@ class RangeReader extends ChangeStream {
38
38
  this.tableReader.rangeTree.insert(...this.rangeDescr, this )
39
39
  this.callbacks = []
40
40
  }
41
- onChange(cb) {
41
+ async onChange(cb) {
42
42
  this.callbacks.push(cb)
43
43
  }
44
44
  async change(obj, oldObj, id, timestamp) {
@@ -421,6 +421,9 @@ class IndexWriter {
421
421
  synchronized(key, code) {
422
422
  return this.index.synchronized(key, code)
423
423
  }
424
+ timeout(date, callback) {
425
+ throw new Error('index timeouts not implemented yet!')
426
+ }
424
427
  debug(...args) {
425
428
  console.log('INDEX', this.index.name, 'DEBUG', ...args)
426
429
  }
package/lib/queryGet.js CHANGED
@@ -37,7 +37,7 @@ class RangeReader extends ChangeStream {
37
37
  }
38
38
  async onChange(cb) {
39
39
  const now = this.#time()
40
- let objects = await (await this.#table).rangeGet(this.#range)
40
+ const objects = await (await this.#table).rangeGet(this.#range)
41
41
  await Promise.all(objects.map(object => cb(object, null, object.id, now)))
42
42
  }
43
43
  unobserve(obs) {}
@@ -167,6 +167,10 @@ class QueryWriter {
167
167
  this.#locks.set(key, promise)
168
168
  return await promise
169
169
  }
170
+ timeout(date, callback) {
171
+ /// ignore
172
+ return () => {}
173
+ }
170
174
  debug(...args) {
171
175
  console.log('QUERY DEBUG', ...args)
172
176
  }
@@ -232,7 +232,6 @@ class QueryReader {
232
232
  } else {
233
233
  reader.dispose()
234
234
  }
235
-
236
235
  }
237
236
  }
238
237
  }
@@ -244,6 +243,7 @@ class QueryWriter {
244
243
  #locks = new Map()
245
244
  #observationMode = false
246
245
  #reverse = false
246
+ #timeouts = new Set()
247
247
 
248
248
  constructor(observable, database) {
249
249
  this.#observable = observable
@@ -335,6 +335,20 @@ class QueryWriter {
335
335
  this.#locks.set(key, promise)
336
336
  return await promise
337
337
  }
338
+ timeout(date, callback) {
339
+ const toTimeout = new Date(date).getTime() - Date.now()
340
+ const timeout = setTimeout(callback, toTimeout)
341
+ this.#timeouts.add(timeout)
342
+ return () => {
343
+ this.#timeouts.delete(timeout)
344
+ }
345
+ }
346
+ dispose() {
347
+ for(let timeout of this.#timeouts) {
348
+ clearTimeout(timeout)
349
+ }
350
+ this.#timeouts.clear()
351
+ }
338
352
  debug(...args) {
339
353
  console.log('QUERY DEBUG', ...args)
340
354
  }
@@ -383,6 +397,7 @@ class QueryObservable extends ReactiveDao.ObservableList {
383
397
  }
384
398
 
385
399
  if(this.reader) this.reader.dispose()
400
+ if(this.writer) this.writer.dispose()
386
401
 
387
402
  this.disposed = true
388
403
  this.respawnId++
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/db",
3
- "version": "0.5.2",
3
+ "version": "0.5.5",
4
4
  "description": "Database with observable data for live queries",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://github.com/live-change/db.git"
11
+ "url": "git+https://github.com/live-change/live-change-db.git"
12
12
  },
13
13
  "author": {
14
14
  "email": "m8@em8.pl",
@@ -17,22 +17,22 @@
17
17
  },
18
18
  "license": "MIT",
19
19
  "bugs": {
20
- "url": "https://github.com/live-change/db/issues"
20
+ "url": "https://github.com/live-change/live-change-db/issues"
21
21
  },
22
- "homepage": "https://github.com/live-change/db",
22
+ "homepage": "https://github.com/live-change/live-change-db",
23
23
  "devDependencies": {
24
- "@live-change/db-store-level": "^0.5.2",
25
- "@live-change/db-store-lmdb": "^0.5.2",
24
+ "@live-change/db-store-level": "^0.5.5",
25
+ "@live-change/db-store-lmdb": "^0.5.5",
26
26
  "minimist": ">=1.2.3",
27
27
  "rimraf": "^3.0.2",
28
- "sockjs": "^0.3.21",
29
- "tape": "^4.13.3",
28
+ "sockjs": "^0.3.24",
29
+ "tape": "^5.3.2",
30
30
  "websocket-extensions": ">=0.1.4"
31
31
  },
32
32
  "dependencies": {
33
- "@live-change/dao": "^0.3.3",
33
+ "@live-change/dao": "0.4.6",
34
34
  "get-random-values": "^1.2.2",
35
35
  "node-interval-tree": "^1.3.3"
36
36
  },
37
- "gitHead": "af756efb8db9ba90d79774786201cffe9c2162cf"
37
+ "gitHead": "bffe88c30f0f0ad2ddbf10308ab8e70b93e4581e"
38
38
  }