Skip to content

Implement $hasAny operator for any-of array-containment matching#335

Merged
albe merged 5 commits into
mainfrom
copilot/wip-implement-hasany-operator
Jul 18, 2026
Merged

Implement $hasAny operator for any-of array-containment matching#335
albe merged 5 commits into
mainfrom
copilot/wip-implement-hasany-operator

Conversation

Copilot AI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Thanks for the feedback on #331. This PR implements the $hasAny operator as a sibling to $has, providing explicit any-of array-containment semantics.

Original PR: #331
Triggering review: #331 (comment)

Changes Made

  • Object mode (src/utils/metadataUtil.js): Added $hasAny case in buildOperatorChecks — compiles to Array.isArray(v) && expectedValues.some(x => v.includes(x)).
  • Raw-buffer mode (src/utils/metadataUtil.js): Added $hasAny branch in buildMatcherTreeChild — anchors on the "key":[ opener and calls indexOfSameLevel for each pre-serialized value pattern, short-circuiting on the first hit.
  • IndexMatcher (src/IndexMatcher.js): Added isLoneHasAnyArray helper and $hasAny handling in findDiscriminant — registers the matcher under each expected value as a discriminant key, enabling O(1) routing when any document array element matches (deduplication handled by the existing called set in forEachMatch).
  • Docs: Updated streams.md, api.md, dcb.md, and changelog.md to document $hasAny alongside $has.
  • Tests: Added object-mode and raw-buffer-mode tests in test/metadataUtil.spec.js and discriminant registration/lookup tests in test/IndexMatcher.spec.js.

Usage

// matches events whose payload.tags array contains 'course:1' OR 'student:9'
{ payload: { tags: { $hasAny: ['course:1', 'student:9'] } } }

Copilot AI changed the title [WIP] [WIP] Implement $hasAny operator in DCB query support based on feedback Implement $hasAny operator for any-of array-containment matching Jul 18, 2026
Copilot finished work on behalf of albe July 18, 2026 11:05
Copilot AI requested a review from albe July 18, 2026 11:05
Comment thread src/IndexMatcher.js
Copilot finished work on behalf of albe July 18, 2026 11:35
Copilot AI requested a review from albe July 18, 2026 11:35
Base automatically changed from dcb-query to main July 18, 2026 12:36
Comment thread docs/changelog.md Outdated
Copilot finished work on behalf of albe July 18, 2026 12:44
Copilot AI requested a review from albe July 18, 2026 12:44
@albe

albe commented Jul 18, 2026

Copy link
Copy Markdown
Owner

@copilot resolve the merge conflicts in this pull request

Copilot AI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Resolved. Two conflicts in the merge with origin/main:

  • docs/changelog.md: kept the condensed 1.4.0 format and added the new "Breaking:" bullet from main.
  • test/IndexMatcher.spec.js: retained both the new $hasAny tests from our branch and the $has edge-case tests added on main.

All 687 tests pass.

Copilot finished work on behalf of albe July 18, 2026 12:52
@albe
albe marked this pull request as ready for review July 18, 2026 12:53
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 98.299% (+0.01%) from 98.288% — copilot/wip-implement-hasany-operator into main

@albe
albe merged commit cf1531a into main Jul 18, 2026
13 checks passed
@albe
albe deleted the copilot/wip-implement-hasany-operator branch July 18, 2026 12:54
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.

3 participants