Beispiel #1
0
import PouchDB from 'pouchdb-core'

import PouchDBMemory from 'pouchdb-adapter-memory'
import mapreduce from 'pouchdb-mapreduce'
import replication from 'pouchdb-replication'

PouchDB.plugin(PouchDBMemory)
    .plugin(mapreduce)
    .plugin(replication)

const pouchdbOptions = {
    name: 'testdb',
    auto_compaction: true,
    adapter: 'memory',
}

const db = PouchDB(pouchdbOptions)
export default db
'use strict';

const DataService = require('composer-runtime').DataService;
const pouchCollate = require('pouchdb-collate');
const PouchDB = require('pouchdb-core');
const PouchDBDataCollection = require('..').PouchDBDataCollection;
const PouchDBDataService = require('..').PouchDBDataService;

const chai = require('chai');
chai.should();
chai.use(require('chai-as-promised'));
const sinon = require('sinon');


// Install the PouchDB plugins.
PouchDB.plugin(require('pouchdb-adapter-memory'));
PouchDB.plugin(require('pouchdb-find'));

// This is the object type used to form composite keys for the collection of collections.
const collectionObjectType = '$syscollections';

describe('PouchDBDataService', () => {

    let dataService;
    let db;
    let sandbox;

    beforeEach(() => {
        db = new PouchDB('Composer', { adapter: 'memory' });
        sandbox = sinon.sandbox.create();
        sandbox.stub(PouchDBDataService, 'createPouchDB').returns(db);
'use strict'

import PouchDB from 'pouchdb-core'
import AsyncStoragePouch from 'pouchdb-adapter-asyncstorage'
import HttpPouch from 'pouchdb-adapter-http'
import mapreduce from 'pouchdb-mapreduce'
import replication from 'pouchdb-replication'

PouchDB.plugin(AsyncStoragePouch)
  .plugin(HttpPouch)
  .plugin(mapreduce)
  .plugin(replication)

export default PouchDB
Beispiel #4
0
/**
 * this handles the pouchdb-instance
 * to easy add modules and manipulate things
 * Adapters can be found here:
 * @link https://github.com/pouchdb/pouchdb/tree/master/packages/node_modules
 */
import PouchDB from 'pouchdb-core';

// pouchdb-find
import PouchDBFind from 'pouchdb-find';
PouchDB.plugin(PouchDBFind);

import RxError from './rx-error';

/**
 * get the number of all undeleted documents
 * @param  {PouchDB}  pouchdb instance
 * @return {Promise<number>} number of documents
 */
PouchDB.countAllUndeleted = function(pouchdb) {
    return pouchdb
        .allDocs({
            include_docs: false,
            attachments: false
        })
        .then(docs => docs
            .rows
            .filter(row => !row.id.startsWith('_design/'))
            .length
        );
};
Beispiel #5
0
var PouchDB = require('pouchdb-core')
var IDBPouch = require('pouchdb-adapter-idb')
var HttpPouch = require('pouchdb-adapter-http')
var replication = require('pouchdb-replication')
var merge = require('lodash.merge')
var get = require('lodash.get')

PouchDB
  .plugin(IDBPouch)
  .plugin(HttpPouch)
  .plugin(replication)

var DBs = {}
var autoIncreaseCount = new PouchDB(`auto_increases`)

function db(dbname) {
  if (!dbname) throw new Error('dbname must be defined')
  if (DBs[dbname]) return DBs[dbname]
  throw new Error('Database have not been created yet.')
}

function CreateDatabase(dbname, conf) {
  DBs[dbname] = new PouchDB(dbname)

  if (conf.coucbdb) {
    DBs[dbname].remote = new PouchDB(conf.coucbdb.url + dbname, {
      auth: conf.coucbdb.auth
    })
    autoIncreaseCount = new PouchDB(conf.coucbdb.url + 'auto_increases')
  }
var tape = require('tape')
var PouchDB = require('pouchdb-core')
var Promise = require('pouchdb-promise')
var upsert = require('pouchdb-utils').upsert

PouchDB.plugin(require('pouchdb-adapter-leveldb'))
PouchDB.plugin(require('./src'))

var test = function (name, fun) {
  var db = new PouchDB('test-' + name, { db: require('memdown') })

  tape(name, function (t) {
    fun(db, t)
  })
}

var docs = [
  {_id: 'a', group: 'letters', val: 1, text: 'ei'},
  {_id: '1', group: 'numbers', val: 1, text: 'one'},
  {_id: '3', group: 'numbers', val: 3, text: 'three'},
  {_id: 'c', group: 'letters', val: 3, text: 'see'},
  {_id: 'b', group: 'letters', val: 2, text: 'bee'},
  {_id: '2', group: 'numbers', val: 2, text: 'two'}
]

test('basic', function (db, t) {
  t.plan(10)
  var derivedDB

  db.bulkDocs(docs)
    .then(() => {
Beispiel #7
0
import PouchDB from 'pouchdb-core';
import idbPouch from 'pouchdb-adapter-indexeddb';
import httpPouch from 'pouchdb-adapter-http';
import replication from 'pouchdb-replication';

export default PouchDB
  .plugin(idbPouch)
  .plugin(httpPouch)
  .plugin(replication);
Beispiel #8
0
import PouchDBCore from 'pouchdb-core';
import PouchDBMemory from 'pouchdb-adapter-memory';
import setupExpressPouchDB from 'express-pouchdb';

const PouchDB = PouchDBCore
  .plugin(PouchDBMemory)
  .defaults({adapter: 'memory'});

const app = setupExpressPouchDB(PouchDB);
/* eslint-disable no-new */
new PouchDB('foo', {
  adapter: 'memory'
});
/* eslint-enable no-new */

const server = app.listen(0, () => {
  const {port} = server.address();
  const dbUrl = `http://localhost:${port}/foo`;

  process.send({dbUrl});
});
Beispiel #9
0
/*
 * Delete old artefacts from the testing db
 */
const { UPLOAD_URL, BUILDS_SERVER, TRAVIS_BUILD_NUMBER } = process.env;
const BUILDS_TO_KEEP = 50;
const END_BUILD_TO_DELETE = TRAVIS_BUILD_NUMBER - BUILDS_TO_KEEP;
const END_KEY = `medic:medic:test-${END_BUILD_TO_DELETE}`;
const MAX_BUILDS_TO_DELETE = 50;
const PouchDB = require('pouchdb-core');
PouchDB.plugin(require('pouchdb-adapter-http'));

const db = new PouchDB(`${UPLOAD_URL}/${BUILDS_SERVER}`);

const get = () => {
  console.log(`Getting builds...`);
  return db.allDocs({ endkey: END_KEY, limit: MAX_BUILDS_TO_DELETE });
};

const markDeleted = response => {
  return response.rows.map(row => {
    return {
      _id: row.id,
      _rev: row.value.rev,
      _deleted: true
    };
  });
};

const remove = docs => {
  if (docs.length) {
    console.log(`Deleting the oldest ${docs.length} builds...`);
Beispiel #10
0
const PouchDB = require('pouchdb-core'),
  logger = require('./logger'),
  environment = require('./environment');
PouchDB.plugin(require('pouchdb-adapter-http'));
PouchDB.plugin(require('pouchdb-find'));
PouchDB.plugin(require('pouchdb-mapreduce'));

const { UNIT_TEST_ENV } = process.env;

if (UNIT_TEST_ENV) {
  const DBS_TO_STUB = [
    'medic',
    'users',
    'medicUsersMeta'
  ];
  const DB_FUNCTIONS_TO_STUB = [
    'allDocs',
    'bulkDocs',
    'bulkGet',
    'put',
    'post',
    'query',
    'get',
    'getAttachment',
    'changes',
    'info',
  ];
  const GLOBAL_FUNCTIONS_TO_STUB = [
    'get',
    'exists'
  ];
Beispiel #11
0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.

/* global FormData */

import FauxtonAPI from "../../../core/api";
import {post} from "../../../core/ajax";
import ActionTypes from "./actiontypes";
import getTree from "visualizeRevTree/lib/getTree";
import PouchDB from "pouchdb-core";
import PouchHttpAdapter from 'pouchdb-adapter-http';
PouchDB.plugin(PouchHttpAdapter);

let db;

export const initDiffEditor = (dbName, docId) => dispatch => {
  // We have to use API url here because PouchDB doesn't take relative urls.
  const url = FauxtonAPI.urls('databaseBaseURL', 'apiurl', dbName);
  db = PouchDB(url);

  Promise.all([db.get(docId), getTree(db, docId)])
    .then(([doc, tree]) => {
      const conflictingRevs = getConflictingRevs(tree.paths, tree.winner, Object.keys(tree.deleted));
      const initialRev = conflictingRevs[0];

      if (!initialRev) {
        return dispatch(treeLoaded(tree, doc, conflictingRevs, null, dbName));