@live-change/db 0.5.3 → 0.5.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/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
@@ -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
@@ -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
  }
@@ -244,6 +244,7 @@ class QueryWriter {
244
244
  #locks = new Map()
245
245
  #observationMode = false
246
246
  #reverse = false
247
+ #timeouts = new Set()
247
248
 
248
249
  constructor(observable, database) {
249
250
  this.#observable = observable
@@ -335,6 +336,20 @@ class QueryWriter {
335
336
  this.#locks.set(key, promise)
336
337
  return await promise
337
338
  }
339
+ timeout(date, callback) {
340
+ const toTimeout = new Date(date).getTime() - Date.now()
341
+ const timeout = setTimeout(callback, toTimeout)
342
+ this.#timeouts.add(timeout)
343
+ return () => {
344
+ this.#timeouts.delete(timeout)
345
+ }
346
+ }
347
+ dispose() {
348
+ for(let timeout of this.#timeouts) {
349
+ clearTimeout(timeout)
350
+ }
351
+ this.#timeouts.clear()
352
+ }
338
353
  debug(...args) {
339
354
  console.log('QUERY DEBUG', ...args)
340
355
  }
@@ -383,6 +398,7 @@ class QueryObservable extends ReactiveDao.ObservableList {
383
398
  }
384
399
 
385
400
  if(this.reader) this.reader.dispose()
401
+ if(this.writer) this.writer.dispose()
386
402
 
387
403
  this.disposed = true
388
404
  this.respawnId++
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/db",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
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,12 +17,12 @@
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.3",
25
- "@live-change/db-store-lmdb": "^0.5.3",
24
+ "@live-change/db-store-level": "^0.5.4",
25
+ "@live-change/db-store-lmdb": "^0.5.4",
26
26
  "minimist": ">=1.2.3",
27
27
  "rimraf": "^3.0.2",
28
28
  "sockjs": "^0.3.21",
@@ -34,5 +34,5 @@
34
34
  "get-random-values": "^1.2.2",
35
35
  "node-interval-tree": "^1.3.3"
36
36
  },
37
- "gitHead": "d92fb65e55f55e246e7a4615cff609cafdc32eba"
37
+ "gitHead": "0dfd0cb953fad982630808934326d00abea2c2b4"
38
38
  }