|
|
|
@ -3,13 +3,13 @@ const env = require("../environment") |
|
|
|
|
|
|
|
let PouchDB |
|
|
|
let initialised = false |
|
|
|
const dbList = new Set() |
|
|
|
|
|
|
|
const put = |
|
|
|
dbPut => |
|
|
|
async (doc, options = {}) => { |
|
|
|
const response = await dbPut(doc, options) |
|
|
|
// TODO: add created / updated
|
|
|
|
return response |
|
|
|
return await dbPut(doc, options) |
|
|
|
} |
|
|
|
|
|
|
|
const checkInitialised = () => { |
|
|
|
@ -28,6 +28,9 @@ exports.init = opts => { |
|
|
|
// in situations that using the function doWithDB does not work
|
|
|
|
exports.dangerousGetDB = (dbName, opts) => { |
|
|
|
checkInitialised() |
|
|
|
if (env.isTest()) { |
|
|
|
dbList.add(dbName) |
|
|
|
} |
|
|
|
const db = new PouchDB(dbName, opts) |
|
|
|
const dbPut = db.put |
|
|
|
db.put = put(dbPut) |
|
|
|
@ -63,6 +66,9 @@ exports.doWithDB = async (dbName, cb, opts) => { |
|
|
|
} |
|
|
|
|
|
|
|
exports.allDbs = () => { |
|
|
|
if (!env.isTest()) { |
|
|
|
throw new Error("Cannot be used outside test environment.") |
|
|
|
} |
|
|
|
checkInitialised() |
|
|
|
return PouchDB.allDbs() |
|
|
|
return [...dbList] |
|
|
|
} |
|
|
|
|