diff --git a/bundle.js b/bundle.js index 1ff4bd1..fd724da 100644 --- a/bundle.js +++ b/bundle.js @@ -1,4 +1,4 @@ -(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0 + var up = 0; + for (var i = parts.length - 1; i >= 0; i--) { + var last = parts[i]; + if (last === '.') { + parts.splice(i, 1); + } else if (last === '..') { + parts.splice(i, 1); + up++; + } else if (up) { + parts.splice(i, 1); + up--; + } + } + + // if the path is allowed to go above the root, restore leading ..s + if (allowAboveRoot) { + for (; up--; up) { + parts.unshift('..'); + } + } + + return parts; +} + +// path.resolve([from ...], to) +// posix version +exports.resolve = function() { + var resolvedPath = '', + resolvedAbsolute = false; + + for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { + var path = (i >= 0) ? arguments[i] : process.cwd(); + + // Skip empty and invalid entries + if (typeof path !== 'string') { + throw new TypeError('Arguments to path.resolve must be strings'); + } else if (!path) { + continue; + } + + resolvedPath = path + '/' + resolvedPath; + resolvedAbsolute = path.charAt(0) === '/'; + } + + // At this point the path should be resolved to a full absolute path, but + // handle relative paths to be safe (might happen when process.cwd() fails) + + // Normalize the path + resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { + return !!p; + }), !resolvedAbsolute).join('/'); + + return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; +}; + +// path.normalize(path) +// posix version +exports.normalize = function(path) { + var isAbsolute = exports.isAbsolute(path), + trailingSlash = substr(path, -1) === '/'; + + // Normalize the path + path = normalizeArray(filter(path.split('/'), function(p) { + return !!p; + }), !isAbsolute).join('/'); + + if (!path && !isAbsolute) { + path = '.'; + } + if (path && trailingSlash) { + path += '/'; + } + + return (isAbsolute ? '/' : '') + path; +}; + +// posix version +exports.isAbsolute = function(path) { + return path.charAt(0) === '/'; +}; + +// posix version +exports.join = function() { + var paths = Array.prototype.slice.call(arguments, 0); + return exports.normalize(filter(paths, function(p, index) { + if (typeof p !== 'string') { + throw new TypeError('Arguments to path.join must be strings'); + } + return p; + }).join('/')); +}; + + +// path.relative(from, to) +// posix version +exports.relative = function(from, to) { + from = exports.resolve(from).substr(1); + to = exports.resolve(to).substr(1); + + function trim(arr) { + var start = 0; + for (; start < arr.length; start++) { + if (arr[start] !== '') break; + } + + var end = arr.length - 1; + for (; end >= 0; end--) { + if (arr[end] !== '') break; + } + + if (start > end) return []; + return arr.slice(start, end - start + 1); + } + + var fromParts = trim(from.split('/')); + var toParts = trim(to.split('/')); + + var length = Math.min(fromParts.length, toParts.length); + var samePartsLength = length; + for (var i = 0; i < length; i++) { + if (fromParts[i] !== toParts[i]) { + samePartsLength = i; + break; + } + } + + var outputParts = []; + for (var i = samePartsLength; i < fromParts.length; i++) { + outputParts.push('..'); + } + + outputParts = outputParts.concat(toParts.slice(samePartsLength)); + + return outputParts.join('/'); +}; + +exports.sep = '/'; +exports.delimiter = ':'; + +exports.dirname = function (path) { + if (typeof path !== 'string') path = path + ''; + if (path.length === 0) return '.'; + var code = path.charCodeAt(0); + var hasRoot = code === 47 /*/*/; + var end = -1; + var matchedSlash = true; + for (var i = path.length - 1; i >= 1; --i) { + code = path.charCodeAt(i); + if (code === 47 /*/*/) { + if (!matchedSlash) { + end = i; + break; + } + } else { + // We saw the first non-path separator + matchedSlash = false; + } + } + + if (end === -1) return hasRoot ? '/' : '.'; + if (hasRoot && end === 1) { + // return '//'; + // Backwards-compat fix: + return '/'; + } + return path.slice(0, end); +}; + +function basename(path) { + if (typeof path !== 'string') path = path + ''; + + var start = 0; + var end = -1; + var matchedSlash = true; + var i; + + for (i = path.length - 1; i >= 0; --i) { + if (path.charCodeAt(i) === 47 /*/*/) { + // If we reached a path separator that was not part of a set of path + // separators at the end of the string, stop now + if (!matchedSlash) { + start = i + 1; + break; + } + } else if (end === -1) { + // We saw the first non-path separator, mark this as the end of our + // path component + matchedSlash = false; + end = i + 1; + } + } + + if (end === -1) return ''; + return path.slice(start, end); +} + +// Uses a mixed approach for backwards-compatibility, as ext behavior changed +// in new Node.js versions, so only basename() above is backported here +exports.basename = function (path, ext) { + var f = basename(path); + if (ext && f.substr(-1 * ext.length) === ext) { + f = f.substr(0, f.length - ext.length); + } + return f; +}; + +exports.extname = function (path) { + if (typeof path !== 'string') path = path + ''; + var startDot = -1; + var startPart = 0; + var end = -1; + var matchedSlash = true; + // Track the state of characters (if any) we see before our first dot and + // after any path separator we find + var preDotState = 0; + for (var i = path.length - 1; i >= 0; --i) { + var code = path.charCodeAt(i); + if (code === 47 /*/*/) { + // If we reached a path separator that was not part of a set of path + // separators at the end of the string, stop now + if (!matchedSlash) { + startPart = i + 1; + break; + } + continue; + } + if (end === -1) { + // We saw the first non-path separator, mark this as the end of our + // extension + matchedSlash = false; + end = i + 1; + } + if (code === 46 /*.*/) { + // If this is our first dot, mark it as the start of our extension + if (startDot === -1) + startDot = i; + else if (preDotState !== 1) + preDotState = 1; + } else if (startDot !== -1) { + // We saw a non-dot and non-path separator before our dot, so we should + // have a good chance at having a non-empty extension + preDotState = -1; + } + } + + if (startDot === -1 || end === -1 || + // We saw a non-dot character immediately before the dot + preDotState === 0 || + // The (right-most) trimmed path component is exactly '..' + preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + return ''; + } + return path.slice(startDot, end); +}; + +function filter (xs, f) { + if (xs.filter) return xs.filter(f); + var res = []; + for (var i = 0; i < xs.length; i++) { + if (f(xs[i], i, xs)) res.push(xs[i]); + } + return res; +} + +// String.prototype.substr - negative index don't work in IE8 +var substr = 'ab'.substr(-1) === 'b' + ? function (str, start, len) { return str.substr(start, len) } + : function (str, start, len) { + if (start < 0) start = str.length + start; + return str.substr(start, len); + } +; + +}).call(this)}).call(this,require('_process')) +},{"_process":4}],4:[function(require,module,exports){ +// shim for using process in browser +var process = module.exports = {}; + +// cached from whatever global is present so that test runners that stub it +// don't break things. But we need to wrap it in a try catch in case it is +// wrapped in strict mode code which doesn't define any globals. It's inside a +// function because try/catches deoptimize in certain engines. + +var cachedSetTimeout; +var cachedClearTimeout; + +function defaultSetTimout() { + throw new Error('setTimeout has not been defined'); +} +function defaultClearTimeout () { + throw new Error('clearTimeout has not been defined'); +} +(function () { + try { + if (typeof setTimeout === 'function') { + cachedSetTimeout = setTimeout; + } else { + cachedSetTimeout = defaultSetTimout; + } + } catch (e) { + cachedSetTimeout = defaultSetTimout; + } + try { + if (typeof clearTimeout === 'function') { + cachedClearTimeout = clearTimeout; + } else { + cachedClearTimeout = defaultClearTimeout; + } + } catch (e) { + cachedClearTimeout = defaultClearTimeout; + } +} ()) +function runTimeout(fun) { + if (cachedSetTimeout === setTimeout) { + //normal enviroments in sane situations + return setTimeout(fun, 0); + } + // if setTimeout wasn't available but was latter defined + if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { + cachedSetTimeout = setTimeout; + return setTimeout(fun, 0); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedSetTimeout(fun, 0); + } catch(e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedSetTimeout.call(null, fun, 0); + } catch(e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error + return cachedSetTimeout.call(this, fun, 0); + } + } + + +} +function runClearTimeout(marker) { + if (cachedClearTimeout === clearTimeout) { + //normal enviroments in sane situations + return clearTimeout(marker); + } + // if clearTimeout wasn't available but was latter defined + if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { + cachedClearTimeout = clearTimeout; + return clearTimeout(marker); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedClearTimeout(marker); + } catch (e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedClearTimeout.call(null, marker); + } catch (e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. + // Some versions of I.E. have different rules for clearTimeout vs setTimeout + return cachedClearTimeout.call(this, marker); + } + } + + + +} +var queue = []; +var draining = false; +var currentQueue; +var queueIndex = -1; + +function cleanUpNextTick() { + if (!draining || !currentQueue) { + return; + } + draining = false; + if (currentQueue.length) { + queue = currentQueue.concat(queue); + } else { + queueIndex = -1; + } + if (queue.length) { + drainQueue(); + } +} + +function drainQueue() { + if (draining) { + return; + } + var timeout = runTimeout(cleanUpNextTick); + draining = true; + + var len = queue.length; + while(len) { + currentQueue = queue; + queue = []; + while (++queueIndex < len) { + if (currentQueue) { + currentQueue[queueIndex].run(); + } + } + queueIndex = -1; + len = queue.length; + } + currentQueue = null; + draining = false; + runClearTimeout(timeout); +} + +process.nextTick = function (fun) { + var args = new Array(arguments.length - 1); + if (arguments.length > 1) { + for (var i = 1; i < arguments.length; i++) { + args[i - 1] = arguments[i]; + } + } + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) { + runTimeout(drainQueue); + } +}; + +// v8 likes predictible objects +function Item(fun, array) { + this.fun = fun; + this.array = array; +} +Item.prototype.run = function () { + this.fun.apply(null, this.array); +}; +process.title = 'browser'; +process.browser = true; +process.env = {}; +process.argv = []; +process.version = ''; // empty string to avoid regexp issues +process.versions = {}; + +function noop() {} + +process.on = noop; +process.addListener = noop; +process.once = noop; +process.off = noop; +process.removeListener = noop; +process.removeAllListeners = noop; +process.emit = noop; +process.prependListener = noop; +process.prependOnceListener = noop; + +process.listeners = function (name) { return [] } + +process.binding = function (name) { + throw new Error('process.binding is not supported'); +}; + +process.cwd = function () { return '/' }; +process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); +}; +process.umask = function() { return 0; }; + +},{}],5:[function(require,module,exports){ module.exports.json2sql = require('./lib/json2sql'); module.exports.sql2json = require('./lib/sql2json'); -},{"./lib/json2sql":3,"./lib/sql2json":4}],3:[function(require,module,exports){ +},{"./lib/json2sql":6,"./lib/sql2json":7}],6:[function(require,module,exports){ function json2sql() {} @@ -296,7 +789,7 @@ json2sql.parseNodeWhere = parseNodeWhere; json2sql.parseFunction = parseFunction; module.exports = json2sql; -},{}],4:[function(require,module,exports){ +},{}],7:[function(require,module,exports){ const lexer = require('sql-parser').lexer; const postgisFunctions = /^(ST_SummaryStatsAgg|ST_value|st_valueCount|st_transform|ST_Intersects|st_buffer|ST_AsGeoJson|ST_SetSRID|ST_GeomFromGeoJSON|ST_METADATA|ST_SUMMARYSTATS|ST_HISTOGRAM|TO_NUMBER|TO_CHAR|ST_GeoHash|first|last|ST_BANDMETADATA|st_centroid|round|trunc|abs|ceil|exp|floor|power|sqrt|acos|asin|atan|atan2|cos|cot|sin|tan|to_timestamp|ST_X|ST_Y|CF_[a-zA-Z0-9_-])$/gi; @@ -1173,7 +1666,7 @@ sql2json.prototype.toJSON = function () { module.exports = sql2json; -},{"sql-parser":5}],5:[function(require,module,exports){ +},{"sql-parser":8}],8:[function(require,module,exports){ sql = require('./lib/sql_parser') for(var key in sql) { @@ -1181,8 +1674,8 @@ for(var key in sql) { } -},{"./lib/sql_parser":10}],6:[function(require,module,exports){ -(function (process){ +},{"./lib/sql_parser":13}],9:[function(require,module,exports){ +(function (process){(function (){ /* parser generated by jison 0.4.15 */ /* Returns a Parser object of the following structure: @@ -1658,8 +2151,8 @@ if (typeof module !== 'undefined' && require.main === module) { exports.main(process.argv.slice(1)); } } -}).call(this,require('_process')) -},{"_process":13,"fs":11,"path":12}],7:[function(require,module,exports){ +}).call(this)}).call(this,require('_process')) +},{"_process":4,"fs":2,"path":3}],10:[function(require,module,exports){ // Generated by CoffeeScript 1.8.0 (function() { var Lexer; @@ -1908,7 +2401,7 @@ if (typeof module !== 'undefined' && require.main === module) { }).call(this); -},{}],8:[function(require,module,exports){ +},{}],11:[function(require,module,exports){ // Generated by CoffeeScript 1.8.0 (function() { var ArgumentListValue, BetweenOp, Field, FunctionValue, Group, Having, Join, Limit, ListValue, LiteralValue, Offset, Op, Order, OrderArgument, ParameterValue, Select, Star, StringValue, SubSelect, Table, UnaryOp, Union, Where, indent; @@ -2166,598 +2659,275 @@ if (typeof module !== 'undefined' && require.main === module) { } FunctionValue.prototype.toString = function() { - if (this["arguments"]) { - return "" + (this.name.toUpperCase()) + "(" + (this["arguments"].toString()) + ")"; - } else { - return "" + (this.name.toUpperCase()) + "()"; - } - }; - - return FunctionValue; - - })(); - - exports.Order = Order = (function() { - function Order(orderings, offset) { - this.orderings = orderings; - this.offset = offset; - } - - Order.prototype.toString = function() { - return ("ORDER BY " + (this.orderings.join(', '))) + (this.offset ? "\n" + this.offset.toString() : ""); - }; - - return Order; - - })(); - - exports.OrderArgument = OrderArgument = (function() { - function OrderArgument(value, direction) { - this.value = value; - this.direction = direction != null ? direction : 'ASC'; - null; - } - - OrderArgument.prototype.toString = function() { - return "" + this.value + " " + this.direction; - }; - - return OrderArgument; - - })(); - - exports.Offset = Offset = (function() { - function Offset(row_count, limit) { - this.row_count = row_count; - this.limit = limit; - null; - } - - Offset.prototype.toString = function() { - return ("OFFSET " + this.row_count + " ROWS") + (this.limit ? "\nFETCH NEXT " + this.limit + " ROWS ONLY" : ""); - }; - - return Offset; - - })(); - - exports.Limit = Limit = (function() { - function Limit(value, offset) { - this.value = value; - this.offset = offset; - null; - } - - Limit.prototype.toString = function() { - return ("LIMIT " + this.value) + (this.offset ? "\nOFFSET " + this.offset : ""); - }; - - return Limit; - - })(); - - exports.Table = Table = (function() { - function Table(name, alias, win, winFn, winArg) { - this.name = name; - this.alias = alias != null ? alias : null; - this.win = win != null ? win : null; - this.winFn = winFn != null ? winFn : null; - this.winArg = winArg != null ? winArg : null; - null; - } - - Table.prototype.toString = function() { - if (this.win) { - return "" + this.name + "." + this.win + ":" + this.winFn + "(" + this.winArg + ")"; - } else if (this.alias) { - return "" + this.name + " AS " + this.alias; - } else { - return this.name.toString(); - } - }; - - return Table; - - })(); - - exports.Group = Group = (function() { - function Group(fields) { - this.fields = fields; - this.having = null; - } - - Group.prototype.toString = function() { - var ret; - ret = ["GROUP BY " + (this.fields.join(', '))]; - if (this.having) { - ret.push(this.having.toString()); - } - return ret.join("\n"); - }; - - return Group; - - })(); - - exports.Where = Where = (function() { - function Where(conditions) { - this.conditions = conditions; - null; - } - - Where.prototype.toString = function() { - return "WHERE " + this.conditions; - }; - - return Where; - - })(); - - exports.Having = Having = (function() { - function Having(conditions) { - this.conditions = conditions; - null; - } - - Having.prototype.toString = function() { - return "HAVING " + this.conditions; - }; - - return Having; - - })(); - - exports.Op = Op = (function() { - function Op(operation, left, right) { - this.operation = operation; - this.left = left; - this.right = right; - null; - } - - Op.prototype.toString = function() { - return "(" + this.left + " " + (this.operation.toUpperCase()) + " " + this.right + ")"; + if (this["arguments"]) { + return "" + (this.name.toUpperCase()) + "(" + (this["arguments"].toString()) + ")"; + } else { + return "" + (this.name.toUpperCase()) + "()"; + } }; - return Op; + return FunctionValue; })(); - exports.UnaryOp = UnaryOp = (function() { - function UnaryOp(operator, operand) { - this.operator = operator; - this.operand = operand; - null; + exports.Order = Order = (function() { + function Order(orderings, offset) { + this.orderings = orderings; + this.offset = offset; } - UnaryOp.prototype.toString = function() { - return "(" + (this.operator.toUpperCase()) + " " + this.operand + ")"; + Order.prototype.toString = function() { + return ("ORDER BY " + (this.orderings.join(', '))) + (this.offset ? "\n" + this.offset.toString() : ""); }; - return UnaryOp; + return Order; })(); - exports.BetweenOp = BetweenOp = (function() { - function BetweenOp(value) { + exports.OrderArgument = OrderArgument = (function() { + function OrderArgument(value, direction) { this.value = value; + this.direction = direction != null ? direction : 'ASC'; null; } - BetweenOp.prototype.toString = function() { - return "" + (this.value.join(' AND ')); + OrderArgument.prototype.toString = function() { + return "" + this.value + " " + this.direction; }; - return BetweenOp; + return OrderArgument; })(); - exports.Field = Field = (function() { - function Field(field, name) { - this.field = field; - this.name = name != null ? name : null; + exports.Offset = Offset = (function() { + function Offset(row_count, limit) { + this.row_count = row_count; + this.limit = limit; null; } - Field.prototype.toString = function() { - if (this.name) { - return "" + this.field + " AS " + this.name; - } else { - return this.field.toString(); - } + Offset.prototype.toString = function() { + return ("OFFSET " + this.row_count + " ROWS") + (this.limit ? "\nFETCH NEXT " + this.limit + " ROWS ONLY" : ""); }; - return Field; + return Offset; })(); - exports.Star = Star = (function() { - function Star() { + exports.Limit = Limit = (function() { + function Limit(value, offset) { + this.value = value; + this.offset = offset; null; } - Star.prototype.toString = function() { - return '*'; + Limit.prototype.toString = function() { + return ("LIMIT " + this.value) + (this.offset ? "\nOFFSET " + this.offset : ""); }; - Star.prototype.star = true; - - return Star; + return Limit; })(); -}).call(this); - -},{}],9:[function(require,module,exports){ -// Generated by CoffeeScript 1.8.0 -(function() { - var buildParser; + exports.Table = Table = (function() { + function Table(name, alias, win, winFn, winArg) { + this.name = name; + this.alias = alias != null ? alias : null; + this.win = win != null ? win : null; + this.winFn = winFn != null ? winFn : null; + this.winArg = winArg != null ? winArg : null; + null; + } - buildParser = function() { - var parser; - parser = require('./compiled_parser').parser; - parser.lexer = { - lex: function() { - var tag, _ref; - _ref = this.tokens[this.pos++] || [''], tag = _ref[0], this.yytext = _ref[1], this.yylineno = _ref[2]; - return tag; - }, - setInput: function(tokens) { - this.tokens = tokens; - return this.pos = 0; - }, - upcomingInput: function() { - return ""; + Table.prototype.toString = function() { + if (this.win) { + return "" + this.name + "." + this.win + ":" + this.winFn + "(" + this.winArg + ")"; + } else if (this.alias) { + return "" + this.name + " AS " + this.alias; + } else { + return this.name.toString(); } }; - parser.yy = require('./nodes'); - return parser; - }; - - exports.parser = buildParser(); - - exports.parse = function(str) { - return buildParser().parse(str); - }; - -}).call(this); - -},{"./compiled_parser":6,"./nodes":8}],10:[function(require,module,exports){ -// Generated by CoffeeScript 1.8.0 -(function() { - exports.lexer = require('./lexer'); - - exports.parser = require('./parser'); - - exports.nodes = require('./nodes'); - - exports.parse = function(sql) { - return exports.parser.parse(exports.lexer.tokenize(sql)); - }; - -}).call(this); - -},{"./lexer":7,"./nodes":8,"./parser":9}],11:[function(require,module,exports){ - -},{}],12:[function(require,module,exports){ -(function (process){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// resolves . and .. elements in a path array with directory names there -// must be no slashes, empty elements, or device names (c:\) in the array -// (so also no leading and trailing slashes - it does not distinguish -// relative and absolute paths) -function normalizeArray(parts, allowAboveRoot) { - // if the path tries to go above the root, `up` ends up > 0 - var up = 0; - for (var i = parts.length - 1; i >= 0; i--) { - var last = parts[i]; - if (last === '.') { - parts.splice(i, 1); - } else if (last === '..') { - parts.splice(i, 1); - up++; - } else if (up) { - parts.splice(i, 1); - up--; - } - } - - // if the path is allowed to go above the root, restore leading ..s - if (allowAboveRoot) { - for (; up--; up) { - parts.unshift('..'); - } - } - return parts; -} - -// Split a filename into [root, dir, basename, ext], unix version -// 'root' is just a slash, or nothing. -var splitPathRe = - /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/; -var splitPath = function(filename) { - return splitPathRe.exec(filename).slice(1); -}; - -// path.resolve([from ...], to) -// posix version -exports.resolve = function() { - var resolvedPath = '', - resolvedAbsolute = false; + return Table; - for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { - var path = (i >= 0) ? arguments[i] : process.cwd(); + })(); - // Skip empty and invalid entries - if (typeof path !== 'string') { - throw new TypeError('Arguments to path.resolve must be strings'); - } else if (!path) { - continue; + exports.Group = Group = (function() { + function Group(fields) { + this.fields = fields; + this.having = null; } - resolvedPath = path + '/' + resolvedPath; - resolvedAbsolute = path.charAt(0) === '/'; - } - - // At this point the path should be resolved to a full absolute path, but - // handle relative paths to be safe (might happen when process.cwd() fails) - - // Normalize the path - resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { - return !!p; - }), !resolvedAbsolute).join('/'); - - return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; -}; - -// path.normalize(path) -// posix version -exports.normalize = function(path) { - var isAbsolute = exports.isAbsolute(path), - trailingSlash = substr(path, -1) === '/'; - - // Normalize the path - path = normalizeArray(filter(path.split('/'), function(p) { - return !!p; - }), !isAbsolute).join('/'); - - if (!path && !isAbsolute) { - path = '.'; - } - if (path && trailingSlash) { - path += '/'; - } + Group.prototype.toString = function() { + var ret; + ret = ["GROUP BY " + (this.fields.join(', '))]; + if (this.having) { + ret.push(this.having.toString()); + } + return ret.join("\n"); + }; - return (isAbsolute ? '/' : '') + path; -}; + return Group; -// posix version -exports.isAbsolute = function(path) { - return path.charAt(0) === '/'; -}; + })(); -// posix version -exports.join = function() { - var paths = Array.prototype.slice.call(arguments, 0); - return exports.normalize(filter(paths, function(p, index) { - if (typeof p !== 'string') { - throw new TypeError('Arguments to path.join must be strings'); + exports.Where = Where = (function() { + function Where(conditions) { + this.conditions = conditions; + null; } - return p; - }).join('/')); -}; + Where.prototype.toString = function() { + return "WHERE " + this.conditions; + }; -// path.relative(from, to) -// posix version -exports.relative = function(from, to) { - from = exports.resolve(from).substr(1); - to = exports.resolve(to).substr(1); + return Where; - function trim(arr) { - var start = 0; - for (; start < arr.length; start++) { - if (arr[start] !== '') break; - } + })(); - var end = arr.length - 1; - for (; end >= 0; end--) { - if (arr[end] !== '') break; + exports.Having = Having = (function() { + function Having(conditions) { + this.conditions = conditions; + null; } - if (start > end) return []; - return arr.slice(start, end - start + 1); - } + Having.prototype.toString = function() { + return "HAVING " + this.conditions; + }; - var fromParts = trim(from.split('/')); - var toParts = trim(to.split('/')); + return Having; - var length = Math.min(fromParts.length, toParts.length); - var samePartsLength = length; - for (var i = 0; i < length; i++) { - if (fromParts[i] !== toParts[i]) { - samePartsLength = i; - break; - } - } + })(); - var outputParts = []; - for (var i = samePartsLength; i < fromParts.length; i++) { - outputParts.push('..'); - } + exports.Op = Op = (function() { + function Op(operation, left, right) { + this.operation = operation; + this.left = left; + this.right = right; + null; + } - outputParts = outputParts.concat(toParts.slice(samePartsLength)); + Op.prototype.toString = function() { + return "(" + this.left + " " + (this.operation.toUpperCase()) + " " + this.right + ")"; + }; - return outputParts.join('/'); -}; + return Op; -exports.sep = '/'; -exports.delimiter = ':'; + })(); -exports.dirname = function(path) { - var result = splitPath(path), - root = result[0], - dir = result[1]; + exports.UnaryOp = UnaryOp = (function() { + function UnaryOp(operator, operand) { + this.operator = operator; + this.operand = operand; + null; + } - if (!root && !dir) { - // No dirname whatsoever - return '.'; - } + UnaryOp.prototype.toString = function() { + return "(" + (this.operator.toUpperCase()) + " " + this.operand + ")"; + }; - if (dir) { - // It has a dirname, strip trailing slash - dir = dir.substr(0, dir.length - 1); - } + return UnaryOp; - return root + dir; -}; + })(); + exports.BetweenOp = BetweenOp = (function() { + function BetweenOp(value) { + this.value = value; + null; + } -exports.basename = function(path, ext) { - var f = splitPath(path)[2]; - // TODO: make this comparison case-insensitive on windows? - if (ext && f.substr(-1 * ext.length) === ext) { - f = f.substr(0, f.length - ext.length); - } - return f; -}; + BetweenOp.prototype.toString = function() { + return "" + (this.value.join(' AND ')); + }; + return BetweenOp; -exports.extname = function(path) { - return splitPath(path)[3]; -}; + })(); -function filter (xs, f) { - if (xs.filter) return xs.filter(f); - var res = []; - for (var i = 0; i < xs.length; i++) { - if (f(xs[i], i, xs)) res.push(xs[i]); + exports.Field = Field = (function() { + function Field(field, name) { + this.field = field; + this.name = name != null ? name : null; + null; } - return res; -} -// String.prototype.substr - negative index don't work in IE8 -var substr = 'ab'.substr(-1) === 'b' - ? function (str, start, len) { return str.substr(start, len) } - : function (str, start, len) { - if (start < 0) start = str.length + start; - return str.substr(start, len); - } -; + Field.prototype.toString = function() { + if (this.name) { + return "" + this.field + " AS " + this.name; + } else { + return this.field.toString(); + } + }; -}).call(this,require('_process')) -},{"_process":13}],13:[function(require,module,exports){ -// shim for using process in browser + return Field; -var process = module.exports = {}; -var queue = []; -var draining = false; -var currentQueue; -var queueIndex = -1; + })(); -function cleanUpNextTick() { - draining = false; - if (currentQueue.length) { - queue = currentQueue.concat(queue); - } else { - queueIndex = -1; - } - if (queue.length) { - drainQueue(); + exports.Star = Star = (function() { + function Star() { + null; } -} -function drainQueue() { - if (draining) { - return; - } - var timeout = setTimeout(cleanUpNextTick); - draining = true; + Star.prototype.toString = function() { + return '*'; + }; - var len = queue.length; - while(len) { - currentQueue = queue; - queue = []; - while (++queueIndex < len) { - if (currentQueue) { - currentQueue[queueIndex].run(); - } - } - queueIndex = -1; - len = queue.length; - } - currentQueue = null; - draining = false; - clearTimeout(timeout); -} + Star.prototype.star = true; -process.nextTick = function (fun) { - var args = new Array(arguments.length - 1); - if (arguments.length > 1) { - for (var i = 1; i < arguments.length; i++) { - args[i - 1] = arguments[i]; - } - } - queue.push(new Item(fun, args)); - if (queue.length === 1 && !draining) { - setTimeout(drainQueue, 0); - } -}; + return Star; -// v8 likes predictible objects -function Item(fun, array) { - this.fun = fun; - this.array = array; -} -Item.prototype.run = function () { - this.fun.apply(null, this.array); -}; -process.title = 'browser'; -process.browser = true; -process.env = {}; -process.argv = []; -process.version = ''; // empty string to avoid regexp issues -process.versions = {}; + })(); -function noop() {} +}).call(this); -process.on = noop; -process.addListener = noop; -process.once = noop; -process.off = noop; -process.removeListener = noop; -process.removeAllListeners = noop; -process.emit = noop; +},{}],12:[function(require,module,exports){ +// Generated by CoffeeScript 1.8.0 +(function() { + var buildParser; -process.binding = function (name) { - throw new Error('process.binding is not supported'); -}; + buildParser = function() { + var parser; + parser = require('./compiled_parser').parser; + parser.lexer = { + lex: function() { + var tag, _ref; + _ref = this.tokens[this.pos++] || [''], tag = _ref[0], this.yytext = _ref[1], this.yylineno = _ref[2]; + return tag; + }, + setInput: function(tokens) { + this.tokens = tokens; + return this.pos = 0; + }, + upcomingInput: function() { + return ""; + } + }; + parser.yy = require('./nodes'); + return parser; + }; -process.cwd = function () { return '/' }; -process.chdir = function (dir) { - throw new Error('process.chdir is not supported'); -}; -process.umask = function() { return 0; }; + exports.parser = buildParser(); + + exports.parse = function(str) { + return buildParser().parse(str); + }; + +}).call(this); + +},{"./compiled_parser":9,"./nodes":11}],13:[function(require,module,exports){ +// Generated by CoffeeScript 1.8.0 +(function() { + exports.lexer = require('./lexer'); + + exports.parser = require('./parser'); + + exports.nodes = require('./nodes'); + + exports.parse = function(sql) { + return exports.parser.parse(exports.lexer.tokenize(sql)); + }; + +}).call(this); -},{}]},{},[1]); +},{"./lexer":10,"./nodes":11,"./parser":12}]},{},[1]); diff --git a/index.html b/index.html index aa14be5..d361a2c 100644 --- a/index.html +++ b/index.html @@ -40,14 +40,16 @@

SQL Obfuscator

- +WHERE height=10 + - +

Result

+

Reach me on github.

diff --git a/index.js b/index.js index 4f8f1e4..7af467d 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,17 @@ +/* + * This project obfuscates arbitrary sql queries by first converting + * the sql to json. Then the json keys are translated to new variable + * names in alphabetical order. + * Like "tableA" -> "a" + * "orders" -> "b" + * ... + * "users" -> "A" + * ... + * "users123" -> "aA" + * ... + * the new json object is then converted back into a valid sql query + * and displayed to the user. + */ const sql2json = require('./sql2json'); const Json2sql = sql2json.json2sql; const Sql2json = sql2json.sql2json; @@ -82,4 +96,4 @@ var obfuscate = function() { document.addEventListener("DOMContentLoaded", function(event) { document.getElementById('submit').onclick = obfuscate; -}); \ No newline at end of file +});