Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

queryablejs

Package Overview
Dependencies
Maintainers
1
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.2 to 0.0.3

1710

dist/index.js

@@ -78,634 +78,802 @@ (function webpackUniversalModuleDefinition(root, factory) {

/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Expression; });
/* unused harmony export ValueExpression */
/* unused harmony export OperationExpression */
class Expression {
constructor() {
this.nodeName = "expression";
}
copy() {
throw new Error("Meant to be overriden");
}
isEqualTo() {
throw new Error("Meant to be overriden");
}
Object.defineProperty(exports, "__esModule", {
value: true
});
static getExpressionType(value) {
if (value instanceof Expression) {
return value;
}
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; }; }();
if (typeof value === "string") {
return Expression.string(value);
} else if (typeof value === "function") {
return Expression["function"](value);
} else if (typeof value === "number") {
return Expression.number(value);
} else if (typeof value === "boolean") {
return Expression.boolean(value);
} else if (value === null) {
return Expression["null"](value);
return Expression["undefined"](value);
} else if (Array.isArray(value)) {
return Expression.array(value);
} else if (value instanceof Date) {
return Expression.date(value);
} else {
return Expression.object(value);
}
}
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
static property(value) {
return new ValueExpression("property", value);
}
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
static constant(value) {
return new ValueExpression("constant", value);
}
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
static boolean(value) {
var expression = new ValueExpression("boolean");
expression.value = value;
return expression;
}
var Expression = function () {
function Expression() {
_classCallCheck(this, Expression);
static string(value) {
var expression = new ValueExpression("string");
expression.value = value;
return expression;
this.nodeName = "expression";
}
static number(value) {
var expression = new ValueExpression("number");
expression.value = value;
return expression;
}
_createClass(Expression, [{
key: "copy",
value: function copy() {
throw new Error("Meant to be overriden");
}
}, {
key: "isEqualTo",
value: function isEqualTo() {
throw new Error("Meant to be overriden");
}
}], [{
key: "getExpressionType",
value: function getExpressionType(value) {
if (value instanceof Expression) {
return value;
}
static object(value) {
var expression = new ValueExpression("object");
expression.value = value;
return expression;
}
if (typeof value === "string") {
return Expression.string(value);
} else if (typeof value === "function") {
return Expression["function"](value);
} else if (typeof value === "number") {
return Expression.number(value);
} else if (typeof value === "boolean") {
return Expression.boolean(value);
} else if (value === null) {
return Expression["null"](value);
return Expression["undefined"](value);
} else if (Array.isArray(value)) {
return Expression.array(value);
} else if (value instanceof Date) {
return Expression.date(value);
} else {
return Expression.object(value);
}
}
}, {
key: "property",
value: function property(value) {
return new ValueExpression("property", value);
}
}, {
key: "constant",
value: function constant(value) {
return new ValueExpression("constant", value);
}
}, {
key: "boolean",
value: function boolean(value) {
var expression = new ValueExpression("boolean");
expression.value = value;
return expression;
}
}, {
key: "string",
value: function string(value) {
var expression = new ValueExpression("string");
expression.value = value;
return expression;
}
}, {
key: "number",
value: function number(value) {
var expression = new ValueExpression("number");
expression.value = value;
return expression;
}
}, {
key: "object",
value: function object(value) {
var expression = new ValueExpression("object");
expression.value = value;
return expression;
}
}, {
key: "date",
value: function date(value) {
var expression = new ValueExpression("date");
expression.value = value;
return expression;
}
}, {
key: "function",
value: function _function(value) {
var expression = new ValueExpression("function");
expression.value = value;
return expression;
}
}, {
key: "type",
value: function type(value) {
var expression = new ValueExpression("type");
expression.value = value || Object;
return expression;
}
}, {
key: "null",
value: function _null(value) {
var expression = new ValueExpression("null");
expression.value = value;
return expression;
}
}, {
key: "undefined",
value: function undefined(value) {
var expression = new ValueExpression("undefined");
expression.value = value;
return expression;
}
}, {
key: "array",
value: function array(value) {
var expression = new ValueExpression("array");
expression.value = value;
return expression;
}
}, {
key: "queryable",
value: function queryable(leftExpression, rightExpression) {
var expression = new OperationExpression("queryable");
expression.children.push(leftExpression, rightExpression);
return expression;
}
static date(value) {
var expression = new ValueExpression("date");
expression.value = value;
return expression;
}
//
// OperationExpression helpers
//
static function(value) {
var expression = new ValueExpression("function");
expression.value = value;
return expression;
}
}, {
key: "equalTo",
value: function equalTo() {
var expression = new OperationExpression("equalTo");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "notEqualTo",
value: function notEqualTo() {
var expression = new OperationExpression("notEqualTo");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "or",
value: function or() {
var expression = new OperationExpression("or");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "and",
value: function and() {
var expression = new OperationExpression("and");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "where",
value: function where() {
var expression = new OperationExpression("where");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "greaterThan",
value: function greaterThan() {
var expression = new OperationExpression("greaterThan");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "lessThan",
value: function lessThan() {
var expression = new OperationExpression("lessThan");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "greaterThanOrEqualTo",
value: function greaterThanOrEqualTo() {
var expression = new OperationExpression("greaterThanOrEqualTo");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "lessThanOrEqualTo",
value: function lessThanOrEqualTo() {
var expression = new OperationExpression("lessThanOrEqualTo");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "orderBy",
value: function orderBy() {
var expression = new OperationExpression("orderBy");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "descending",
value: function descending() {
var expression = new OperationExpression("descending");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "ascending",
value: function ascending() {
var expression = new OperationExpression("ascending");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "skip",
value: function skip(value) {
var expression = new OperationExpression("skip");
var valueExpression = Expression.constant(value);
expression.children.push(valueExpression);
static type(value) {
var expression = new ValueExpression("type");
expression.value = value || Object;
return expression;
}
return expression;
}
}, {
key: "take",
value: function take(value) {
var expression = new OperationExpression("take");
var valueExpression = Expression.constant(value);
expression.children.push(valueExpression);
static null(value) {
var expression = new ValueExpression("null");
expression.value = value;
return expression;
}
return expression;
}
}, {
key: "buildOperatorExpression",
value: function buildOperatorExpression(name) {
var expression = new OperationExpression(name);
var args = Array.prototype.slice.call(arguments, 1);
args.forEach(function (arg) {
expression.children.push(arg);
});
static undefined(value) {
var expression = new ValueExpression("undefined");
expression.value = value;
return expression;
}
return expression;
}
}, {
key: "guid",
value: function guid() {
var expression = new OperationExpression("guid");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "substring",
value: function substring() {
var expression = new OperationExpression("substring");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "substringOf",
value: function substringOf() {
var expression = new OperationExpression("substringOf");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "startsWith",
value: function startsWith() {
var expression = new OperationExpression("startsWith");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "endsWith",
value: function endsWith() {
var expression = new OperationExpression("endsWith");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "isIn",
value: function isIn(property, array) {
var expression = new OperationExpression("isIn");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "isNotIn",
value: function isNotIn(property, array) {
var expression = new OperationExpression("isNotIn");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "include",
value: function include() {
var expression = new OperationExpression("include");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
expression.children.push(arg);
});
return expression;
}
}, {
key: "any",
value: function any(propertyAccessExpression, expression) {
var anyExpression = new OperationExpression("any");
var expressionExpression = Expression.expression(expression);
static array(value) {
var expression = new ValueExpression("array");
expression.value = value;
return expression;
}
anyExpression.children.push(propertyAccessExpression, expressionExpression);
return anyExpression;
}
}, {
key: "all",
value: function all(propertyAccessExpression, expression) {
var allExpression = new OperationExpression("all");
var expressionExpression = Expression.expression(expression);
static queryable(leftExpression, rightExpression) {
var expression = new OperationExpression("queryable");
expression.children.push(leftExpression, rightExpression);
return expression;
}
allExpression.children.push(propertyAccessExpression, expressionExpression);
return allExpression;
}
}, {
key: "expression",
value: function expression(value) {
var expresssionExpression = new ValueExpression("expression", value);
//
// OperationExpression helpers
//
return expresssionExpression;
}
}, {
key: "propertyAccess",
value: function propertyAccess(leftExpression, propertyName) {
var propertyExpression = Expression.property(propertyName);
var propertyAccessExpression = new OperationExpression("propertyAccess");
propertyAccessExpression.children.push(leftExpression, propertyExpression);
static equalTo() {
var expression = new OperationExpression("equalTo");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
return propertyAccessExpression;
}
}, {
key: "contains",
value: function contains(type, namespace, expression) {
var containsExpression = new OperationExpression("contains");
var ofTypeExpression = new ValueExpression("ofType", type);
var propertyExpression = new ValueExpression("property", namespace);
static notEqualTo() {
var expression = new OperationExpression("notEqualTo");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
containsExpression.children.push(ofTypeExpression, propertyExpression, expression);
static or() {
var expression = new OperationExpression("or");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
return containsExpression;
}
}, {
key: "intersects",
value: function intersects(type, namespace, expression) {
var intersectsExpression = new OperationExpression("intersects");
var ofTypeExpression = new ValueExpression("ofType", type);
var propertyExpression = new ValueExpression("property", namespace);
static and() {
var expression = new OperationExpression("and");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
intersectsExpression.children.push(ofTypeExpression, propertyExpression, expression);
static where() {
var expression = new OperationExpression("where");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
return intersectsExpression;
}
}]);
static greaterThan() {
var expression = new OperationExpression("greaterThan");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
return Expression;
}();
static lessThan() {
var expression = new OperationExpression("lessThan");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
var ValueExpression = function (_Expression) {
_inherits(ValueExpression, _Expression);
static greaterThanOrEqualTo() {
var expression = new OperationExpression("greaterThanOrEqualTo");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
function ValueExpression(nodeName, value) {
_classCallCheck(this, ValueExpression);
static lessThanOrEqualTo() {
var expression = new OperationExpression("lessThanOrEqualTo");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
var _this = _possibleConstructorReturn(this, (ValueExpression.__proto__ || Object.getPrototypeOf(ValueExpression)).call(this));
static orderBy() {
var expression = new OperationExpression("orderBy");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
_this.value = value;
_this.nodeName = nodeName;
return _this;
}
static descending() {
var expression = new OperationExpression("descending");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
_createClass(ValueExpression, [{
key: "copy",
value: function copy() {
return new ValueExpression(this.nodeName, this.value);
}
}, {
key: "isEqualTo",
value: function isEqualTo(node) {
if (node && this.nodeName === node.nodeName && this.value === node.value) {
return true;
}
return false;
}
}, {
key: "contains",
value: function contains(node) {
return this.isEqualTo(node);
}
}]);
static ascending() {
var expression = new OperationExpression("ascending");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
return ValueExpression;
}(Expression);
static skip(value) {
var expression = new OperationExpression("skip");
var valueExpression = Expression.constant(value);
expression.children.push(valueExpression);
var OperationExpression = function (_Expression2) {
_inherits(OperationExpression, _Expression2);
return expression;
}
function OperationExpression(nodeName) {
_classCallCheck(this, OperationExpression);
static take(value) {
var expression = new OperationExpression("take");
var valueExpression = Expression.constant(value);
expression.children.push(valueExpression);
var _this2 = _possibleConstructorReturn(this, (OperationExpression.__proto__ || Object.getPrototypeOf(OperationExpression)).call(this));
return expression;
var args = Array.prototype.slice.call(arguments, 0);
_this2.nodeName = nodeName;
_this2.children = args.slice(1);
return _this2;
}
static buildOperatorExpression(name) {
var expression = new OperationExpression(name);
var args = Array.prototype.slice.call(arguments, 1);
args.forEach(arg => {
expression.children.push(arg);
});
_createClass(OperationExpression, [{
key: "copy",
value: function copy() {
var children = [];
var copy = new OperationExpression(this.nodeName);
return expression;
}
this.children.forEach(function (expression) {
copy.children.push(expression.copy());
});
static guid() {
var expression = new OperationExpression("guid");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
return copy;
}
}, {
key: "isEqualTo",
value: function isEqualTo() {
if (!Array.isArray(node.children) || this.nodeName !== node.nodeName) {
return false;
}
static substring() {
var expression = new OperationExpression("substring");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
if (node.children.length !== this.children.length) {
return false;
}
static substringOf() {
var expression = new OperationExpression("substringOf");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
return this.children.every(function (expression, index) {
return expression.isEqualTo(node.children[index]);
});
}
}, {
key: "contains",
value: function contains(node) {
var _this3 = this;
static startsWith() {
var expression = new OperationExpression("startsWith");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
if (node.nodeName === this.nodeName && Array.isArray(node.children)) {
var matched = node.children.every(function (childNode, index) {
return childNode.contains(_this3.children[index]);
});
static endsWith() {
var expression = new OperationExpression("endsWith");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
if (matched) {
return true;
}
}
static isIn(property, array) {
var expression = new OperationExpression("isIn");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
return this.children.some(function (childNode) {
return childNode.contains(node);
});
}
}, {
key: "getMatchingNodes",
value: function getMatchingNodes(node, matchedNodes) {
var _this4 = this;
static isNotIn(property, array) {
var expression = new OperationExpression("isNotIn");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
matchedNodes = Array.isArray(matchedNodes) ? matchedNodes : [];
static include() {
var expression = new OperationExpression("include");
Array.prototype.slice.call(arguments, 0).forEach(arg => {
expression.children.push(arg);
});
return expression;
}
if (node.nodeName === this.nodeName && Array.isArray(node.children)) {
var matched = node.children.every(function (childNode, index) {
return childNode.contains(_this4.children[index], matchedNodes);
});
static any(propertyAccessExpression, expression) {
var anyExpression = new OperationExpression("any");
var expressionExpression = Expression.expression(expression);
if (matched) {
matchedNodes.push(this);
}
}
anyExpression.children.push(propertyAccessExpression, expressionExpression);
return anyExpression;
}
this.children.forEach(function (childNode) {
if (Array.isArray(childNode.children)) {
childNode.getMatchingNodes(node, matchedNodes);
}
}, matchedNodes);
static all(propertyAccessExpression, expression) {
var allExpression = new OperationExpression("all");
var expressionExpression = Expression.expression(expression);
return matchedNodes;
}
}]);
allExpression.children.push(propertyAccessExpression, expressionExpression);
return allExpression;
}
return OperationExpression;
}(Expression);
static expression(value) {
var expresssionExpression = new ValueExpression("expression", value);
exports.Expression = Expression;
exports.ValueExpression = ValueExpression;
exports.OperationExpression = OperationExpression;
//# sourceMappingURL=Expression.js.map
return expresssionExpression;
}
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
static propertyAccess(leftExpression, propertyName) {
var propertyExpression = Expression.property(propertyName);
var propertyAccessExpression = new OperationExpression("propertyAccess");
propertyAccessExpression.children.push(leftExpression, propertyExpression);
"use strict";
return propertyAccessExpression;
}
static contains(type, namespace, expression) {
var containsExpression = new OperationExpression("contains");
var ofTypeExpression = new ValueExpression("ofType", type);
var propertyExpression = new ValueExpression("property", namespace);
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.OperationExpressionBuilder = exports.ExpressionBuilder = undefined;
containsExpression.children.push(ofTypeExpression, propertyExpression, expression);
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; }; }();
return containsExpression;
}
var _Expression = __webpack_require__(0);
static intersects(type, namespace, expression) {
var intersectsExpression = new OperationExpression("intersects");
var ofTypeExpression = new ValueExpression("ofType", type);
var propertyExpression = new ValueExpression("property", namespace);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
intersectsExpression.children.push(ofTypeExpression, propertyExpression, expression);
var returnExpression = function returnExpression(expression) {
return expression;
};
return intersectsExpression;
}
}
var OperationExpressionBuilder = function () {
function OperationExpressionBuilder(getLeftExpression) {
_classCallCheck(this, OperationExpressionBuilder);
class ValueExpression extends Expression {
constructor(nodeName, value) {
super();
this.value = value;
this.nodeName = nodeName;
this.getLeftExpression = getLeftExpression || returnExpression;
}
copy() {
return new ValueExpression(this.nodeName, this.value);
}
isEqualTo(node) {
if (node && this.nodeName === node.nodeName && this.value === node.value) {
return true;
_createClass(OperationExpressionBuilder, [{
key: "any",
value: function any(fn) {
var expressionBuilder = new ExpressionBuilder();
var expression = fn(expressionBuilder);
return _Expression.Expression.any(this.getLeftExpression(), expression);
}
return false;
}
}, {
key: "where",
value: function where(fn) {
var propertyAccessExpression = this.getLeftExpression();
contains(node) {
return this.isEqualTo(node);
}
}
this.getLeftExpression = function () {
var expressionBuilder = new ExpressionBuilder(Object);
var expression = fn(expressionBuilder);
class OperationExpression extends Expression {
constructor(nodeName) {
super();
var args = Array.prototype.slice.call(arguments, 0);
return _Expression.Expression.queryable(propertyAccessExpression, _Expression.Expression.expression(_Expression.Expression.where(expression)));
};
this.nodeName = nodeName;
this.children = args.slice(1);
}
copy() {
var children = [];
var copy = new OperationExpression(this.nodeName);
this.children.forEach(expression => {
copy.children.push(expression.copy());
});
return copy;
}
isEqualTo() {
if (!Array.isArray(node.children) || this.nodeName !== node.nodeName) {
return false;
return this;
}
if (node.children.length !== this.children.length) {
return false;
}, {
key: "all",
value: function all(fn) {
var expressionBuilder = new ExpressionBuilder();
var expression = fn(expressionBuilder);
return _Expression.Expression.all(this.getLeftExpression(), expression);
}
return this.children.every((expression, index) => {
return expression.isEqualTo(node.children[index]);
});
}
contains(node) {
if (node.nodeName === this.nodeName && Array.isArray(node.children)) {
var matched = node.children.every((childNode, index) => {
return childNode.contains(this.children[index]);
});
if (matched) {
return true;
}, {
key: "isEqualTo",
value: function isEqualTo(value) {
var constant = _Expression.Expression.getExpressionType(value);
return _Expression.Expression.equalTo(this.getLeftExpression(), constant);
}
}, {
key: "isNotEqualTo",
value: function isNotEqualTo(value) {
var constant = _Expression.Expression.getExpressionType(value);
return _Expression.Expression.notEqualTo(this.getLeftExpression(), constant);
}
}, {
key: "contains",
value: function contains(value) {
var constant = _Expression.Expression.getExpressionType(value);
return _Expression.Expression.substringOf(this.getLeftExpression(), constant);
}
}, {
key: "isIn",
value: function isIn(array) {
if (Array.isArray(array)) {
return _Expression.Expression.isIn(this.getLeftExpression(), _Expression.Expression.array(array));
} else {
throw new Error("isIn is expecting to be passed an array!");
}
}
}, {
key: "isNotIn",
value: function isNotIn(array) {
if (Array.isArray(array)) {
return _Expression.Expression.isNotIn(this.getLeftExpression(), _Expression.Expression.array(array));
} else {
throw new Error("isNotIn is expecting to be passed an array!");
}
}
}, {
key: "isGreaterThan",
value: function isGreaterThan(value) {
var constant = _Expression.Expression.getExpressionType(value);
return _Expression.Expression.greaterThan(this.getLeftExpression(), constant);
}
}, {
key: "isGreaterThanOrEqualTo",
value: function isGreaterThanOrEqualTo(value) {
var constant = _Expression.Expression.getExpressionType(value);
return _Expression.Expression.greaterThanOrEqualTo(this.getLeftExpression(), constant);
}
}, {
key: "isLessThanOrEqualTo",
value: function isLessThanOrEqualTo(value) {
var constant = _Expression.Expression.getExpressionType(value);
return _Expression.Expression.lessThanOrEqualTo(this.getLeftExpression(), constant);
}
}, {
key: "isLessThan",
value: function isLessThan(value) {
var constant = _Expression.Expression.getExpressionType(value);
return _Expression.Expression.lessThan(this.getLeftExpression(), constant);
}
}, {
key: "endsWith",
value: function endsWith(value) {
return _Expression.Expression.endsWith(this.getLeftExpression(), _Expression.Expression.string(value));
}
}, {
key: "startsWith",
value: function startsWith(value) {
return _Expression.Expression.startsWith(this.getLeftExpression(), _Expression.Expression.string(value));
}
}, {
key: "property",
value: function property(value) {
var _this = this;
return this.children.some(childNode => {
return childNode.contains(node);
});
}
getMatchingNodes(node, matchedNodes) {
matchedNodes = Array.isArray(matchedNodes) ? matchedNodes : [];
if (node.nodeName === this.nodeName && Array.isArray(node.children)) {
var matched = node.children.every((childNode, index) => {
return childNode.contains(this.children[index], matchedNodes);
return new OperationExpressionBuilder(function () {
return _Expression.Expression.propertyAccess(_this.getLeftExpression(), value);
});
if (matched) {
matchedNodes.push(this);
}
}
}, {
key: "getExpression",
value: function getExpression() {
return this.getLeftExpression();
}
}]);
this.children.forEach(childNode => {
if (Array.isArray(childNode.children)) {
childNode.getMatchingNodes(node, matchedNodes);
}
}, matchedNodes);
return OperationExpressionBuilder;
}();
return matchedNodes;
}
}
var ExpressionBuilder = function () {
function ExpressionBuilder(type) {
_classCallCheck(this, ExpressionBuilder);
/***/ }),
/* 1 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ExpressionBuilder; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return OperationExpressionBuilder; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Expression__ = __webpack_require__(0);
const returnExpression = expression => {
return expression;
};
class OperationExpressionBuilder {
constructor(getLeftExpression) {
this.getLeftExpression = getLeftExpression || returnExpression;
this.type = type || Object;
}
any(fn) {
var expressionBuilder = new ExpressionBuilder();
var expression = fn(expressionBuilder);
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].any(this.getLeftExpression(), expression);
}
_createClass(ExpressionBuilder, [{
key: "property",
value: function property(_property) {
var _this2 = this;
where(fn) {
var propertyAccessExpression = this.getLeftExpression();
this.getLeftExpression = () => {
var expressionBuilder = new ExpressionBuilder(Object);
var expression = fn(expressionBuilder);
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].queryable(propertyAccessExpression, __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].expression(__WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].where(expression)));
};
return this;
}
all(fn) {
var expressionBuilder = new ExpressionBuilder();
var expression = fn(expressionBuilder);
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].all(this.getLeftExpression(), expression);
}
isEqualTo(value) {
var constant = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].getExpressionType(value);
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].equalTo(this.getLeftExpression(), constant);
}
isNotEqualTo(value) {
var constant = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].getExpressionType(value);
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].notEqualTo(this.getLeftExpression(), constant);
}
contains(value) {
var constant = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].getExpressionType(value);
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].substringOf(this.getLeftExpression(), constant);
}
isIn(array) {
if (Array.isArray(array)) {
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].isIn(this.getLeftExpression(), __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].array(array));
} else {
throw new Error("isIn is expecting to be passed an array!");
return new OperationExpressionBuilder(function () {
return _Expression.Expression.propertyAccess(_Expression.Expression.type(_this2.type), _property);
});
}
}
}, {
key: "and",
value: function and() {
return _Expression.Expression.and.apply(_Expression.Expression, arguments);
}
}, {
key: "or",
value: function or() {
return _Expression.Expression.or.apply(_Expression.Expression, arguments);
}
}, {
key: "value",
value: function value() {
var _this3 = this;
isNotIn(array) {
if (Array.isArray(array)) {
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].isNotIn(this.getLeftExpression(), __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].array(array));
} else {
throw new Error("isNotIn is expecting to be passed an array!");
return new OperationExpressionBuilder(function () {
return _Expression.Expression.type(_this3.type);
});
}
}
}]);
isGreaterThan(value) {
var constant = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].getExpressionType(value);
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].greaterThan(this.getLeftExpression(), constant);
}
return ExpressionBuilder;
}();
isGreaterThanOrEqualTo(value) {
var constant = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].getExpressionType(value);
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].greaterThanOrEqualTo(this.getLeftExpression(), constant);
}
exports.ExpressionBuilder = ExpressionBuilder;
exports.OperationExpressionBuilder = OperationExpressionBuilder;
//# sourceMappingURL=ExpressionBuilder.js.map
isLessThanOrEqualTo(value) {
var constant = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].getExpressionType(value);
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].lessThanOrEqualTo(this.getLeftExpression(), constant);
}
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
isLessThan(value) {
var constant = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].getExpressionType(value);
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].lessThan(this.getLeftExpression(), constant);
}
"use strict";
endsWith(value) {
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].endsWith(this.getLeftExpression(), __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].string(value));
}
startsWith(value) {
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].startsWith(this.getLeftExpression(), __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].string(value));
}
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ExpressionVisitor = exports.ExpressionBuilder = exports.Expression = exports.Queryable = undefined;
property(value) {
return new OperationExpressionBuilder(() => {
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].propertyAccess(this.getLeftExpression(), value);
});
}
var _Queryable = __webpack_require__(3);
getExpression() {
return this.getLeftExpression();
}
}
var _Queryable2 = _interopRequireDefault(_Queryable);
class ExpressionBuilder {
constructor(type) {
this.type = type || Object;
}
var _Expression = __webpack_require__(0);
property(property) {
return new OperationExpressionBuilder(() => {
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].propertyAccess(__WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].type(this.type), property);
});
}
var _Expression2 = _interopRequireDefault(_Expression);
and() {
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].and.apply(__WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */], arguments);
}
var _ExpressionBuilder = __webpack_require__(1);
or() {
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].or.apply(__WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */], arguments);
}
var _ExpressionBuilder2 = _interopRequireDefault(_ExpressionBuilder);
value() {
return new OperationExpressionBuilder(() => {
return __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].type(this.type);
});
}
}
var _ExpressionVisitor = __webpack_require__(4);
var _ExpressionVisitor2 = _interopRequireDefault(_ExpressionVisitor);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.Queryable = _Queryable2.default;
exports.Expression = _Expression2.default;
exports.ExpressionBuilder = _ExpressionBuilder2.default;
exports.ExpressionVisitor = _ExpressionVisitor2.default;
//# sourceMappingURL=index.js.map
/***/ }),
/* 2 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Queryable__ = __webpack_require__(3);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Expression__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__ExpressionBuilder__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__ExpressionVisitor__ = __webpack_require__(4);
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "Queryable", function() { return __WEBPACK_IMPORTED_MODULE_0__Queryable__["a"]; });
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "Expression", function() { return __WEBPACK_IMPORTED_MODULE_1__Expression__["default"]; });
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "ExpressionBuilder", function() { return __WEBPACK_IMPORTED_MODULE_2__ExpressionBuilder__["default"]; });
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "ExpressionVisitor", function() { return __WEBPACK_IMPORTED_MODULE_3__ExpressionVisitor__["a"]; });
Object.defineProperty(exports, "__esModule", {
value: true
});
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; }; }();
var _Expression = __webpack_require__(0);
var _ExpressionBuilder = __webpack_require__(1);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/***/ }),
/* 3 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Expression__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__ExpressionBuilder__ = __webpack_require__(1);
const assertHasProvider = queryable => {
var assertHasProvider = function assertHasProvider(queryable) {
if (!queryable.provider) {

@@ -716,3 +884,3 @@ throw new Error("No provider found.");

const copyQuery = query => {
var copyQuery = function copyQuery(query) {
var copy = {};

@@ -730,4 +898,6 @@

class Queryable {
constructor(type, query) {
var Queryable = function () {
function Queryable(type, query) {
_classCallCheck(this, Queryable);
query = query || {};

@@ -738,3 +908,3 @@

this.query = {};
this.query.parameters = (query && query.parameters) || {};
this.query.parameters = query && query.parameters || {};

@@ -744,3 +914,3 @@ if (query.where != null && query.where.nodeName === "where") {

} else {
this.query.where = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].where();
this.query.where = _Expression.Expression.where();
}

@@ -751,3 +921,3 @@

} else {
this.query.skip = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].skip(0);
this.query.skip = _Expression.Expression.skip(0);
}

@@ -758,3 +928,3 @@

} else {
this.query.take = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].take(Infinity);
this.query.take = _Expression.Expression.take(Infinity);
}

@@ -765,3 +935,3 @@

} else {
this.query.include = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].include();
this.query.include = _Expression.Expression.include();
}

@@ -772,291 +942,331 @@

} else {
this.query.orderBy = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].orderBy();
this.query.orderBy = _Expression.Expression.orderBy();
}
}
getExpression() {
return this.query;
}
getQuery() {
return this.query;
}
or(lambda) {
var rightExpression;
var query = copyQuery(this.getQuery());
if (typeof lambda === "function") {
lambda = lambda || function() {};
rightExpression = lambda.call(__WEBPACK_IMPORTED_MODULE_1__ExpressionBuilder__["a" /* ExpressionBuilder */], new __WEBPACK_IMPORTED_MODULE_1__ExpressionBuilder__["a" /* ExpressionBuilder */](this.type));
} else if (lambda instanceof __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */]) {
rightExpression = lambda;
} else {
throw new Error("Expected an expression to be supplied.");
_createClass(Queryable, [{
key: "getExpression",
value: function getExpression() {
return this.query;
}
if (query.where.children.length === 0) {
query.where.children.push(rightExpression);
} else {
var leftExpression = query.where.children.pop();
query.where.children.push(__WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].or(leftExpression, rightExpression));
}, {
key: "getQuery",
value: function getQuery() {
return this.query;
}
}, {
key: "or",
value: function or(lambda) {
var rightExpression;
var query = copyQuery(this.getQuery());
return this.copy(query);
}
if (typeof lambda === "function") {
lambda = lambda || function () {};
rightExpression = lambda.call(_ExpressionBuilder.ExpressionBuilder, new _ExpressionBuilder.ExpressionBuilder(this.type));
} else if (lambda instanceof _Expression.Expression) {
rightExpression = lambda;
} else {
throw new Error("Expected an expression to be supplied.");
}
where(lambda) {
var rightExpression;
var query = copyQuery(this.getQuery());
if (query.where.children.length === 0) {
query.where.children.push(rightExpression);
} else {
var leftExpression = query.where.children.pop();
query.where.children.push(_Expression.Expression.or(leftExpression, rightExpression));
}
if (typeof lambda === "function") {
lambda = lambda || function() {};
rightExpression = lambda.call(__WEBPACK_IMPORTED_MODULE_1__ExpressionBuilder__["a" /* ExpressionBuilder */], new __WEBPACK_IMPORTED_MODULE_1__ExpressionBuilder__["a" /* ExpressionBuilder */](this.type));
} else if (lambda instanceof __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */]) {
rightExpression = lambda;
} else {
throw new Error("Expected an expression to be supplied.");
return this.copy(query);
}
}, {
key: "where",
value: function where(lambda) {
var rightExpression;
var query = copyQuery(this.getQuery());
if (query.where.children.length === 0) {
query.where.children.push(rightExpression);
} else {
var leftExpression = query.where.children.pop();
query.where.children.push(__WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].and(leftExpression, rightExpression));
}
if (typeof lambda === "function") {
lambda = lambda || function () {};
rightExpression = lambda.call(_ExpressionBuilder.ExpressionBuilder, new _ExpressionBuilder.ExpressionBuilder(this.type));
} else if (lambda instanceof _Expression.Expression) {
rightExpression = lambda;
} else {
throw new Error("Expected an expression to be supplied.");
}
return this.copy(query);
}
if (query.where.children.length === 0) {
query.where.children.push(rightExpression);
} else {
var leftExpression = query.where.children.pop();
query.where.children.push(_Expression.Expression.and(leftExpression, rightExpression));
}
and(lambda) {
return this.where(lambda);
}
take(value) {
if (typeof value !== "number") {
throw new Error("Illegal Argument Exception: value needs to be a number.");
return this.copy(query);
}
var query = copyQuery(this.getQuery());
query.take = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].take(value);
return this.copy(query);
}
skip(value) {
if (typeof value !== "number") {
throw new Error("Illegal Argument Exception: value needs to be a number.");
}, {
key: "and",
value: function and(lambda) {
return this.where(lambda);
}
}, {
key: "take",
value: function take(value) {
if (typeof value !== "number") {
throw new Error("Illegal Argument Exception: value needs to be a number.");
}
var query = copyQuery(this.getQuery());
query.skip = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].skip(value);
var query = copyQuery(this.getQuery());
query.take = _Expression.Expression.take(value);
return this.copy(query);
}
orderByDesc(lambda) {
var propertyExpression;
var query = copyQuery(this.getQuery());
if (typeof lambda === "function") {
lambda = lambda || function() {};
propertyExpression = lambda.call(__WEBPACK_IMPORTED_MODULE_1__ExpressionBuilder__["a" /* ExpressionBuilder */], new __WEBPACK_IMPORTED_MODULE_1__ExpressionBuilder__["a" /* ExpressionBuilder */](this.type)).getExpression();
} else if (lambda instanceof __WEBPACK_IMPORTED_MODULE_1__ExpressionBuilder__["b" /* OperationExpressionBuilder */]) {
propertyExpression = lambda.getExpression();
} else {
throw new Error("Expected a property to orderByDesc.");
}
var descendingExpression = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].descending(propertyExpression);
if (!query.orderBy.contains(propertyExpression)) {
query.orderBy.children.push(descendingExpression);
return this.copy(query);
} else {
return this;
}
}
}, {
key: "skip",
value: function skip(value) {
if (typeof value !== "number") {
throw new Error("Illegal Argument Exception: value needs to be a number.");
}
orderBy(lambda) {
var propertyExpression;
var query = copyQuery(this.getQuery());
var query = copyQuery(this.getQuery());
query.skip = _Expression.Expression.skip(value);
if (typeof lambda === "function") {
lambda = lambda || function() {};
propertyExpression = lambda.call(__WEBPACK_IMPORTED_MODULE_1__ExpressionBuilder__["a" /* ExpressionBuilder */], new __WEBPACK_IMPORTED_MODULE_1__ExpressionBuilder__["a" /* ExpressionBuilder */](this.type)).getExpression();
} else if (lambda instanceof __WEBPACK_IMPORTED_MODULE_1__ExpressionBuilder__["b" /* OperationExpressionBuilder */]) {
propertyExpression = lambda.getExpression();
} else {
throw new Error("Expected a property to orderBy.");
}
var ascendingExpression = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].ascending(propertyExpression);
if (!query.orderBy.contains(propertyExpression)) {
query.orderBy.children.push(ascendingExpression);
return this.copy(query);
} else {
return this;
}
}
}, {
key: "orderByDesc",
value: function orderByDesc(lambda) {
var propertyExpression;
var query = copyQuery(this.getQuery());
setParameters(params) {
if (!params) {
throw new Error("Expected parameters to be passed in.");
}
var parameters = this.query.parameters;
if (typeof lambda === "function") {
lambda = lambda || function () {};
propertyExpression = lambda.call(_ExpressionBuilder.ExpressionBuilder, new _ExpressionBuilder.ExpressionBuilder(this.type)).getExpression();
} else if (lambda instanceof _ExpressionBuilder.OperationExpressionBuilder) {
propertyExpression = lambda.getExpression();
} else {
throw new Error("Expected a property to orderByDesc.");
}
Object.keys(params).forEach(function(key) {
parameters[key] = params[key];
});
return this;
}
var descendingExpression = _Expression.Expression.descending(propertyExpression);
withParameters(params) {
if (!params) {
throw new Error("Expected parameters to be passed in.");
if (!query.orderBy.contains(propertyExpression)) {
query.orderBy.children.push(descendingExpression);
return this.copy(query);
} else {
return this;
}
}
}, {
key: "orderBy",
value: function orderBy(lambda) {
var propertyExpression;
var query = copyQuery(this.getQuery());
var parameters = (this.query.parameters = {});
Object.keys(params).forEach(function(key) {
parameters[key] = params[key];
});
return this;
}
if (typeof lambda === "function") {
lambda = lambda || function () {};
propertyExpression = lambda.call(_ExpressionBuilder.ExpressionBuilder, new _ExpressionBuilder.ExpressionBuilder(this.type)).getExpression();
} else if (lambda instanceof _ExpressionBuilder.OperationExpressionBuilder) {
propertyExpression = lambda.getExpression();
} else {
throw new Error("Expected a property to orderBy.");
}
include(lambda) {
var propertyExpression;
var query = copyQuery(this.getQuery());
var ascendingExpression = _Expression.Expression.ascending(propertyExpression);
if (typeof lambda === "function") {
lambda = lambda || function() {};
propertyExpression = lambda.call(__WEBPACK_IMPORTED_MODULE_1__ExpressionBuilder__["a" /* ExpressionBuilder */], new __WEBPACK_IMPORTED_MODULE_1__ExpressionBuilder__["a" /* ExpressionBuilder */](this.type)).getExpression();
} else if (lambda instanceof __WEBPACK_IMPORTED_MODULE_1__ExpressionBuilder__["b" /* OperationExpressionBuilder */]) {
propertyExpression = lambda.getExpression();
} else {
throw new Error("Expected a property to include.");
if (!query.orderBy.contains(propertyExpression)) {
query.orderBy.children.push(ascendingExpression);
return this.copy(query);
} else {
return this;
}
}
}, {
key: "setParameters",
value: function setParameters(params) {
if (!params) {
throw new Error("Expected parameters to be passed in.");
}
var parameters = this.query.parameters;
if (propertyExpression.nodeName !== "queryable") {
propertyExpression = __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].queryable(propertyExpression, __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].expression(__WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].where()));
Object.keys(params).forEach(function (key) {
parameters[key] = params[key];
});
return this;
}
}, {
key: "withParameters",
value: function withParameters(params) {
if (!params) {
throw new Error("Expected parameters to be passed in.");
}
query.include.children.push(propertyExpression);
return this.copy(query);
}
merge(queryable) {
if (!(queryable instanceof Queryable)) {
throw new Error("Expected a queryable to be passed in.");
var parameters = this.query.parameters = {};
Object.keys(params).forEach(function (key) {
parameters[key] = params[key];
});
return this;
}
}, {
key: "include",
value: function include(lambda) {
var propertyExpression;
var query = copyQuery(this.getQuery());
var clone = this.copy();
var cloneQuery = clone.getQuery();
var query = queryable.getQuery();
var rightExpression = query.where.children[0];
if (rightExpression != null) {
// No need to copy if there is nothing to copy.
if (cloneQuery.where.children.length === 0) {
cloneQuery.where.children.push(rightExpression.copy());
} else if (cloneQuery.where.children.length === 1 && cloneQuery.where.children[0].nodeName === "and") {
cloneQuery.where.children[0].children.push(rightExpression.copy());
if (typeof lambda === "function") {
lambda = lambda || function () {};
propertyExpression = lambda.call(_ExpressionBuilder.ExpressionBuilder, new _ExpressionBuilder.ExpressionBuilder(this.type)).getExpression();
} else if (lambda instanceof _ExpressionBuilder.OperationExpressionBuilder) {
propertyExpression = lambda.getExpression();
} else {
var leftExpression = cloneQuery.where.children.pop();
cloneQuery.where.children.push(__WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */].and(leftExpression, rightExpression.copy()));
throw new Error("Expected a property to include.");
}
}
query.include.children.forEach(function(expression) {
cloneQuery.include.children.push(expression.copy());
});
if (propertyExpression.nodeName !== "queryable") {
propertyExpression = _Expression.Expression.queryable(propertyExpression, _Expression.Expression.expression(_Expression.Expression.where()));
}
query.orderBy.children.forEach(function(expression) {
if (!cloneQuery.orderBy.contains(expression)) {
cloneQuery.orderBy.children.push(expression.copy());
query.include.children.push(propertyExpression);
return this.copy(query);
}
}, {
key: "merge",
value: function merge(queryable) {
if (!(queryable instanceof Queryable)) {
throw new Error("Expected a queryable to be passed in.");
}
});
return this.copy(cloneQuery);
}
var clone = this.copy();
var cloneQuery = clone.getQuery();
var query = queryable.getQuery();
var rightExpression = query.where.children[0];
toArrayAsync() {
assertHasProvider(this);
return this.provider.toArrayAsync(this);
}
if (rightExpression != null) {
// No need to copy if there is nothing to copy.
if (cloneQuery.where.children.length === 0) {
cloneQuery.where.children.push(rightExpression.copy());
} else if (cloneQuery.where.children.length === 1 && cloneQuery.where.children[0].nodeName === "and") {
cloneQuery.where.children[0].children.push(rightExpression.copy());
} else {
var leftExpression = cloneQuery.where.children.pop();
cloneQuery.where.children.push(_Expression.Expression.and(leftExpression, rightExpression.copy()));
}
}
countAsync() {
assertHasProvider(this);
return this.provider.countAsync(this);
}
query.include.children.forEach(function (expression) {
cloneQuery.include.children.push(expression.copy());
});
toArrayWithCountAsync() {
assertHasProvider(this);
return this.provider.toArrayWithCountAsync(this);
}
query.orderBy.children.forEach(function (expression) {
if (!cloneQuery.orderBy.contains(expression)) {
cloneQuery.orderBy.children.push(expression.copy());
}
});
ofType(type) {
var queryable = new Queryable(type);
queryable.provider = this.provider;
return queryable;
}
return this.copy(cloneQuery);
}
}, {
key: "toArrayAsync",
value: function toArrayAsync() {
assertHasProvider(this);
return this.provider.toArrayAsync(this);
}
}, {
key: "countAsync",
value: function countAsync() {
assertHasProvider(this);
return this.provider.countAsync(this);
}
}, {
key: "toArrayWithCountAsync",
value: function toArrayWithCountAsync() {
assertHasProvider(this);
return this.provider.toArrayWithCountAsync(this);
}
}, {
key: "ofType",
value: function ofType(type) {
var queryable = new Queryable(type);
queryable.provider = this.provider;
return queryable;
}
}, {
key: "copy",
value: function copy(query) {
var queryable = new Queryable(this.type, query || copyQuery(this.query));
queryable.provider = this.provider;
return queryable;
}
}]);
copy(query) {
var queryable = new Queryable(this.type, query || copyQuery(this.query));
queryable.provider = this.provider;
return queryable;
}
}
/* harmony export (immutable) */ __webpack_exports__["a"] = Queryable;
return Queryable;
}();
exports.default = Queryable;
//# sourceMappingURL=Queryable.js.map
/***/ }),
/* 4 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Expression__ = __webpack_require__(0);
class ExpressionVisitor {
Object.defineProperty(exports, "__esModule", {
value: true
});
parse(expression) {
let children = [];
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; }; }();
if (!expression) {
return null;
}
var _Expression = __webpack_require__(0);
expression.children.forEach((expression) => {
if (!expression.children) {
children.push(expression);
} else {
children.push(this.parse(expression));
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var ExpressionVisitor = function () {
function ExpressionVisitor() {
_classCallCheck(this, ExpressionVisitor);
}
_createClass(ExpressionVisitor, [{
key: "parse",
value: function parse(expression) {
var _this = this;
var children = [];
if (!expression) {
return null;
}
});
let func = this[expression.nodeName];
expression.children.forEach(function (expression) {
if (!expression.children) {
children.push(expression);
} else {
children.push(_this.parse(expression));
}
});
if (!func) {
throw new Error("The builder doesn't support the \"" + expression.nodeName + "\" expression.");
}
var func = this[expression.nodeName];
children.forEach((child, index) => {
if (child instanceof __WEBPACK_IMPORTED_MODULE_0__Expression__["a" /* Expression */]) {
var func = this[child.nodeName];
if (!func) {
throw new Error("The builder doesn't support the \"" + child.nodeName + "\" expression.");
}
children[index] = func.call(this, child);
if (!func) {
throw new Error("The builder doesn't support the \"" + expression.nodeName + "\" expression.");
}
});
return func.apply(this, children);
}
children.forEach(function (child, index) {
if (child instanceof _Expression.Expression) {
var func = _this[child.nodeName];
if (!func) {
throw new Error("The builder doesn't support the \"" + child.nodeName + "\" expression.");
}
children[index] = func.call(_this, child);
}
});
}
/* harmony export (immutable) */ __webpack_exports__["a"] = ExpressionVisitor;
return func.apply(this, children);
}
}]);
return ExpressionVisitor;
}();
exports.default = ExpressionVisitor;
//# sourceMappingURL=ExpressionVisitor.js.map

@@ -1063,0 +1273,0 @@ /***/ })

{
"name": "queryablejs",
"version": "0.0.2",
"version": "0.0.3",
"description": "",

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

const path = require('path');
module.exports = {
entry: './src/index.js',
entry: './lib/index.js',
output: {

@@ -6,0 +6,0 @@ path: path.resolve(__dirname, 'dist'),

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

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