Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{
port: options.port || 27017,
host: options.host || '127.0.0.1'
}
]
conn = uri.format(options)
}
} else {
this.client = conn
}
}
conn = conn || 'mongodb://127.0.0.1:27017'
var coll = (this.coll = options.collection || 'cacheman')
this.compression = options.compression || false
this.ready = thunky((cb) => {
function createIndex(err, db) {
db.ensureIndex(coll, { expireAt: 1 }, { expireAfterSeconds: 0 }, (err) => {
cb(err, db)
})
}
if ('string' === typeof conn) {
const mongoOptions = OPTIONS_LIST.reduce((opt, key) => {
delete opt[key]
return opt
}, Object.assign({}, options))
MongoClient.connect(conn, mongoOptions, (err, db) => {
if (err) return cb(err)
createIndex(null, (this.client = db))
db.ensureIndex(coll, { expireAt: 1 }, { expireAfterSeconds: 0 }, (err) => {
export default function rpc () {
const d = dnode()
return thunky((cb) => {
d.pipe(ws).pipe(d)
d.on('remote', (remote) => cb(remote))
})
}
import hype from 'hyperpc'
import thunky from 'thunky'
import isElectron from 'is-electron-renderer'
import websocket from 'websocket-stream'
import { debugFactory } from './debug'
const debug = debugFactory('rpc')
const clientApi = {
foo: (bar, cb) => cb(null, bar.toUpper() + ' from client!!')
}
const rpc = thunky((cb) => {
if (isElectron) {
import('electron').then(({ipcRenderer}) => {
ipcRenderer.send('rpc')
ipcRenderer.on('rpc', (ev, port) => {
create('ws://localhost:' + port + '/rpc', cb)
})
})
} else {
create(window.location.origin.replace(/^http/, 'ws') + '/rpc', cb)
}
})
function create (url, cb) {
const ws = websocket(url)
const rpc = hype(clientApi, {promise: true, debug: true})
export default function rpc () {
const d = dnode()
return thunky((cb) => {
ipcRenderer.send('init')
ipcRenderer.on('init', () => {
d.on('remote', (remote) => cb(remote))
d.on('data', (data) => ipcRenderer.send('dnode', data))
ipcRenderer.on('dnode', (event, data) => {
d.write(data)
})
})
})
}