Skip to content

fix: async issues#763

Merged
carlbrugger merged 1 commit intomainfrom
fix/external-constraint-async-issue
Feb 28, 2025
Merged

fix: async issues#763
carlbrugger merged 1 commit intomainfrom
fix/external-constraint-async-issue

Conversation

@carlbrugger
Copy link
Contributor

Please explain how to summarize this PR for the Changelog:

This adds support for async cb()

Tell code reviewer how and what to test:

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2025

Walkthrough

This pull request introduces asynchronous callback support for the @flatfile/plugin-constraints package. It updates two functions—externalConstraint and externalSheetConstraint—to allow callbacks to return either a direct value or a promise. The modifications change the iteration method from forEach to for...of loops so that await can be used, ensuring proper asynchronous execution while preserving error handling.

Changes

File(s) Change Summary
.changeset/healthy-donuts-invite.md Added a new patch entry for @flatfile/plugin-constraints signaling support for asynchronous callbacks.
plugins/constraints/src/external.constraint.ts
plugins/constraints/src/external.sheet.constraint.ts
Updated callback return types from any to `any

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant ConstraintFunction
    participant AsyncCallback

    Caller->>ConstraintFunction: Invoke constraint validation
    ConstraintFunction->>ConstraintFunction: Iterate constraints using for...of
    ConstraintFunction->>AsyncCallback: await cb(value, ...)
    AsyncCallback-->>ConstraintFunction: Return value or promise resolution
    ConstraintFunction->>Caller: Return aggregated results
Loading

Possibly related PRs

  • fix: async issue #674: Addresses similar asynchronous operation enhancements in Flatfile plugins, closely aligning with the changes introduced in this PR.

Suggested reviewers

  • bangarang
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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 (1)
plugins/constraints/src/external.constraint.ts (1)

38-41: Good refactoring from forEach to for...of loops to support await.

The loop structure has been properly changed to enable awaiting asynchronous callbacks. This ensures each callback is fully processed before moving to the next one, maintaining proper execution order.

Consider adding documentation comments mentioning that async callbacks are now supported, which would make the API more self-documenting.

 /**
+ * @param validator - The name of the validator to apply
+ * @param cb - The callback function to execute, which can now be async
  */

Also applies to: 50-51

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eeafb79 and cab3b98.

📒 Files selected for processing (3)
  • .changeset/healthy-donuts-invite.md (1 hunks)
  • plugins/constraints/src/external.constraint.ts (3 hunks)
  • plugins/constraints/src/external.sheet.constraint.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Setup
🔇 Additional comments (5)
plugins/constraints/src/external.constraint.ts (1)

20-20: Correctly updated return type to support async callbacks.

The return type now includes Promise<any>, allowing for asynchronous callback functions.

.changeset/healthy-donuts-invite.md (1)

1-6: Changeset message is clear and concise.

The changeset correctly identifies this as a patch update for the @flatfile/plugin-constraints package and clearly states the purpose: supporting async callbacks.

plugins/constraints/src/external.sheet.constraint.ts (3)

29-29: Correctly updated function signature to support async callbacks.

The return type now properly includes Promise<any>, which aligns with the PR objective of adding async callback support.


47-63: Good refactoring to support async operations.

Converting from forEach to for...of loops is essential for proper async execution, as it allows the use of await within the loop. This change properly ensures that:

  1. Each constraint is processed sequentially
  2. Each record within a constraint is processed sequentially
  3. The callback is properly awaited with await cb(...)

The error handling is preserved and works correctly with the async pattern.


51-51: Correctly implemented await for callback execution.

Adding await here ensures that the callback is properly awaited, whether it returns a direct value or a Promise.

Copy link
Contributor

@meritmalling meritmalling left a comment

Choose a reason for hiding this comment

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

Tested & works great!

@carlbrugger carlbrugger merged commit 362e0f9 into main Feb 28, 2025
37 checks passed
@carlbrugger carlbrugger deleted the fix/external-constraint-async-issue branch February 28, 2025 17:24
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.

2 participants