Files
Antonio PallaresandCursor 2deacfd190 Add Scope plumbing and custom operator extension point (#7433)
* Add Scope plumbing and custom operator extension point

Thread evaluation scope through the rules engine and delegate unknown
operators to an empty CustomOperators dispatcher, without changing behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Fix project.pbxproj: restore RewardedAdTrackingMetadata entries

The RulesEngine registration edit accidentally dropped four
RewardedAdTrackingMetadata.swift entries from the Xcode project.
Restore them and normalize CustomOperators identifiers to 24 hex chars.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Promote firstArgEvaluated to shared Operators helpers

Move the unary-arg helper from LogicOperators to Operators so custom
operators can use the same json-logic-js spread convention.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Address review comments on custom operator extension point

Drop the cross-engine registration note from CustomOperators, and restore
the single-line var extra-args warning that was reflowed without changing
its text.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-19 08:04:21 +00:00

41 lines
1.4 KiB
Swift

//
// EqualityOperators.swift
//
// Created by Antonio Pallares.
//
import Foundation
extension RulesEngine {
/// Equality operators: `==`, `!=`, `===`, `!==`.
enum EqualityOperators {
/// `{"==": [a, b]}` — JSON Logic loose equality. Coerces across primitive
/// types (e.g. `1 == "1"` is true). Full coercion table in `looseEq`.
static func opLooseEq(args: Value, vars: Scope) throws -> Value {
let (lhs, rhs) = try Operators.evalTwo(args, vars: vars)
return .bool(looseEq(lhs, rhs))
}
/// `{"!=": [a, b]}` — JSON Logic loose inequality. Negation of `==`.
static func opLooseNe(args: Value, vars: Scope) throws -> Value {
let (lhs, rhs) = try Operators.evalTwo(args, vars: vars)
return .bool(!looseEq(lhs, rhs))
}
/// `{"===": [a, b]}` — JSON Logic strict equality. Same type, same
/// value (`1 === "1"` is false).
static func opStrictEq(args: Value, vars: Scope) throws -> Value {
let (lhs, rhs) = try Operators.evalTwo(args, vars: vars)
return .bool(strictEq(lhs, rhs))
}
/// `{"!==": [a, b]}` — JSON Logic strict inequality. Negation of `===`.
static func opStrictNe(args: Value, vars: Scope) throws -> Value {
let (lhs, rhs) = try Operators.evalTwo(args, vars: vars)
return .bool(!strictEq(lhs, rhs))
}
}
}