diff --git a/modules/compiler/lib/peg/ql.js b/modules/compiler/lib/peg/ql.js index cfa34a1b..c0bd7e84 100644 --- a/modules/compiler/lib/peg/ql.js +++ b/modules/compiler/lib/peg/ql.js @@ -5977,7 +5977,7 @@ module.exports = (function(){ var result1 = parse_number(); var result2 = result1 !== null ? (function(n) { - return parseFloat(n); + return parseFloat(append(n)); })(result1) : null; if (result2 !== null) { @@ -6743,7 +6743,7 @@ module.exports = (function(){ } var result2 = result1 !== null ? (function(c) { - return append('' + c); + return append(c); })(result1) : null; if (result2 !== null) { @@ -6771,7 +6771,29 @@ module.exports = (function(){ } - var result4 = parse_digits(); + var savedPos1 = pos; + if (input.substr(pos, 1) === "+") { + var result7 = "+"; + pos += 1; + } else { + var result7 = null; + if (reportMatchFailures) { + matchFailed("\"+\""); + } + } + var result5 = result7 !== null ? result7 : ''; + if (result5 !== null) { + var result6 = parse_digits(); + if (result6 !== null) { + var result4 = [result5, result6]; + } else { + var result4 = null; + pos = savedPos1; + } + } else { + var result4 = null; + pos = savedPos1; + } if (result4 !== null) { var result0 = result4; } else { @@ -6833,7 +6855,8 @@ module.exports = (function(){ } } if (result1 !== null) { - var result2 = parse_digits(); + var result3 = parse_digits(); + var result2 = result3 !== null ? result3 : ''; if (result2 !== null) { var result0 = [result1, result2]; } else { @@ -6866,7 +6889,8 @@ module.exports = (function(){ var savedPos0 = pos; var result1 = parse_e(); if (result1 !== null) { - var result2 = parse_digits(); + var result3 = parse_int(); + var result2 = result3 !== null ? result3 : ''; if (result2 !== null) { var result0 = [result1, result2]; } else { @@ -6897,158 +6921,74 @@ module.exports = (function(){ if (input.substr(pos, 1) === "e") { - var result14 = "e"; + var result6 = "e"; pos += 1; } else { - var result14 = null; + var result6 = null; if (reportMatchFailures) { matchFailed("\"e\""); } } - if (result14 !== null) { - var result0 = result14; + if (result6 !== null) { + var result0 = result6; } else { - var savedPos3 = pos; - if (input.substr(pos, 1) === "e") { - var result12 = "e"; - pos += 1; + if (input.substr(pos, 2) === "e+") { + var result5 = "e+"; + pos += 2; } else { - var result12 = null; + var result5 = null; if (reportMatchFailures) { - matchFailed("\"e\""); + matchFailed("\"e+\""); } } - if (result12 !== null) { - if (input.substr(pos, 1) === "+") { - var result13 = "+"; - pos += 1; - } else { - var result13 = null; - if (reportMatchFailures) { - matchFailed("\"+\""); - } - } - if (result13 !== null) { - var result11 = [result12, result13]; - } else { - var result11 = null; - pos = savedPos3; - } - } else { - var result11 = null; - pos = savedPos3; - } - if (result11 !== null) { - var result0 = result11; + if (result5 !== null) { + var result0 = result5; } else { - var savedPos2 = pos; - if (input.substr(pos, 1) === "e") { - var result9 = "e"; - pos += 1; + if (input.substr(pos, 2) === "e-") { + var result4 = "e-"; + pos += 2; } else { - var result9 = null; + var result4 = null; if (reportMatchFailures) { - matchFailed("\"e\""); + matchFailed("\"e-\""); } } - if (result9 !== null) { - if (input.substr(pos, 1) === "-") { - var result10 = "-"; - pos += 1; - } else { - var result10 = null; - if (reportMatchFailures) { - matchFailed("\"-\""); - } - } - if (result10 !== null) { - var result8 = [result9, result10]; - } else { - var result8 = null; - pos = savedPos2; - } - } else { - var result8 = null; - pos = savedPos2; - } - if (result8 !== null) { - var result0 = result8; + if (result4 !== null) { + var result0 = result4; } else { if (input.substr(pos, 1) === "E") { - var result7 = "E"; + var result3 = "E"; pos += 1; } else { - var result7 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"E\""); } } - if (result7 !== null) { - var result0 = result7; + if (result3 !== null) { + var result0 = result3; } else { - var savedPos1 = pos; - if (input.substr(pos, 1) === "E") { - var result5 = "E"; - pos += 1; + if (input.substr(pos, 2) === "E+") { + var result2 = "E+"; + pos += 2; } else { - var result5 = null; + var result2 = null; if (reportMatchFailures) { - matchFailed("\"E\""); - } - } - if (result5 !== null) { - if (input.substr(pos, 1) === "+") { - var result6 = "+"; - pos += 1; - } else { - var result6 = null; - if (reportMatchFailures) { - matchFailed("\"+\""); - } - } - if (result6 !== null) { - var result4 = [result5, result6]; - } else { - var result4 = null; - pos = savedPos1; + matchFailed("\"E+\""); } - } else { - var result4 = null; - pos = savedPos1; } - if (result4 !== null) { - var result0 = result4; + if (result2 !== null) { + var result0 = result2; } else { - var savedPos0 = pos; - if (input.substr(pos, 1) === "E") { - var result2 = "E"; - pos += 1; + if (input.substr(pos, 2) === "E-") { + var result1 = "E-"; + pos += 2; } else { - var result2 = null; + var result1 = null; if (reportMatchFailures) { - matchFailed("\"E\""); + matchFailed("\"E-\""); } } - if (result2 !== null) { - if (input.substr(pos, 1) === "-") { - var result3 = "-"; - pos += 1; - } else { - var result3 = null; - if (reportMatchFailures) { - matchFailed("\"-\""); - } - } - if (result3 !== null) { - var result1 = [result2, result3]; - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } if (result1 !== null) { var result0 = result1; } else { @@ -7526,28 +7466,38 @@ module.exports = (function(){ var str = ''; - for(var i = 0; i < arr.length; i++) { + if(typeOf(arr) === 'array') { + + for(var i = 0; i < arr.length; i++) { + + if(typeOf(arr[i]) == 'array') { - if(typeOf(arr[i]) == 'array') { + str += append(arr[i]); - str += append(arr[i]); + } - } + else if (typeof arr[i] === 'object') { - else if (typeof arr[i] === 'object') { + str += JSON.stringify(arr[i].object); - str += JSON.stringify(arr[i].object); + } - } + else { - else { + str += arr[i]; - str += arr[i]; + } } } + else { + + str = str + arr; + + } + return str; } @@ -7662,6 +7612,8 @@ module.exports = (function(){ type: 'select', + line: statement.line, + columns: [], extras: [], // used only during selection @@ -8076,4 +8028,4 @@ module.exports = (function(){ result.SyntaxError.prototype = Error.prototype; return result; -})(); +})(); \ No newline at end of file diff --git a/modules/compiler/package.json b/modules/compiler/package.json index 8336611a..8d7d8c3a 100644 --- a/modules/compiler/package.json +++ b/modules/compiler/package.json @@ -1,7 +1,7 @@ { "author": "ql.io", "name": "ql.io-compiler", - "version": "0.2.13", + "version": "0.2.14", "repository": { "type": "git", "url": "https://github.com/ql-io/ql.io" diff --git a/modules/compiler/pegs/ql.peg b/modules/compiler/pegs/ql.peg index 9a829b90..e8b8bcf6 100755 --- a/modules/compiler/pegs/ql.peg +++ b/modules/compiler/pegs/ql.peg @@ -1,3 +1,4 @@ + /* * Copyright 2011 eBay Software Foundation * @@ -34,17 +35,22 @@ } function append(arr) { var str = ''; - for(var i = 0; i < arr.length; i++) { - if(typeOf(arr[i]) == 'array') { - str += append(arr[i]); - } - else if (typeof arr[i] === 'object') { - str += JSON.stringify(arr[i].object); - } - else { - str += arr[i]; + if(typeOf(arr) === 'array') { + for(var i = 0; i < arr.length; i++) { + if(typeOf(arr[i]) == 'array') { + str += append(arr[i]); + } + else if (typeof arr[i] === 'object') { + str += JSON.stringify(arr[i].object); + } + else { + str += arr[i]; + } } } + else { + str = str + arr; + } return str; } function merge(arr) { @@ -102,6 +108,7 @@ }; join = { type: 'select', + line: statement.line, columns: [], extras: [], // used only during selection whereCriteria: [] @@ -750,7 +757,7 @@ stringval = s:string { } numberval = n:number { - return parseFloat(n); + return parseFloat(append(n)); } arrayval = n:array { @@ -786,16 +793,16 @@ elements = (value insig comma insig elements) / value string = dquote ([\u0020-\u0021]/[\u0023-\u005B]/[\u005D-\uFFFF]/['\\'])* dquote number = c:((int frac exp) / (int frac) / (int exp) / (int)) { - return append('' + c); + return append(c); } -int = digits / ('-' digits) +int =('+'? digits) / ('-' digits) -frac = '.' digits +frac = '.' digits? -exp = e digits +exp = e int? -e = 'e' / ('e' '+') / ('e' '-') / 'E' / ('E' '+') / ('E' '-') +e = ('e') / ('e+') / ('e-') / 'E' / ('E+') / ('E-') digits = d:[0-9]+ { return parseInt(append(d)); diff --git a/modules/compiler/test/ql-script-test.js b/modules/compiler/test/ql-script-test.js index 773a42f3..d0d2fb29 100644 --- a/modules/compiler/test/ql-script-test.js +++ b/modules/compiler/test/ql-script-test.js @@ -16,7 +16,7 @@ "use strict"; -var compiler = require('lib/compiler'), +var compiler = require('../lib/compiler'), _ = require('underscore'), sys = require('sys'); @@ -459,5 +459,27 @@ return {"result" : "{fields}"};\ test.fail(e); test.done(); } + }, + + 'number-parsing': function(test) { + var script = 'a = 1;\n\ + b = +1;\n\ + c = -1;\n\ + d = 1.234;\n\ + e = -1.234;\n\ + f = 1e;\n\ + g = 1e1;\n\ + h = 1e+1;\n\ + i = 1e-1;\n\ + j = 1.0e-1;\n\ + return j'; + var cooked; + var res = [1, 1, -1, 1.234, -1.234, 1, 10, 10, 0.1, 0.01]; + cooked = compiler.compile(script); + for(var i = 0; i < i.length; i++) { + test.equals(cooked[i].type, 'define'); + test.equals(cooked[i].object, res[i]); + } + test.done(); } }; diff --git a/modules/compiler/test/select-test.js b/modules/compiler/test/select-test.js index b1b3a88d..f26f8a95 100644 --- a/modules/compiler/test/select-test.js +++ b/modules/compiler/test/select-test.js @@ -211,6 +211,7 @@ module.exports = { ], "joiner": { "type": "select", + "line": 1, "columns": [ {name: "g.geometry.location"}, {name: "g.address"} diff --git a/modules/console/app.js b/modules/console/app.js index 50592a08..85bf757b 100644 --- a/modules/console/app.js +++ b/modules/console/app.js @@ -102,7 +102,7 @@ var Console = module.exports = function(config) { app.use(bodyParser); // parses the body for application/x-www-form-urlencoded and application/json if(config['enable console']) { - var assetManagerGroups = { + var qlAssets = { 'js': { 'stale': true, // If set to false, this adds a watch file listener - which messes up shutdown via cluster. 'route': /\/scripts\/all.js/, @@ -127,7 +127,6 @@ var Console = module.exports = function(config) { 'codemirror.css', 'qlio-editor.css', 'treeview.css', - 'jquery.splitter.css', 'jquery-ui.css' ], 'preManipulate': { @@ -147,9 +146,9 @@ var Console = module.exports = function(config) { } } }; - var assetsManagerMiddleware = assetManager(assetManagerGroups); + var qlAssetLoader = assetManager(qlAssets); + app.use(qlAssetLoader); - app.use(assetsManagerMiddleware); app.set('views', __dirname + '/public/views'); app.use(express.static(__dirname + '/public')); app.set('view engine', 'html'); diff --git a/modules/console/package.json b/modules/console/package.json index 20f1eaf5..3cd15799 100755 --- a/modules/console/package.json +++ b/modules/console/package.json @@ -1,7 +1,7 @@ { "author": "ql.io", "name": "ql.io-console", - "version": "0.2.15", + "version": "0.2.16", "repository": { "type": "git", "url": "ssh://gitolite@crpgit.corp.ebay.com/ql.io.git" diff --git a/modules/console/public/css/console.css b/modules/console/public/css/console.css index 491a310a..4d9ca40f 100644 --- a/modules/console/public/css/console.css +++ b/modules/console/public/css/console.css @@ -1,10 +1,42 @@ -body { - margin-left: 2%; - width: 95%; +html, body { + margin: 0; + padding: 0; + height: 100%; + overflow: hidden; + width: 100%; font-family: 'Droid Sans', 'Helvetica', 'Arial', sans-serif; color: #333333; } +#splitter { + min-width: 500px; + min-height: 800px; + width: 100%; + height: 100%; +} + +#top-pane { + padding: 5px; + overflow: auto; +} + +#bottom-pane { + width: 100%; + overflow: auto; + bottom: 0; + position: fixed; + min-height: 100px; +} + +#splitter .hsplitbar { + height: 4px; + background: #d3d3d3 url(/images/hgrabber.gif) no-repeat center; +} + +#splitter .hsplitbar.active, #splitter .hsplitbar:hover { + background: #e88 url(/images/hgrabber.gif) no-repeat center; +} + textarea.query-input { background-color: #f8f8ff; padding: 10px 10px; @@ -12,7 +44,7 @@ textarea.query-input { } .parse-status { - font-family: 'Droid Sans Mono', 'DejaVu Sans Mono', 'Monaco', Courier, monospace ; + font-family: 'Droid Sans Mono', 'DejaVu Sans Mono', 'Monaco', Courier, monospace; color: red; width: 60%; float: left; @@ -32,12 +64,12 @@ textarea.query-input { } .code, textarea.query-input { - padding: 2px; + padding: 4px; white-space: pre; } .results { - overflow-x: scroll; + overflow: scroll; font-family: monospace; border: 1px solid #eee; min-height: 2em; @@ -55,7 +87,7 @@ textarea.query-input { div.footer { font-size: small; - padding-top: 3em; + padding-top: 1em; } div.html { @@ -152,47 +184,6 @@ pre, code { word-wrap: break-word; /* Internet Explorer 5.5+ */ } -div#trace-data { - background: white; -} - -div#trace-data table { - border: 1px solid #eee; - border-collapse: collapse; -} - -div#trace-data table tbody tr td { - border-color: #eee; - border-width: 1px 1px 0 0; - border-style: solid; - margin: 0; - padding: 4px; - vertical-align: top; -} - -div#trace-data table tbody tr td pre { - padding: 0; - margin: 0; -} - -#split-panel { - overflow: auto; -} - -.SplitterPane { - overflow: auto; -} - -.vsplitbar { - width: 6px; -} - -.vsplitbar.active, .vsplitbar:hover { - width: 6px; - opacity: 0.5; - filter: alpha(opacity = 50); /* IE */ -} - .red { color: red; } @@ -201,3 +192,11 @@ div#trace-data table tbody tr td pre { color: green; } +#har-title { + font-size: small; + padding: 1px; + color: white; + font-weight: bold; + background-color: rgba(38, 38, 38, 0.73); + box-shadow: 0px 5px 5px lightgray; +} \ No newline at end of file diff --git a/modules/console/public/css/images/ui-icons_222222_256x240.png b/modules/console/public/css/images/ui-icons_222222_256x240.png new file mode 100644 index 00000000..ee039dc0 Binary files /dev/null and b/modules/console/public/css/images/ui-icons_222222_256x240.png differ diff --git a/modules/console/public/css/jquery.splitter.css b/modules/console/public/css/jquery.splitter.css deleted file mode 100644 index f0538579..00000000 --- a/modules/console/public/css/jquery.splitter.css +++ /dev/null @@ -1,45 +0,0 @@ -/*! - * StyleSheet for JQuery Spliter Plugin - * Copyright (C) 2010 Jakub Jankiewicz - * - * Same license as plugin - */ -.spliter_panel { - position: relative; -} -.spliter_panel .vspliter { - background-color: grey; - cursor: col-resize; - z-index:900; - width: 4px; -} - -.spliter_panel .hspliter { - background-color: #5F5F5F; - cursor: row-resize; - z-index: 800; - height: 4px; -} -.spliter_panel .vspliter, .spliter_panel .left_panel, .spliter_panel .right_panel, -.spliter_panel .hspliter, .spliter_panel .top_panel, .spliter_panel .bottom_panel { - position: absolute; - overflow: auto; -} -.spliter_panel .vspliter, .spliter_panel .left_panel, .spliter_panel .right_panel { - height: 100%; -} -.spliter_panel .hspliter, .spliter_panel .top_panel, .spliter_panel .bottom_panel { - width: 100%; -} -.spliter_panel .top_panel, .spliter_panel .left_panel, .spliter_panel .vspliter { - top: 0; -} -.spliter_panel .top_panel, .spliter_panel .bottom_panel, .spliter_panel .left_panel, .spliter_panel .hspliter { - left: 0; -} -.spliter_panel .bottom_panel { - bottom: 0; -} -.spliter_panel .right_panel { - right: 0; -} \ No newline at end of file diff --git a/modules/console/public/images/hgrabber.gif b/modules/console/public/images/hgrabber.gif new file mode 100644 index 00000000..6a59bf83 Binary files /dev/null and b/modules/console/public/images/hgrabber.gif differ diff --git a/modules/console/public/scripts/console.js b/modules/console/public/scripts/console.js index 99a68d1b..dc29dcd3 100644 --- a/modules/console/public/scripts/console.js +++ b/modules/console/public/scripts/console.js @@ -1,6 +1,6 @@ $(document).ready(function() { - var oldInput, parseTimer, compiler, editor, markers = [], headers, mustache, split = false, - runState = {}, socket, emitter, state, results, html, waitOnLoad = false, wsEnabled, + var oldInput, parseTimer, compiler, editor, markers = [], headers, mustache, + runState, socket, emitter, state, results, html, waitOnLoad = false, wsEnabled, EventEmitter = require('events').EventEmitter, formatter = new JSONFormatter(); // IE8 is not supported @@ -13,7 +13,17 @@ $(document).ready(function() { }).dialog('open'); } - $("#trace-panel").hide(); + $(window).resize(function() { + $("#top-pane").width("99%"); + $("#bottom-pane").width("100%"); + $(".hsplitbar").width("100%"); + }); + // Splitter to show har data + $("#splitter").splitter({ + splitHorizontal: true, + resizeTo: window, + sizeBottom: true + }); compiler = require('ql.io-compiler'); headers = require('headers'); @@ -25,7 +35,7 @@ $(document).ready(function() { a = /\+/g, // Regex for replacing addition symbol with a space r = /([^&=]+)=?([^&]*)/g, d = function (s) { - return decodeURIComponent(s.replace(a, " ")); + return decodeURIComponent(s.replace(a, ' ')); }, q = window.location.search.substring(1); @@ -42,27 +52,7 @@ $(document).ready(function() { onChange: function() { scheduleParse(); }, - onGutterClick: function(e, line) { - state = runState[(line + 1) + '']; - if(state) { - if(!split) { - results = $('#results'); - $('#results-placeholder').html($('#results-split-template').html()); - $("#split-panel").splitter({ - type: "v", - outline: true, - minRight: 10, - anchorToWindow: true, - accessKey: "T" - }); - results.appendTo('#split-left'); - split = true; - } - html = mustache.to_html($('#trace-template').html(), state); - $('#trace-data').html(html); - } - }, - mode: "text/x-qlio" + mode: 'text/x-qlio' }); $('#util-links').hide(); @@ -123,8 +113,10 @@ $(document).ready(function() { } // Reset state - runState = {},split = false; - $('#results-placeholder').html($('#results-normal-template').html()); + runState = { + version: '1.2', + entries: [] + } if(parseTimer !== null) { clearTimeout(parseTimer); @@ -147,7 +139,7 @@ $(document).ready(function() { $('#run-again').attr('href', share); $('#copy-uri').unbind(); // unbind any previous registered handler. $('#copy-uri').click(function() { - window.prompt("Copy the URI below", + window.prompt('Copy the URI below', window.location.protocol + '//' + window.location.host + '/q?s=' + escaped); }); $('#util-links').show(); @@ -171,7 +163,7 @@ $(document).ready(function() { function doXhr(statement, escaped, compiled) { var mediaType, link, execState, data, x, i, status, event - $('#conn-status').html('Not connected. Use latest versions of Firefox or Chrome for better experience.'); + $('#conn-status').html('Use latest versions of Firefox or Chrome for better experience.'); emitter = new EventEmitter(); wireup(emitter); @@ -206,7 +198,7 @@ $(document).ready(function() { if(mediaType === 'application/json') { data = JSON.parse(data); $('#results').attr('class', 'results tree json').html(formatter.jsonToHTML(data)); - $("#results").treeview(); + $('#results').treeview(); } else if(mediaType === 'text/html') { $('#results').attr('class', 'results html').html(data); @@ -223,7 +215,7 @@ $(document).ready(function() { if(mediaType == 'application/json') { data = JSON.parse(req.responseText); $('#results').attr('class', 'results tree json').html(formatter.jsonToHTML(data)); - $("#results").treeview(); + $('#results').treeview(); } else if(mediaType === 'text/html') { $('#results').attr('class', 'results').html(data); @@ -249,7 +241,6 @@ $(document).ready(function() { var wsCtor = window['MozWebSocket'] ? MozWebSocket : WebSocket; socket = new wsCtor(uri, 'ql.io-console'); socket.onopen = function () { - $('#conn-status').html('Connected. Click on the gutter to see request/response trace.'); subscribe(socket); var packet = { type: 'script', @@ -266,7 +257,6 @@ $(document).ready(function() { socket.send(JSON.stringify(packet)); } socket.onerror = function() { - $('#conn-status').html('Not connected'); doXhr(statement, escaped, compiled); } socket.onmessage = function(e) { @@ -274,7 +264,6 @@ $(document).ready(function() { emitter.emit(event.type, event.data); } socket.onclose = function() { - $('#conn-status').html('Disconnected.'); } wireup(emitter); emitter.on('ql.io-script-result', function(data) { @@ -282,7 +271,7 @@ $(document).ready(function() { if(contentType === 'application/json') { try { $('#results').attr('class', 'results tree json').html(formatter.jsonToHTML(data.body)); - $("#results").treeview(); + $('#results').treeview(); } catch(e) { alert(e); @@ -363,14 +352,39 @@ $(document).ready(function() { }); emitter.on('ql.io-statement-request', function (data) { var key = data.line + ''; - runState[key] = runState[key] || {}; - runState[key].req = data; - $("#trace-panel").show(); + var entry = { + line: key, + id: data.id, + startDateTime: data.start, + request: { + method: data.method, + url: data.uri, + headers: data.headers, + body: data.body + } + } + runState.entries.push(entry); + + $('#har').attr('class', 'results tree json').html(formatter.jsonToHTML(runState.entries)); + $('#har').treeview(); }); emitter.on('ql.io-statement-response', function (data) { - var key = data.line + ''; - runState[key] = runState[key] || {}; - runState[key].res = data; + var key = data.id; + var entry; + for(var i = 0; i < runState.entries.length; i++) { + if(runState.entries[i].id === key) { + entry = runState.entries[i]; + break; + } + } + entry.time = data.time; + entry.response = { + status: data.status, + headers: data.headers, + body: data.body + } + $('#har').attr('class', 'results tree json').html(formatter.jsonToHTML(runState.entries)); + $('#har').treeview(); }); emitter.on('ql.io-statement-success', function (data) { markers.push(editor.setMarker(data.line - 1, data.elapsed + ' ms', 'green')); diff --git a/modules/console/public/views/console-layout.ejs b/modules/console/public/views/console-layout.ejs index a7a8b32b..d111d390 100644 --- a/modules/console/public/views/console-layout.ejs +++ b/modules/console/public/views/console-layout.ejs @@ -1,20 +1,35 @@ - <%=title%> - - - - - + <%=title%> + + + + - <%- partial("header") %> - <%- body %> - <%- partial("footer") %> - - + + +
+
+ <%- partial("header") %> + <%- body %> + <%- partial("footer") %> +
+ +
+
+
Req/resp traces
+
+
+
+
+ + + + diff --git a/modules/console/public/views/console/index.ejs b/modules/console/public/views/console/index.ejs index 2d67ec31..b19863e3 100644 --- a/modules/console/public/views/console/index.ejs +++ b/modules/console/public/views/console/index.ejs @@ -1,59 +1,3 @@ - - - -
@@ -67,5 +11,5 @@ copy uri
-
-
+ +
diff --git a/modules/engine/lib/engine/http.request.js b/modules/engine/lib/engine/http.request.js index a4c1522d..88658adb 100644 --- a/modules/engine/lib/engine/http.request.js +++ b/modules/engine/lib/engine/http.request.js @@ -33,6 +33,7 @@ var strTemplate = require('./peg/str-template.js'), mustache = require('mustache'), async = require('async'), headers = require('headers'), + uuid = require('node-uuid'), os = require('os'); exports.exec = function(args) { @@ -327,14 +328,20 @@ function sendOneRequest(args, resourceUri, params, holder, cb) { // Emit if(emitter) { + var uniqueId = uuid(); var packet = { line: statement.line, + id: uniqueId, uuid: httpReqTx.event.uuid, + method: options.method, uri: resourceUri, headers: [], - body: requestBody, + start: toISO(new Date()), type: eventTypes.STATEMENT_REQUEST }; + if(requestBody) { + packet.body = requestBody; + } _.each(h, function(v, n) { packet.headers.push({ name: n, @@ -356,8 +363,10 @@ function sendOneRequest(args, resourceUri, params, holder, cb) { var packet = { line: statement.line, uuid: httpReqTx.event.uuid, + id: uniqueId, status: res.statusCode, headers: [], + time: new Date() - start, body: respData, type: eventTypes.STATEMENT_RESPONSE }; @@ -667,4 +676,16 @@ function mergeArray(arr, prop, merge) { }); } return merged; +} + +function pad(n) { + return n < 10 ? '0' + n : n +} +function toISO(d) { + return d.getUTCFullYear() + '-' + + pad(d.getUTCMonth() + 1) + '-' + + pad(d.getUTCDate()) + 'T' + + pad(d.getUTCHours()) + ':' + + pad(d.getUTCMinutes()) + ':' + + pad(d.getUTCSeconds()) + 'Z' } \ No newline at end of file diff --git a/modules/engine/lib/engine/jsonfill.js b/modules/engine/lib/engine/jsonfill.js index 0cffd890..4dc2c3f6 100644 --- a/modules/engine/lib/engine/jsonfill.js +++ b/modules/engine/lib/engine/jsonfill.js @@ -57,7 +57,7 @@ function fill(obj, bag) { } function lookup(key, bag) { - var ref, index, obj = bag[key] || key, path, resource, stripped = 0, i; + var ref, index, obj = key, path, resource, stripped = 0, i; if(key && _.isString(key) && key.indexOf("{") === 0 && key.indexOf("}") === key.length - 1) { ref = key.substring(1, key.length - 1); path = ref; diff --git a/modules/engine/package.json b/modules/engine/package.json index ac6164c6..05f62b2a 100644 --- a/modules/engine/package.json +++ b/modules/engine/package.json @@ -1,7 +1,7 @@ { "author": "ql.io", "name": "ql.io-engine", - "version": "0.2.27", + "version": "0.2.28", "repository": { "type": "git", "url": "https://github.com/ql-io/ql.io" diff --git a/modules/engine/test/exec-js-vars.js b/modules/engine/test/exec-js-vars.js index d0ab0af3..ba853f61 100644 --- a/modules/engine/test/exec-js-vars.js +++ b/modules/engine/test/exec-js-vars.js @@ -87,5 +87,37 @@ module.exports = { test.done(); } }); + }, + 'return obj': function(test) { + var script = 'a = true;\n\ + b = false;\n\ + c = [1,2,3,4];\n\ + d = [1, true, 3, false];\n\ + e = "hello";\n\ + f = {\n\ + "a": "A",\n\ + "b": "B",\n\ + "carr": ["a", "b", "c"]\n\ + };\n\ + g = {};\n\ + return f;'; + engine.exec(script, function(err, result) { + if(err) { + test.fail('got error: ' + err.stack); + test.done(); + } + else { + test.deepEqual(result.body, { + "a": "A", + "b": "B", + "carr": [ + "a", + "b", + "c" + ] + }); + test.done(); + } + }); } };