Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* eslint-env mocha */
// eslint-disable-next-line no-unused-vars
import 'isomorphic-fetch'
import should from 'should'
import { Client } from '../../src'
import PouchDB from 'pouchdb-browser'
import pouchdbFind from 'pouchdb-find'
PouchDB.plugin(require('pouchdb-adapter-memory'))
// PouchDB should not be a mandatory dependency as it is only used in mobile
// environment, so we declare it in global scope here.
global.PouchDB = PouchDB
global.pouchdbFind = pouchdbFind
describe('offline', () => {
const fileDoctype = 'io.cozy.files'
const otherDoctype = 'io.cozy.others'
const cozyUrl = 'http://cozy.tools:8080/'
let offlineParameter = {
doctypes: [fileDoctype, otherDoctype],
options: { adapter: 'memory' }
}
const cozy = {}
import PouchDB from 'pouchdb-browser';
let opt = {};
if (global && global.IS_TEST === true) {
PouchDB.plugin(require('pouchdb-adapter-memory'));
opt.adapter = 'memory';
}
else {
opt.adapter = 'idb';
}
const KakuDB = new PouchDB('kaku', opt);
// Note:
// Because we add something new in the prototype chain and this is not safe,
// we added some prefix to make it unique
PouchDB.prototype.resetDatabase = function() {
return this.destroy().catch((error) => {
console.log('Something goes wrong when dropping database');
console.log(error);
});
// Internal State
this._dbs = {};
this._watch = {};
this._state = {};
// Throw Error if Global Config not defined
if (!schema.config) throw new Error('[VuePouchDB]: Global Config is not declared in the upper level!');
// Referencing Actions to the $bucket
if (schema.actions) merge(this, schema.actions);
// Init PouchDB plugins
if (Array.isArray(schema.plugins) && (schema.plugins.length > 0)) {
for (let i = 0; i < schema.plugins.length; i += 1) {
PouchDB.plugin(schema.plugins[i]);
}
}
// Initializing DBs that are declared in the schema{}
Object.keys(schema).forEach((dbname) => {
// If is ignored Key, skip!
if (ignoredKeys.indexOf(dbname) !== -1) return null;
// Initialize the DB
return this._initDB(dbname, merge(
{},
schema.config,
schema[dbname]
));
});
}
import PouchDB from 'pouchdb-browser';
import pouchDBFind from 'pouchdb-find';
import pouchDBUpsert from 'pouchdb-upsert';
import cryptoPouch from 'crypto-pouch';
import Emittery from 'emittery';
import PQueue from 'p-queue';
import roundTo from 'round-to';
import {subDays, isAfter} from 'date-fns';
import appContainer from 'containers/App';
import {appTimeStarted} from '../constants';
import {translate} from './translate';
const t = translate('swap');
PouchDB.plugin(pouchDBFind);
PouchDB.plugin(pouchDBUpsert);
PouchDB.plugin(cryptoPouch);
class SwapDB {
constructor(portfolioId, seedPhrase) {
// Using `2` so it won't conflict with HyperDEX versions using marketmaker v1.
this.db = new PouchDB(`swaps2-${portfolioId}`, {adapter: 'idb'});
this.db.crypto(seedPhrase);
const ee = new Emittery();
this.on = ee.on.bind(ee);
this.off = ee.off.bind(ee);
this.once = ee.once.bind(ee);
this.db.changes({
since: 'now',
import PouchDB from 'pouchdb-browser';
import pouchDBFind from 'pouchdb-find';
import pouchDBUpsert from 'pouchdb-upsert';
import cryptoPouch from 'crypto-pouch';
import Emittery from 'emittery';
import PQueue from 'p-queue';
import roundTo from 'round-to';
import {subDays, isAfter} from 'date-fns';
import appContainer from 'containers/App';
import {appTimeStarted} from '../constants';
import {translate} from './translate';
const t = translate('swap');
PouchDB.plugin(pouchDBFind);
PouchDB.plugin(pouchDBUpsert);
PouchDB.plugin(cryptoPouch);
class SwapDB {
constructor(portfolioId, seedPhrase) {
// Using `2` so it won't conflict with HyperDEX versions using marketmaker v1.
this.db = new PouchDB(`swaps2-${portfolioId}`, {adapter: 'idb'});
this.db.crypto(seedPhrase);
const ee = new Emittery();
this.on = ee.on.bind(ee);
this.off = ee.off.bind(ee);
this.once = ee.once.bind(ee);
this.db.changes({
import get from 'lodash/fp/get'
import fromPairs from 'lodash/fp/fromPairs'
import PouchDB from 'pouchdb-browser' // maps to pouchdb-memory in Jest, see .jest-config.json
import PouchDBFind from 'pouchdb-find'
import PouchDBErase from 'pouchdb-erase'
import { blobToBase64String, arrayBufferToBlob } from 'blob-util'
import { pageKeyPrefix, pageDocsSelector } from 'src/page-storage'
import { visitKeyPrefix } from 'src/activity-logger'
import { bookmarkKeyPrefix } from 'src/search/bookmarks'
import { normalizeAndEncode } from 'src/util/encode-url-for-id'
PouchDB.plugin(PouchDBFind)
PouchDB.plugin(PouchDBErase)
const pouchdbOptions = {
name: 'webmemex',
auto_compaction: true,
}
const db = PouchDB(pouchdbOptions)
export default db
// DEBUG Expose db for debugging or direct user access.
window.db = db
// The couch/pouch way to match keys with a given prefix (e.g. one type of docs).
export const keyRangeForPrefix = prefix => ({
startkey: `${prefix}`,
endkey: `${prefix}\uffff`,
export function createDatabase(cozy, doctype, options = {}) {
if (!pluginLoaded) {
PouchDB.plugin(pouchdbFind)
pluginLoaded = true
}
if (hasDatabase(cozy, doctype)) {
return Promise.resolve(getDatabase(cozy, doctype))
}
setDatabase(cozy, doctype, new PouchDB(doctype, options))
return createIndexes(cozy, doctype).then(() => getDatabase(cozy, doctype))
}
import PouchDebug from 'pouchdb-debug'
import PouchUpsert from 'pouchdb-upsert'
import PouchFind from 'pouchdb-find'
import PouchLiveFind from 'pouchdb-live-find'
import Model from '@/models/model'
PouchDB.plugin(PouchDebug)
if (process.env.DEBUG_POUCHDB) {
PouchDB.debug.enable('*')
} else {
PouchDB.debug.disable()
}
PouchDB.plugin(PouchUpsert)
PouchDB.plugin(PouchFind)
PouchDB.plugin(PouchLiveFind)
/**
* This class wraps the PouchDB interface to provide some methods that deal with
* the revisions (`_rev`) automatically.
*/
class DbInterface {
/**
* Creates an instance of DbInterface and the main index
* @param {String} name
* @return {DbInterface}
*/
static create (name) {
const db = new DbInterface(name)
import PouchDB from 'pouchdb-browser';
import PouchFind from 'pouchdb-find';
//import PouchSearch from 'pouchdb-quick-search';
import RelationalPouch from 'relational-pouch';
PouchDB.plugin(PouchFind);
//PouchDB.plugin(PouchSearch);
PouchDB.plugin(RelationalPouch);
PouchDB.plugin(require('pouchdb-debug').default);
window.PouchDB = PouchDB;
window.session_db = new PouchDB('session');
if (!window.rapyd_config) window.rapyd_config = {};
if (!window.localStorage.rapyd_server_url) {
if (window.rapyd_config.url) {
window.localStorage.rapyd_server_url = window.rapyd_config.url;
}
else if (window.location.protocol === 'file:') {
window.localStorage.rapyd_server_url = 'http://localhost:8069';
}
else {
window.localStorage.rapyd_server_url = ((href) => href.substring(0, href.lastIndexOf('/')) + '/')(window.location.origin + window.location.pathname);
}
}