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

queryablejs

Package Overview
Dependencies
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

queryablejs - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

2

lib/ExpressionVisitor.js

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

if (!expression) {
if (expression == null) {
return null;

@@ -32,0 +32,0 @@ }

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

} else {
this.query.select = new _OperationExpression2.default("select");
this.query.select = new _ValueExpression2.default("select", {});
}

@@ -188,2 +188,52 @@ }

}, {
key: "_validatePropertyName",
value: function _validatePropertyName(name) {
return typeof name === "string" && name.length > 0 && isNaN(parseInt(name.charAt(0), 10));
}
}, {
key: "_selectArray",
value: function _selectArray(properties) {
var _this = this;
var hasValidMapping = properties.every(function (property) {
return _this._validatePropertyName(property);
});
if (!hasValidMapping) {
throw new Error("Invalid mapping: The mappings need to be a string that is at least one character long and doesn't start with a number.");
}
var query = this._copyQuery(this.getQuery());
var existingMapping = query.select.value;
properties.forEach(function (property) {
existingMapping[property] = property;
});
return this.copy(query);
}
}, {
key: "_selectObject",
value: function _selectObject(mapping) {
var _this2 = this;
var mappingKeys = Object.keys(mapping);
var hasValidMapping = mappingKeys.every(function (key) {
return _this2._validatePropertyName(key) && _this2._validatePropertyName(mapping[key]);
});
if (!hasValidMapping) {
throw new Error("Invalid mapping: The mappings need to be a string that is at least one character long and doesn't start with a number.");
}
var query = this._copyQuery(this.getQuery());
var existingMapping = query.select.value;
mappingKeys.forEach(function (key) {
existingMapping[key] = mapping[key];
});
return this.copy(query);
}
}, {
key: "and",

@@ -217,21 +267,2 @@ value: function and(lambda) {

}, {
key: "include",
value: function include(propertyName) {
if (typeof propertyName !== "string") {
throw new Error("Illegal Argument: Expected a string.");
}
var query = this._copyQuery(this.getQuery());
var propertyAccess = new _OperationExpression2.default("propertyAccess");
propertyAccess.children.push(new _ValueExpression2.default("type", "Object"), new _ValueExpression2.default("property", propertyName));
if (!query.include.contains(propertyAccess)) {
query.include.children.push(propertyAccess);
return this.copy(query);
} else {
return this;
}
}
}, {
key: "merge",

@@ -335,26 +366,8 @@ value: function merge(queryable) {

key: "select",
value: function select(properties) {
var _this = this;
if (!Array.isArray(properties)) {
throw new Error("Illegal Argument: Expected an array of strings.");
value: function select(mapping) {
if (Array.isArray(mapping)) {
return this._selectArray(mapping);
} else {
return this._selectObject(mapping);
}
var query = this._copyQuery(this.getQuery());
properties.forEach(function (propertyName) {
if (typeof propertyName !== "string") {
throw new Error("Illegal Argument: Expected a string.");
}
var propertyAccess = new _OperationExpression2.default("propertyAccess");
propertyAccess.children.push(new _ValueExpression2.default("type", _this.type), new _ValueExpression2.default("property", propertyName));
if (!query.select.contains(propertyAccess)) {
query.select.children.push(propertyAccess);
}
});
return this.copy(query);
}

@@ -361,0 +374,0 @@ }, {

@@ -138,32 +138,2 @@ "use strict";

exports["Queryable: Constructor with query (include: single)"] = function () {
var queryable = new _Queryable2.default();
queryable = queryable.include("property");
var query = queryable.getQuery();
assert.equal("propertyAccess", query.include.children[0].nodeName);
assert.equal("property", query.include.children[0].children[1].value);
};
exports["Queryable: Constructor with query (include: chain)"] = function () {
var queryable = new _Queryable2.default();
queryable = queryable.include("propertyOne").include("propertyTwo");
var query = queryable.getQuery();
assert.equal("propertyAccess", query.include.children[0].nodeName);
assert.equal("propertyOne", query.include.children[0].children[1].value);
assert.equal("propertyAccess", query.include.children[1].nodeName);
assert.equal("propertyTwo", query.include.children[1].children[1].value);
};
exports["Queryable: Constructor with query (include: w/o lambda or ExpressionBuilder instance)"] = function () {
var queryable = new _Queryable2.default();
assert.throws(function () {
queryable = queryable.include();
});
};
exports["Queryable: Constructor with query (take: value === number)"] = function () {

@@ -429,14 +399,2 @@ var queryable = new _Queryable2.default();

exports["Queryable: Constructor with query (merge: merging queryable has an include expression)"] = function () {
var queryable1 = new _Queryable2.default();
var queryable2 = new _Queryable2.default();
queryable1 = queryable1.include("property");
queryable2 = queryable2.merge(queryable1);
var query = queryable2.getQuery();
assert.equal("property", query.include.children[0].children[1].value);
};
exports["Queryable: Constructor with query (merge: merging queryable has an orderBy expression)"] = function () {

@@ -563,7 +521,10 @@ var queryable1 = new _Queryable2.default();

exports["Queryable: Select."] = function () {
var queryable = new _Queryable2.default().select(["one", "two"]);
var queryable = new _Queryable2.default().select({
"one": "otherOne",
"two": "otherTwo"
});
assert.equal(queryable.query.select.children[0].children[1].value, "one");
assert.equal(queryable.query.select.children[1].children[1].value, "two");
assert.equal(queryable.query.select.value.one, "otherOne");
assert.equal(queryable.query.select.value.two, "otherTwo");
};
//# sourceMappingURL=Queryable.js.map

@@ -7,2 +7,4 @@ "use strict";

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -38,3 +40,9 @@

value: function copy() {
return new ValueExpression(this.nodeName, this.value);
var value = this.value;
if ((typeof value === "undefined" ? "undefined" : _typeof(value)) === "object" && value != null) {
value = JSON.parse(JSON.stringify(value));
}
return new ValueExpression(this.nodeName, value);
}

@@ -41,0 +49,0 @@ }, {

{
"name": "queryablejs",
"version": "0.0.8",
"version": "0.0.9",
"description": "",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

@@ -8,3 +8,3 @@ import Expression from "./Expression";

if (!expression) {
if (expression == null) {
return null;

@@ -11,0 +11,0 @@ }

@@ -50,3 +50,3 @@ import Expression from "./Expression";

} else {
this.query.select = new OperationExpression("select");
this.query.select = new ValueExpression("select", {});
}

@@ -151,2 +151,45 @@

_validatePropertyName(name) {
return typeof name === "string" && name.length > 0 && isNaN(parseInt(name.charAt(0), 10))
}
_selectArray(properties) {
let hasValidMapping = properties.every((property) => {
return this._validatePropertyName(property);
});
if (!hasValidMapping) {
throw new Error("Invalid mapping: The mappings need to be a string that is at least one character long and doesn't start with a number.");
}
let query = this._copyQuery(this.getQuery());
let existingMapping = query.select.value;
properties.forEach((property) => {
existingMapping[property] = property;
});
return this.copy(query);
}
_selectObject(mapping) {
let mappingKeys = Object.keys(mapping);
let hasValidMapping = mappingKeys.every((key) => {
return this._validatePropertyName(key) && this._validatePropertyName(mapping[key]);
});
if (!hasValidMapping) {
throw new Error("Invalid mapping: The mappings need to be a string that is at least one character long and doesn't start with a number.");
}
let query = this._copyQuery(this.getQuery());
let existingMapping = query.select.value;
mappingKeys.forEach((key) => {
existingMapping[key] = mapping[key];
});
return this.copy(query);
}
and(lambda) {

@@ -175,23 +218,2 @@ return this._createQueryableFromLambda("and", lambda);

include(propertyName) {
if (typeof propertyName !== "string") {
throw new Error("Illegal Argument: Expected a string.");
}
let query = this._copyQuery(this.getQuery());
let propertyAccess = new OperationExpression("propertyAccess");
propertyAccess.children.push(
new ValueExpression("type", "Object"),
new ValueExpression("property", propertyName)
);
if (!query.include.contains(propertyAccess)) {
query.include.children.push(propertyAccess);
return this.copy(query);
} else {
return this;
}
}
merge(queryable) {

@@ -287,28 +309,8 @@ if (!(queryable instanceof Queryable)) {

select(properties) {
if (!Array.isArray(properties)) {
throw new Error("Illegal Argument: Expected an array of strings.");
select(mapping) {
if (Array.isArray(mapping)) {
return this._selectArray(mapping)
} else {
return this._selectObject(mapping);
}
let query = this._copyQuery(this.getQuery());
properties.forEach((propertyName) => {
if (typeof propertyName !== "string") {
throw new Error("Illegal Argument: Expected a string.");
}
let propertyAccess = new OperationExpression("propertyAccess");
propertyAccess.children.push(
new ValueExpression("type", this.type),
new ValueExpression("property", propertyName)
);
if (!query.select.contains(propertyAccess)) {
query.select.children.push(propertyAccess);
}
});
return this.copy(query);
}

@@ -315,0 +317,0 @@

@@ -130,34 +130,2 @@ import * as assert from "assert";

exports["Queryable: Constructor with query (include: single)"] = function () {
let queryable = new Queryable();
queryable = queryable.include("property");
const query = queryable.getQuery();
assert.equal("propertyAccess", query.include.children[0].nodeName);
assert.equal("property", query.include.children[0].children[1].value);
};
exports["Queryable: Constructor with query (include: chain)"] = function () {
let queryable = new Queryable();
queryable = queryable
.include("propertyOne")
.include("propertyTwo");
const query = queryable.getQuery();
assert.equal("propertyAccess", query.include.children[0].nodeName);
assert.equal("propertyOne", query.include.children[0].children[1].value);
assert.equal("propertyAccess", query.include.children[1].nodeName);
assert.equal("propertyTwo", query.include.children[1].children[1].value);
};
exports["Queryable: Constructor with query (include: w/o lambda or ExpressionBuilder instance)"] = function () {
let queryable = new Queryable();
assert.throws(() => {
queryable = queryable.include();
});
};
exports["Queryable: Constructor with query (take: value === number)"] = function () {

@@ -434,14 +402,2 @@ let queryable = new Queryable();

exports["Queryable: Constructor with query (merge: merging queryable has an include expression)"] = function () {
let queryable1 = new Queryable();
let queryable2 = new Queryable();
queryable1 = queryable1.include("property");
queryable2 = queryable2.merge(queryable1);
const query = queryable2.getQuery();
assert.equal("property", query.include.children[0].children[1].value);
};
exports["Queryable: Constructor with query (merge: merging queryable has an orderBy expression)"] = function () {

@@ -564,6 +520,9 @@ let queryable1 = new Queryable();

exports["Queryable: Select."] = function () {
let queryable = new Queryable().select(["one", "two"]);
let queryable = new Queryable().select({
"one": "otherOne",
"two": "otherTwo"
});
assert.equal(queryable.query.select.children[0].children[1].value, "one");
assert.equal(queryable.query.select.children[1].children[1].value, "two");
assert.equal(queryable.query.select.value.one, "otherOne");
assert.equal(queryable.query.select.value.two, "otherTwo");
};

@@ -11,3 +11,9 @@ import Expression from "./Expression";

copy() {
return new ValueExpression(this.nodeName, this.value);
let value = this.value;
if (typeof value === "object" && value != null) {
value = JSON.parse(JSON.stringify(value));
}
return new ValueExpression(this.nodeName, value);
}

@@ -14,0 +20,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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