Skip to content

feat: add bypassDataItemFilter flag and convert to object parameters (PE-8173) #433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

djwhitt
Copy link
Collaborator

@djwhitt djwhitt commented Jun 11, 2025

Summary

Add bypassDataItemFilter flag and convert function parameters to object-based pattern for better maintainability and extensibility.

Changes

  • Added bypassDataItemFilter parameter to bypass data item filtering during bundle processing
  • Converted multiple function signatures from positional parameters to object-based parameters
  • Maintained backward compatibility for legacy bypassFilter parameter in API endpoint
  • Updated all related tests to use new object parameter pattern

Test plan

  • All existing tests pass
  • New parameter functionality tested
  • Backward compatibility maintained for API endpoints
  • Object parameter pattern applied consistently across codebase

🤖 Generated with Claude Code

…(PE-8173)

* Rename bypassFilter to bypassBundleFilter for clarity
* Add new bypassDataItemFilter flag that only bypasses ANS104_INDEX_FILTER
* Convert all queue methods from positional to object parameters
* Update system.queueBundle to accept QueueBundleOptions interface
* Update DataImporter, Ans104Unbundler, and ANS-104 parser to use object params
* Update admin API to support both new and legacy parameter formats
* Update data verification worker to use new parameter structure
* Update all unit tests to use new object parameter format
* Maintain backward compatibility for legacy bypassFilter parameter

The new implementation allows independent control of bundle and data item
filtering, providing more granular control over the unbundling process.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

coderabbitai bot commented Jun 11, 2025

📝 Walkthrough

Walkthrough

This change refactors the filtering mechanism for bundle processing by replacing a single bypassFilter flag with two distinct flags: bypassBundleFilter and bypassDataItemFilter. These flags are propagated through API routes, system logic, worker classes, and tests, providing finer control over filter bypassing at both the bundle and data item levels. All related method signatures and interfaces are updated accordingly.

Changes

Files/Groups Change Summary
src/lib/ans-104.ts Updated parseBundle to accept bypassDataItemFilter parameter; logic modified to allow bypassing data item filter if flag is true.
src/routes/ar-io.ts Route handler updated to support bypassBundleFilter and bypassDataItemFilter flags; validation and parameter passing logic adjusted.
src/system.ts Refactored queueBundle to accept a single options object with bypassBundleFilter and bypassDataItemFilter; updated event listeners.
src/workers/ans104-unbundler.ts,
src/workers/ans104-unbundler.test.ts
Changed queueItem and unbundle signatures to use options object with two bypass flags; updated queueing and unbundling logic and corresponding tests.
src/workers/data-importer.ts,
src/workers/data-importer.test.ts
Replaced single bypassFilter flag with bypassBundleFilter and bypassDataItemFilter in interfaces and method signatures; updated queueing, download logic, and tests.
src/workers/data-verification.ts Changed queueBundle property and invocations to use options object with two bypass flags; updated calls to dataImporter.queueItem.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_Route as /ar-io/admin/queue-bundle
    participant System
    participant DataImporter
    participant Ans104Unbundler
    participant Ans104Parser

    Client->>API_Route: POST /ar-io/admin/queue-bundle (with bypassBundleFilter, bypassDataItemFilter)
    API_Route->>System: queueBundle({ item, prioritized, bypassBundleFilter, bypassDataItemFilter })
    System->>DataImporter: queueItem({ item, prioritized, bypassBundleFilter, bypassDataItemFilter })
    DataImporter->>Ans104Unbundler: queueItem({ item, prioritized, bypassBundleFilter, bypassDataItemFilter })
    Ans104Unbundler->>Ans104Parser: parseBundle({ ..., bypassDataItemFilter })
    Ans104Parser-->>Ans104Unbundler: Processed bundle (with/without data item filter)
Loading

Possibly related PRs

  • ar-io/ar-io-node#259: Introduces a single bypassFilter flag to the queueBundle function and related logic; the current PR extends this by splitting into two distinct flags.
  • ar-io/ar-io-node#248: Adds the original bypass filter mechanism; the current PR directly builds upon this by refining and separating the filter bypass logic.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

yarn install v1.22.22
[1/4] Resolving packages...
(node:17720) [DEP0169] DeprecationWarning: url.parse() behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for url.parse() vulnerabilities.
(Use node --trace-deprecation ... to show where the warning was created)
[2/4] Fetching packages...
error @permaweb/aoconnect@0.0.57: The engine "yarn" is incompatible with this module. Expected version "please-use-npm". Got "1.22.22"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (12)
src/routes/ar-io.ts (1)

