diff --git a/package-shared/utils/deserialize-query.js b/package-shared/utils/deserialize-query.js new file mode 100644 index 0000000..c6d16d2 --- /dev/null +++ b/package-shared/utils/deserialize-query.js @@ -0,0 +1,30 @@ +// @ts-check + +const EJSON = require("./ejson"); +/** + * + * @param {string | Object} query + * @returns {Object} + */ +function deserializeQuery(query) { + /** @type {Object} */ + let queryObject = + typeof query == "object" ? query : Object(EJSON.parse(query)); + + const keys = Object.keys(queryObject); + + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; + const value = queryObject[key]; + + if (typeof value == "string") { + if (value.match(/^\{|^\[/)) { + queryObject[key] = EJSON.parse(value); + } + } + } + + return queryObject; +} + +module.exports = deserializeQuery; diff --git a/package.json b/package.json index 7d160da..622eebf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/datasquirel", - "version": "3.2.9", + "version": "3.3.0", "description": "Cloud-based SQL data management tool", "main": "index.js", "bin": { diff --git a/utils/get.js b/utils/get.js index 61d91ca..537a7a9 100644 --- a/utils/get.js +++ b/utils/get.js @@ -81,16 +81,13 @@ async function get({ const queryObject = { db: process.env.DSQL_API_DB_NAME || String(db), query: String( - query - .replace(/\n|\r|\n\r/g, "") - .replace(/ {2,}/g, " ") - .replace(/ /g, "+") + query.replace(/\n|\r|\n\r/g, "").replace(/ {2,}/g, " ") ), queryValues: queryValues ? JSON.stringify(queryValues) : undefined, tableName, }; - const queryString = serializeQuery({ query: queryObject }); + const queryString = serializeQuery({ ...queryObject }); let path = `/api/query/${ user_id || grabedHostNames.user_id @@ -109,7 +106,7 @@ async function get({ }, port, hostname: host, - path: encodeURI(path), + path, }; scheme