@usex/rule-engine
Version:
The ultimate JSON-based rule engine that turns complex business logic into declarative configurations. Built for developers who believe code should be expressive, not repetitive.
454 lines (446 loc) • 91.8 kB
TypeScript
declare enum ConditionTypes {
OR = "or",// Logical OR operator. If any condition is true, the result is true. Otherwise, the result is false.
AND = "and",// Logical AND operator. If all conditions are true, the result is true. Otherwise, the result is false.
NONE = "none"
}
declare enum Operators {
Equals = "equals",// Check if the field value is equal to the provided value. The comparison is case-sensitive. The value must be a string. The field value must be a string. Example: { "field": "name", "operator": "equals", "value": "John Doe" } will check if the name field is equal to "John Doe".
NotEquals = "not-equals",// Check if the field value is not equal to the provided value. The comparison is case-sensitive. The value must be a string. The field value must be a string. Example: { "field": "name", "operator": "not-equals", "value": "John Doe" } will check if the name field is not equal to "John Doe".
Like = "like",// Check if the field value is like the provided value. The comparison is case-insensitive. The value must be a string. The field value must be a string. Example: { "field": "name", "operator": "like", "value": "john" } will check if the name field is like "john".
NotLike = "not-like",// Check if the field value is not like the provided value. The comparison is case-insensitive. The value must be a string. The field value must be a string. Example: { "field": "name", "operator": "not-like", "value": "john" } will check if the name field is not like "john".
StartsWith = "starts-with",// Check if the field value starts with the provided value. The field value must be a string. Example: { "field": "name", "operator": "starts-with", "value": "John" } will check if the name field starts with "John".
EndsWith = "ends-with",// Check if the field value ends with the provided value. The field value must be a string. Example: { "field": "email", "operator": "ends-with", "value": ".com" } will check if the email field ends with ".com".
ContainsString = "contains-string",// Check if the field value contains the provided substring. The field value must be a string. Example: { "field": "description", "operator": "contains-string", "value": "error" } will check if the description field contains "error".
GreaterThan = "greater-than",// Check if the field value is greater than the provided value. The value must be a number. The field value must be a number. Example: { "field": "age", "operator": "greater-than", "value": 18 } will check if the age field is greater than 18.
LessThan = "less-than",// Check if the field value is less than the provided value. The value must be a number. The field value must be a number. Example: { "field": "age", "operator": "less-than", "value": 18 } will check if the age field is less than 18.
GreaterThanOrEquals = "greater-than-or-equals",// Check if the field value is greater than or equal to the provided value. The value must be a number. The field value must be a number. Example: { "field": "age", "operator": "greater-than-or-equals", "value": 18 } will check if the age field is greater than or equal to 18.
LessThanOrEquals = "less-than-or-equals",// Check if the field value is less than or equal to the provided value. The value must be a number. The field value must be a number. Example: { "field": "age", "operator": "less-than-or-equals", "value": 18 } will check if the age field is less than or equal to 18.
In = "in",// Check if the field value is in the provided array of values. The values must be an array. The field value must be a string. Example: { "field": "name", "operator": "in", "value": ["John Doe", "Jane Doe"] } will check if the name field is in ["John Doe", "Jane Doe"].
NotIn = "not-in",// Check if the field value is not in the provided array of values. The values must be an array. The field value must be a string. Example: { "field": "name", "operator": "not-in", "value": ["John Doe", "Jane Doe"] } will check if the name field is not in ["John Doe", "Jane Doe"].
Contains = "contains",// Check if the field value contains the provided value. The comparison is case-sensitive. The value must be a string. The field value must be a string. Example: { "field": "name", "operator": "contains", "value": "John" } will check if the name field contains "John".
NotContains = "not-contains",// Check if the field value does not contain the provided value. The comparison is case-sensitive. The value must be a string. The field value must be a string. Example: { "field": "name", "operator": "not-contains", "value": "John" } will check if the name field does not contain "John".
ContainsAny = "contains-any",// Check if the field value contains any of the provided values. The values must be an array. The field value must be a string. Example: { "field": "name", "operator": "contains-any", "value": ["John", "Jane"] } will check if the name field contains any of ["John", "Jane"].
SelfContainsAny = "self-contains-any",// Check if the field value contains any of the values in the provided array. The values must be an array. The field value must be an array. Example: { "field": "tags", "operator": "self-contains-any", "value": ["tag1", "tag2"] } will check if the tags field contains any of ["tag1", "tag2"].
NotContainsAny = "not-contains-any",// Check if the field value does not contain any of the provided values. The values must be an array. The field value must be a string. Example: { "field": "name", "operator": "not-contains-any", "value": ["John", "Jane"] } will check if the name field does not contain any of ["John", "Jane"].
SelfNotContainsAny = "self-not-contains-any",// Check if the field value does not contain any of the values in the provided array. The values must be an array. The field value must be an array. Example: { "field": "tags", "operator": "self-not-contains-any", "value": ["tag1", "tag2"] } will check if the tags field does not contain any of ["tag1", "tag2"].
SelfContainsNone = "self-not-contains-none",// Check if the field value does not contain any of the values in the provided array. The values must be an array. The field value must be an array. Example: { "field": "tags", "operator": "self-not-contains-none", "value": ["tag1", "tag2"] } will check if the tags field does not contain any of ["tag1", "tag2"].
ContainsAll = "contains-all",// Check if the field value contains all the provided values. The values must be an array. The field value must be a string. Example: { "field": "name", "operator": "contains-all", "value": ["John", "Doe"] } will check if the name field contains all of ["John", "Doe"].
SelfContainsAll = "self-contains-all",// Check if the field value contains all the values in the provided array. The values must be an array. The field value must be an array. Example: { "field": "tags", "operator": "self-contains-all", "value": ["tag1", "tag2"] } will check if the tags field contains all of ["tag1", "tag2"].
NotContainsAll = "not-contains-all",// Check if the field value does not contain all the provided values. The values must be an array. The field value must be a string. Example: { "field": "name", "operator": "not-contains-all", "value": ["John", "Doe"] } will check if the name field does not contain all of ["John", "Doe"].
SelfNotContainsAll = "self-not-contains-all",// Check if the field value does not contain all the values in the provided array. The values must be an array. The field value must be an array. Example: { "field": "tags", "operator": "self-not-contains-all", "value": ["tag1", "tag2"] } will check if the tags field does not contain all of ["tag1", "tag2"].
Matches = "matches",// Check if the field value matches the provided regular expression. The value must be a string. The field value must be a string. Example: { "field": "name", "operator": "matches", "value": "John" } will check if the name field matches the regular expression "John".
NotMatches = "not-matches",// Check if the field value does not match the provided regular expression. The value must be a string. The field value must be a string. Example: { "field": "name", "operator": "not-matches", "value": "John" } will check if the name field does not match the regular expression "John".
Exists = "exists",// Check if the field exists in the object. The field must be a string. Example: { "field": "name", "operator": "exists" } will check if the name field exists in the object.
NotExists = "not-exists",// Check if the field does not exist in the object. The field must be a string. Example: { "field": "name", "operator": "not-ex
NullOrUndefined = "null-or-undefined",// Check if the field value is null or undefined. The field value must be a string. Example: { "field": "name", "operator": "null-or-undefined" } will check if the name field value is null or undefined.
NotNullOrUndefined = "not-null-or-undefined",// Check if the field value is not null or undefined. The field value must be a string. Example: { "field": "name", "operator": "not-null-or-undefined" } will check if the name field value is not null or undefined.
Empty = "empty",// Check if the field value is empty. The field value must be string, array or object. Example: { "field": "name", "operator": "empty" } will check if the name field value is empty.
NotEmpty = "not-empty",// Check if the field value is not empty. The field value must be string, array or object. Example: { "field": "name", "operator": "not-empty" } will check if the name field value is not empty.
DateAfter = "date-after",// Check if the field value is after the provided date. The value must be a date. The field value must be a date. Example: { "field": "date", "operator": "date-after", "value": "2021-01-01" } will check if the date field is after "2021-01-01".
DateAfterNow = "date-after-now",// Check if the field value is after the current date and time. The field value must be a date. Example: { "field": "date", "operator": "date-after-now" } will check if the date field is after the current date and time.
DateBefore = "date-before",// Check if the field value is before the provided date. The value must be a date. The field value must be a date. Example: { "field": "date", "operator": "date-before", "value": "2021-01-01" } will check if the date field is before "2021-01-01".
DateBeforeNow = "date-before-now",// Check if the field value is before the current date and time. The field value must be a date. Example: { "field": "date", "operator": "date-before-now" } will check if the date field is before the current date and time.
DateAfterOrEquals = "date-after-or-equals",// Check if the field value is after or equal to the provided date. The value must be a date. The field value must be a date. Example: { "field": "date", "operator": "date-after-or-equals", "value": "2021-01-01" } will check if the date field is after or equal to "2021-01-01".
DateAfterNowOrEquals = "date-after-now-or-equals",// Check if the field value is after or equal to the current date and time. The field value must be a date. Example: { "field": "date", "operator": "date-after-now-or-equals" } will check if the date field is after or equal to the current date and time.
DateBeforeOrEquals = "date-before-or-equals",// Check if the field value is before or equal to the provided date. The value must be a date. The field value must be a date. Example: { "field": "date", "operator": "date-before-or-equals", "value": "2021-01-01" } will check if the date field is before or equal to "2021-01-01".
DateBeforeNowOrEquals = "date-before-now-or-equals",// Check if the field value is before or equal to the current date and time. The field value must be a date. Example: { "field": "date", "operator": "date-before-now-or-equals" } will check if the date field is before or equal to the current date and time.
DateEquals = "date-equals",// Check if the field value is equal to the provided date. The value must be a date. The field value must be a date. Example: { "field": "date", "operator": "date-equals", "value": "2021-01-01" } will check if the date field is equal to "2021-01-01".
DateEqualsToNow = "date-equals-to-now",// Check if the field value is equal to the current date and time. The field value must be a date. Example: { "field": "date", "operator": "date-equals-to-now" } will check if the date field is equal to the current date and time.
DateNotEquals = "date-not-equals",// Check if the field value is not equal to the provided date. The value must be a date. The field value must be a date. Example: { "field": "date", "operator": "date-not-equals", "value": "2021-01-01" } will check if the date field is not equal to "2021-01-01".
DateNotEqualsToNow = "date-not-equals-to-now",// Check if the field value is not equal to the current date and time. The field value must be a date. Example: { "field": "date", "operator": "date-not-equals-to-now" } will check if the date field is not equal to the current date and time.
DateBetween = "date-between",// Check if the field value is between the provided dates. The values must be an array of two dates. The field value must be a date. Example: { "field": "date", "operator": "date-between", "value": ["2021-01-01", "2021-12-31"] } will check if the date field is between "2021-01-01" and "2021-12-31".
DateNotBetween = "date-not-between",// Check if the field value is not between the provided dates. The values must be an array of two dates. The field value must be a date. Example: { "field": "date", "operator": "date-not-between", "value": ["2021-01-01", "2021-12-31"] } will check if the date field is not between "2021-01-01" and "2021-12-31".
TimeAfter = "time-after",// Check if the field value is after the provided time. The value must be a time. The field value must be a time. Example: { "field": "time", "operator": "time-after", "value": "12:00:00" } will check if the time field is after "12:00:00".
TimeBefore = "time-before",// Check if the field value is before the provided time. The value must be a time. The field value must be a time. Example: { "field": "time", "operator": "time-before", "value": "12:00:00" } will check if the time field is before "12:00:00".
TimeAfterOrEquals = "time-after-or-equals",// Check if the field value is after or equal to the provided time. The value must be a time. The field value must be a time. Example: { "field": "time", "operator": "time-after-or-equals", "value": "12:00:00" } will check if the time field is after or equal to "12:00:00".
TimeBeforeOrEquals = "time-before-or-equals",// Check if the field value is before or equal to the provided time. The value must be a time. The field value must be a time. Example: { "field": "time", "operator": "time-before-or-equals", "value": "12:00:00" } will check if the time field is before or equal to "12:00:00".
TimeEquals = "time-equals",// Check if the field value is equal to the provided time. The value must be a time. The field value must be a time. Example: { "field": "time", "operator": "time-equals", "value": "12:00:00" } will check if the time field is equal to "12:00:00".
TimeNotEquals = "time-not-equals",// Check if the field value is not equal to the provided time. The value must be a time. The field value must be a time. Example: { "field": "time", "operator": "time-not-equals", "value": "12:00:00" } will check if the time field is not equal to "12:00:00".
TimeBetween = "time-between",// Check if the field value is between the provided times. The values must be an array of two times. The field value must be a time. Example: { "field": "time", "operator": "time-between", "value": ["08:00:00", "17:00:00"] } will check if the time field is between "08:00:00" and "17:00:00".
TimeNotBetween = "time-not-between",// Check if the field value is not between the provided times. The values must be an array of two times. The field value must be a time. Example: { "field": "time", "operator": "time-not-between", "value": ["08:00:00", "17:00:00"] } will check if the time field is not between "08:00:00" and "17:00:00".
NullOrWhiteSpace = "null-or-white-space",// Check if the field value is null or white space. The field value must be a string. Example: { "field": "name", "operator": "null-or-white-space" } will check if the name field value is null or white space.
NotNullOrWhiteSpace = "not-null-or-white-space",// Check if the field value is not null or white space. The field value must be a string. Example: { "field": "name", "operator": "not-null-or-white-space" } will check if the name field value is not null or white space.
Numeric = "numeric",// Check if the field value is numeric. The field value must be a string. Example: { "field": "age", "operator": "numeric" } will check if the age field value is numeric.
NotNumeric = "not-numeric",// Check if the field value is not numeric. The field value must be a string. Example: { "field": "age", "operator": "not-numeric" } will check if the age field value is not numeric.
Boolean = "boolean",// Check if the field value is boolean. The field value must be a string. Example: { "field": "active", "operator": "boolean" } will check if the active field value is boolean.
NotBoolean = "not-boolean",// Check if the field value is not boolean. The field value must be a string. Example: { "field": "active", "operator": "not-boolean" } will check if the active field value is not boolean.
Date = "date",// Check if the field value is a date. The field value must be a string. Example: { "field": "date", "operator": "date" } will check if the date field value is a date.
NotDate = "not-date",// Check if the field value is not a date. The field value must be a string. Example: { "field": "date", "operator": "not-date" } will check if the date field value is not a date.
Email = "email",// Check if the field value is an email. The field value must be a string. Example: { "field": "email", "operator": "email" } will check if the email field value is an email.
NotEmail = "not-email",// Check if the field value is not an email. The field value must be a string. Example: { "field": "email", "operator": "not-email" } will check if the email field value is not an email.
Url = "url",// Check if the field value is a URL. The field value must be a string. Example: { "field": "url", "operator": "url" } will check if the url field value is a URL.
NotUrl = "not-url",// Check if the field value is not a URL. The field value must be a string. Example: { "field": "url", "operator": "not-url" } will check if the url field value is not a URL.
UUID = "uuid",// Check if the field value is a UUID. The field value must be a string. Example: { "field": "uuid", "operator": "uuid" } will check if the uuid field value is a UUID.
NotUUID = "not-uuid",// Check if the field value is not a UUID. The field value must be a string. Example: { "field": "uuid", "operator": "not-uuid" } will check if the uuid field value is not a UUID.
Alpha = "alpha",// Check if the field value is alpha. The field value must be a string. Example: { "field": "name", "operator": "alpha" } will check if the name field value is alpha.
NotAlpha = "not-alpha",// Check if the field value is not alpha. The field value must be a string. Example: { "field": "name", "operator": "not-alpha" } will check if the name field value is not alpha.
AlphaNumeric = "alpha-numeric",// Check if the field value is alpha-numeric. The field value must be a string. Example: { "field": "name", "operator": "alpha-numeric" } will check if the name field value is alpha-numeric.
NotAlphaNumeric = "not-alpha-numeric",// Check if the field value is not alpha-numeric. The field value must be a string. Example: { "field": "name", "operator": "not-alpha-numeric" } will check if the name field value is not alpha-numeric.
PersianAlpha = "persian-alpha",// Check if the field value is Persian alpha. The field value must be a string. Example: { "field": "name", "operator": "persian-alpha" } will check if the name field value is Persian alpha.
NotPersianAlpha = "not-persian-alpha",// Check if the field value is not Persian alpha. The field value must be a string. Example: { "field": "name", "operator": "not-persian-alpha" } will check if the name field value is not Persian alpha.
PersianAlphaNumeric = "persian-alpha-numeric",// Check if the field value is Persian alpha-numeric. The field value must be a string. Example: { "field": "name", "operator": "persian-alpha-numeric" } will check if the name field value is Persian alpha-numeric.
NotPersianAlphaNumeric = "not-persian-alpha-numeric",// Check if the field value is not Persian alpha-numeric. The field value must be a string. Example: { "field": "name", "operator": "not-persian-alpha-numeric" } will check if the name field value is not Persian alpha-numeric.
LowerCase = "lower-case",// Check if the field value is lower case. The field value must be a string. Example: { "field": "name", "operator": "lower-case" } will check if the name field value is lower case.
NotLowerCase = "not-lower-case",// Check if the field value is not lower case. The field value must be a string. Example: { "field": "name", "operator": "not-lower-case" } will check if the name field value is not lower case.
UpperCase = "upper-case",// Check if the field value is upper case. The field value must be a string. Example: { "field": "name", "operator": "upper-case" } will check if the name field value is upper case.
NotUpperCase = "not-upper-case",// Check if the field value is not upper case. The field value must be a string. Example: { "field": "name", "operator": "not-upper-case" } will check if the name field value is not upper case.
String = "string",// Check if the field value is a string. The field value must be a string. Example: { "field": "name", "operator": "string" } will check if the name field value is a string.
NotString = "not-string",// Check if the field value is not a string. The field value must be a string. Example: { "field": "name", "operator": "not-string" } will check if the name field value is not a string.
Object = "object",// Check if the field value is an object. The field value must be an object. Example: { "field": "user", "operator": "object" } will check if the user field value is an object.
NotObject = "not-object",// Check if the field value is not an object. The field value must be an object. Example: { "field": "user", "operator": "not-object" } will check if the user field value is not an object.
Array = "array",// Check if the field value is an array. The field value must be an array. Example: { "field": "tags", "operator": "array" } will check if the tags field value is an array.
NotArray = "not-array",// Check if the field value is not an array. The field value must be an array. Example: { "field": "tags", "operator": "not-array" } will check if the tags field value is not an array.
ArrayLength = "array-length",// Check if the array length equals the specified value. The field value must be an array. Example: { "field": "items", "operator": "array-length", "value": 5 } will check if the items field has exactly 5 elements.
ArrayMinLength = "array-min-length",// Check if the array length is at least the specified value. The field value must be an array. Example: { "field": "attendees", "operator": "array-min-length", "value": 2 } will check if the attendees field has at least 2 elements.
ArrayMaxLength = "array-max-length",// Check if the array length is at most the specified value. The field value must be an array. Example: { "field": "tags", "operator": "array-max-length", "value": 10 } will check if the tags field has at most 10 elements.
BooleanString = "boolean-string",// Check if the field value is a boolean string. The field value must be a string. Example: { "field": "active", "operator": "boolean-string" } will check if the active field value is a boolean string.
NotBooleanString = "not-boolean-string",// Check if the field value is not a boolean string. The field value must be a string. Example: { "field": "active", "operator": "not-boolean-string" } will check if the active field value is not a boolean string.
BooleanNumber = "boolean-number",// Check if the field value is a boolean number. The field value must be a number. Example: { "field": "active", "operator": "boolean-number" } will check if the active field value is a boolean number.
NotBooleanNumber = "not-boolean-number",// Check if the field value is not a boolean number. The field value must be a number. Example: { "field": "active", "operator": "not-boolean-number" } will check if the active field value is not a boolean number.
BooleanNumberString = "boolean-number-string",// Check if the field value is a boolean number string. The field value must be a string. Example: { "field": "active", "operator": "boolean-number-string" } will check if the active field value is a boolean number string.
NotBooleanNumberString = "not-boolean-number-string",// Check if the field value is not a boolean number string. The field value must be a string. Example: { "field": "active", "operator": "not-boolean-number-string" } will check if the active field value is not a boolean number string.
Number = "number",// Check if the field value is a number. The field value must be a number. Example: { "field": "age", "operator": "number" } will check if the age field value is a number.
NotNumber = "not-number",// Check if the field value is not a number. The field value must be a number. Example: { "field": "age", "operator": "not-number" } will check if the age field value is not a number.
Integer = "integer",// Check if the field value is an integer. The field value must be a number. Example: { "field": "age", "operator": "integer" } will check if the age field value is an integer.
NotInteger = "not-integer",// Check if the field value is not an integer. The field value must be a number. Example: { "field": "age", "operator": "not-integer" } will check if the age field value is not an integer.
Float = "float",// Check if the field value is a float. The field value must be a number. Example: { "field": "age", "operator": "float" } will check if the age field value is a float.
NotFloat = "not-float",// Check if the field value is not a float. The field value must be a number. Example: { "field": "age", "operator": "not-float" } will check if the age field value is not a float.
Positive = "positive",// Check if the field value is positive. The field value must be a number. Example: { "field": "age", "operator": "positive" } will check if the age field value is positive.
NotPositive = "not-positive",// Check if the field value is not positive. The field value must be a number. Example: { "field": "age", "operator": "not-positive" } will check if the age field value is not positive.
Negative = "negative",// Check if the field value is negative. The field value must be a number. Example: { "field": "age", "operator": "negative" } will check if the age field value is negative.
NotNegative = "not-negative",// Check if the field value is not negative. The field value must be a number. Example: { "field": "age", "operator": "not-negative" } will check if the age field value is not negative.
Zero = "zero",// Check if the field value is zero. The field value must be a number. Example: { "field": "age", "operator": "zero" } will check if the age field value is zero.
NotZero = "not-zero",// Check if the field value is not zero. The field value must be a number. Example: { "field": "age", "operator": "not-zero" } will check if the age field value is not zero.
Min = "min",// Check if the field value is greater than or equal to the provided value. The value must be a number. The field value must be a number. Example: { "field": "age", "operator": "min", "value": 18 } will check if the age field value is greater than or equal to 18.
NotMin = "not-min",// Check if the field value is less than the provided value. The value must be a number. The field value must be a number. Example: { "field": "age", "operator": "not-min", "value": 18 } will check if the age field value is less than 18.
Max = "max",// Check if the field value is less than or equal to the provided value. The value must be a number. The field value must be a number. Example: { "field": "age", "operator": "max", "value": 65 } will check if the age field value is less than or equal to 65.
NotMax = "not-max",// Check if the field value is greater than the provided value. The value must be a number. The field value must be a number. Example: { "field": "age", "operator": "not-max", "value": 65 } will check if the age field value is greater than 65.
Between = "between",// Check if the field value is between the provided values. The values must be an array of two numbers. The field value must be a number. Example: { "field": "age", "operator": "between", "value": [18, 65] } will check if the age field value is between 18 and 65.
NotBetween = "not-between",// Check if the field value is not between the provided values. The values must be an array of two numbers. The field value must be a number. Example: { "field": "age", "operator": "not-between", "value": [18, 65] } will check if the age field value is not between 18 and 65.
NumberBetween = "number-between",// Check if the field value is between the provided values. The values must be an array of two numbers. The field value must be a number. Example: { "field": "age", "operator": "number-between", "value": [18, 65] } will check if the age field value is between 18 and 65.
NotNumberBetween = "not-number-between",// Check if the field value is not between the provided values. The values must be an array of two numbers. The field value must be a number. Example: { "field": "age", "operator": "not-number-between", "value": [18, 65] } will check if the age field value is not between 18 and 65.
StringLength = "string-length",// Check if the field value length is equal to the provided value. The value must be a number. The field value must be a string. Example: { "field": "name", "operator": "string-length", "value": 4 } will check if the name field value length is equal to 4.
NotStringLength = "not-string-length",// Check if the field value length is not equal to the provided value. The value must be a number. The field value must be a string. Example: { "field": "name", "operator": "not-string-length", "value": 4 } will check if the name field value length is not equal to 4.
MinLength = "min-length",// Check if the field value length is greater than or equal to the provided value. The value must be a number. The field value must be a string. Example: { "field": "name", "operator": "min-length", "value": 4 } will check if the name field value length is greater than or equal to 4.
NotMinLength = "not-min-length",// Check if the field value length is less than the provided value. The value must be a number. The field value must be a string. Example: { "field": "name", "operator": "not-min-length", "value": 4 } will check if the name field value length is less than 4.
MaxLength = "max-length",// Check if the field value length is less than or equal to the provided value. The value must be a number. The field value must be a string. Example: { "field": "name", "operator": "max-length", "value": 4 } will check if the name field value length is less than or equal to 4.
NotMaxLength = "not-max-length",// Check if the field value length is greater than the provided value. The value must be a number. The field value must be a string. Example: { "field": "name", "operator": "not-max-length", "value": 4 } will check if the name field value length is greater than 4.
LengthBetween = "length-between",// Check if the field value length is between the provided values. The values must be an array of two numbers. The field value must be a string. Example: { "field": "name", "operator": "between-length", "value": [4, 8] } will check if the name field value length is between 4 and 8.
NotLengthBetween = "not-length-between",// Check if the field value length is not between the provided values. The values must be an array of two numbers. The field value must be a string. Example: { "field": "name", "operator": "not-between-length", "value": [4, 8] } will check if the name field value length is not between 4 and 8.
Falsy = "falsy",// Check if the field value is falsy. The field value must be a string. Example: { "field": "active", "operator": "falsy" } will check if the active field value is falsy.
NotFalsy = "not-falsy",// Check if the field value is not falsy. The field value must be a string. Example: { "field": "active", "operator": "not-falsy" } will check if the active field value is not falsy.
Truthy = "truthy",// Check if the field value is truthy. The field value must be a string. Example: { "field": "active", "operator": "truthy" } will check if the active field value is truthy.
NotTruthy = "not-truthy"
}
/**
* Checks if the value is equal to the compareValue. Both values must be of the same type. If the values are objects, it will compare the stringifies versions of the objects.
* @param value
* @param compareValue
* @returns boolean
* @example
* equalsOperator(1, 1) // true
* equalsOperator(1, 2) // false
* equalsOperator('a', 'a') // true
* equalsOperator('a', 'b') // false
* equalsOperator(1, '1') // false
* equalsOperator({ a: 1 }, { a: 1 }) // true
* equalsOperator({ a: 1 }, { a: 2 }) // false
* equalsOperator({ a: 1 }, { b: 1 }) // false
* equalsOperator({ a: 1 }, { a: '1' }) // false
* equalsOperator({ a: 1 }, { a: 1, b: 2 }) // false
* equalsOperator(null, 1) // false
* equalsOperator(1, null) // false
* equalsOperator(undefined, 1) // false
* equalsOperator(1, undefined) // false
*/
declare function equalsOperator(value: any, compareValue: any): boolean;
/**
* Checks if the value is less than the compareValue. Both values must be of the same type.
* @param value
* @param compareValue
* @returns boolean
* @example
* lessThanOperator(1, 2) // true
* lessThanOperator(2, 1) // false
* lessThanOperator('a', 'b') // true
* lessThanOperator('b', 'a') // false
* lessThanOperator(1, 'a') // false
* lessThanOperator('a', 1) // false
* lessThanOperator(null, 1) // false
* lessThanOperator(1, null) // false
* lessThanOperator(undefined, 1) // false
* lessThanOperator(1, undefined) // false
*/
declare function greaterThanOperator(value: any, compareValue: any): boolean;
/**
* Checks if the value is greater than the compareValue. Both values must be of the same type.
* @param value
* @param compareValue
*/
declare function greaterThanOrEqualsOperator(value: any, compareValue: any): boolean;
/**
* Checks if the value is less than the compareValue. Both values must be of the same type.
* @param value
* @param compareValue
*/
declare function lessThanOperator(value: any, compareValue: any): boolean;
/**
* Checks if the value is less than or equal to the compareValue. Both values must be of the same type.
* @param value
* @param compareValue
*/
declare function lessThanOrEqualsOperator(value: any, compareValue: any): boolean;
/**
* Parses and evaluates a safe and comprehensive SQL WHERE LIKE filter expression.
*
* @param text The text string to search (string).
* @param pattern The pattern to match (string).
* @param caseInsensitive (optional) A boolean flag indicating case-insensitive matching (default: false).
* @returns boolean True if the text matches the pattern, False otherwise.
* @example
* likeOperator("Hello, World!", "Hello, World!") // true
* likeOperator("Hello, World!", "Hello, %") // true
* likeOperator("Hello, World!", "%World!") // true
* likeOperator("Hello, World!", "%World") // false
* likeOperator("Hello, World!", "Hello, %!", true) // true
* likeOperator("Hello, World!", "hello, %", true) // true
* likeOperator("Hello, World!", "Hello, %", true) // false
* // startsWith
* likeOperator("Hello, World!", "^Hello, World!") // true
* likeOperator("Hello, World!", "^Hello, %") // true
* likeOperator("Hello, World!", "^Hello, World!") // false
* // endsWith
* likeOperator("Hello, World!", "Hello, World!$") // true
* likeOperator("Hello, World!", "%World!$") // true
* likeOperator("Hello, World!", "Hello, World!$") // false
* // startsWith and endsWith
* likeOperator("Hello, World!", "^Hello, World!$") // true
* likeOperator("Hello, World!", "^Hello, %$") // true
* likeOperator("Hello, World!", "^Hello, World!$") // false
*/
declare function likeOperator(text: string, pattern: string, caseInsensitive?: boolean): boolean;
declare function isNullOrWhiteSpaceOperator(value: string): boolean;
declare function isNumericOperator(value: any): boolean;
declare function isBooleanOperator(value: any): boolean;
declare function isDateOperator(value: any): boolean;
declare function isEmailOperator(value: string): boolean;
declare function isUrlOperator(value: string): boolean;
declare function isUuidOperator(value: string): boolean;
declare const faAlphabet = "\u0627\u0628\u067E\u062A\u062B\u062C\u0686\u062D\u062E\u062F\u0630\u0631\u0632\u0698\u0633\u0634\u0635\u0636\u0637\u0638\u0639\u063A\u0641\u0642\u06A9\u06AF\u0644\u0645\u0646\u0648\u0647\u06CC";
declare const faNumber = "\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9";
declare const faShortVowels = "\u064E\u0650\u064F";
declare const faOthers = "\u200C\u0622\u0627\u064B";
declare const faMixedWithArabic = "\u0652\u064C\u064D\u064B\u064F\u0650\u064E\u0651\u0654\u0670\u0621\u0643\u200C\u0629\u06C0\u0623\u0625\u064A\u0640\u0626\u0624\u060C";
declare const faText: string;
declare const faAlphaText: string;
declare const faComplexText: string;
declare const faAlphaComplexText: string;
declare function isAlphaOperator(value: string): boolean;
declare function isPersianAlphaOperator(value: string): boolean;
declare function isAlphaNumericOperator(value: string): boolean;
declare function isPersianAlphaNumericOperator(value: string): boolean;
declare function isLowerCaseOperator(value: string): boolean;
declare function isUpperCaseOperator(value: string): boolean;
declare function isStringOperator(value: any): boolean;
declare function isObjectOperator(value: any): boolean;
declare function isArrayOperator(value: any): boolean;
declare function isBooleanStringOperator(value: string): boolean;
declare function isBooleanNumberOperator(value: any): boolean;
declare function isBooleanNumberStringOperator(value: any): boolean;
declare function isNumberOperator(value: any): boolean;
declare function isIntegerOperator(value: any): boolean;
declare function isFloatOperator(value: any): boolean;
declare function isPositiveOperator(value: any): boolean;
declare function isNegativeOperator(value: any): boolean;
declare function isZeroOperator(value: any): boolean;
declare function isNumberBetweenOperator(value: any, compareValues: any[]): boolean;
declare function isLengthOperator(value: any, compareValue: any): boolean;
declare function isMinLengthOperator(value: any, compareValue: any): boolean;
declare function isMaxLengthOperator(value: any, compareValue: any): boolean;
declare function IsLengthBetweenOperator(value: any, compareValues: any[]): boolean;
declare function isMinOperator(value: any, compareValue: any): boolean;
declare function isMaxOperator(value: any, compareValue: any): boolean;
declare function isBetweenOperator(value: any, compareValues: any[]): boolean;
declare function isFalsyOperator(value: any): boolean;
declare function isTruthyOperator(value: any): boolean;
/**
* Checks if the value is not equal to the compareValue. Both values must be of the same type.
* @param value
* @param compareValues
* @constructor
*/
declare function inOperator(value: any, compareValues: any[]): boolean;
declare function containsOperator(value: any, compareValue: any): boolean;
declare function selfContainsAllOperator(value: any, compareValues: any[]): boolean;
declare function selfContainsAnyOperator(value: any, compareValues: any[]): boolean;
declare function selfContainsNoneOperator(value: any, compareValues: any[]): boolean;
declare function containsAnyOperator(value: any, compareValues: any[]): boolean;
declare function containsAllOperator(value: any, compareValues: any[]): boolean;
declare function matchesOperator(value: string, pattern: string): boolean;
declare function isExistsInObjectOperator(key: any, obj: any): boolean;
declare function isNullOrUndefinedOperator(value: any): boolean;
declare function isEmptyOperator(value: any): boolean;
declare function isDateAfterOperator(left: any, right: any): boolean;
declare function isDateAfterNowOperator(value: any): boolean;
declare function isDateBeforeOperator(left: any, right: any): boolean;
declare function isDateBeforeNowOperator(value: any): boolean;
declare function isDateAfterOrEqualsOperator(left: any, right: any): boolean;
declare function isDateAfterNowOrEqualsOperator(value: any): boolean;
declare function isDateBeforeOrEqualsOperator(left: any, right: any): boolean;
declare function isDateBeforeNowOrEqualsOperator(value: any): boolean;
declare function isDateEqualsOperator(left: any, right: any): boolean;
declare function isDateEqualsToNowOperator(dateValue: any): boolean;
declare function isDateBetweenOperator(left: any, rightRange: any[]): boolean;
declare function isTimeAfterOperator(left: any, right: any): boolean;
declare function isTimeBeforeOperator(left: any, right: any): boolean;
declare function isTimeAfterOrEqualsOperator(left: any, right: any): boolean;
declare function isTimeBeforeOrEqualsOperator(left: any, right: any): boolean;
declare function isTimeEqualsOperator(left: any, right: any): boolean;
declare function isTimeBetweenOperator(left: any, right: any[]): boolean;
interface IntrospectionStepChange {
key: string;
value: unknown;
}
interface IntrospectionStep {
parentType?: ConditionType;
currType: ConditionType;
depth: number;
option: Record<string, unknown>;
changes?: Array<IntrospectionStepChange>;
}
type ConditionType = ConditionTypes.OR | ConditionTypes.AND | ConditionTypes.NONE;
type OperatorsType = Operators.Equals | Operators.NotEquals | Operators.GreaterThan | Operators.LessThan | Operators.GreaterThanOrEquals | Operators.LessThanOrEquals | Operators.Like | Operators.NotLike | Operators.StartsWith | Operators.EndsWith | Operators.ContainsString | Operators.In | Operators.NotIn | Operators.Contains | Operators.NotContains | Operators.ContainsAny | Operators.SelfContainsAny | Operators.NotContainsAny | Operators.SelfContainsNone | Operators.SelfNotContainsAny | Operators.ContainsAll | Operators.SelfContainsAll | Operators.NotContainsAll | Operators.SelfNotContainsAll | Operators.Matches | Operators.NotMatches | Operators.Exists | Operators.NotExists | Operators.NullOrUndefined | Operators.NotNullOrUndefined | Operators.Empty | Operators.NotEmpty | Operators.DateAfter | Operators.DateAfterNow | Operators.DateBefore | Operators.DateBeforeNow | Operators.DateAfterOrEquals | Operators.DateAfterNowOrEquals | Operators.DateBeforeOrEquals | Operators.DateBeforeNowOrEquals | Operators.DateEquals | Operators.DateEqualsToNow | Operators.DateNotEquals | Operators.DateNotEqualsToNow | Operators.DateBetween | Operators.DateNotBetween | Operators.TimeAfter | Operators.TimeBefore | Operators.TimeAfterOrEquals | Operators.TimeBeforeOrEquals | Operators.TimeEquals | Operators.TimeNotEquals | Operators.TimeBetween | Operators.TimeNotBetween | Operators.NullOrWhiteSpace | Operators.NotNullOrWhiteSpace | Operators.Numeric | Operators.NotNumeric | Operators.Boolean | Operators.NotBoolean | Operators.Date | Operators.NotDate | Operators.Email | Operators.NotEmail | Operators.Url | Operators.NotUrl | Operators.UUID | Operators.NotUUID | Operators.Alpha | Operators.NotAlpha | Operators.AlphaNumeric | Operators.NotAlphaNumeric | Operators.PersianAlpha | Operators.NotPersianAlpha | Operators.PersianAlphaNumeric | Operators.NotPersianAlphaNumeric | Operators.LowerCase | Operators.NotLowerCase | Operators.UpperCase | Operators.NotUpperCase | Operators.String | Operators.NotString | Operators.Object | Operators.NotObject | Operators.Array | Operators.NotArray | Operators.ArrayLength | Operators.ArrayMinLength | Operators.ArrayMaxLength | Operators.BooleanString | Operators.NotBooleanString | Operators.BooleanNumber | Operators.NotBooleanNumber | Operators.BooleanNumberString | Operators.NotBooleanNumberString | Operators.Number | Operators.NotNumber | Operators.Integer | Operators.NotInteger | Operators.Float | Operators.NotFloat | Operators.Positive | Operators.NotPositive | Operators.Negative | Operators.NotNegative | Operators.Zero | Operators.NotZero | Operators.Min | Operators.NotMin | Operators.Max | Operators.NotMax | Operators.Between | Operators.NotBetween | Operators.NumberBetween | Operators.NotNumberBetween | Operators.StringLength | Operators.NotStringLength | Operators.MinLength | Operators.NotMinLength | Operators.MaxLength | Operators.NotMaxLength | Operators.LengthBetween | Operators.NotLengthBetween | Operators.Falsy | Operators.NotFalsy | Operators.Truthy | Operators.NotTruthy;
interface Constraint {
/**
* The field to evaluate.
* @example "name"
* @example "age"
* @example "$.meta.default.password"
* @example "$.foo[0].bar"
*/
field: string;
/**
* The operator to use for the evaluation.
* @example Operators.Equals
*/
operator: OperatorsType;
/**
* The value to compare against the field.
* @example "test"
* @example 5
* @example true
* @example { name: "test" }
* @example ["test", 5, true, { name: "test" }]
* @example ["$.username", "$.name", "$.family"]
*/
value?: string | number | boolean | Record<string, unknown> | Array<string | number | boolean | Record<string, unknown>>;
/**
* The message to display if the constraint is invalid. This is optional and only used if the constraint is invalid.
* @default "The constraint is invalid."
* @example "The field must be a string."
* @example "The field must be a number."
* @example "The field must be a boolean."
* @example "The field must be an object."
*/
message?: string;
}
/**
* The result of the evaluation.
* This is the value of the field that was evaluated.
* - If the field is valid, then the `isPassed` property is `true`.
* - If the field is invalid, then the `isPassed` property is `false`.
* - The `message` property is optional and only used if the field is invalid.
*
* @example { value: "The field is valid." }
* @example { value: "The field is invalid.", isPassed: false }
* @example { value: "The field is invalid.", isPassed: false, message: "The field must be a string." }
*/
interface EvaluationResult<T = any> {
value: T;
isPassed: boolean;
message?: string;
}
type EngineResult<T = any> = Omit<EvaluationResult<T>, "isPassed">;
type CriteriaObject<T = any> = Record<string, T>;
type Criteria<T = any> = CriteriaObject<T> | Array<T>;
interface Condition<R = any> {
/**
* The constraints to evaluate. This is optional.
* - If one of the constraints is met, then the result is valid.
* @example { or: [{ field: "name", operator: Operators.Equals, value: "test" }] } // The result is valid if the name field equals "test".
*/
or?: Array<Constraint | Condition<R>>;
/**
* The constraints to evaluate. This is optional.
* - If all the constraints are met, then the result is valid.
* @example { and: [{ field: "name", operator: Operators.Equals, value: "test" }] } // The result is valid if the name field equals "test".
*/
and?: Array<Constraint | Condition<R>>;
/**
* The constraints to evaluate. This is optional.
* - If none of the constraints are met, then the result is valid.
* @example { none: [{ field: "name", operator: Operators.Equals, value: "test" }] } // The result is valid if the name field does not equal "test".
*/
none?: Array<Constraint | Condition<R>>;
/**
* The result of the evaluation.
* - This is the value of the field that was evaluated.
* - This is optional.
*/
result?: EngineResult<R>;
}
interface RuleType<R = any> {
conditions: Condition<R> | Array<Condition<R>>;
default?: EngineResult<R>;
}
interface CriteriaRange<R = any> {
result: EngineResult<R>;
options?: Array<Record<string, unknown>>;
}
interface IntrospectionResult<R = any> {
results: Array<CriteriaRange<R>>;
default?: EngineResult<R>;
}
interface ValidationResult$1 {
isValid: boolean;
error?: {
message: string;
element: object;
};
}
/**
* Base types and interfaces for the operator system using Strategy pattern
*/
/**
* Type representing the expected field types for operators
*/
type FieldType = "string" | "number" | "boolean" | "date" | "array" | "object" | "any" | "time";
/**
* Type representing the expected value types for operators
*/
type ValueType = FieldType | "regex" | "range" | "void";
/**
* Metadata for an operator
*/
interface OperatorMetadata {
/**
* Unique name of the operator
*/
name: OperatorsType;
/**
* Human-readable display name
*/
displayName: string;
/**
* Category for grouping operators
*/
category: OperatorCategory;
/**
* Description of what the operator does
*/
description: string;
/**
* Accepted field types
*/
acceptedFieldTypes: FieldType[];
/**