From b63607967e52e29ca0e97e1b8580aa34f649ee76 Mon Sep 17 00:00:00 2001 From: Jack Farley Date: Sun, 12 Apr 2020 14:15:16 +0100 Subject: [PATCH 1/4] Remove node version restriction --- package.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/package.json b/package.json index 5e63bd8..eeb182c 100644 --- a/package.json +++ b/package.json @@ -18,10 +18,6 @@ "bugs": { "url": "https://github.com/JamesOsgood/mongodb-grafana/issues" }, - "engines": { - "node": "6.10.0" - }, - "engineStrict": true, "devDependencies": { "babel": "^6.23.0", "chai": "~3.5.0", From 9ee99790aad21747e7e810f9696cd9c95f2e0c6f Mon Sep 17 00:00:00 2001 From: Jack Farley Date: Sun, 12 Apr 2020 14:16:36 +0100 Subject: [PATCH 2/4] Fix organisation of dependencies --- package.json | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index eeb182c..514c907 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,9 @@ }, "devDependencies": { "babel": "^6.23.0", + "babel-plugin-transform-es2015-for-of": "^6.6.0", + "babel-plugin-transform-es2015-modules-systemjs": "^6.24.1", + "babel-preset-es2015": "^6.24.1", "chai": "~3.5.0", "grunt": "^1.0.3", "grunt-babel": "~6.0.0", @@ -33,19 +36,15 @@ "grunt-systemjs-builder": "^1.0.0", "jsdom": "~9.12.0", "load-grunt-tasks": "^3.5.2", + "mocha": "^5.2.0", "prunk": "^1.3.0", "q": "^1.5.0" }, "dependencies": { - "babel-plugin-transform-es2015-for-of": "^6.6.0", - "babel-plugin-transform-es2015-modules-systemjs": "^6.24.1", - "babel-preset-es2015": "^6.24.1", "body-parser": "^1.18.3", "config": "^1.30.0", "express": "^4.16.3", - "fs": "0.0.1-security", "lodash": "^4.17.10", - "mocha": "^5.2.0", "moment": "^2.22.1", "mongodb": "^3.0.8", "statman-stopwatch": "^2.7.0" From fc00bf16d83697e9b6877855871a5b54a5728cf3 Mon Sep 17 00:00:00 2001 From: Jack Farley Date: Sun, 12 Apr 2020 14:16:52 +0100 Subject: [PATCH 3/4] Add Dockerfile --- Dockerfile | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..809935b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +from node:lts-alpine + +WORKDIR /app +COPY dist/server /app +COPY package.json /app + +RUN npm install --production + +VOLUME /app/config +EXPOSE 3333 + +CMD node mongodb-proxy.js From 2b3fcc29ae40069ba99db731629079322ff32c0d Mon Sep 17 00:00:00 2001 From: Jack Farley Date: Thu, 21 May 2020 21:05:51 +0100 Subject: [PATCH 4/4] Change forIn to handle deep substitutions Change forIn to handle deep substitutions to allow for changing of date values inside of a $date object --- dist/server/mongodb-proxy.js | 24 +++++++++++++++++------- server/mongodb-proxy.js | 24 +++++++++++++++++------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/dist/server/mongodb-proxy.js b/dist/server/mongodb-proxy.js index a3fc84e..a1d0cf6 100644 --- a/dist/server/mongodb-proxy.js +++ b/dist/server/mongodb-proxy.js @@ -188,13 +188,21 @@ function forIn(obj, processFunc) var key; for (key in obj) { - var value = obj[key] - processFunc(obj, key, value) - if ( value != null && typeof(value) == "object") + obj[key] = processFunc(obj, key, obj[key]) + if ( obj[key] != null && typeof(obj[key]) == "object") { - forIn(value, processFunc) + obj[key] = forIn(obj[key], processFunc) } } + + if ( + !Array.isArray(obj) && Object.keys(obj).length === 1 && + typeof obj['$date'] !== 'undefined' + ) { + return new Date(obj['$date']); + } + + return obj; } function parseQuery(query, substitutions) @@ -256,15 +264,17 @@ function parseQuery(query, substitutions) for ( var i = 0; i < doc.pipeline.length; i++) { var stage = doc.pipeline[i] - forIn(stage, function (obj, key, value) + stage = forIn(stage, function (obj, key, value) { if ( typeof(value) == "string" ) { if ( value in substitutions ) { - obj[key] = substitutions[value] + return substitutions[value] } } + + return value; }) } } @@ -525,4 +535,4 @@ function getBucketCount(from, to, intervalMs) } return count -} \ No newline at end of file +} diff --git a/server/mongodb-proxy.js b/server/mongodb-proxy.js index a3fc84e..a1d0cf6 100644 --- a/server/mongodb-proxy.js +++ b/server/mongodb-proxy.js @@ -188,13 +188,21 @@ function forIn(obj, processFunc) var key; for (key in obj) { - var value = obj[key] - processFunc(obj, key, value) - if ( value != null && typeof(value) == "object") + obj[key] = processFunc(obj, key, obj[key]) + if ( obj[key] != null && typeof(obj[key]) == "object") { - forIn(value, processFunc) + obj[key] = forIn(obj[key], processFunc) } } + + if ( + !Array.isArray(obj) && Object.keys(obj).length === 1 && + typeof obj['$date'] !== 'undefined' + ) { + return new Date(obj['$date']); + } + + return obj; } function parseQuery(query, substitutions) @@ -256,15 +264,17 @@ function parseQuery(query, substitutions) for ( var i = 0; i < doc.pipeline.length; i++) { var stage = doc.pipeline[i] - forIn(stage, function (obj, key, value) + stage = forIn(stage, function (obj, key, value) { if ( typeof(value) == "string" ) { if ( value in substitutions ) { - obj[key] = substitutions[value] + return substitutions[value] } } + + return value; }) } } @@ -525,4 +535,4 @@ function getBucketCount(from, to, intervalMs) } return count -} \ No newline at end of file +}