New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mb-vqb-core

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mb-vqb-core - npm Package Compare versions

Comparing version 0.4.2 to 0.5.1

dist/codeGenerator/csharpFakeBson.d.ts

67

dist/index.d.ts

@@ -0,7 +1,35 @@

export * from "./utils";
export * from "./mongoQuery";
export * from "./parseMongoQuery";
export * from "./codeGenerator";
export * from "./RuleOperator";
import * as fakeMongoMod from "./fakeMongoBsonClasses";
import * as codeGenMod from "./codeGenerator";
export declare const codegen: typeof codeGenMod;
import * as fakeMongoMod from "./fakeMongoClass";
export declare let fakeMongo: typeof fakeMongoMod;
export declare const regexHelper: {
contains: (val: any) => {
$regex: string;
$options: string;
};
notContains: (val: any) => {
"$regex": string;
$options: string;
};
startsWith: (val: any) => {
$regex: string;
$options: string;
};
notStartsWith: (val: any) => {
$regex: string;
$options: string;
};
endsWith: (val: any) => {
$regex: string;
$options: string;
};
notEndsWith: (val: any) => {
$regex: string;
$options: string;
};
};
export declare const options: {

@@ -23,2 +51,35 @@ convertBsonTypeToNumber: boolean;

}
export declare function valueToBoolean(val: any): boolean | undefined;
export interface TransFindParams {
query: QueryGroupRst;
projection?: Object;
sort?: Object;
skip?: number;
limit?: number;
}
export interface StringifyFuncParams {
obj: any;
readonly imports: string[];
fakeMod?: any;
}
export declare enum CodeGenType {
ShellJs = "MongoDB shell js",
NodeJS = "Javascript Node.js ES5",
NodeJSPromise = "Javascript Node.js ES6 Promise",
NodeJSAsync = "Javascript Node.js ES7 Async/Await",
Python = "Python (PyMongo3.x)",
CSharp = "C# (2.x driver)",
Java3x = "Java (3.x driver)",
}
export interface GenerateCodeParams {
type: CodeGenType;
pipeline: {
$match: Object;
$project: any;
$sort: any;
$skip: any;
$limit: any;
};
database: string;
collection: string;
isAggr: boolean;
}

41

dist/index.js

