Skip to content

Conversation

@sydneygrivers
Copy link

@sydneygrivers sydneygrivers commented Jan 22, 2026

Added Scoped Nested Rules Feature

  1. New ScopedAlmanac class (src/scoped-almanac.js)
    - Wraps a parent almanac with a specific array item context
    - Allows conditions inside nested rules to access properties directly on the current array item
    - Supports resolvePath() to resolve JSONPath directly on the scoped item
    - Falls back to parent almanac for facts not found on the item
  2. New some operator for nested conditions (src/condition.js)
    - Added isNestedCondition() - detects operator: 'some' with a conditions property
    - Added isScopedCondition() - detects path-only conditions (no fact, just path + operator)
    - Scoped conditions work inside nested blocks where the "fact" is implicitly the current array item
  3. Updated rule evaluation (src/rule.js)
    - Added evaluateNestedCondition() to iterate over array items
    - Creates a ScopedAlmanac for each array item and evaluates nested conditions against it
    - Short-circuits on first match (returns true as soon as any item matches)
    - Threaded currentAlmanac through all evaluation functions (evaluateCondition, all, any, not, realize, etc.)
  4. Error handling (src/almanac.js)
    - Added resolvePath() stub that throws helpful error if path-only conditions are used outside nested context
  5. TypeScript definitions (types/index.d.ts) - Updated types to support the new structures
  6. Comprehensive tests (test/engine-nested-conditions.test.js) - ~1100 lines of test coverage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant