Updates
This commit is contained in:
parent
c208975b44
commit
956497a499
30
package-shared/utils/deserialize-query.js
Normal file
30
package-shared/utils/deserialize-query.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// @ts-check
|
||||||
|
|
||||||
|
const EJSON = require("./ejson");
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string | Object<string,any>} query
|
||||||
|
* @returns {Object<string,any>}
|
||||||
|
*/
|
||||||
|
function deserializeQuery(query) {
|
||||||
|
/** @type {Object<string,any>} */
|
||||||
|
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;
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "3.2.9",
|
"version": "3.3.0",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
@ -81,16 +81,13 @@ async function get({
|
|||||||
const queryObject = {
|
const queryObject = {
|
||||||
db: process.env.DSQL_API_DB_NAME || String(db),
|
db: process.env.DSQL_API_DB_NAME || String(db),
|
||||||
query: String(
|
query: String(
|
||||||
query
|
query.replace(/\n|\r|\n\r/g, "").replace(/ {2,}/g, " ")
|
||||||
.replace(/\n|\r|\n\r/g, "")
|
|
||||||
.replace(/ {2,}/g, " ")
|
|
||||||
.replace(/ /g, "+")
|
|
||||||
),
|
),
|
||||||
queryValues: queryValues ? JSON.stringify(queryValues) : undefined,
|
queryValues: queryValues ? JSON.stringify(queryValues) : undefined,
|
||||||
tableName,
|
tableName,
|
||||||
};
|
};
|
||||||
|
|
||||||
const queryString = serializeQuery({ query: queryObject });
|
const queryString = serializeQuery({ ...queryObject });
|
||||||
|
|
||||||
let path = `/api/query/${
|
let path = `/api/query/${
|
||||||
user_id || grabedHostNames.user_id
|
user_id || grabedHostNames.user_id
|
||||||
@ -109,7 +106,7 @@ async function get({
|
|||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path: encodeURI(path),
|
path,
|
||||||
};
|
};
|
||||||
|
|
||||||
scheme
|
scheme
|
||||||
|
Loading…
Reference in New Issue
Block a user