273-289: Boolean-type validation can never hit the undefined branch

Because bypassBundleFilter receives a default (= true) the derived effectiveBypassBundleFilter is always defined.
The ... !== undefined guard therefore always evaluates to true, making the undefined branch dead code.

Not harmful, but removing the unnecessary check would simplify the condition:

- if (
-   effectiveBypassBundleFilter !== undefined &&
-   typeof effectiveBypassBundleFilter !== 'boolean'
- ) {
+ if (typeof effectiveBypassBundleFilter !== 'boolean') {
src/workers/ans104-unbundler.test.ts (1)

71-73: Missing await on queueItem may hide async failures

queueItem returns a Promise<void>; invoking it without await means any rejection would be unhandled and the test would still pass.

-ans104Unbundler.queueItem({ item: mockItem, prioritized: false });
+await ans104Unbundler.queueItem({ item: mockItem, prioritized: false });

Same pattern repeats in this block of tests.

src/lib/ans-104.ts (1)

284-291: Constructor overload expanded cleanly – consider documenting the new flag

bypassDataItemFilter is now part of the public contract of parseBundle.
Please update any JSDoc / README snippet so integrators know the exact behaviour (bundle filter may still run while data-item filter is bypassed).

src/workers/data-importer.test.ts (1)

167-173: Hard-coding both bypass flags to false is fine, but widen test coverage

Consider adding another test where one or both flags are true, to ensure they propagate through downloadqueueItemAns104Unbundler.

src/workers/data-verification.ts (3)

46-52: Type definition duplicated – lift to a shared Options type?

The same { item, prioritized?, bypassBundleFilter?, bypassDataItemFilter? } shape now appears in several modules.
Extracting a QueueBundleOptions interface (e.g. in types.ts) would reduce drift as the parameter list evolves.


160-165: bypassDataItemFilter not forwarded

You set bypassBundleFilter: true but omit bypassDataItemFilter, relying on the default false.
If future callers ever need to tweak just the data-item flag, they’ll have to touch this code again.
Consider passing it explicitly (even as false) for clarity.


195-197: prioritized omitted when re-queueing corrupted bundles

DataImporter.queueItem treats prioritized as optional, but semantics suggest retries should stay prioritized.
Add prioritized: true for consistency with the earlier call.

src/workers/ans104-unbundler.ts (1)

110-120: Consider defaulting prioritized to false in the parameter destructuring

prioritized is later compared to the boolean literal true. Supplying a default avoids the extra undefined check and communicates the intent more clearly.

-  async queueItem({
-    item,
-    prioritized,
+  async queueItem({
+    item,
+    prioritized = false,
src/workers/data-importer.ts (2)

40-45: Make prioritized optional in DataImporterQueueItem for consistency

The field is optional in callers, yet the interface declares it as mandatory (albeit boolean | undefined).
Declaring it as optional (prioritized?: boolean) keeps the types aligned with usage and removes the confusing undefined union.

-  prioritized: boolean | undefined;
+  prioritized?: boolean;

84-94: Default prioritized to false to avoid tri-state logic

Same rationale as in the unbundler: defaulting removes the need for undefined checks later while preserving current behaviour.

-  async queueItem({
-    item,
-    prioritized,
+  async queueItem({
+    item,
+    prioritized = false,
src/system.ts (2)

614-619: Minor: prioritized can be marked optional in QueueBundleOptions

prioritized already has a default in queueBundle, so marking it optional in the interface tightens type expectations.

-  prioritized?: boolean;
+  prioritized?: boolean;

(This is purely cosmetic and can be skipped if interface consistency is preferred.)


676-687: Magic number -1 for parent index could be extracted

Using a named constant (e.g., NO_PARENT_INDEX = -1) improves readability and reduces the chance of silent misuse elsewhere.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c99787e and dd27fe6.

📒 Files selected for processing (8)
  • src/lib/ans-104.ts (4 hunks)
  • src/routes/ar-io.ts (2 hunks)
  • src/system.ts (4 hunks)
  • src/workers/ans104-unbundler.test.ts (6 hunks)
  • src/workers/ans104-unbundler.ts (6 hunks)
  • src/workers/data-importer.test.ts (5 hunks)
  • src/workers/data-importer.ts (5 hunks)
  • src/workers/data-verification.ts (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
src/workers/ans104-unbundler.test.ts (1)
Learnt from: karlprieb
PR: ar-io/ar-io-node#228
File: src/workers/ans104-unbundler.ts:41-45
Timestamp: 2024-10-31T17:48:59.599Z
Learning: In `src/workers/ans104-unbundler.ts`, when defining `isNormalizedBundleDataItem`, avoid checking for `null` values of `root_parent_offset` and `data_offset`, as `null` values signify that the item is a `NormalizedOptimisticDataItem`, not a `NormalizedBundleDataItem`.
src/workers/ans104-unbundler.ts (1)
Learnt from: karlprieb
PR: ar-io/ar-io-node#228
File: src/workers/ans104-unbundler.ts:41-45
Timestamp: 2024-10-31T17:48:59.599Z
Learning: In `src/workers/ans104-unbundler.ts`, when defining `isNormalizedBundleDataItem`, avoid checking for `null` values of `root_parent_offset` and `data_offset`, as `null` values signify that the item is a `NormalizedOptimisticDataItem`, not a `NormalizedBundleDataItem`.
🧬 Code Graph Analysis (4)
src/workers/data-verification.ts (2)
src/types.d.ts (1)
  • PartialJsonTransaction (49-61)
src/system.ts (1)
  • QueueBundleResponse (610-613)
src/workers/data-importer.test.ts (1)
src/system.ts (1)
  • bundleDataImporter (600-606)
src/routes/ar-io.ts (1)
src/types.d.ts (1)
  • PartialJsonTransaction (49-61)
src/system.ts (2)
src/types.d.ts (1)
  • PartialJsonTransaction (49-61)
src/workers/data-verification.ts (1)
  • QueueBundleResponse (33-36)
🔇 Additional comments (9)
src/routes/ar-io.ts (3)

260-266: Defaulting bypassBundleFilter to true silently relaxes filtering for callers who omit the flag

Prior behaviour required an explicit bypassFilter:true to ignore bundle-level filtering; now the same result occurs when the flag is simply absent.
If any existing automation relied on “filter unless I explicitly say otherwise”, this change weakens that guarantee.

Please double-check downstream consumers / scripts before merging.
If the relaxed default is intentional, consider calling it out in the API docs and bumping a minor version.


298-306: bypassDataItemFilter ignored when delegating to /queue-tx path

When effectiveBypassBundleFilter === false, the request is downgraded to a TX-queue.
Any user-supplied bypassDataItemFilter is silently discarded, which may surprise clients that set it.

If this is intentional, consider returning a warning message; if not, propagate the flag (where technically feasible).


313-320: Object parameter construction looks good

Nice adoption of the new { item, prioritized, bypassBundleFilter, bypassDataItemFilter } pattern – improves readability and future extensibility.

src/workers/ans104-unbundler.test.ts (1)

118-123: Great coverage for bypassBundleFilter path

Verifying that bypassDataItemFilter defaults to false in the forwarded payload tightens confidence in the new flag handling. 👍

src/lib/ans-104.ts (2)

352-353: Worker message extended correctly

Passing bypassDataItemFilter through the worker message keeps the main/worker APIs symmetrical – nice.


490-492: Short-circuit keeps filter cost negligible when bypassing

if (bypassDataItemFilter || (await filter.match(...))) is the right precedence – avoids an unnecessary async call when bypassing.
Looks solid.

src/workers/data-importer.test.ts (1)

108-112: Updated queueItem invocation aligns with new signature

Call site now uses the object-parameter style; tests compile under the new API – good catch.

src/workers/ans104-unbundler.ts (2)

135-140: prioritized flag is discarded after deciding between unshift and push

If we ever need this flag again in the unbundle phase (e.g., to influence metrics or logging), it will be unavailable because it is not forwarded into the queue payload.
That may be intentional, but worth a quick double-check.


185-187: Good propagation of the new bypassDataItemFilter flag

The flag is forwarded to ans104Parser.parseBundle, keeping behaviour consistent with the refactor.

Copy link

codecov bot commented Jun 11, 2025

Codecov Report

Attention: Patch coverage is 75.55556% with 22 lines in your changes missing coverage. Please review.

Project coverage is 72.89%. Comparing base (bddcc1a) to head (dd27fe6).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
src/lib/ans-104.ts 0.00% 12 Missing ⚠️
src/workers/data-verification.ts 57.14% 9 Missing ⚠️
src/workers/ans104-unbundler.ts 95.83% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #433      +/-   ##
===========================================
+ Coverage    72.88%   72.89%   +0.01%     
===========================================
  Files           49       49              
  Lines        12526    12576      +50     
  Branches       727      727              
===========================================
+ Hits          9129     9167      +38     
- Misses        3391     3403      +12     
  Partials         6        6              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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