Fully end to end encrypted anonymous chat program. Server only stores public key lookup for users and the encrypted messages. No credentials are transfered to the server, but kept in local browser storage. This allows 100% safe chatting.
https://safechat.ch
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
3.1 KiB
138 lines
3.1 KiB
9 years ago
|
var Classes = Object.create(null);
|
||
|
|
||
|
/**
|
||
|
* Create a new Connection instance.
|
||
|
* @param {object} config
|
||
|
* @public
|
||
|
*/
|
||
|
exports.createConnection = function createConnection(config) {
|
||
|
var Connection = loadClass('Connection');
|
||
|
var ConnectionConfig = loadClass('ConnectionConfig');
|
||
|
|
||
|
return new Connection({config: new ConnectionConfig(config)});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Create a new Pool instance.
|
||
|
* @param {object} config
|
||
|
* @public
|
||
|
*/
|
||
|
exports.createPool = function createPool(config) {
|
||
|
var Pool = loadClass('Pool');
|
||
|
var PoolConfig = loadClass('PoolConfig');
|
||
|
|
||
|
return new Pool({config: new PoolConfig(config)});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Create a new PoolCluster instance.
|
||
|
* @param {object} config
|
||
|
* @public
|
||
|
*/
|
||
|
exports.createPoolCluster = function createPoolCluster(config) {
|
||
|
var PoolCluster = loadClass('PoolCluster');
|
||
|
|
||
|
return new PoolCluster(config);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Create a new Query instance.
|
||
|
* @public
|
||
|
*/
|
||
|
exports.createQuery = function createQuery(sql, values, callback) {
|
||
|
var Connection = loadClass('Connection');
|
||
|
|
||
|
return Connection.createQuery(sql, values, callback);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Escape a value for SQL.
|
||
|
* @param {*} value
|
||
|
* @param {boolean} [stringifyObjects=false]
|
||
|
* @param {string} [timeZone=local]
|
||
|
* @public
|
||
|
*/
|
||
|
exports.escape = function escape(value, stringifyObjects, timeZone) {
|
||
|
var SqlString = loadClass('SqlString');
|
||
|
|
||
|
return SqlString.escape(value, stringifyObjects, timeZone);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Escape an identifier for SQL.
|
||
|
* @param {*} value
|
||
|
* @param {boolean} [forbidQualified]
|
||
|
* @public
|
||
|
*/
|
||
|
exports.escapeId = function escapeId(value, forbidQualified) {
|
||
|
var SqlString = loadClass('SqlString');
|
||
|
|
||
|
return SqlString.escapeId(value, forbidQualified);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Format SQL and replacement values into a SQL string.
|
||
|
* @param {string} sql
|
||
|
* @param {array} [values]
|
||
|
* @param {boolean} [stringifyObjects=false]
|
||
|
* @param {string} [timeZone=local]
|
||
|
* @public
|
||
|
*/
|
||
|
exports.format = function format(sql, values, stringifyObjects, timeZone) {
|
||
|
var SqlString = loadClass('SqlString');
|
||
|
|
||
|
return SqlString.format(sql, values, stringifyObjects, timeZone);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* The type constants.
|
||
|
* @public
|
||
|
*/
|
||
|
Object.defineProperty(exports, 'Types', {
|
||
|
get: loadClass.bind(null, 'Types')
|
||
|
});
|
||
|
|
||
|
/**
|
||
|
* Load the given class.
|
||
|
* @private
|
||
|
*/
|
||
|
function loadClass(className) {
|
||
|
var Class = Classes[className];
|
||
|
|
||
|
if (Class !== undefined) {
|
||
|
return Class;
|
||
|
}
|
||
|
|
||
|
// This uses a switch for static require analysis
|
||
|
switch (className) {
|
||
|
case 'Connection':
|
||
|
Class = require('./lib/Connection');
|
||
|
break;
|
||
|
case 'ConnectionConfig':
|
||
|
Class = require('./lib/ConnectionConfig');
|
||
|
break;
|
||
|
case 'Pool':
|
||
|
Class = require('./lib/Pool');
|
||
|
break;
|
||
|
case 'PoolCluster':
|
||
|
Class = require('./lib/PoolCluster');
|
||
|
break;
|
||
|
case 'PoolConfig':
|
||
|
Class = require('./lib/PoolConfig');
|
||
|
break;
|
||
|
case 'SqlString':
|
||
|
Class = require('./lib/protocol/SqlString');
|
||
|
break;
|
||
|
case 'Types':
|
||
|
Class = require('./lib/protocol/constants/types');
|
||
|
break;
|
||
|
default:
|
||
|
throw new Error('Cannot find class \'' + className + '\'');
|
||
|
}
|
||
|
|
||
|
// Store to prevent invoking require()
|
||
|
Classes[className] = Class;
|
||
|
|
||
|
return Class;
|
||
|
}
|