Comparing version 0.0.1-next.2 to 0.0.1-next.3
// Generated by dts-bundle v0.7.3 | ||
declare module '@rsql/ast' { | ||
export * from "@rsql/ast/ComparisonOperator"; | ||
export * from "@rsql/ast/LogicOperator"; | ||
export * from "@rsql/ast/ReservedChars"; | ||
export * from "@rsql/ast/Node"; | ||
} | ||
const EQ: "=="; | ||
const NEQ: "!="; | ||
const LE: "<="; | ||
const GE: ">="; | ||
const LT: "<"; | ||
const GT: ">"; | ||
const IN: "=in="; | ||
const OUT: "=out="; | ||
const LE_VERBOSE: "=le="; | ||
const GE_VERBOSE: "=ge="; | ||
const LT_VERBOSE: "=lt="; | ||
const GT_VERBOSE: "=gt="; | ||
type CustomComparisonOperator = string; | ||
const CanonicalComparisonOperators: ("==" | "!=" | "<=" | ">=" | "<" | ">" | "=in=" | "=out=")[]; | ||
type CanonicalComparisonOperator = typeof CanonicalComparisonOperators[number]; | ||
const VerboseComparisonOperators: ("=le=" | "=ge=" | "=lt=" | "=gt=")[]; | ||
type VerboseComparisonOperator = typeof VerboseComparisonOperators[number]; | ||
const ComparisonOperators: ( | ||
| "==" | ||
| "!=" | ||
| "<=" | ||
| ">=" | ||
| "<" | ||
| ">" | ||
| "=in=" | ||
| "=out=" | ||
| "=le=" | ||
| "=ge=" | ||
| "=lt=" | ||
| "=gt=" | ||
)[]; | ||
type ComparisonOperator = typeof ComparisonOperators[number] | CustomComparisonOperator; | ||
function isComparisonOperator(candidate: string, operator?: ComparisonOperator): candidate is ComparisonOperator; | ||
export { | ||
EQ, | ||
NEQ, | ||
LE, | ||
GE, | ||
LT, | ||
GT, | ||
IN, | ||
OUT, | ||
LE_VERBOSE, | ||
GE_VERBOSE, | ||
LT_VERBOSE, | ||
GT_VERBOSE, | ||
ComparisonOperators, | ||
CanonicalComparisonOperators, | ||
VerboseComparisonOperators, | ||
isComparisonOperator, | ||
ComparisonOperator, | ||
CanonicalComparisonOperator, | ||
VerboseComparisonOperator, | ||
}; | ||
declare module '@rsql/ast/ComparisonOperator' { | ||
const EQ: "=="; | ||
const NEQ: "!="; | ||
const LE: "<="; | ||
const GE: ">="; | ||
const LT: "<"; | ||
const GT: ">"; | ||
const IN: "=in="; | ||
const OUT: "=out="; | ||
const LE_VERBOSE: "=le="; | ||
const GE_VERBOSE: "=ge="; | ||
const LT_VERBOSE: "=lt="; | ||
const GT_VERBOSE: "=gt="; | ||
type CustomComparisonOperator = string; | ||
const CanonicalComparisonOperators: ("==" | "!=" | "<=" | ">=" | "<" | ">" | "=in=" | "=out=")[]; | ||
type CanonicalComparisonOperator = typeof CanonicalComparisonOperators[number]; | ||
const VerboseComparisonOperators: ("=le=" | "=ge=" | "=lt=" | "=gt=")[]; | ||
type VerboseComparisonOperator = typeof VerboseComparisonOperators[number]; | ||
const ComparisonOperators: ("==" | "!=" | "<=" | ">=" | "<" | ">" | "=in=" | "=out=" | "=le=" | "=ge=" | "=lt=" | "=gt=")[]; | ||
type ComparisonOperator = typeof ComparisonOperators[number] | CustomComparisonOperator; | ||
function isComparisonOperator(candidate: string, operator?: ComparisonOperator): candidate is ComparisonOperator; | ||
export { EQ, NEQ, LE, GE, LT, GT, IN, OUT, LE_VERBOSE, GE_VERBOSE, LT_VERBOSE, GT_VERBOSE, ComparisonOperators, CanonicalComparisonOperators, VerboseComparisonOperators, isComparisonOperator, ComparisonOperator, CanonicalComparisonOperator, VerboseComparisonOperator, }; | ||
} | ||
const AND: ";"; | ||
const OR: ","; | ||
const AND_VERBOSE: "and"; | ||
const OR_VERBOSE: "or"; | ||
const CanonicalLogicOperators: (";" | ",")[]; | ||
type CanonicalLogicOperator = typeof CanonicalLogicOperators[number]; | ||
const VerboseLogicOperators: ("and" | "or")[]; | ||
type VerboseLogicOperator = typeof VerboseLogicOperators[number]; | ||
const LogicOperators: (";" | "," | "and" | "or")[]; | ||
type LogicOperator = typeof LogicOperators[number]; | ||
function isLogicOperator(candidate: string, operator?: LogicOperator): candidate is LogicOperator; | ||
export { | ||
AND, | ||
OR, | ||
AND_VERBOSE, | ||
OR_VERBOSE, | ||
CanonicalLogicOperators, | ||
VerboseLogicOperators, | ||
LogicOperators, | ||
isLogicOperator, | ||
CanonicalLogicOperator, | ||
VerboseLogicOperator, | ||
LogicOperator, | ||
}; | ||
declare module '@rsql/ast/LogicOperator' { | ||
const AND: ";"; | ||
const OR: ","; | ||
const AND_VERBOSE: "and"; | ||
const OR_VERBOSE: "or"; | ||
const CanonicalLogicOperators: (";" | ",")[]; | ||
type CanonicalLogicOperator = typeof CanonicalLogicOperators[number]; | ||
const VerboseLogicOperators: ("and" | "or")[]; | ||
type VerboseLogicOperator = typeof VerboseLogicOperators[number]; | ||
const LogicOperators: (";" | "," | "and" | "or")[]; | ||
type LogicOperator = typeof LogicOperators[number]; | ||
function isLogicOperator(candidate: string, operator?: LogicOperator): candidate is LogicOperator; | ||
export { AND, OR, AND_VERBOSE, OR_VERBOSE, CanonicalLogicOperators, VerboseLogicOperators, LogicOperators, isLogicOperator, CanonicalLogicOperator, VerboseLogicOperator, LogicOperator, }; | ||
} | ||
const ReservedChars: readonly ['"', "'", "(", ")", ";", ",", "=", "!", "~", "<", ">", " ", "\n", "\t", "\r"]; | ||
type ReservedChar = typeof ReservedChars[number]; | ||
export { ReservedChars, ReservedChar }; | ||
declare module '@rsql/ast/ReservedChars' { | ||
const ReservedChars: readonly ["\"", "'", "(", ")", ";", ",", "=", "!", "~", "<", ">", " ", "\n", "\t", "\r"]; | ||
type ReservedChar = typeof ReservedChars[number]; | ||
export { ReservedChars, ReservedChar }; | ||
const NodeType: { | ||
readonly SELECTOR: "SELECTOR"; | ||
readonly VALUE: "VALUE"; | ||
readonly COMPARISON: "COMPARISON"; | ||
readonly LOGIC: "LOGIC"; | ||
}; | ||
interface Node<TType = string> { | ||
readonly type: TType; | ||
} | ||
declare module '@rsql/ast/Node' { | ||
import { ComparisonOperator } from "@rsql/ast/ComparisonOperator"; | ||
import { LogicOperator } from "@rsql/ast/LogicOperator"; | ||
const NodeType: { | ||
readonly SELECTOR: "SELECTOR"; | ||
readonly VALUE: "VALUE"; | ||
readonly COMPARISON: "COMPARISON"; | ||
readonly LOGIC: "LOGIC"; | ||
}; | ||
interface Node<TType = string> { | ||
readonly type: TType; | ||
} | ||
interface SelectorNode extends Node<typeof NodeType.SELECTOR> { | ||
readonly selector: string; | ||
} | ||
interface ValueNode extends Node<typeof NodeType.VALUE> { | ||
readonly value: string | string[]; | ||
} | ||
interface BinaryNode<TType extends string = string, TLeft extends Node = Node, TOperator extends string = string, TRight extends Node = Node> extends Node<TType> { | ||
readonly left: TLeft; | ||
readonly operator: TOperator; | ||
readonly right: TRight; | ||
} | ||
type ComparisonNode = BinaryNode<typeof NodeType.COMPARISON, SelectorNode, ComparisonOperator, ValueNode>; | ||
type LogicNode = BinaryNode<typeof NodeType.LOGIC, ExpressionNode, LogicOperator, ExpressionNode>; | ||
type ExpressionNode = ComparisonNode | LogicNode; | ||
function createSelectorNode(selector: string, skipChecks?: boolean): SelectorNode; | ||
function createValueNode(value: string | string[], skipChecks?: boolean): ValueNode; | ||
function createComparisonNode(selector: SelectorNode, operator: ComparisonOperator, value: ValueNode, skipChecks?: boolean): ComparisonNode; | ||
function createLogicNode(left: ExpressionNode, operator: LogicOperator, right: ExpressionNode, skipChecks?: boolean): LogicNode; | ||
function isNode(candidate: unknown): candidate is Node; | ||
function isSelectorNode(candidate: unknown): candidate is SelectorNode; | ||
function isValueNode(candidate: unknown): candidate is ValueNode; | ||
function isComparisonNode(candidate: unknown, operator?: ComparisonOperator): candidate is ComparisonNode; | ||
function isLogicNode(candidate: unknown, operator?: LogicOperator): candidate is LogicNode; | ||
function isExpressionNode(candidate: unknown): candidate is ExpressionNode; | ||
function getSelector(comparison: ComparisonNode): string; | ||
function getValue(comparison: ComparisonNode): string | string[]; | ||
function getSingleValue(comparison: ComparisonNode): string; | ||
function getMultiValue(comparison: ComparisonNode): string[]; | ||
export { createSelectorNode, createValueNode, createComparisonNode, createLogicNode, isNode, isSelectorNode, isValueNode, isComparisonNode, isLogicNode, isExpressionNode, getSelector, getValue, getSingleValue, getMultiValue, Node, SelectorNode, ValueNode, BinaryNode, ComparisonNode, LogicNode, ExpressionNode, }; | ||
interface SelectorNode extends Node<typeof NodeType.SELECTOR> { | ||
readonly selector: string; | ||
} | ||
interface ValueNode extends Node<typeof NodeType.VALUE> { | ||
readonly value: string | string[]; | ||
} | ||
interface BinaryNode< | ||
TType extends string = string, | ||
TLeft extends Node = Node, | ||
TOperator extends string = string, | ||
TRight extends Node = Node | ||
> extends Node<TType> { | ||
readonly left: TLeft; | ||
readonly operator: TOperator; | ||
readonly right: TRight; | ||
} | ||
type ComparisonNode = BinaryNode<typeof NodeType.COMPARISON, SelectorNode, ComparisonOperator, ValueNode>; | ||
type LogicNode = BinaryNode<typeof NodeType.LOGIC, ExpressionNode, LogicOperator, ExpressionNode>; | ||
type ExpressionNode = ComparisonNode | LogicNode; | ||
function createSelectorNode(selector: string, skipChecks?: boolean): SelectorNode; | ||
function createValueNode(value: string | string[], skipChecks?: boolean): ValueNode; | ||
function createComparisonNode( | ||
selector: SelectorNode, | ||
operator: ComparisonOperator, | ||
value: ValueNode, | ||
skipChecks?: boolean | ||
): ComparisonNode; | ||
function createLogicNode( | ||
left: ExpressionNode, | ||
operator: LogicOperator, | ||
right: ExpressionNode, | ||
skipChecks?: boolean | ||
): LogicNode; | ||
function isNode(candidate: unknown): candidate is Node; | ||
function isSelectorNode(candidate: unknown): candidate is SelectorNode; | ||
function isValueNode(candidate: unknown): candidate is ValueNode; | ||
function isComparisonNode(candidate: unknown, operator?: ComparisonOperator): candidate is ComparisonNode; | ||
function isLogicNode(candidate: unknown, operator?: LogicOperator): candidate is LogicNode; | ||
function isExpressionNode(candidate: unknown): candidate is ExpressionNode; | ||
function getSelector(comparison: ComparisonNode): string; | ||
function getValue(comparison: ComparisonNode): string | string[]; | ||
function getSingleValue(comparison: ComparisonNode): string; | ||
function getMultiValue(comparison: ComparisonNode): string[]; | ||
export { | ||
createSelectorNode, | ||
createValueNode, | ||
createComparisonNode, | ||
createLogicNode, | ||
isNode, | ||
isSelectorNode, | ||
isValueNode, | ||
isComparisonNode, | ||
isLogicNode, | ||
isExpressionNode, | ||
getSelector, | ||
getValue, | ||
getSingleValue, | ||
getMultiValue, | ||
Node, | ||
SelectorNode, | ||
ValueNode, | ||
BinaryNode, | ||
ComparisonNode, | ||
LogicNode, | ||
ExpressionNode, | ||
}; |
@@ -17,43 +17,44 @@ var EQ = "=="; | ||
function mapToCanonicalComparisonOperator(operator) { | ||
switch (operator) { | ||
case LE_VERBOSE: | ||
return LE; | ||
case LT_VERBOSE: | ||
return LT; | ||
case GE_VERBOSE: | ||
return GE; | ||
case GT_VERBOSE: | ||
return GT; | ||
default: | ||
return operator; | ||
} | ||
switch (operator) { | ||
case LE_VERBOSE: | ||
return LE; | ||
case LT_VERBOSE: | ||
return LT; | ||
case GE_VERBOSE: | ||
return GE; | ||
case GT_VERBOSE: | ||
return GT; | ||
default: | ||
return operator; | ||
} | ||
} | ||
var CUSTOM_OPERATOR_REGEXP = /^=[a-z]+=$/; | ||
function isCustomComparisonOperator(candidate) { | ||
return candidate.length > 2 && CUSTOM_OPERATOR_REGEXP.test(candidate); | ||
return candidate.length > 2 && CUSTOM_OPERATOR_REGEXP.test(candidate); | ||
} | ||
function isComparisonOperator(candidate, operator) { | ||
switch (candidate) { | ||
case EQ: | ||
case NEQ: | ||
case LE: | ||
case GE: | ||
case LT: | ||
case GT: | ||
case IN: | ||
case OUT: | ||
case LE_VERBOSE: | ||
case GE_VERBOSE: | ||
case LT_VERBOSE: | ||
case GT_VERBOSE: | ||
return (operator === undefined || | ||
mapToCanonicalComparisonOperator(candidate) === mapToCanonicalComparisonOperator(operator)); | ||
default: | ||
if (isCustomComparisonOperator(candidate)) { | ||
return operator === undefined || candidate === operator; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
switch (candidate) { | ||
case EQ: | ||
case NEQ: | ||
case LE: | ||
case GE: | ||
case LT: | ||
case GT: | ||
case IN: | ||
case OUT: | ||
case LE_VERBOSE: | ||
case GE_VERBOSE: | ||
case LT_VERBOSE: | ||
case GT_VERBOSE: | ||
return ( | ||
operator === undefined || | ||
mapToCanonicalComparisonOperator(candidate) === mapToCanonicalComparisonOperator(operator) | ||
); | ||
default: | ||
if (isCustomComparisonOperator(candidate)) { | ||
return operator === undefined || candidate === operator; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
@@ -69,21 +70,21 @@ | ||
function mapToCanonicalLogicOperator(operator) { | ||
switch (operator) { | ||
case AND_VERBOSE: | ||
return AND; | ||
case OR_VERBOSE: | ||
return OR; | ||
default: | ||
return operator; | ||
} | ||
switch (operator) { | ||
case AND_VERBOSE: | ||
return AND; | ||
case OR_VERBOSE: | ||
return OR; | ||
default: | ||
return operator; | ||
} | ||
} | ||
function isLogicOperator(candidate, operator) { | ||
switch (candidate) { | ||
case AND: | ||
case OR: | ||
case AND_VERBOSE: | ||
case OR_VERBOSE: | ||
return operator === undefined || mapToCanonicalLogicOperator(candidate) === mapToCanonicalLogicOperator(operator); | ||
default: | ||
return false; | ||
} | ||
switch (candidate) { | ||
case AND: | ||
case OR: | ||
case AND_VERBOSE: | ||
case OR_VERBOSE: | ||
return operator === undefined || mapToCanonicalLogicOperator(candidate) === mapToCanonicalLogicOperator(operator); | ||
default: | ||
return false; | ||
} | ||
} | ||
@@ -94,146 +95,232 @@ | ||
var NodeType = { | ||
SELECTOR: "SELECTOR", | ||
VALUE: "VALUE", | ||
COMPARISON: "COMPARISON", | ||
LOGIC: "LOGIC", | ||
SELECTOR: "SELECTOR", | ||
VALUE: "VALUE", | ||
COMPARISON: "COMPARISON", | ||
LOGIC: "LOGIC", | ||
}; | ||
function createNamedNode(node, toString) { | ||
Object.defineProperty(node, "toString", { | ||
value: toString, | ||
enumerable: false, | ||
configurable: false, | ||
writable: false, | ||
}); | ||
return node; | ||
Object.defineProperty(node, "toString", { | ||
value: toString, | ||
enumerable: false, | ||
configurable: false, | ||
writable: false, | ||
}); | ||
return node; | ||
} | ||
function createSelectorNode(selector, skipChecks) { | ||
if (skipChecks === void 0) { skipChecks = false; } | ||
if (!skipChecks) { | ||
if (typeof selector !== "string") { | ||
throw new TypeError("The \"selector\" has to be a \"string\", \"" + String(selector) + "\" passed."); | ||
} | ||
if (!selector || selector.length === 0) { | ||
throw new Error('The "selector" cannot be an empty string.'); | ||
} | ||
var reservedChar = ReservedChars.find(function (reservedChar) { return selector.indexOf(reservedChar) !== -1; }); | ||
if (reservedChar) { | ||
var position = selector.indexOf(reservedChar) + 1; | ||
throw new Error("The \"selector\" contains reserved character '" + reservedChar + "' at position " + position + " in \"" + selector + "\"."); | ||
} | ||
if (skipChecks === void 0) { | ||
skipChecks = false; | ||
} | ||
if (!skipChecks) { | ||
if (typeof selector !== "string") { | ||
throw new TypeError('The "selector" has to be a "string", "' + String(selector) + '" passed.'); | ||
} | ||
return createNamedNode({ | ||
type: NodeType.SELECTOR, | ||
selector: selector, | ||
}, function () { return "SelectorNode(\"" + selector + "\")"; }); | ||
if (!selector || selector.length === 0) { | ||
throw new Error('The "selector" cannot be an empty string.'); | ||
} | ||
var reservedChar = ReservedChars.find(function (reservedChar) { | ||
return selector.indexOf(reservedChar) !== -1; | ||
}); | ||
if (reservedChar) { | ||
var position = selector.indexOf(reservedChar) + 1; | ||
throw new Error( | ||
'The "selector" contains reserved character \'' + | ||
reservedChar + | ||
"' at position " + | ||
position + | ||
' in "' + | ||
selector + | ||
'".' | ||
); | ||
} | ||
} | ||
return createNamedNode( | ||
{ | ||
type: NodeType.SELECTOR, | ||
selector: selector, | ||
}, | ||
function () { | ||
return 'SelectorNode("' + selector + '")'; | ||
} | ||
); | ||
} | ||
function createValueNode(value, skipChecks) { | ||
if (skipChecks === void 0) { skipChecks = false; } | ||
if (!skipChecks) { | ||
if (typeof value !== "string" && !Array.isArray(value)) { | ||
throw new TypeError("The \"value\" has to be a \"string | string[]\", \"" + String(value) + "\" passed."); | ||
} | ||
if (Array.isArray(value) && value.length === 0) { | ||
throw new Error('The "value" cannot be an empty array.'); | ||
} | ||
if (skipChecks === void 0) { | ||
skipChecks = false; | ||
} | ||
if (!skipChecks) { | ||
if (typeof value !== "string" && !Array.isArray(value)) { | ||
throw new TypeError('The "value" has to be a "string | string[]", "' + String(value) + '" passed.'); | ||
} | ||
return createNamedNode({ | ||
type: NodeType.VALUE, | ||
value: value, | ||
}, function () { return "ValueNode(" + JSON.stringify(value) + ")"; }); | ||
if (Array.isArray(value) && value.length === 0) { | ||
throw new Error('The "value" cannot be an empty array.'); | ||
} | ||
} | ||
return createNamedNode( | ||
{ | ||
type: NodeType.VALUE, | ||
value: value, | ||
}, | ||
function () { | ||
return "ValueNode(" + JSON.stringify(value) + ")"; | ||
} | ||
); | ||
} | ||
function createComparisonNode(selector, operator, value, skipChecks) { | ||
if (skipChecks === void 0) { skipChecks = false; } | ||
if (!skipChecks) { | ||
if (!isSelectorNode(selector)) { | ||
throw new TypeError("The \"selector\" has to be a \"SelectorNode\", \"" + String(selector) + "\" passed."); | ||
} | ||
if (typeof operator !== "string") { | ||
throw new TypeError("The \"operator\" has to be a \"SelectorNode\", \"" + String(operator) + "\" passed."); | ||
} | ||
if (!isComparisonOperator(operator)) { | ||
throw new TypeError("The \"operator\" has to be a valid \"ComparisonOperator\", " + String(operator) + " passed."); | ||
} | ||
if (!isValueNode(value)) { | ||
throw new TypeError("The \"value\" has to be a \"ValueNode\", \"" + String(value) + "\" passed."); | ||
} | ||
if (skipChecks === void 0) { | ||
skipChecks = false; | ||
} | ||
if (!skipChecks) { | ||
if (!isSelectorNode(selector)) { | ||
throw new TypeError('The "selector" has to be a "SelectorNode", "' + String(selector) + '" passed.'); | ||
} | ||
return createNamedNode({ | ||
type: NodeType.COMPARISON, | ||
left: selector, | ||
operator: operator, | ||
right: value, | ||
}, function () { return "ComparisonNode(" + selector + "," + operator + "," + value + ")"; }); | ||
if (typeof operator !== "string") { | ||
throw new TypeError('The "operator" has to be a "SelectorNode", "' + String(operator) + '" passed.'); | ||
} | ||
if (!isComparisonOperator(operator)) { | ||
throw new TypeError('The "operator" has to be a valid "ComparisonOperator", ' + String(operator) + " passed."); | ||
} | ||
if (!isValueNode(value)) { | ||
throw new TypeError('The "value" has to be a "ValueNode", "' + String(value) + '" passed.'); | ||
} | ||
} | ||
return createNamedNode( | ||
{ | ||
type: NodeType.COMPARISON, | ||
left: selector, | ||
operator: operator, | ||
right: value, | ||
}, | ||
function () { | ||
return "ComparisonNode(" + selector + "," + operator + "," + value + ")"; | ||
} | ||
); | ||
} | ||
function createLogicNode(left, operator, right, skipChecks) { | ||
if (skipChecks === void 0) { skipChecks = false; } | ||
if (!skipChecks) { | ||
if (!isExpressionNode(left)) { | ||
throw new TypeError("The \"left\" has to be a \"ExpressionNode\", \"" + String(left) + "\" passed."); | ||
} | ||
if (typeof operator !== "string") { | ||
throw new TypeError("The \"operator\" has to be a \"string\", \"" + String(operator) + "\" passed."); | ||
} | ||
if (!isLogicOperator(operator)) { | ||
throw new TypeError("The \"operator\" has to be a valid \"LogicOperator\", " + String(operator) + " passed."); | ||
} | ||
if (!isExpressionNode(right)) { | ||
throw new TypeError("The \"right\" has to be a \"ExpressionNode\", \"" + String(right) + "\" passed."); | ||
} | ||
if (skipChecks === void 0) { | ||
skipChecks = false; | ||
} | ||
if (!skipChecks) { | ||
if (!isExpressionNode(left)) { | ||
throw new TypeError('The "left" has to be a "ExpressionNode", "' + String(left) + '" passed.'); | ||
} | ||
return createNamedNode({ | ||
type: NodeType.LOGIC, | ||
left: left, | ||
operator: operator, | ||
right: right, | ||
}, function () { return "LogicNode(" + left + "," + operator + "," + right + ")"; }); | ||
if (typeof operator !== "string") { | ||
throw new TypeError('The "operator" has to be a "string", "' + String(operator) + '" passed.'); | ||
} | ||
if (!isLogicOperator(operator)) { | ||
throw new TypeError('The "operator" has to be a valid "LogicOperator", ' + String(operator) + " passed."); | ||
} | ||
if (!isExpressionNode(right)) { | ||
throw new TypeError('The "right" has to be a "ExpressionNode", "' + String(right) + '" passed.'); | ||
} | ||
} | ||
return createNamedNode( | ||
{ | ||
type: NodeType.LOGIC, | ||
left: left, | ||
operator: operator, | ||
right: right, | ||
}, | ||
function () { | ||
return "LogicNode(" + left + "," + operator + "," + right + ")"; | ||
} | ||
); | ||
} | ||
function isNode(candidate) { | ||
return candidate !== undefined && candidate !== null && Object.prototype.hasOwnProperty.call(candidate, "type"); | ||
return candidate !== undefined && candidate !== null && Object.prototype.hasOwnProperty.call(candidate, "type"); | ||
} | ||
function isSelectorNode(candidate) { | ||
return isNode(candidate) && candidate.type === NodeType.SELECTOR; | ||
return isNode(candidate) && candidate.type === NodeType.SELECTOR; | ||
} | ||
function isValueNode(candidate) { | ||
return isNode(candidate) && candidate.type === NodeType.VALUE; | ||
return isNode(candidate) && candidate.type === NodeType.VALUE; | ||
} | ||
function isComparisonNode(candidate, operator) { | ||
return (isNode(candidate) && | ||
candidate.type === NodeType.COMPARISON && | ||
(operator === undefined || isComparisonOperator(candidate.operator, operator))); | ||
return ( | ||
isNode(candidate) && | ||
candidate.type === NodeType.COMPARISON && | ||
(operator === undefined || isComparisonOperator(candidate.operator, operator)) | ||
); | ||
} | ||
function isLogicNode(candidate, operator) { | ||
return (isNode(candidate) && | ||
candidate.type === NodeType.LOGIC && | ||
(operator === undefined || isLogicOperator(candidate.operator, operator))); | ||
return ( | ||
isNode(candidate) && | ||
candidate.type === NodeType.LOGIC && | ||
(operator === undefined || isLogicOperator(candidate.operator, operator)) | ||
); | ||
} | ||
function isExpressionNode(candidate) { | ||
return isComparisonNode(candidate) || isLogicNode(candidate); | ||
return isComparisonNode(candidate) || isLogicNode(candidate); | ||
} | ||
function getSelector(comparison) { | ||
if (!isComparisonNode(comparison)) { | ||
throw new TypeError("The \"comparison\" has to be a valid \"ComparisonNode\", " + String(comparison) + " passed."); | ||
} | ||
return comparison.left.selector; | ||
if (!isComparisonNode(comparison)) { | ||
throw new TypeError('The "comparison" has to be a valid "ComparisonNode", ' + String(comparison) + " passed."); | ||
} | ||
return comparison.left.selector; | ||
} | ||
function getValue(comparison) { | ||
if (!isComparisonNode(comparison)) { | ||
throw new TypeError("The \"comparison\" has to be a valid \"ComparisonNode\", " + String(comparison) + " passed."); | ||
} | ||
return comparison.right.value; | ||
if (!isComparisonNode(comparison)) { | ||
throw new TypeError('The "comparison" has to be a valid "ComparisonNode", ' + String(comparison) + " passed."); | ||
} | ||
return comparison.right.value; | ||
} | ||
function getSingleValue(comparison) { | ||
var value = getValue(comparison); | ||
if (Array.isArray(value)) { | ||
throw new Error('The "comparison" passed to the "getSingleValue" function has to contain string value, but contains an array.'); | ||
} | ||
return value; | ||
var value = getValue(comparison); | ||
if (Array.isArray(value)) { | ||
throw new Error( | ||
'The "comparison" passed to the "getSingleValue" function has to contain string value, but contains an array.' | ||
); | ||
} | ||
return value; | ||
} | ||
function getMultiValue(comparison) { | ||
var value = getValue(comparison); | ||
if (typeof value === "string") { | ||
throw new Error('The "comparison" passed to the "getMultiValue" function has to contain array value, but contains a single string.'); | ||
} | ||
return value; | ||
var value = getValue(comparison); | ||
if (typeof value === "string") { | ||
throw new Error( | ||
'The "comparison" passed to the "getMultiValue" function has to contain array value, but contains a single string.' | ||
); | ||
} | ||
return value; | ||
} | ||
export { AND, AND_VERBOSE, CanonicalComparisonOperators, CanonicalLogicOperators, ComparisonOperators, EQ, GE, GE_VERBOSE, GT, GT_VERBOSE, IN, LE, LE_VERBOSE, LT, LT_VERBOSE, LogicOperators, NEQ, OR, OR_VERBOSE, OUT, ReservedChars, VerboseComparisonOperators, VerboseLogicOperators, createComparisonNode, createLogicNode, createSelectorNode, createValueNode, getMultiValue, getSelector, getSingleValue, getValue, isComparisonNode, isComparisonOperator, isExpressionNode, isLogicNode, isLogicOperator, isNode, isSelectorNode, isValueNode }; | ||
export { | ||
AND, | ||
AND_VERBOSE, | ||
CanonicalComparisonOperators, | ||
CanonicalLogicOperators, | ||
ComparisonOperators, | ||
EQ, | ||
GE, | ||
GE_VERBOSE, | ||
GT, | ||
GT_VERBOSE, | ||
IN, | ||
LE, | ||
LE_VERBOSE, | ||
LT, | ||
LT_VERBOSE, | ||
LogicOperators, | ||
NEQ, | ||
OR, | ||
OR_VERBOSE, | ||
OUT, | ||
ReservedChars, | ||
VerboseComparisonOperators, | ||
VerboseLogicOperators, | ||
createComparisonNode, | ||
createLogicNode, | ||
createSelectorNode, | ||
createValueNode, | ||
getMultiValue, | ||
getSelector, | ||
getSingleValue, | ||
getValue, | ||
isComparisonNode, | ||
isComparisonOperator, | ||
isExpressionNode, | ||
isLogicNode, | ||
isLogicOperator, | ||
isNode, | ||
isSelectorNode, | ||
isValueNode, | ||
}; |
@@ -1,4 +0,4 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -21,43 +21,44 @@ var EQ = "=="; | ||
function mapToCanonicalComparisonOperator(operator) { | ||
switch (operator) { | ||
case LE_VERBOSE: | ||
return LE; | ||
case LT_VERBOSE: | ||
return LT; | ||
case GE_VERBOSE: | ||
return GE; | ||
case GT_VERBOSE: | ||
return GT; | ||
default: | ||
return operator; | ||
} | ||
switch (operator) { | ||
case LE_VERBOSE: | ||
return LE; | ||
case LT_VERBOSE: | ||
return LT; | ||
case GE_VERBOSE: | ||
return GE; | ||
case GT_VERBOSE: | ||
return GT; | ||
default: | ||
return operator; | ||
} | ||
} | ||
var CUSTOM_OPERATOR_REGEXP = /^=[a-z]+=$/; | ||
function isCustomComparisonOperator(candidate) { | ||
return candidate.length > 2 && CUSTOM_OPERATOR_REGEXP.test(candidate); | ||
return candidate.length > 2 && CUSTOM_OPERATOR_REGEXP.test(candidate); | ||
} | ||
function isComparisonOperator(candidate, operator) { | ||
switch (candidate) { | ||
case EQ: | ||
case NEQ: | ||
case LE: | ||
case GE: | ||
case LT: | ||
case GT: | ||
case IN: | ||
case OUT: | ||
case LE_VERBOSE: | ||
case GE_VERBOSE: | ||
case LT_VERBOSE: | ||
case GT_VERBOSE: | ||
return (operator === undefined || | ||
mapToCanonicalComparisonOperator(candidate) === mapToCanonicalComparisonOperator(operator)); | ||
default: | ||
if (isCustomComparisonOperator(candidate)) { | ||
return operator === undefined || candidate === operator; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
switch (candidate) { | ||
case EQ: | ||
case NEQ: | ||
case LE: | ||
case GE: | ||
case LT: | ||
case GT: | ||
case IN: | ||
case OUT: | ||
case LE_VERBOSE: | ||
case GE_VERBOSE: | ||
case LT_VERBOSE: | ||
case GT_VERBOSE: | ||
return ( | ||
operator === undefined || | ||
mapToCanonicalComparisonOperator(candidate) === mapToCanonicalComparisonOperator(operator) | ||
); | ||
default: | ||
if (isCustomComparisonOperator(candidate)) { | ||
return operator === undefined || candidate === operator; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
@@ -73,21 +74,21 @@ | ||
function mapToCanonicalLogicOperator(operator) { | ||
switch (operator) { | ||
case AND_VERBOSE: | ||
return AND; | ||
case OR_VERBOSE: | ||
return OR; | ||
default: | ||
return operator; | ||
} | ||
switch (operator) { | ||
case AND_VERBOSE: | ||
return AND; | ||
case OR_VERBOSE: | ||
return OR; | ||
default: | ||
return operator; | ||
} | ||
} | ||
function isLogicOperator(candidate, operator) { | ||
switch (candidate) { | ||
case AND: | ||
case OR: | ||
case AND_VERBOSE: | ||
case OR_VERBOSE: | ||
return operator === undefined || mapToCanonicalLogicOperator(candidate) === mapToCanonicalLogicOperator(operator); | ||
default: | ||
return false; | ||
} | ||
switch (candidate) { | ||
case AND: | ||
case OR: | ||
case AND_VERBOSE: | ||
case OR_VERBOSE: | ||
return operator === undefined || mapToCanonicalLogicOperator(candidate) === mapToCanonicalLogicOperator(operator); | ||
default: | ||
return false; | ||
} | ||
} | ||
@@ -98,144 +99,190 @@ | ||
var NodeType = { | ||
SELECTOR: "SELECTOR", | ||
VALUE: "VALUE", | ||
COMPARISON: "COMPARISON", | ||
LOGIC: "LOGIC", | ||
SELECTOR: "SELECTOR", | ||
VALUE: "VALUE", | ||
COMPARISON: "COMPARISON", | ||
LOGIC: "LOGIC", | ||
}; | ||
function createNamedNode(node, toString) { | ||
Object.defineProperty(node, "toString", { | ||
value: toString, | ||
enumerable: false, | ||
configurable: false, | ||
writable: false, | ||
}); | ||
return node; | ||
Object.defineProperty(node, "toString", { | ||
value: toString, | ||
enumerable: false, | ||
configurable: false, | ||
writable: false, | ||
}); | ||
return node; | ||
} | ||
function createSelectorNode(selector, skipChecks) { | ||
if (skipChecks === void 0) { skipChecks = false; } | ||
if (!skipChecks) { | ||
if (typeof selector !== "string") { | ||
throw new TypeError("The \"selector\" has to be a \"string\", \"" + String(selector) + "\" passed."); | ||
} | ||
if (!selector || selector.length === 0) { | ||
throw new Error('The "selector" cannot be an empty string.'); | ||
} | ||
var reservedChar = ReservedChars.find(function (reservedChar) { return selector.indexOf(reservedChar) !== -1; }); | ||
if (reservedChar) { | ||
var position = selector.indexOf(reservedChar) + 1; | ||
throw new Error("The \"selector\" contains reserved character '" + reservedChar + "' at position " + position + " in \"" + selector + "\"."); | ||
} | ||
if (skipChecks === void 0) { | ||
skipChecks = false; | ||
} | ||
if (!skipChecks) { | ||
if (typeof selector !== "string") { | ||
throw new TypeError('The "selector" has to be a "string", "' + String(selector) + '" passed.'); | ||
} | ||
return createNamedNode({ | ||
type: NodeType.SELECTOR, | ||
selector: selector, | ||
}, function () { return "SelectorNode(\"" + selector + "\")"; }); | ||
if (!selector || selector.length === 0) { | ||
throw new Error('The "selector" cannot be an empty string.'); | ||
} | ||
var reservedChar = ReservedChars.find(function (reservedChar) { | ||
return selector.indexOf(reservedChar) !== -1; | ||
}); | ||
if (reservedChar) { | ||
var position = selector.indexOf(reservedChar) + 1; | ||
throw new Error( | ||
'The "selector" contains reserved character \'' + | ||
reservedChar + | ||
"' at position " + | ||
position + | ||
' in "' + | ||
selector + | ||
'".' | ||
); | ||
} | ||
} | ||
return createNamedNode( | ||
{ | ||
type: NodeType.SELECTOR, | ||
selector: selector, | ||
}, | ||
function () { | ||
return 'SelectorNode("' + selector + '")'; | ||
} | ||
); | ||
} | ||
function createValueNode(value, skipChecks) { | ||
if (skipChecks === void 0) { skipChecks = false; } | ||
if (!skipChecks) { | ||
if (typeof value !== "string" && !Array.isArray(value)) { | ||
throw new TypeError("The \"value\" has to be a \"string | string[]\", \"" + String(value) + "\" passed."); | ||
} | ||
if (Array.isArray(value) && value.length === 0) { | ||
throw new Error('The "value" cannot be an empty array.'); | ||
} | ||
if (skipChecks === void 0) { | ||
skipChecks = false; | ||
} | ||
if (!skipChecks) { | ||
if (typeof value !== "string" && !Array.isArray(value)) { | ||
throw new TypeError('The "value" has to be a "string | string[]", "' + String(value) + '" passed.'); | ||
} | ||
return createNamedNode({ | ||
type: NodeType.VALUE, | ||
value: value, | ||
}, function () { return "ValueNode(" + JSON.stringify(value) + ")"; }); | ||
if (Array.isArray(value) && value.length === 0) { | ||
throw new Error('The "value" cannot be an empty array.'); | ||
} | ||
} | ||
return createNamedNode( | ||
{ | ||
type: NodeType.VALUE, | ||
value: value, | ||
}, | ||
function () { | ||
return "ValueNode(" + JSON.stringify(value) + ")"; | ||
} | ||
); | ||
} | ||
function createComparisonNode(selector, operator, value, skipChecks) { | ||
if (skipChecks === void 0) { skipChecks = false; } | ||
if (!skipChecks) { | ||
if (!isSelectorNode(selector)) { | ||
throw new TypeError("The \"selector\" has to be a \"SelectorNode\", \"" + String(selector) + "\" passed."); | ||
} | ||
if (typeof operator !== "string") { | ||
throw new TypeError("The \"operator\" has to be a \"SelectorNode\", \"" + String(operator) + "\" passed."); | ||
} | ||
if (!isComparisonOperator(operator)) { | ||
throw new TypeError("The \"operator\" has to be a valid \"ComparisonOperator\", " + String(operator) + " passed."); | ||
} | ||
if (!isValueNode(value)) { | ||
throw new TypeError("The \"value\" has to be a \"ValueNode\", \"" + String(value) + "\" passed."); | ||
} | ||
if (skipChecks === void 0) { | ||
skipChecks = false; | ||
} | ||
if (!skipChecks) { | ||
if (!isSelectorNode(selector)) { | ||
throw new TypeError('The "selector" has to be a "SelectorNode", "' + String(selector) + '" passed.'); | ||
} | ||
return createNamedNode({ | ||
type: NodeType.COMPARISON, | ||
left: selector, | ||
operator: operator, | ||
right: value, | ||
}, function () { return "ComparisonNode(" + selector + "," + operator + "," + value + ")"; }); | ||
if (typeof operator !== "string") { | ||
throw new TypeError('The "operator" has to be a "SelectorNode", "' + String(operator) + '" passed.'); | ||
} | ||
if (!isComparisonOperator(operator)) { | ||
throw new TypeError('The "operator" has to be a valid "ComparisonOperator", ' + String(operator) + " passed."); | ||
} | ||
if (!isValueNode(value)) { | ||
throw new TypeError('The "value" has to be a "ValueNode", "' + String(value) + '" passed.'); | ||
} | ||
} | ||
return createNamedNode( | ||
{ | ||
type: NodeType.COMPARISON, | ||
left: selector, | ||
operator: operator, | ||
right: value, | ||
}, | ||
function () { | ||
return "ComparisonNode(" + selector + "," + operator + "," + value + ")"; | ||
} | ||
); | ||
} | ||
function createLogicNode(left, operator, right, skipChecks) { | ||
if (skipChecks === void 0) { skipChecks = false; } | ||
if (!skipChecks) { | ||
if (!isExpressionNode(left)) { | ||
throw new TypeError("The \"left\" has to be a \"ExpressionNode\", \"" + String(left) + "\" passed."); | ||
} | ||
if (typeof operator !== "string") { | ||
throw new TypeError("The \"operator\" has to be a \"string\", \"" + String(operator) + "\" passed."); | ||
} | ||
if (!isLogicOperator(operator)) { | ||
throw new TypeError("The \"operator\" has to be a valid \"LogicOperator\", " + String(operator) + " passed."); | ||
} | ||
if (!isExpressionNode(right)) { | ||
throw new TypeError("The \"right\" has to be a \"ExpressionNode\", \"" + String(right) + "\" passed."); | ||
} | ||
if (skipChecks === void 0) { | ||
skipChecks = false; | ||
} | ||
if (!skipChecks) { | ||
if (!isExpressionNode(left)) { | ||
throw new TypeError('The "left" has to be a "ExpressionNode", "' + String(left) + '" passed.'); | ||
} | ||
return createNamedNode({ | ||
type: NodeType.LOGIC, | ||
left: left, | ||
operator: operator, | ||
right: right, | ||
}, function () { return "LogicNode(" + left + "," + operator + "," + right + ")"; }); | ||
if (typeof operator !== "string") { | ||
throw new TypeError('The "operator" has to be a "string", "' + String(operator) + '" passed.'); | ||
} | ||
if (!isLogicOperator(operator)) { | ||
throw new TypeError('The "operator" has to be a valid "LogicOperator", ' + String(operator) + " passed."); | ||
} | ||
if (!isExpressionNode(right)) { | ||
throw new TypeError('The "right" has to be a "ExpressionNode", "' + String(right) + '" passed.'); | ||
} | ||
} | ||
return createNamedNode( | ||
{ | ||
type: NodeType.LOGIC, | ||
left: left, | ||
operator: operator, | ||
right: right, | ||
}, | ||
function () { | ||
return "LogicNode(" + left + "," + operator + "," + right + ")"; | ||
} | ||
); | ||
} | ||
function isNode(candidate) { | ||
return candidate !== undefined && candidate !== null && Object.prototype.hasOwnProperty.call(candidate, "type"); | ||
return candidate !== undefined && candidate !== null && Object.prototype.hasOwnProperty.call(candidate, "type"); | ||
} | ||
function isSelectorNode(candidate) { | ||
return isNode(candidate) && candidate.type === NodeType.SELECTOR; | ||
return isNode(candidate) && candidate.type === NodeType.SELECTOR; | ||
} | ||
function isValueNode(candidate) { | ||
return isNode(candidate) && candidate.type === NodeType.VALUE; | ||
return isNode(candidate) && candidate.type === NodeType.VALUE; | ||
} | ||
function isComparisonNode(candidate, operator) { | ||
return (isNode(candidate) && | ||
candidate.type === NodeType.COMPARISON && | ||
(operator === undefined || isComparisonOperator(candidate.operator, operator))); | ||
return ( | ||
isNode(candidate) && | ||
candidate.type === NodeType.COMPARISON && | ||
(operator === undefined || isComparisonOperator(candidate.operator, operator)) | ||
); | ||
} | ||
function isLogicNode(candidate, operator) { | ||
return (isNode(candidate) && | ||
candidate.type === NodeType.LOGIC && | ||
(operator === undefined || isLogicOperator(candidate.operator, operator))); | ||
return ( | ||
isNode(candidate) && | ||
candidate.type === NodeType.LOGIC && | ||
(operator === undefined || isLogicOperator(candidate.operator, operator)) | ||
); | ||
} | ||
function isExpressionNode(candidate) { | ||
return isComparisonNode(candidate) || isLogicNode(candidate); | ||
return isComparisonNode(candidate) || isLogicNode(candidate); | ||
} | ||
function getSelector(comparison) { | ||
if (!isComparisonNode(comparison)) { | ||
throw new TypeError("The \"comparison\" has to be a valid \"ComparisonNode\", " + String(comparison) + " passed."); | ||
} | ||
return comparison.left.selector; | ||
if (!isComparisonNode(comparison)) { | ||
throw new TypeError('The "comparison" has to be a valid "ComparisonNode", ' + String(comparison) + " passed."); | ||
} | ||
return comparison.left.selector; | ||
} | ||
function getValue(comparison) { | ||
if (!isComparisonNode(comparison)) { | ||
throw new TypeError("The \"comparison\" has to be a valid \"ComparisonNode\", " + String(comparison) + " passed."); | ||
} | ||
return comparison.right.value; | ||
if (!isComparisonNode(comparison)) { | ||
throw new TypeError('The "comparison" has to be a valid "ComparisonNode", ' + String(comparison) + " passed."); | ||
} | ||
return comparison.right.value; | ||
} | ||
function getSingleValue(comparison) { | ||
var value = getValue(comparison); | ||
if (Array.isArray(value)) { | ||
throw new Error('The "comparison" passed to the "getSingleValue" function has to contain string value, but contains an array.'); | ||
} | ||
return value; | ||
var value = getValue(comparison); | ||
if (Array.isArray(value)) { | ||
throw new Error( | ||
'The "comparison" passed to the "getSingleValue" function has to contain string value, but contains an array.' | ||
); | ||
} | ||
return value; | ||
} | ||
function getMultiValue(comparison) { | ||
var value = getValue(comparison); | ||
if (typeof value === "string") { | ||
throw new Error('The "comparison" passed to the "getMultiValue" function has to contain array value, but contains a single string.'); | ||
} | ||
return value; | ||
var value = getValue(comparison); | ||
if (typeof value === "string") { | ||
throw new Error( | ||
'The "comparison" passed to the "getMultiValue" function has to contain array value, but contains a single string.' | ||
); | ||
} | ||
return value; | ||
} | ||
@@ -242,0 +289,0 @@ |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.RSQLAst = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
typeof exports === "object" && typeof module !== "undefined" | ||
? factory(exports) | ||
: typeof define === "function" && define.amd | ||
? define(["exports"], factory) | ||
: ((global = global || self), factory((global.RSQLAst = {}))); | ||
})(this, function (exports) { | ||
"use strict"; | ||
var EQ = "=="; | ||
var NEQ = "!="; | ||
var LE = "<="; | ||
var GE = ">="; | ||
var LT = "<"; | ||
var GT = ">"; | ||
var IN = "=in="; | ||
var OUT = "=out="; | ||
var LE_VERBOSE = "=le="; | ||
var GE_VERBOSE = "=ge="; | ||
var LT_VERBOSE = "=lt="; | ||
var GT_VERBOSE = "=gt="; | ||
var CanonicalComparisonOperators = [EQ, NEQ, LE, GE, LT, GT, IN, OUT]; | ||
var VerboseComparisonOperators = [LE_VERBOSE, GE_VERBOSE, LT_VERBOSE, GT_VERBOSE]; | ||
var ComparisonOperators = [EQ, NEQ, LE, GE, LT, GT, IN, OUT, LE_VERBOSE, GE_VERBOSE, LT_VERBOSE, GT_VERBOSE]; | ||
function mapToCanonicalComparisonOperator(operator) { | ||
switch (operator) { | ||
case LE_VERBOSE: | ||
return LE; | ||
case LT_VERBOSE: | ||
return LT; | ||
case GE_VERBOSE: | ||
return GE; | ||
case GT_VERBOSE: | ||
return GT; | ||
default: | ||
return operator; | ||
} | ||
var EQ = "=="; | ||
var NEQ = "!="; | ||
var LE = "<="; | ||
var GE = ">="; | ||
var LT = "<"; | ||
var GT = ">"; | ||
var IN = "=in="; | ||
var OUT = "=out="; | ||
var LE_VERBOSE = "=le="; | ||
var GE_VERBOSE = "=ge="; | ||
var LT_VERBOSE = "=lt="; | ||
var GT_VERBOSE = "=gt="; | ||
var CanonicalComparisonOperators = [EQ, NEQ, LE, GE, LT, GT, IN, OUT]; | ||
var VerboseComparisonOperators = [LE_VERBOSE, GE_VERBOSE, LT_VERBOSE, GT_VERBOSE]; | ||
var ComparisonOperators = [EQ, NEQ, LE, GE, LT, GT, IN, OUT, LE_VERBOSE, GE_VERBOSE, LT_VERBOSE, GT_VERBOSE]; | ||
function mapToCanonicalComparisonOperator(operator) { | ||
switch (operator) { | ||
case LE_VERBOSE: | ||
return LE; | ||
case LT_VERBOSE: | ||
return LT; | ||
case GE_VERBOSE: | ||
return GE; | ||
case GT_VERBOSE: | ||
return GT; | ||
default: | ||
return operator; | ||
} | ||
var CUSTOM_OPERATOR_REGEXP = /^=[a-z]+=$/; | ||
function isCustomComparisonOperator(candidate) { | ||
return candidate.length > 2 && CUSTOM_OPERATOR_REGEXP.test(candidate); | ||
} | ||
function isComparisonOperator(candidate, operator) { | ||
switch (candidate) { | ||
case EQ: | ||
case NEQ: | ||
case LE: | ||
case GE: | ||
case LT: | ||
case GT: | ||
case IN: | ||
case OUT: | ||
case LE_VERBOSE: | ||
case GE_VERBOSE: | ||
case LT_VERBOSE: | ||
case GT_VERBOSE: | ||
return (operator === undefined || | ||
mapToCanonicalComparisonOperator(candidate) === mapToCanonicalComparisonOperator(operator)); | ||
default: | ||
if (isCustomComparisonOperator(candidate)) { | ||
return operator === undefined || candidate === operator; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
var CUSTOM_OPERATOR_REGEXP = /^=[a-z]+=$/; | ||
function isCustomComparisonOperator(candidate) { | ||
return candidate.length > 2 && CUSTOM_OPERATOR_REGEXP.test(candidate); | ||
} | ||
function isComparisonOperator(candidate, operator) { | ||
switch (candidate) { | ||
case EQ: | ||
case NEQ: | ||
case LE: | ||
case GE: | ||
case LT: | ||
case GT: | ||
case IN: | ||
case OUT: | ||
case LE_VERBOSE: | ||
case GE_VERBOSE: | ||
case LT_VERBOSE: | ||
case GT_VERBOSE: | ||
return ( | ||
operator === undefined || | ||
mapToCanonicalComparisonOperator(candidate) === mapToCanonicalComparisonOperator(operator) | ||
); | ||
default: | ||
if (isCustomComparisonOperator(candidate)) { | ||
return operator === undefined || candidate === operator; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
var AND = ";"; | ||
var OR = ","; | ||
var AND_VERBOSE = "and"; | ||
var OR_VERBOSE = "or"; | ||
var CanonicalLogicOperators = [AND, OR]; | ||
var VerboseLogicOperators = [AND_VERBOSE, OR_VERBOSE]; | ||
var LogicOperators = [AND, OR, AND_VERBOSE, OR_VERBOSE]; | ||
function mapToCanonicalLogicOperator(operator) { | ||
switch (operator) { | ||
case AND_VERBOSE: | ||
return AND; | ||
case OR_VERBOSE: | ||
return OR; | ||
default: | ||
return operator; | ||
} | ||
var AND = ";"; | ||
var OR = ","; | ||
var AND_VERBOSE = "and"; | ||
var OR_VERBOSE = "or"; | ||
var CanonicalLogicOperators = [AND, OR]; | ||
var VerboseLogicOperators = [AND_VERBOSE, OR_VERBOSE]; | ||
var LogicOperators = [AND, OR, AND_VERBOSE, OR_VERBOSE]; | ||
function mapToCanonicalLogicOperator(operator) { | ||
switch (operator) { | ||
case AND_VERBOSE: | ||
return AND; | ||
case OR_VERBOSE: | ||
return OR; | ||
default: | ||
return operator; | ||
} | ||
function isLogicOperator(candidate, operator) { | ||
switch (candidate) { | ||
case AND: | ||
case OR: | ||
case AND_VERBOSE: | ||
case OR_VERBOSE: | ||
return operator === undefined || mapToCanonicalLogicOperator(candidate) === mapToCanonicalLogicOperator(operator); | ||
default: | ||
return false; | ||
} | ||
} | ||
function isLogicOperator(candidate, operator) { | ||
switch (candidate) { | ||
case AND: | ||
case OR: | ||
case AND_VERBOSE: | ||
case OR_VERBOSE: | ||
return ( | ||
operator === undefined || mapToCanonicalLogicOperator(candidate) === mapToCanonicalLogicOperator(operator) | ||
); | ||
default: | ||
return false; | ||
} | ||
} | ||
var ReservedChars = ['"', "'", "(", ")", ";", ",", "=", "!", "~", "<", ">", " ", "\n", "\t", "\r"]; | ||
var ReservedChars = ['"', "'", "(", ")", ";", ",", "=", "!", "~", "<", ">", " ", "\n", "\t", "\r"]; | ||
var NodeType = { | ||
SELECTOR: "SELECTOR", | ||
VALUE: "VALUE", | ||
COMPARISON: "COMPARISON", | ||
LOGIC: "LOGIC", | ||
}; | ||
function createNamedNode(node, toString) { | ||
Object.defineProperty(node, "toString", { | ||
value: toString, | ||
enumerable: false, | ||
configurable: false, | ||
writable: false, | ||
}); | ||
return node; | ||
var NodeType = { | ||
SELECTOR: "SELECTOR", | ||
VALUE: "VALUE", | ||
COMPARISON: "COMPARISON", | ||
LOGIC: "LOGIC", | ||
}; | ||
function createNamedNode(node, toString) { | ||
Object.defineProperty(node, "toString", { | ||
value: toString, | ||
enumerable: false, | ||
configurable: false, | ||
writable: false, | ||
}); | ||
return node; | ||
} | ||
function createSelectorNode(selector, skipChecks) { | ||
if (skipChecks === void 0) { | ||
skipChecks = false; | ||
} | ||
function createSelectorNode(selector, skipChecks) { | ||
if (skipChecks === void 0) { skipChecks = false; } | ||
if (!skipChecks) { | ||
if (typeof selector !== "string") { | ||
throw new TypeError("The \"selector\" has to be a \"string\", \"" + String(selector) + "\" passed."); | ||
} | ||
if (!selector || selector.length === 0) { | ||
throw new Error('The "selector" cannot be an empty string.'); | ||
} | ||
var reservedChar = ReservedChars.find(function (reservedChar) { return selector.indexOf(reservedChar) !== -1; }); | ||
if (reservedChar) { | ||
var position = selector.indexOf(reservedChar) + 1; | ||
throw new Error("The \"selector\" contains reserved character '" + reservedChar + "' at position " + position + " in \"" + selector + "\"."); | ||
} | ||
} | ||
return createNamedNode({ | ||
type: NodeType.SELECTOR, | ||
selector: selector, | ||
}, function () { return "SelectorNode(\"" + selector + "\")"; }); | ||
if (!skipChecks) { | ||
if (typeof selector !== "string") { | ||
throw new TypeError('The "selector" has to be a "string", "' + String(selector) + '" passed.'); | ||
} | ||
if (!selector || selector.length === 0) { | ||
throw new Error('The "selector" cannot be an empty string.'); | ||
} | ||
var reservedChar = ReservedChars.find(function (reservedChar) { | ||
return selector.indexOf(reservedChar) !== -1; | ||
}); | ||
if (reservedChar) { | ||
var position = selector.indexOf(reservedChar) + 1; | ||
throw new Error( | ||
'The "selector" contains reserved character \'' + | ||
reservedChar + | ||
"' at position " + | ||
position + | ||
' in "' + | ||
selector + | ||
'".' | ||
); | ||
} | ||
} | ||
function createValueNode(value, skipChecks) { | ||
if (skipChecks === void 0) { skipChecks = false; } | ||
if (!skipChecks) { | ||
if (typeof value !== "string" && !Array.isArray(value)) { | ||
throw new TypeError("The \"value\" has to be a \"string | string[]\", \"" + String(value) + "\" passed."); | ||
} | ||
if (Array.isArray(value) && value.length === 0) { | ||
throw new Error('The "value" cannot be an empty array.'); | ||
} | ||
} | ||
return createNamedNode({ | ||
type: NodeType.VALUE, | ||
value: value, | ||
}, function () { return "ValueNode(" + JSON.stringify(value) + ")"; }); | ||
return createNamedNode( | ||
{ | ||
type: NodeType.SELECTOR, | ||
selector: selector, | ||
}, | ||
function () { | ||
return 'SelectorNode("' + selector + '")'; | ||
} | ||
); | ||
} | ||
function createValueNode(value, skipChecks) { | ||
if (skipChecks === void 0) { | ||
skipChecks = false; | ||
} | ||
function createComparisonNode(selector, operator, value, skipChecks) { | ||
if (skipChecks === void 0) { skipChecks = false; } | ||
if (!skipChecks) { | ||
if (!isSelectorNode(selector)) { | ||
throw new TypeError("The \"selector\" has to be a \"SelectorNode\", \"" + String(selector) + "\" passed."); | ||
} | ||
if (typeof operator !== "string") { | ||
throw new TypeError("The \"operator\" has to be a \"SelectorNode\", \"" + String(operator) + "\" passed."); | ||
} | ||
if (!isComparisonOperator(operator)) { | ||
throw new TypeError("The \"operator\" has to be a valid \"ComparisonOperator\", " + String(operator) + " passed."); | ||
} | ||
if (!isValueNode(value)) { | ||
throw new TypeError("The \"value\" has to be a \"ValueNode\", \"" + String(value) + "\" passed."); | ||
} | ||
} | ||
return createNamedNode({ | ||
type: NodeType.COMPARISON, | ||
left: selector, | ||
operator: operator, | ||
right: value, | ||
}, function () { return "ComparisonNode(" + selector + "," + operator + "," + value + ")"; }); | ||
if (!skipChecks) { | ||
if (typeof value !== "string" && !Array.isArray(value)) { | ||
throw new TypeError('The "value" has to be a "string | string[]", "' + String(value) + '" passed.'); | ||
} | ||
if (Array.isArray(value) && value.length === 0) { | ||
throw new Error('The "value" cannot be an empty array.'); | ||
} | ||
} | ||
function createLogicNode(left, operator, right, skipChecks) { | ||
if (skipChecks === void 0) { skipChecks = false; } | ||
if (!skipChecks) { | ||
if (!isExpressionNode(left)) { | ||
throw new TypeError("The \"left\" has to be a \"ExpressionNode\", \"" + String(left) + "\" passed."); | ||
} | ||
if (typeof operator !== "string") { | ||
throw new TypeError("The \"operator\" has to be a \"string\", \"" + String(operator) + "\" passed."); | ||
} | ||
if (!isLogicOperator(operator)) { | ||
throw new TypeError("The \"operator\" has to be a valid \"LogicOperator\", " + String(operator) + " passed."); | ||
} | ||
if (!isExpressionNode(right)) { | ||
throw new TypeError("The \"right\" has to be a \"ExpressionNode\", \"" + String(right) + "\" passed."); | ||
} | ||
} | ||
return createNamedNode({ | ||
type: NodeType.LOGIC, | ||
left: left, | ||
operator: operator, | ||
right: right, | ||
}, function () { return "LogicNode(" + left + "," + operator + "," + right + ")"; }); | ||
return createNamedNode( | ||
{ | ||
type: NodeType.VALUE, | ||
value: value, | ||
}, | ||
function () { | ||
return "ValueNode(" + JSON.stringify(value) + ")"; | ||
} | ||
); | ||
} | ||
function createComparisonNode(selector, operator, value, skipChecks) { | ||
if (skipChecks === void 0) { | ||
skipChecks = false; | ||
} | ||
function isNode(candidate) { | ||
return candidate !== undefined && candidate !== null && Object.prototype.hasOwnProperty.call(candidate, "type"); | ||
if (!skipChecks) { | ||
if (!isSelectorNode(selector)) { | ||
throw new TypeError('The "selector" has to be a "SelectorNode", "' + String(selector) + '" passed.'); | ||
} | ||
if (typeof operator !== "string") { | ||
throw new TypeError('The "operator" has to be a "SelectorNode", "' + String(operator) + '" passed.'); | ||
} | ||
if (!isComparisonOperator(operator)) { | ||
throw new TypeError('The "operator" has to be a valid "ComparisonOperator", ' + String(operator) + " passed."); | ||
} | ||
if (!isValueNode(value)) { | ||
throw new TypeError('The "value" has to be a "ValueNode", "' + String(value) + '" passed.'); | ||
} | ||
} | ||
function isSelectorNode(candidate) { | ||
return isNode(candidate) && candidate.type === NodeType.SELECTOR; | ||
return createNamedNode( | ||
{ | ||
type: NodeType.COMPARISON, | ||
left: selector, | ||
operator: operator, | ||
right: value, | ||
}, | ||
function () { | ||
return "ComparisonNode(" + selector + "," + operator + "," + value + ")"; | ||
} | ||
); | ||
} | ||
function createLogicNode(left, operator, right, skipChecks) { | ||
if (skipChecks === void 0) { | ||
skipChecks = false; | ||
} | ||
function isValueNode(candidate) { | ||
return isNode(candidate) && candidate.type === NodeType.VALUE; | ||
if (!skipChecks) { | ||
if (!isExpressionNode(left)) { | ||
throw new TypeError('The "left" has to be a "ExpressionNode", "' + String(left) + '" passed.'); | ||
} | ||
if (typeof operator !== "string") { | ||
throw new TypeError('The "operator" has to be a "string", "' + String(operator) + '" passed.'); | ||
} | ||
if (!isLogicOperator(operator)) { | ||
throw new TypeError('The "operator" has to be a valid "LogicOperator", ' + String(operator) + " passed."); | ||
} | ||
if (!isExpressionNode(right)) { | ||
throw new TypeError('The "right" has to be a "ExpressionNode", "' + String(right) + '" passed.'); | ||
} | ||
} | ||
function isComparisonNode(candidate, operator) { | ||
return (isNode(candidate) && | ||
candidate.type === NodeType.COMPARISON && | ||
(operator === undefined || isComparisonOperator(candidate.operator, operator))); | ||
return createNamedNode( | ||
{ | ||
type: NodeType.LOGIC, | ||
left: left, | ||
operator: operator, | ||
right: right, | ||
}, | ||
function () { | ||
return "LogicNode(" + left + "," + operator + "," + right + ")"; | ||
} | ||
); | ||
} | ||
function isNode(candidate) { | ||
return candidate !== undefined && candidate !== null && Object.prototype.hasOwnProperty.call(candidate, "type"); | ||
} | ||
function isSelectorNode(candidate) { | ||
return isNode(candidate) && candidate.type === NodeType.SELECTOR; | ||
} | ||
function isValueNode(candidate) { | ||
return isNode(candidate) && candidate.type === NodeType.VALUE; | ||
} | ||
function isComparisonNode(candidate, operator) { | ||
return ( | ||
isNode(candidate) && | ||
candidate.type === NodeType.COMPARISON && | ||
(operator === undefined || isComparisonOperator(candidate.operator, operator)) | ||
); | ||
} | ||
function isLogicNode(candidate, operator) { | ||
return ( | ||
isNode(candidate) && | ||
candidate.type === NodeType.LOGIC && | ||
(operator === undefined || isLogicOperator(candidate.operator, operator)) | ||
); | ||
} | ||
function isExpressionNode(candidate) { | ||
return isComparisonNode(candidate) || isLogicNode(candidate); | ||
} | ||
function getSelector(comparison) { | ||
if (!isComparisonNode(comparison)) { | ||
throw new TypeError('The "comparison" has to be a valid "ComparisonNode", ' + String(comparison) + " passed."); | ||
} | ||
function isLogicNode(candidate, operator) { | ||
return (isNode(candidate) && | ||
candidate.type === NodeType.LOGIC && | ||
(operator === undefined || isLogicOperator(candidate.operator, operator))); | ||
return comparison.left.selector; | ||
} | ||
function getValue(comparison) { | ||
if (!isComparisonNode(comparison)) { | ||
throw new TypeError('The "comparison" has to be a valid "ComparisonNode", ' + String(comparison) + " passed."); | ||
} | ||
function isExpressionNode(candidate) { | ||
return isComparisonNode(candidate) || isLogicNode(candidate); | ||
return comparison.right.value; | ||
} | ||
function getSingleValue(comparison) { | ||
var value = getValue(comparison); | ||
if (Array.isArray(value)) { | ||
throw new Error( | ||
'The "comparison" passed to the "getSingleValue" function has to contain string value, but contains an array.' | ||
); | ||
} | ||
function getSelector(comparison) { | ||
if (!isComparisonNode(comparison)) { | ||
throw new TypeError("The \"comparison\" has to be a valid \"ComparisonNode\", " + String(comparison) + " passed."); | ||
} | ||
return comparison.left.selector; | ||
return value; | ||
} | ||
function getMultiValue(comparison) { | ||
var value = getValue(comparison); | ||
if (typeof value === "string") { | ||
throw new Error( | ||
'The "comparison" passed to the "getMultiValue" function has to contain array value, but contains a single string.' | ||
); | ||
} | ||
function getValue(comparison) { | ||
if (!isComparisonNode(comparison)) { | ||
throw new TypeError("The \"comparison\" has to be a valid \"ComparisonNode\", " + String(comparison) + " passed."); | ||
} | ||
return comparison.right.value; | ||
} | ||
function getSingleValue(comparison) { | ||
var value = getValue(comparison); | ||
if (Array.isArray(value)) { | ||
throw new Error('The "comparison" passed to the "getSingleValue" function has to contain string value, but contains an array.'); | ||
} | ||
return value; | ||
} | ||
function getMultiValue(comparison) { | ||
var value = getValue(comparison); | ||
if (typeof value === "string") { | ||
throw new Error('The "comparison" passed to the "getMultiValue" function has to contain array value, but contains a single string.'); | ||
} | ||
return value; | ||
} | ||
return value; | ||
} | ||
exports.AND = AND; | ||
exports.AND_VERBOSE = AND_VERBOSE; | ||
exports.CanonicalComparisonOperators = CanonicalComparisonOperators; | ||
exports.CanonicalLogicOperators = CanonicalLogicOperators; | ||
exports.ComparisonOperators = ComparisonOperators; | ||
exports.EQ = EQ; | ||
exports.GE = GE; | ||
exports.GE_VERBOSE = GE_VERBOSE; | ||
exports.GT = GT; | ||
exports.GT_VERBOSE = GT_VERBOSE; | ||
exports.IN = IN; | ||
exports.LE = LE; | ||
exports.LE_VERBOSE = LE_VERBOSE; | ||
exports.LT = LT; | ||
exports.LT_VERBOSE = LT_VERBOSE; | ||
exports.LogicOperators = LogicOperators; | ||
exports.NEQ = NEQ; | ||
exports.OR = OR; | ||
exports.OR_VERBOSE = OR_VERBOSE; | ||
exports.OUT = OUT; | ||
exports.ReservedChars = ReservedChars; | ||
exports.VerboseComparisonOperators = VerboseComparisonOperators; | ||
exports.VerboseLogicOperators = VerboseLogicOperators; | ||
exports.createComparisonNode = createComparisonNode; | ||
exports.createLogicNode = createLogicNode; | ||
exports.createSelectorNode = createSelectorNode; | ||
exports.createValueNode = createValueNode; | ||
exports.getMultiValue = getMultiValue; | ||
exports.getSelector = getSelector; | ||
exports.getSingleValue = getSingleValue; | ||
exports.getValue = getValue; | ||
exports.isComparisonNode = isComparisonNode; | ||
exports.isComparisonOperator = isComparisonOperator; | ||
exports.isExpressionNode = isExpressionNode; | ||
exports.isLogicNode = isLogicNode; | ||
exports.isLogicOperator = isLogicOperator; | ||
exports.isNode = isNode; | ||
exports.isSelectorNode = isSelectorNode; | ||
exports.isValueNode = isValueNode; | ||
exports.AND = AND; | ||
exports.AND_VERBOSE = AND_VERBOSE; | ||
exports.CanonicalComparisonOperators = CanonicalComparisonOperators; | ||
exports.CanonicalLogicOperators = CanonicalLogicOperators; | ||
exports.ComparisonOperators = ComparisonOperators; | ||
exports.EQ = EQ; | ||
exports.GE = GE; | ||
exports.GE_VERBOSE = GE_VERBOSE; | ||
exports.GT = GT; | ||
exports.GT_VERBOSE = GT_VERBOSE; | ||
exports.IN = IN; | ||
exports.LE = LE; | ||
exports.LE_VERBOSE = LE_VERBOSE; | ||
exports.LT = LT; | ||
exports.LT_VERBOSE = LT_VERBOSE; | ||
exports.LogicOperators = LogicOperators; | ||
exports.NEQ = NEQ; | ||
exports.OR = OR; | ||
exports.OR_VERBOSE = OR_VERBOSE; | ||
exports.OUT = OUT; | ||
exports.ReservedChars = ReservedChars; | ||
exports.VerboseComparisonOperators = VerboseComparisonOperators; | ||
exports.VerboseLogicOperators = VerboseLogicOperators; | ||
exports.createComparisonNode = createComparisonNode; | ||
exports.createLogicNode = createLogicNode; | ||
exports.createSelectorNode = createSelectorNode; | ||
exports.createValueNode = createValueNode; | ||
exports.getMultiValue = getMultiValue; | ||
exports.getSelector = getSelector; | ||
exports.getSingleValue = getSingleValue; | ||
exports.getValue = getValue; | ||
exports.isComparisonNode = isComparisonNode; | ||
exports.isComparisonOperator = isComparisonOperator; | ||
exports.isExpressionNode = isExpressionNode; | ||
exports.isLogicNode = isLogicNode; | ||
exports.isLogicOperator = isLogicOperator; | ||
exports.isNode = isNode; | ||
exports.isSelectorNode = isSelectorNode; | ||
exports.isValueNode = isValueNode; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
}); |
@@ -7,3 +7,3 @@ { | ||
"author": "Piotr Oleś <piotrek.oles@gmail.com>", | ||
"version": "0.0.1-next.2", | ||
"version": "0.0.1-next.3", | ||
"sideEffects": false, | ||
@@ -23,5 +23,6 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"clean": "rm -rf ./lib && rm -f tsconfig.tsbuildinfo && rm -rf ./dist", | ||
"compile": "tsc -b tsconfig.json && rollup -c && dts-bundle --name \"@rsql/ast\" --main lib/index.d.ts --out ../dist/index.d.ts", | ||
"build": "yarn clean && yarn compile" | ||
"build:clean": "rm -rf ./lib && rm -f tsconfig.tsbuildinfo && rm -rf ./dist", | ||
"build:lib": "tsc -b tsconfig.json", | ||
"build:dist": "rollup -c && dts-bundle --name \"@rsql/ast\" --main lib/index.d.ts --out ../dist/index.d.ts --outputAsModuleFolder && prettier --write ./dist", | ||
"build": "yarn build:clean && yarn build:lib && yarn build:dist" | ||
}, | ||
@@ -39,3 +40,3 @@ "engines": { | ||
}, | ||
"gitHead": "1a690bf021f57c9201d1e02d263f170a419f5c6c" | ||
"gitHead": "501c3c00630ce8668f5d9caf4b79ef17d3555419" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1124
0
42289