@@ -6,9 +6,12 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var _ = require("lodash");
__export(require("./utils"));
__export(require("./mongoQuery"));
__export(require("./parseMongoQuery"));
__export(require("./codeGenerator"));
__export(require("./RuleOperator"));
var fakeMongoMod = require("./fakeMongoBsonClasses");
var codeGenMod = require("./codeGenerator");
exports.codegen = codeGenMod;
var fakeMongoMod = require("./fakeMongoClass");
exports.fakeMongo = fakeMongoMod;
var mbRegex = require("./mbRegex");
exports.regexHelper = mbRegex.regex;
exports.options = {

@@ -19,23 +22,13 @@ convertBsonTypeToNumber: true

exports.DATE_TIME_PATTERN = "MM/DD/YYYY hh:mm:ss";
function valueToBoolean(val) {
if (val === "")
return undefined;
if (_.isUndefined(val))
return val;
if (_.isBoolean(val))
return val;
if (!_.isString(val))
return !!val;
switch (val.toLowerCase().trim()) {
case "true":
case "yes":
case "1": return true;
case "false":
case "no":
case "0":
case null: return false;
default: return Boolean(val);
}
}
exports.valueToBoolean = valueToBoolean;
var CodeGenType;
(function (CodeGenType) {
CodeGenType["ShellJs"] = "MongoDB shell js";
//FluentShellJs = "MongoBooster Fluent shell js",
CodeGenType["NodeJS"] = "Javascript Node.js ES5";
CodeGenType["NodeJSPromise"] = "Javascript Node.js ES6 Promise";
CodeGenType["NodeJSAsync"] = "Javascript Node.js ES7 Async/Await";
CodeGenType["Python"] = "Python (PyMongo3.x)";
CodeGenType["CSharp"] = "C# (2.x driver)";
CodeGenType["Java3x"] = "Java (3.x driver)";
})(CodeGenType = exports.CodeGenType || (exports.CodeGenType = {}));
//# sourceMappingURL=index.js.map
import * as vqb from "./";
export declare const Mquery_ext_methods: string[];
export declare function takeOnQuoted(str: string): string;
export declare function isTakeOnQuoted(str: any): boolean;
export declare function takeOffQuoted(str: any, inJson?: boolean): any;
export declare function getGroupMongoQuery(qry: vqb.QueryGroupRst): any;
export declare function isValidVar(val: any): any;
export declare function getRuleMongoQuery(params: vqb.QueryRuleRst): {};
export declare function stringify(obj_from_json: any, replacer?: any, space?: any): any;
export declare function getRuleMongoQuery(params: vqb.QueryRuleRst): any;
export declare function stringifyWithOpt(obj: any, opt?: {
replacer?;
space?;
doTakeOffQuoted?;
alwayQuoteKey?;
}): any;
export declare function stringify(obj: any, replacer?: any, space?: any, doTakeOffQuoted?: boolean): any;
export declare function getMongoQueryAsString(grp: vqb.QueryGroupRst): any;
export declare function getFluentMongoQueryString(grp: vqb.QueryGroupRst): string;

@@ -57,4 +57,10 @@ "use strict";

exports.takeOnQuoted = takeOnQuoted;
function isTakeOnQuoted(str) {
return str && (str.indexOf(TAKEON_MAGIC) > -1);
}
exports.isTakeOnQuoted = isTakeOnQuoted;
function takeOffQuoted(str, inJson) {
if (inJson === void 0) { inJson = true; }
if (!isTakeOnQuoted(str))
return str;
if (inJson)

@@ -102,9 +108,2 @@ str = str.replace(new RegExp("\"" + TAKEON_MAGIC + "(.*?)" + TAKEON_MAGIC + "\"", "g"), "$1");

exports.getGroupMongoQuery = getGroupMongoQuery;
function isValidVar(val) {
var varVal = require('var-validator');
varVal.enableScope = false;
varVal.enableBrackets = false;
return varVal.isValid(val);
}
exports.isValidVar = isValidVar;
function parseDate(v, dateOnly) {

@@ -169,3 +168,4 @@ if (!dateOnly) {

if (params.type === "Any") {
if (isValidVar(params.value))
var needQuote = (["MinKey", "MaxKey"].indexOf(params.value) > -1) || (!vqb.isValidVar(params.value));
if (!needQuote)
return params.value;

@@ -229,3 +229,3 @@ else

var key0 = _.keys(it)[0];
var key = isValidVar(key0) ? key0 : "\"" + key0 + "\"";
var key = vqb.isValidVar(key0) ? key0 : "\"" + key0 + "\"";
hasBuildPart_1 = true;

@@ -309,28 +309,53 @@ if (_.isString(it[key0])) {

}
function stringify(obj_from_json, replacer, space) {
if (_.isArray(obj_from_json)) {
return "[" + obj_from_json.map(function (it) { return stringify(it); }).join(",") + "]";
function stringifyWithOpt(obj, opt) {
if (_.isArray(obj)) {
return "[" + obj.map(function (it) { return stringifyWithOpt(it, opt); }).join(",") + "]";
}
if (!_.isObject(obj_from_json)) {
if (_.isRegExp(obj)) {
return obj.toString();
}
var doTakeOffQuoted = (opt && opt.doTakeOffQuoted) || false;
var replacer = opt && opt.replacer;
var space = opt && opt.space;
var alwayQuoteKey = opt && opt.alwayQuoteKey;
if (doTakeOffQuoted && _.isString(obj) && isTakeOnQuoted(obj)) {
return takeOffQuoted(obj);
}
if (!_.isObject(obj)) {
// not an object, stringify using native function
return JSON.stringify(obj_from_json, replacer, space);
return JSON.stringify(obj, replacer, space);
}
if (obj_from_json && obj_from_json.toJSON && _.isFunction(obj_from_json.toJSON)) {
return "\"" + obj_from_json.toJSON() + "\"";
if (obj && obj.toJSON && _.isFunction(obj.toJSON)) {
return "\"" + obj.toJSON() + "\"";
}
// Implements recursive object serialization according to JSON spec
// but without quotes around the keys.
var joiner = (space > 0) ? ",\n" : ",";
var props = Object
.keys(obj_from_json)
.keys(obj)
.map(function (key) {
var val = stringify(obj_from_json[key], replacer, space);
//val=_.isString(obj_from_json[key])?`"${val}"`:val;
return (vqb.isValidVar(key) ? key : "\"" + key + "\"") + ":" + val;
var v = (function () {
if (replacer) {
return replacer(key, obj[key]);
}
else
return obj[key];
})();
var val = stringifyWithOpt(v, opt);
return _.repeat(" ", space || 0) + (((!alwayQuoteKey && vqb.isValidVar(key)) ? key : "\"" + key + "\"") + ":" + val);
})
.join(",");
return "{" + props + "}";
.join(joiner);
if (space > 0) {
return "{\n" + props + "\n}";
}
else
return "{" + props + "}";
}
exports.stringifyWithOpt = stringifyWithOpt;
function stringify(obj, replacer, space, doTakeOffQuoted) {
return stringifyWithOpt(obj, { replacer: replacer, space: space, doTakeOffQuoted: doTakeOffQuoted });
}
exports.stringify = stringify;
function getMongoQueryAsString(grp) {
return vqb.takeOffQuoted(stringify(vqb.getGroupMongoQuery(grp), null, 4)).replace(/\\\"/g, '"');
return stringify(vqb.getGroupMongoQuery(grp), null, 4, true); //doTakeOffQuoted
}

@@ -337,0 +362,0 @@ exports.getMongoQueryAsString = getMongoQueryAsString;

@@ -26,3 +26,3 @@ "use strict";

if (it instanceof vqb.fakeMongo.FakeMongoToJson) {
if (it.bsonType === "ISODate") {
if (it.mgfunc === "ISODate") {
var v = it.params[0] || "";

@@ -32,3 +32,3 @@ //console.log("ISODate", v);

}
if (["NumberInt", "NumberLong", "NumberDecimal"].indexOf(it.bsonType) > -1) {
if (["NumberInt", "NumberLong", "NumberDecimal"].indexOf(it.mgfunc) > -1) {
return it.params[0] || "";

@@ -64,3 +64,3 @@ }

if (v instanceof vqb.fakeMongo.FakeMongoToJson) {
var type = v.bsonType;
var type = v.mgfunc;
if (type === "ObjectId")

@@ -232,2 +232,6 @@ return "ObjectId";

});
var hasCustom = (rules.length > 1) && (_.find(rules, function (it) { return it.operator === "(custom)"; }));
if (hasCustom) {
return { field: field, operator: "(custom)", value: "" + vqb.stringify(value), type: "Any" };
}
if (rules.length === 1) {

@@ -234,0 +238,0 @@ rules = rules[0];

{
"name": "mb-vqb-core",
"version": "0.4.2",
"description": "mb query builder core",
"version": "0.5.1",
"description": "mb query core, internal project",
"main": "dist/index.js",

@@ -15,3 +15,29 @@ "types": "dist/index.d.ts",

"adhoc-debug": "tsc && node --inspect-brk ./test/adhoc.js",
"adhoc": "tsc && node ./test/adhoc.js"
"adhoc": "tsc && node ./test/adhoc.js",
"adhoc-py": "python ./docs/python_adhoc.py",
"codegen-debug": "node --inspect-brk ./test/codegen.js",
"codegen": "node ./test/codegen.js",
"node-es5-find": "node ./test/codegen-out/find/javascript_node_js_es_5.js",
"node-es5-aggr": "node ./test/codegen-out/aggregate/javascript_node_js_es_5.js",
"node-es5": "npm run node-es5-find && npm run node-es5-aggr",
"node-es6-find": "node ./test/codegen-out/find/javascript_node_js_es_6_promise.js",
"node-es6-aggr": "node ./test/codegen-out/aggregate/javascript_node_js_es_6_promise.js",
"node-es6": "npm run node-es6-find && npm run node-es6-aggr",
"node-es7-find": "node ./test/codegen-out/find/javascript_node_js_es_7_async_await.js",
"node-es7-aggr": "node ./test/codegen-out/aggregate/javascript_node_js_es_7_async_await.js",
"node-es7": "npm run node-es7-find && npm run node-es7-aggr",
"node": "npm run node-es5 && npm run node-es6 && npm run node-es7",
"python-find": "python ./test/codegen-out/find/python_py_mongo_3_x.py",
"python-aggr": "python ./test/codegen-out/aggregate/python_py_mongo_3_x.py",
"python": "npm run python-find && npm run python-aggr",
"java-find": "cd docs/java-prj/find && gradle run",
"java-aggr": "cd docs/java-prj/aggregate && gradle run",
"java": "npm run java-find && npm run java-aggr",
"csharp-find": "dotnet run --project docs/csharp-prj/find",
"csharp-aggr": "dotnet run --project docs/csharp-prj/aggregate",
"csharp": "npm run csharp-find && npm run csharp-aggr",
"codegen-all":"rm -rf dist && npm run tsc && npm run codegen && npm run node && npm run python && npm run java && npm run csharp"
},

@@ -22,3 +48,3 @@ "publishConfig": {

"keywords": [],
"author": "",
"author": "qh",
"license": "ISC",

@@ -31,2 +57,3 @@ "devDependencies": {

"js-beautify": "^1.7.3",
"mongodb": "^2.2.33",
"npm-scripts-info": "^0.3.6",

@@ -33,0 +60,0 @@ "typescript": "^2.6"

@@ -0,4 +1,12 @@

QueryBuilder rules core.
Code geneartor
Start coding!
npm run test
cmd 1:
npm run tsc-watch
cmd 2:
npm run codegen

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc