UNPKG

@prismatic-io/spectral

Version:

Utility library for building Prismatic connectors and code-native integrations

161 lines (160 loc) 6.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OPERATOR_PHRASE_TO_EXPRESSION = exports.TermOperatorPhrase = exports.BinaryOperatorPhrase = exports.BinaryOperator = exports.UnaryOperatorPhrase = exports.UnaryOperator = exports.BooleanOperatorPhrase = exports.BooleanOperator = void 0; // GraphQL-derived enums use the same name as the constant for the value, // but depending on how things shake out, we may be able to combine with the phrases below. var BooleanOperator; (function (BooleanOperator) { BooleanOperator["and"] = "and"; BooleanOperator["or"] = "or"; })(BooleanOperator || (exports.BooleanOperator = BooleanOperator = {})); exports.BooleanOperatorPhrase = Object.keys(BooleanOperator); var UnaryOperator; (function (UnaryOperator) { UnaryOperator["isTrue"] = "isTrue"; UnaryOperator["isFalse"] = "isFalse"; UnaryOperator["doesNotExist"] = "doesNotExist"; UnaryOperator["exists"] = "exists"; UnaryOperator["isEmpty"] = "isEmpty"; UnaryOperator["isNotEmpty"] = "isNotEmpty"; })(UnaryOperator || (exports.UnaryOperator = UnaryOperator = {})); exports.UnaryOperatorPhrase = { [UnaryOperator.isTrue]: "is true", [UnaryOperator.isFalse]: "is false", [UnaryOperator.doesNotExist]: "does not exist", [UnaryOperator.exists]: "exists", [UnaryOperator.isEmpty]: "is empty", [UnaryOperator.isNotEmpty]: "is not empty", }; var BinaryOperator; (function (BinaryOperator) { BinaryOperator["equal"] = "equal"; BinaryOperator["notEqual"] = "notEqual"; BinaryOperator["greaterThan"] = "greaterThan"; BinaryOperator["greaterThanOrEqual"] = "greaterThanOrEqual"; BinaryOperator["lessThan"] = "lessThan"; BinaryOperator["lessThanOrEqual"] = "lessThanOrEqual"; BinaryOperator["in"] = "in"; BinaryOperator["notIn"] = "notIn"; BinaryOperator["exactlyMatches"] = "exactlyMatches"; BinaryOperator["doesNotExactlyMatch"] = "doesNotExactlyMatch"; BinaryOperator["startsWith"] = "startsWith"; BinaryOperator["doesNotStartWith"] = "doesNotStartWith"; BinaryOperator["endsWith"] = "endsWith"; BinaryOperator["doesNotEndWith"] = "doesNotEndWith"; BinaryOperator["dateTimeAfter"] = "dateTimeAfter"; BinaryOperator["dateTimeBefore"] = "dateTimeBefore"; BinaryOperator["dateTimeSame"] = "dateTimeSame"; })(BinaryOperator || (exports.BinaryOperator = BinaryOperator = {})); exports.BinaryOperatorPhrase = { [BinaryOperator.equal]: "equals", [BinaryOperator.exactlyMatches]: "exactly matches", [BinaryOperator.notEqual]: "does not equal", [BinaryOperator.doesNotExactlyMatch]: "does not exactly match", [BinaryOperator.greaterThan]: "is greater than", [BinaryOperator.greaterThanOrEqual]: "is greater than or equal to", [BinaryOperator.lessThan]: "is less than", [BinaryOperator.lessThanOrEqual]: "is less than or equal to", [BinaryOperator.in]: "contained in", [BinaryOperator.notIn]: "not contained in", [BinaryOperator.startsWith]: "starts the string", [BinaryOperator.doesNotStartWith]: "does not start the string", [BinaryOperator.endsWith]: "ends the string", [BinaryOperator.doesNotEndWith]: "does not end the string", [BinaryOperator.dateTimeAfter]: "is after (date/time)", [BinaryOperator.dateTimeBefore]: "is before (date/time)", [BinaryOperator.dateTimeSame]: "is the same (date/time)", }; exports.TermOperatorPhrase = Object.assign(Object.assign({}, exports.UnaryOperatorPhrase), exports.BinaryOperatorPhrase); exports.OPERATOR_PHRASE_TO_EXPRESSION = { [BinaryOperator.equal]: { expression: "isEqual($LEFT_TERM, $RIGHT_TERM)", includes: ["isEqual"], }, [BinaryOperator.exactlyMatches]: { expression: "$LEFT_TERM === $RIGHT_TERM || isDeepEqual($LEFT_TERM, $RIGHT_TERM)", includes: ["isDeepEqual"], }, [BinaryOperator.notEqual]: { expression: "!(isEqual($LEFT_TERM, $RIGHT_TERM))", includes: ["isEqual"], }, [BinaryOperator.doesNotExactlyMatch]: { expression: "!($LEFT_TERM === $RIGHT_TERM || isDeepEqual($LEFT_TERM, $RIGHT_TERM))", includes: ["isDeepEqual"], }, [BinaryOperator.greaterThan]: { expression: "$LEFT_TERM > $RIGHT_TERM", }, [BinaryOperator.greaterThanOrEqual]: { expression: "$LEFT_TERM >= $RIGHT_TERM", }, [BinaryOperator.lessThan]: { expression: "$LEFT_TERM < $RIGHT_TERM", }, [BinaryOperator.lessThanOrEqual]: { expression: "$LEFT_TERM <= $RIGHT_TERM", }, [BinaryOperator.in]: { expression: "contains($RIGHT_TERM, $LEFT_TERM)", includes: ["contains"], }, [BinaryOperator.notIn]: { expression: "!contains($RIGHT_TERM, $LEFT_TERM)", includes: ["contains"], }, [BinaryOperator.startsWith]: { expression: "$RIGHT_TERM.startsWith($LEFT_TERM)", }, [BinaryOperator.doesNotStartWith]: { expression: "!$RIGHT_TERM.startsWith($LEFT_TERM)", }, [BinaryOperator.endsWith]: { expression: "$RIGHT_TERM.endsWith($LEFT_TERM)", }, [BinaryOperator.doesNotEndWith]: { expression: "!$RIGHT_TERM.endsWith($LEFT_TERM)", }, [BinaryOperator.dateTimeAfter]: { expression: "dateIsAfter($LEFT_TERM, $RIGHT_TERM)", includes: ["dateIsAfter"], }, [BinaryOperator.dateTimeBefore]: { expression: "dateIsBefore($LEFT_TERM, $RIGHT_TERM)", includes: ["dateIsBefore"], }, [BinaryOperator.dateTimeSame]: { expression: "dateIsEqual($LEFT_TERM, $RIGHT_TERM)", includes: ["dateIsEqual"], }, [BooleanOperator.and]: { expression: "$LEFT_TERM && $RIGHT_TERM", }, [BooleanOperator.or]: { expression: "$LEFT_TERM || $RIGHT_TERM", }, [UnaryOperator.isTrue]: { expression: "evaluatesTrue($LEFT_TERM)", includes: ["evaluatesTrue"], }, [UnaryOperator.isFalse]: { expression: "evaluatesFalse($LEFT_TERM)", includes: ["evaluatesFalse"], }, [UnaryOperator.doesNotExist]: { expression: "evaluatesNull($LEFT_TERM)", includes: ["evaluatesNull"], }, [UnaryOperator.exists]: { expression: "!evaluatesNull($LEFT_TERM)", includes: ["evaluatesNull"], }, [UnaryOperator.isEmpty]: { expression: "evaluatesEmpty($LEFT_TERM)", includes: ["evaluatesEmpty"], }, [UnaryOperator.isNotEmpty]: { expression: "!evaluatesNull($LEFT_TERM)", includes: ["evaluatesNull"], }, };