@live-change/db-web
Advanced tools
Comparing version 0.8.15 to 0.8.16
223
lib/dbDao.js
@@ -6,3 +6,3 @@ import ReactiveDao from "@live-change/dao" | ||
createDatabase: async (dbName, options = {}) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
if(server.metadata.databases[dbName]) throw new Error("databaseAlreadyExists") | ||
@@ -22,3 +22,3 @@ server.metadata.databases[dbName] = options | ||
deleteDatabase: async (dbName) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
if(!server.metadata.databases[dbName]) throw new Error("databaseNotFound") | ||
@@ -61,3 +61,3 @@ delete server.metadata.databases[dbName] | ||
createTable: async (dbName, tableName, options = {}) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
const db = server.databases.get(dbName) | ||
@@ -74,10 +74,10 @@ if(!db) throw new Error('databaseNotFound') | ||
deleteTable: async (dbName, tableName, options) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
if(tableName[tableName.length - 1] == "*") { | ||
if(tableName[tableName.length - 1] === "*") { | ||
const list = db.tablesListObservable.list.slice() | ||
for(const foundTableName of list) { | ||
const base = tableName.slice(0, -1) | ||
if(foundTableName.slice(0, base.length) != base) continue | ||
if(foundTableName.slice(0, base.length) !== base) continue | ||
const table = db.table(foundTableName) | ||
@@ -99,3 +99,3 @@ if(!table) throw new Error("tableNotFound") | ||
renameTable: async (dbName, tableName, newTableName) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
const db = server.databases.get(dbName) | ||
@@ -112,3 +112,3 @@ if(!db) throw new Error('databaseNotFound') | ||
createIndex: async (dbName, indexName, code, params, options = {}) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
const db = server.databases.get(dbName) | ||
@@ -125,10 +125,10 @@ if(!db) throw new Error('databaseNotFound') | ||
deleteIndex: async (dbName, indexName, options) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
if(indexName[indexName.length - 1] == "*") { | ||
if(indexName[indexName.length - 1] === "*") { | ||
const base = indexName.slice(0, -1) | ||
const list = db.indexesListObservable.list.slice() | ||
for(const foundIndexName of list) { | ||
if(foundIndexName.slice(0, base.length) != base) continue | ||
if(foundIndexName.slice(0, base.length) !== base) continue | ||
const index = await db.index(foundIndexName) | ||
@@ -150,3 +150,3 @@ if(!index) throw new Error("indexNotFound") | ||
renameIndex: async (dbName, indexName, newIndexName) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
const db = server.databases.get(dbName) | ||
@@ -163,3 +163,3 @@ if(!db) throw await new Error('databaseNotFound') | ||
createLog: async (dbName, logName, options = {}) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
const db = server.databases.get(dbName) | ||
@@ -176,3 +176,3 @@ if(!db) throw new Error('databaseNotFound') | ||
deleteLog: async (dbName, logName, options) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
const db = server.databases.get(dbName) | ||
@@ -188,3 +188,3 @@ if(!db) throw new Error('databaseNotFound') | ||
renameLog: async (dbName, logName, newLogName) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
const db = server.databases.get(dbName) | ||
@@ -201,3 +201,3 @@ if(!db) throw new Error('databaseNotFound') | ||
put: (dbName, tableName, object) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
const db = server.databases.get(dbName) | ||
@@ -210,3 +210,3 @@ if(!db) throw new Error('databaseNotFound') | ||
delete: (dbName, tableName, id) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
const db = server.databases.get(dbName) | ||
@@ -219,3 +219,3 @@ if(!db) throw new Error('databaseNotFound') | ||
update: (dbName, tableName, id, operations, options) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
const db = server.databases.get(dbName) | ||
@@ -228,3 +228,3 @@ if(!db) throw new Error('databaseNotFound') | ||
putLog: (dbName, logName, object) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
const db = server.databases.get(dbName) | ||
@@ -237,3 +237,3 @@ if(!db) throw new Error('databaseNotFound') | ||
putOldLog: (dbName, logName, object) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
const db = server.databases.get(dbName) | ||
@@ -246,3 +246,3 @@ if(!db) throw new Error('databaseNotFound') | ||
query: (dbName, code, params) => { | ||
if(dbName == 'system') throw new Error("system database is not writable") | ||
if(dbName === 'system') throw new Error("system database is not writable") | ||
if(!dbName) throw new Error("databaseNameRequired") | ||
@@ -257,130 +257,2 @@ const db = server.databases.get(dbName) | ||
function remoteRequests(server) { | ||
return { | ||
createDatabase: async (dbName, options = {}) => { | ||
if(server.metadata.databases[dbName]) throw new Error("databaseAlreadyExists") | ||
return server.masterDao.request(['database', 'createDatabase'], dbName, options) | ||
}, | ||
deleteDatabase: async (dbName) => { | ||
if(!server.metadata.databases[dbName]) throw new Error("databaseNotFound") | ||
return server.masterDao.request(['database', 'deleteDatabase'], dbName, options) | ||
}, | ||
clearDatabaseOpLogs: async (dbName, lastTimestamp, limit) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
if(typeof lastTimestamp == 'string') lastTimestamp = new Date(lastTimestamp) | ||
return server.masterDao.request(['database', 'clearDatabaseOpLogs'], dbName, lastTimestamp, limit) | ||
}, | ||
clearTableOpLog: async (dbName, tableName, lastTimestamp, limit) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
const table = db.table(tableName) | ||
if(!table) throw new Error("tableNotFound") | ||
if(typeof lastTimestamp == 'string') lastTimestamp = new Date(lastTimestamp) | ||
return server.masterDao.request(['database', 'clearTableOpLog'], dbName, tableName, lastTimestamp, limit) | ||
}, | ||
clearIndexOpLog: async (dbName, indexName, lastTimestamp, limit) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
const index = db.table(indexName) | ||
if(!index) throw new Error("indexNotFound") | ||
if(typeof lastTimestamp == 'string') lastTimestamp = new Date(lastTimestamp) | ||
return server.masterDao.request(['database', 'clearIndexOpLog'], dbName, indexName, lastTimestamp, limit) | ||
}, | ||
createTable: async (dbName, tableName, options = {}) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
return server.masterDao.request(['database', 'createTable'], dbName, tableName, options) | ||
}, | ||
deleteTable: async (dbName, tableName, options) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
return server.masterDao.request(['database', 'deleteTable'], dbName, tableName, options) | ||
}, | ||
renameTable: async (dbName, tableName, newTableName) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
const table = db.table(tableName) | ||
if(!table) throw new Error("tableNotFound") | ||
return server.masterDao.request(['database', 'renameTable'], dbName, tableName, newTableName) | ||
}, | ||
createIndex: async (dbName, indexName, code, params, options = {}) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
return server.masterDao.request(['database', 'createIndex'], dbName, indexName, code, params, options ) | ||
}, | ||
deleteIndex: async (dbName, indexName, options) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
return server.masterDao.request(['database', 'deleteIndex'], dbName, indexName, options ) | ||
}, | ||
renameIndex: async (dbName, indexName, newIndexName) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
const index = db.index(indexName) | ||
if(!index) throw new Error("indexNotFound") | ||
return server.masterDao.request(['database', 'renameIndex'], dbName, indexName, newIndexName ) | ||
}, | ||
createLog: async (dbName, logName, options = {}) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
return server.masterDao.request(['database', 'createLog'], dbName, logName, options ) | ||
}, | ||
deleteLog: async (dbName, logName, options) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
await db.deleteLog(logName) | ||
return server.masterDao.request(['database', 'deleteLog'], dbName, logName, options ) | ||
}, | ||
renameLog: async (dbName, logName, newLogName) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
const log = db.log(logName) | ||
if(!log) throw new Error("logNotFound") | ||
return server.masterDao.request(['database', 'renameLog'], dbName, logName, newLogName ) | ||
}, | ||
put: (dbName, tableName, object) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
const table = db.table(tableName) | ||
if(!table) throw new Error("tableNotFound") | ||
return server.masterDao.request(['database', 'put'], dbName, tableName, object ) | ||
}, | ||
delete: (dbName, tableName, id) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
const table = db.table(tableName) | ||
if(!table) throw new Error("tableNotFound") | ||
return server.masterDao.request(['database', 'delete'], dbName, tableName, id ) | ||
}, | ||
update: (dbName, tableName, id, operations, options) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
const table = db.table(tableName) | ||
if(!table) throw new Error("tableNotFound") | ||
return server.masterDao.request(['database', 'update'], dbName, tableName, id, operations, options ) | ||
}, | ||
putLog: (dbName, logName, object) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
const log = db.log(logName) | ||
if(!log) throw new Error("logNotFound") | ||
return server.masterDao.request(['database', 'putLog'], dbName, logName, object ) | ||
}, | ||
putOldLog: (dbName, logName, object) => { | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
const log = db.log(logName) | ||
if(!log) throw new Error("logNotFound") | ||
return server.masterDao.request(['database', 'putOldLog'], dbName, logName, object ) | ||
}, | ||
query: (dbName, code, params) => { | ||
if(!dbName) throw new Error("databaseNameRequired") | ||
const db = server.databases.get(dbName) | ||
if(!db) throw new Error('databaseNotFound') | ||
return server.masterDao.request(['database', 'query'], dbName, code, params ) | ||
} | ||
} | ||
} | ||
function localReads(server, scriptContext) { | ||
@@ -409,3 +281,3 @@ return { | ||
tablesList: { | ||
observable: (dbName, tableName, id) => { | ||
observable: (dbName) => { | ||
const db = server.databases.get(dbName) | ||
@@ -415,3 +287,3 @@ if(!db) return new ReactiveDao.ObservableError('databaseNotFound') | ||
}, | ||
get: async (dbName, tableName, id) =>{ | ||
get: async (dbName) =>{ | ||
const db = server.databases.get(dbName) | ||
@@ -423,3 +295,3 @@ if(!db) throw new Error('databaseNotFound') | ||
indexesList: { | ||
observable: (dbName, indexName, id) => { | ||
observable: (dbName) => { | ||
const db = server.databases.get(dbName) | ||
@@ -429,3 +301,3 @@ if(!db) return new ReactiveDao.ObservableError('databaseNotFound') | ||
}, | ||
get: async (dbName, indexName, id) =>{ | ||
get: async (dbName) =>{ | ||
const db = server.databases.get(dbName) | ||
@@ -437,3 +309,3 @@ if(!db) throw new Error('databaseNotFound') | ||
logsList: { | ||
observable: (dbName, logName, id) => { | ||
observable: (dbName) => { | ||
const db = server.databases.get(dbName) | ||
@@ -443,3 +315,3 @@ if(!db) return new ReactiveDao.ObservableError('databaseNotFound') | ||
}, | ||
get: async (dbName, logName, id) => { | ||
get: async (dbName) => { | ||
const db = server.databases.get(dbName) | ||
@@ -451,3 +323,3 @@ if(!db) throw new Error('databaseNotFound') | ||
tablesCount: { | ||
observable: (dbName, tableName, id) => { | ||
observable: (dbName) => { | ||
const db = server.databases.get(dbName) | ||
@@ -457,3 +329,3 @@ if(!db) return new ReactiveDao.ObservableError('databaseNotFound') | ||
}, | ||
get: async (dbName, tableName, id) =>{ | ||
get: async (dbName) =>{ | ||
const db = server.databases.get(dbName) | ||
@@ -465,3 +337,3 @@ if(!db) throw new Error('databaseNotFound') | ||
indexesCount: { | ||
observable: (dbName, tableName, id) => { | ||
observable: (dbName) => { | ||
const db = server.databases.get(dbName) | ||
@@ -471,3 +343,3 @@ if(!db) return new ReactiveDao.ObservableError('databaseNotFound') | ||
}, | ||
get: async (dbName, tableName, id) =>{ | ||
get: async (dbName) =>{ | ||
const db = server.databases.get(dbName) | ||
@@ -479,3 +351,3 @@ if(!db) throw new Error('databaseNotFound') | ||
logsCount: { | ||
observable: (dbName, tableName, id) => { | ||
observable: (dbName) => { | ||
const db = server.databases.get(dbName) | ||
@@ -485,3 +357,3 @@ if(!db) return new ReactiveDao.ObservableError('databaseNotFound') | ||
}, | ||
get: async (dbName, tableName, id) =>{ | ||
get: async (dbName) =>{ | ||
const db = server.databases.get(dbName) | ||
@@ -493,3 +365,3 @@ if(!db) throw new Error('databaseNotFound') | ||
tables: { | ||
observable: (dbName, tableName, id) => { | ||
observable: (dbName) => { | ||
const db = server.databases.get(dbName) | ||
@@ -499,3 +371,3 @@ if(!db) return new ReactiveDao.ObservableError('databaseNotFound') | ||
}, | ||
get: async (dbName, tableName, id) =>{ | ||
get: async (dbName) =>{ | ||
const db = server.databases.get(dbName) | ||
@@ -507,3 +379,3 @@ if(!db) throw new Error('databaseNotFound') | ||
indexes: { | ||
observable: (dbName, indexName, id) => { | ||
observable: (dbName) => { | ||
const db = server.databases.get(dbName) | ||
@@ -513,3 +385,3 @@ if(!db) return new ReactiveDao.ObservableError('databaseNotFound') | ||
}, | ||
get: async (dbName, indexName, id) =>{ | ||
get: async (dbName) =>{ | ||
const db = server.databases.get(dbName) | ||
@@ -521,3 +393,3 @@ if(!db) throw new Error('databaseNotFound') | ||
logs: { | ||
observable: (dbName, logName, id) => { | ||
observable: (dbName) => { | ||
const db = server.databases.get(dbName) | ||
@@ -527,3 +399,3 @@ if(!db) return new ReactiveDao.ObservableError('databaseNotFound') | ||
}, | ||
get: async (dbName, logName, id) => { | ||
get: async (dbName) => { | ||
const db = server.databases.get(dbName) | ||
@@ -535,3 +407,3 @@ if(!db) throw new Error('databaseNotFound') | ||
tableConfig: { | ||
observable: (dbName, tableName, id) => { | ||
observable: (dbName, tableName) => { | ||
const db = server.databases.get(dbName) | ||
@@ -543,3 +415,3 @@ if(!db) return new ReactiveDao.ObservableError('databaseNotFound') | ||
}, | ||
get: async (dbName, tableName, id) => { | ||
get: async (dbName, tableName) => { | ||
const db = server.databases.get(dbName) | ||
@@ -553,3 +425,3 @@ if(!db) throw new Error('databaseNotFound') | ||
indexConfig: { | ||
observable: async (dbName, indexName, id) => { | ||
observable: async (dbName, indexName) => { | ||
const db = server.databases.get(dbName) | ||
@@ -561,3 +433,3 @@ if(!db) return new ReactiveDao.ObservableError('databaseNotFound') | ||
}, | ||
get: async (dbName, indexName, id) =>{ | ||
get: async (dbName, indexName) =>{ | ||
const db = server.databases.get(dbName) | ||
@@ -571,3 +443,3 @@ if(!db) throw new Error('databaseNotFound') | ||
indexCode: { | ||
observable: async (dbName, indexName, id) => { | ||
observable: async (dbName, indexName) => { | ||
const db = server.databases.get(dbName) | ||
@@ -579,3 +451,3 @@ if(!db) return new ReactiveDao.ObservableError('databaseNotFound') | ||
}, | ||
get: async (dbName, indexName, id) =>{ | ||
get: async (dbName, indexName) =>{ | ||
const db = server.databases.get(dbName) | ||
@@ -589,3 +461,3 @@ if(!db) throw new Error('databaseNotFound') | ||
logConfig: { | ||
observable: (dbName, logName, id) => { | ||
observable: (dbName, logName) => { | ||
const db = server.databases.get(dbName) | ||
@@ -597,3 +469,3 @@ if(!db) return new ReactiveDao.ObservableError('databaseNotFound') | ||
}, | ||
get: async (dbName, logName, id) =>{ | ||
get: async (dbName, logName) =>{ | ||
const db = server.databases.get(dbName) | ||
@@ -896,4 +768,3 @@ if(!db) throw new Error('databaseNotFound') | ||
localRequests, | ||
remoteRequests, | ||
localReads | ||
} |
{ | ||
"name": "@live-change/db-web", | ||
"version": "0.8.15", | ||
"version": "0.8.16", | ||
"author": { | ||
@@ -32,10 +32,10 @@ "email": "michal@laszczewski.com", | ||
"dependencies": { | ||
"@live-change/dao": "^0.8.15", | ||
"@live-change/db": "^0.8.15", | ||
"@live-change/db-store-indexeddb": "^0.8.15", | ||
"@live-change/db-store-localstorage": "^0.8.15", | ||
"@live-change/db-store-rbtree": "^0.8.15", | ||
"@live-change/dao": "^0.8.16", | ||
"@live-change/db": "^0.8.16", | ||
"@live-change/db-store-indexeddb": "^0.8.16", | ||
"@live-change/db-store-localstorage": "^0.8.16", | ||
"@live-change/db-store-rbtree": "^0.8.16", | ||
"debug": "^4.3.4" | ||
}, | ||
"gitHead": "4897eefbf3ce9ace57630127da89503c71114563" | ||
"gitHead": "b8ac84cbe1a8c435c7b5003dfc64ddc41a4e15a6" | ||
} |
68451
1627