2020-04-24 20:54:20 +12:00
|
|
|
const PouchDB = require("pouchdb")
|
2020-09-26 01:47:42 +12:00
|
|
|
const replicationStream = require("pouchdb-replication-stream")
|
2020-04-25 19:35:34 +12:00
|
|
|
const allDbs = require("pouchdb-all-dbs")
|
2021-02-02 10:02:54 +13:00
|
|
|
const find = require("pouchdb-find")
|
2020-05-15 02:12:30 +12:00
|
|
|
const env = require("../environment")
|
2020-04-08 02:12:08 +12:00
|
|
|
|
2021-03-23 04:43:26 +13:00
|
|
|
const COUCH_DB_URL = env.COUCH_DB_URL || "http://localhost:10000/db/"
|
2020-05-15 02:12:30 +12:00
|
|
|
|
2020-09-26 01:47:42 +12:00
|
|
|
PouchDB.plugin(replicationStream.plugin)
|
2021-02-02 10:02:54 +13:00
|
|
|
PouchDB.plugin(find)
|
2020-09-26 01:47:42 +12:00
|
|
|
PouchDB.adapter("writableStream", replicationStream.adapters.writableStream)
|
|
|
|
|
2020-05-18 21:28:38 +12:00
|
|
|
let POUCH_DB_DEFAULTS = {
|
2020-05-18 22:01:09 +12:00
|
|
|
prefix: COUCH_DB_URL,
|
|
|
|
}
|
2020-04-29 01:39:35 +12:00
|
|
|
|
2021-03-25 07:21:23 +13:00
|
|
|
if (env.isTest()) {
|
2020-05-18 21:28:38 +12:00
|
|
|
PouchDB.plugin(require("pouchdb-adapter-memory"))
|
|
|
|
POUCH_DB_DEFAULTS = {
|
|
|
|
prefix: undefined,
|
2020-05-18 22:01:09 +12:00
|
|
|
adapter: "memory",
|
|
|
|
}
|
2020-05-18 21:28:38 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
const Pouch = PouchDB.defaults(POUCH_DB_DEFAULTS)
|
2020-04-29 01:39:35 +12:00
|
|
|
|
2020-05-07 21:53:34 +12:00
|
|
|
allDbs(Pouch)
|
2020-04-29 01:39:35 +12:00
|
|
|
|
2020-11-03 03:53:51 +13:00
|
|
|
// replicate your local levelDB pouch to a running HTTP compliant couch or pouchdb server.
|
2021-03-16 05:36:38 +13:00
|
|
|
/* istanbul ignore next */
|
2020-11-03 03:53:51 +13:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
function replicateLocal() {
|
2021-05-04 22:32:22 +12:00
|
|
|
Pouch.allDbs().then(dbs => {
|
2020-11-03 03:53:51 +13:00
|
|
|
for (let db of dbs) {
|
|
|
|
new Pouch(db).sync(
|
|
|
|
new PouchDB(`http://127.0.0.1:5984/${db}`, { live: true })
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-12 23:41:49 +13:00
|
|
|
// replicateLocal()
|
2020-11-03 03:53:51 +13:00
|
|
|
|
2020-10-09 22:00:57 +13:00
|
|
|
module.exports = Pouch
|