2026-08-19 10:04:21 +02:00
|
|
|
//
|
|
|
|
|
// CustomOperators.swift
|
|
|
|
|
//
|
|
|
|
|
// Created by Antonio Pallares.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
|
|
extension RulesEngine {
|
|
|
|
|
|
|
|
|
|
/// RevenueCat-specific JSON Logic operators.
|
|
|
|
|
///
|
|
|
|
|
/// Operators here are namespaced under `rc.` so they cannot collide with a
|
|
|
|
|
/// future standard JSON Logic operator.
|
|
|
|
|
enum CustomOperators {
|
|
|
|
|
|
2026-08-31 08:52:53 +02:00
|
|
|
// swiftlint:disable:next cyclomatic_complexity
|
2026-08-19 10:04:21 +02:00
|
|
|
static func dispatch(
|
|
|
|
|
op operatorName: String,
|
|
|
|
|
args: Value,
|
|
|
|
|
vars: Scope
|
|
|
|
|
) throws -> Value {
|
|
|
|
|
switch operatorName {
|
2026-08-24 12:57:04 +02:00
|
|
|
case "rc.entries":
|
|
|
|
|
return try EntriesOperators.opEntries(args: args, vars: vars)
|
|
|
|
|
case "rc.fromEntries":
|
|
|
|
|
return try EntriesOperators.opFromEntries(args: args, vars: vars)
|
|
|
|
|
|
2026-09-01 09:50:17 +02:00
|
|
|
case "rc.let":
|
|
|
|
|
return try LetOperator.opLet(args: args, vars: vars)
|
|
|
|
|
|
2026-08-21 07:41:56 +02:00
|
|
|
case "rc.lower":
|
|
|
|
|
return try CaseOperators.opLower(args: args, vars: vars)
|
|
|
|
|
case "rc.upper":
|
|
|
|
|
return try CaseOperators.opUpper(args: args, vars: vars)
|
|
|
|
|
|
2026-09-02 13:09:58 +02:00
|
|
|
case "rc.regexExtract":
|
|
|
|
|
return try RegexOperators.opRegexExtract(args: args, vars: vars)
|
2026-09-02 13:09:58 +02:00
|
|
|
case "rc.regexMatch":
|
|
|
|
|
return try RegexOperators.opRegexMatch(args: args, vars: vars)
|
2026-09-02 13:09:59 +02:00
|
|
|
case "rc.regexReplace":
|
|
|
|
|
return try RegexOperators.opRegexReplace(args: args, vars: vars)
|
2026-09-02 13:09:58 +02:00
|
|
|
|
2026-08-19 18:07:53 +02:00
|
|
|
case "rc.rootVar":
|
|
|
|
|
return try RootVarOperator.opRootVar(args: args, vars: vars)
|
|
|
|
|
|
2026-08-25 11:26:54 +02:00
|
|
|
case "rc.semverCompare":
|
|
|
|
|
return try SemverOperator.opSemverCompare(args: args, vars: vars)
|
|
|
|
|
|
2026-08-31 08:52:53 +02:00
|
|
|
case "rc.slice":
|
|
|
|
|
return try SliceOperator.opSlice(args: args, vars: vars)
|
|
|
|
|
|
2026-08-31 08:10:18 +02:00
|
|
|
case "rc.sortBy":
|
|
|
|
|
return try SortByOperator.opSortBy(args: args, vars: vars)
|
|
|
|
|
|
2026-08-24 09:47:39 +02:00
|
|
|
case "rc.split":
|
|
|
|
|
return try SplitOperator.opSplit(args: args, vars: vars)
|
|
|
|
|
|
2026-08-19 10:04:21 +02:00
|
|
|
default:
|
|
|
|
|
throw EvaluationError.unsupportedOperator(name: operatorName)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|