@live-change/db
Advanced tools
Comparing version 0.3.62 to 0.3.63
@@ -31,3 +31,3 @@ const Table = require('./Table.js') | ||
this.indexesListObservable = new ReactiveDao.ObservableList(Object.keys(this.config.indexes)) | ||
this.logsListObservable = new ReactiveDao.ObservableList(Object.keys(this.config.logs)) | ||
this.logsListObservable = new ReactiveDao.ObservableList(Object.keys(this.config.logs)) | ||
} | ||
@@ -97,3 +97,3 @@ | ||
} | ||
renameTable(name, newName) { | ||
@@ -232,21 +232,34 @@ if(this.config.tables[newName]) throw new Error(`Table ${newName} already exists`) | ||
async openIndex(name) { | ||
let config = this.config.indexes[name] | ||
if(!config) { | ||
console.log("INDEX", name, "NOT EXISTS - WAITING!") | ||
await new Promise(r => setTimeout(r, 500)) | ||
config = this.config.indexes[name] | ||
} | ||
let index, code | ||
if(!config) throw new Error(`Index ${name} not found`) | ||
code = config.code | ||
const params = config.parameters | ||
index = new Index(this, name, code, params, config) | ||
try { | ||
console.log("STARTING INDEX", name) | ||
await index.startIndex() | ||
console.log("STARTED INDEX", name) | ||
} catch(error) { | ||
console.error("INDEX", name, "ERROR", error, "CODE:\n", code) | ||
console.error("DELETING INDEX", name) | ||
delete this.config.indexes[name] | ||
this.indexesListObservable.remove(name) | ||
if(this.onAutoRemoveIndex && config) this.onAutoRemoveIndex(name, config.uid) | ||
await this.saveConfig(this.config) | ||
throw error | ||
} | ||
this.indexes.set(name, index) | ||
return index | ||
} | ||
async index(name) { | ||
let index = this.indexes.get(name) | ||
if(!index) { | ||
const config = this.config.indexes[name] | ||
if(!config) throw new Error(`Index ${name} not found`) | ||
const code = config.code | ||
const params = config.parameters | ||
index = new Index(this, name, code, params, config) | ||
try { | ||
await index.startIndex() | ||
} catch(error) { | ||
console.error("INDEX", name, "ERROR", error, "CODE:\n", index.code) | ||
console.error("DELETING INDEX", name) | ||
delete this.config.indexes[name] | ||
this.indexesListObservable.remove(name) | ||
if(this.onAutoRemoveIndex) this.onAutoRemoveIndex(name, config.uid) | ||
await this.saveConfig(this.config) | ||
throw error | ||
} | ||
index = this.openIndex(name) | ||
this.indexes.set(name, index) | ||
@@ -253,0 +266,0 @@ } |
@@ -66,2 +66,3 @@ const IntervalTree = require('node-interval-tree').default | ||
this.table = table | ||
Promise.resolve(this.table).then(t=> {if(!t) throw new Error("TABLE NOT FOUND!!!")}) | ||
this.isLog = isLog | ||
@@ -68,0 +69,0 @@ this.objectReaders = new Map() |
@@ -38,2 +38,3 @@ const vm = require('vm') | ||
'performance': require('perf_hooks').performance, | ||
constructor: null | ||
} | ||
@@ -51,5 +52,5 @@ | ||
/* vm.runInContext(` | ||
(function() { | ||
const allowed = ${JSON.stringify(nativeGlobals.concat(Object.keys(userContext)))} | ||
const keys = Object.getOwnPropertyNames(this) | ||
(function() { | ||
const allowed = ${JSON.stringify(nativeGlobals.concat(Object.keys(userContext)))} | ||
const keys = Object.getOwnPropertyNames(this) | ||
keys.forEach((key) => { | ||
@@ -56,0 +57,0 @@ const item = this[key] |
{ | ||
"name": "@live-change/db", | ||
"version": "0.3.62", | ||
"version": "0.3.63", | ||
"description": "Database with observable data for live queries", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
96824
2855