Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
/* eslint id-length: ["off"], newline-per-chained-call: ["off"] */
const Pg = require('pg');
const URL = require('url');
const ShareDBDB = require('sharedb').DB;
Pg.on('end', onPgEnd);
const pgPool = new Pg.Pool(parseDatabaseURL());
class ShareDBPGCanvas extends ShareDBDB {
commit(orgID, canvasID, op, snapshot, options, cb) {
return pgPool.connect().then(client => {
return client.query('BEGIN').then(_ => {
return this.doGetSnapshot(client, orgID, canvasID, [], options)
.then(existingSnap => {
if (snapshot.v !== existingSnap.v + 1) return false;
return this.doCommit(client, canvasID, op, snapshot);
}).then(success => {
return client.query('COMMIT').then(_ => {
return resolveQuery(success, cb, client);
var async = require('async');
var mongodb = require('mongodb');
var DB = require('sharedb').DB;
module.exports = ShareDbMongo;
function ShareDbMongo(mongo, options) {
// use without new
if (!(this instanceof ShareDbMongo)) {
return new ShareDbMongo(mongo, options);
}
if (typeof mongo === 'object') {
options = mongo;
mongo = options.mongo;
}
if (!options) options = {};
// pollDelay is a dodgy hack to work around race conditions replicating the
/* MySQL-backed ShareDB (https://github.com/share/sharedb) database
* Wraps https://www.npmjs.com/package/mysql
* @author Win Min Tun (sawrochelais@gmail.com)
* @version 1.0.5
*/
// @TODO: add support for MySQL JSON type
var DB = require('sharedb').DB;
var mysql = require('mysql');
var pool;
var mysql_config;
var ops_table;
var snapshots_table;
var debug = false;
// options = { db: { host: 'localhost', user: 'root', password: '', database: 'somedb', connectionLimit: 10 }, ops_table: 'ops_table_name', snapshots_table: 'snapshots_table_name', debug: false }
// connectionLimit [default=10], debug [default=false], ops_table[default=ops], snapshots[default=snapshots] are optional
function MySQLDB(options) {
if (!(this instanceof MySQLDB)) return new MySQLDB(options);
DB.call(this, options);
this.closed = false;
var DB = require('sharedb').DB;
var pg = require('pg');
// Postgres-backed ShareDB database
function PostgresDB(options) {
if (!(this instanceof PostgresDB)) return new PostgresDB(options);
DB.call(this, options);
this.closed = false;
this.pg_config = options;
};
module.exports = PostgresDB;
PostgresDB.prototype = Object.create(DB.prototype);
var async = require('async');
var mongodb = require('mongodb');
var DB = require('sharedb').DB;
var OpLinkValidator = require('./op-link-validator');
module.exports = ShareDbMongo;
function ShareDbMongo(mongo, options) {
// use without new
if (!(this instanceof ShareDbMongo)) {
return new ShareDbMongo(mongo, options);
}
if (typeof mongo === 'object') {
options = mongo;
mongo = options.mongo;
}
if (!options) options = {};