Skip to content

feat: add registerOutgoingProcessor to JavaScript WebSocket client#2101

Open
10done wants to merge 7 commits into
asyncapi:masterfrom
10done:feat/js-websocket-register-outgoing-processor
Open

feat: add registerOutgoingProcessor to JavaScript WebSocket client#2101
10done wants to merge 7 commits into
asyncapi:masterfrom
10done:feat/js-websocket-register-outgoing-processor

Conversation

@10done
Copy link
Copy Markdown
Contributor

@10done 10done commented May 24, 2026

Description

  • Added registerOutgoingProcessor(processor) method to the JavaScript WebSocket client template, mirroring the existing feature in the Python WebSocket client
  • Initialized this.outgoingProcessors = [] in the JavaScript client constructor to store registered processor functions
  • Added unit test and snapshot for the new RegisterOutgoingProcessor component
  • Updated integration snapshots to reflect the new method and constructor field in generated JavaScript clients

Related issue(s)

Fixes #1975

Testing Screenshots

image image image

Summary by CodeRabbit

  • New Features

    • WebSocket JavaScript client template now supports registering outgoing message processors that run before messages are sent, enabling transformation or enrichment of outgoing payloads.
  • Examples

    • Example client updated to show registering an outgoing processor that augments messages with an ISO timestamp and logs the processed output.
  • Tests

    • Added test coverage for outgoing processor registration and its runtime behavior.

Review Change Stack

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 24, 2026

⚠️ No Changeset found

Latest commit: 2c943d0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@asyncapi-bot
Copy link
Copy Markdown
Contributor

What reviewer looks at during PR review

The following are ideal points maintainers look for during review. Reviewing these points yourself beforehand can help streamline the review process and reduce time to merge.

  1. PR Title: Use a concise title that follows our Conventional Commits guidelines and clearly summarizes the change using imperative mood (it means spoken or written as if giving a command or instruction, like "add new helper for listing operations")

    Note - In Generator, prepend feat: or fix: in PR title only when PATCH/MINOR release must be triggered.

  2. PR Description: Clearly explain the issue being solved, summarize the changes made, and mention the related issue.

    Note - In Generator, we use Maintainers Work board to track progress. Ensure the PR Description includes Resolves #<issue-number> or Fixes #<issue-number> this will automatically close the linked issue when the PR is merged and helps automate the maintainers workflow.

  3. Documentation: Update the relevant Generator documentation to accurately reflect the changes introduced in the PR, ensuring users and contributors have up-to-date guidance.

  4. Comments and JSDoc: Write clear and consistent JSDoc comments for functions, including parameter types, return values, and error conditions, so others can easily understand and use the code.

  5. DRY Code: Ensure the code follows the Don't Repeat Yourself principle. Look out for duplicate logic that can be reused.

  6. Test Coverage: Ensure the new code is well-tested with meaningful test cases that pass consistently and cover all relevant edge cases.

  7. Commit History: Contributors should avoid force-pushing as much as possible. It makes it harder to track incremental changes and review the latest updates.

  8. Template Design Principles Alignment: While reviewing template-related changes in the packages/ directory, ensure they align with the Assumptions and Principles. If any principle feels outdated or no longer applicable, start a discussion these principles are meant to evolve with the project.

  9. Reduce Scope When Needed: If an issue or PR feels too large or complex, consider splitting it and creating follow-up issues. Smaller, focused PRs are easier to review and merge.

  10. Bot Comments: As reviewers, check that contributors have appropriately addressed comments or suggestions made by automated bots. If there are bot comments the reviewer disagrees with, react to them or mark them as resolved, so the review history remains clear and accurate.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ea913c00-e949-45ea-9040-dbf95a154720

📥 Commits

Reviewing files that changed from the base of the PR and between 4ca9d81 and d43a500.

📒 Files selected for processing (1)
  • packages/templates/clients/websocket/javascript/test/components/RegisterOutgoingProcessor.test.js

📝 Walkthrough

Walkthrough

Adds outgoing processor registration to the JavaScript WebSocket client template: a RegisterOutgoingProcessor component generates registration code, the constructor stores processors, send logic runs processors before sending, and the example registers an outgoing processor.

Changes

Outgoing Processor Registration

Layer / File(s) Summary
RegisterOutgoingProcessor component and test
packages/templates/clients/websocket/javascript/components/RegisterOutgoingProcessor.js, packages/templates/clients/websocket/javascript/test/components/RegisterOutgoingProcessor.test.js
New component emits registerOutgoingProcessor(processor) that guards for function input and pushes processors into this.outgoingProcessors; test asserts generated code fragments exist.
Client class constructor and JSX integration
packages/templates/clients/websocket/javascript/components/Constructor.js, packages/templates/clients/websocket/javascript/components/ClientClass.js
Constructor initializes this.outgoingProcessors = []. ClientClass imports and renders <RegisterOutgoingProcessor /> in the generated class JSX.
Send operations: apply outgoing processors
packages/components/src/components/SendOperations.js
Generated instance send method now composes processedMessage by running each function in this.outgoingProcessors (preserving previous value when a processor returns null/undefined) before schema selection and calling the client's send. Method comment updated.
Example wiring
packages/templates/clients/websocket/javascript/example.js
Adds outgoingProcessor(message) example that appends an ISO timestamp and logs the processed value; main() registers it via wsClient.registerOutgoingProcessor(...).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title follows Conventional Commits with 'feat:' prefix, uses imperative mood ('add registerOutgoingProcessor'), and clearly summarizes the main change of adding processor registration to the JavaScript WebSocket client.
Linked Issues check ✅ Passed The PR successfully implements the requested feature from issue #1975: adds RegisterOutgoingProcessor component, updates the constructor to initialize outgoingProcessors array, integrates processors into the send path, includes comprehensive tests, and mirrors Python client functionality.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the registerOutgoingProcessor feature: new component, constructor initialization, send operations integration, tests, and example usage demonstrating the feature.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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: 1

🧹 Nitpick comments (1)
packages/templates/clients/websocket/javascript/components/RegisterOutgoingProcessor.js (1)

3-17: ⚡ Quick win

Add JSDoc for the exported component function.

RegisterOutgoingProcessor is missing JSDoc. Add a function-level docblock describing purpose, return type, and that it emits runtime warning logic in generated code.

As per coding guidelines, "**/*.{js,ts,jsx,tsx}: Write clear and consistent JSDoc comments for functions, including parameter types, return values, and error conditions".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/templates/clients/websocket/javascript/components/RegisterOutgoingProcessor.js`
around lines 3 - 17, Add a JSDoc block above the exported function
RegisterOutgoingProcessor describing its purpose (returns a JSX/Text snippet
that renders a JS function for registering outgoing processors), the return type
(JSX.Element), and noting that the generated code includes runtime warning logic
when a non-function processor is provided; include tags for `@returns`
{JSX.Element} and a brief description of the emitted runtime behavior
(console.warn on invalid input). Ensure the docblock sits immediately above the
RegisterOutgoingProcessor declaration and follows existing project JSDoc style.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@packages/templates/clients/websocket/javascript/test/components/RegisterOutgoingProcessor.test.js`:
- Around line 4-9: The test uses a snapshot for a purely presentational
component (RegisterOutgoingProcessor) which violates the template-local policy;
replace the snapshot-only test with a focused assertion that verifies the
component's static output (e.g., render(<RegisterOutgoingProcessor />) and
assert on specific DOM nodes/text or testIds using
getByText/getByRole/getByTestId), or remove the test if integration/acceptance
covers it; update the test file to import the appropriate query helpers from
your test utils and assert specific elements instead of calling
toMatchSnapshot().

---

Nitpick comments:
In
`@packages/templates/clients/websocket/javascript/components/RegisterOutgoingProcessor.js`:
- Around line 3-17: Add a JSDoc block above the exported function
RegisterOutgoingProcessor describing its purpose (returns a JSX/Text snippet
that renders a JS function for registering outgoing processors), the return type
(JSX.Element), and noting that the generated code includes runtime warning logic
when a non-function processor is provided; include tags for `@returns`
{JSX.Element} and a brief description of the emitted runtime behavior
(console.warn on invalid input). Ensure the docblock sits immediately above the
RegisterOutgoingProcessor declaration and follows existing project JSDoc style.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fab3c219-7211-4148-b03d-7d0f37b1c6c8

📥 Commits

Reviewing files that changed from the base of the PR and between 917a555 and e5e5bed.

⛔ Files ignored due to path filters (2)
  • packages/templates/clients/websocket/javascript/test/components/__snapshots__/RegisterOutgoingProcessor.test.js.snap is excluded by !**/*.snap
  • packages/templates/clients/websocket/test/integration-test/__snapshots__/integration.test.js.javascript.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • packages/templates/clients/websocket/javascript/components/ClientClass.js
  • packages/templates/clients/websocket/javascript/components/Constructor.js
  • packages/templates/clients/websocket/javascript/components/RegisterOutgoingProcessor.js
  • packages/templates/clients/websocket/javascript/test/components/RegisterOutgoingProcessor.test.js

Copy link
Copy Markdown
Member

@Adi-204 Adi-204 left a comment

Choose a reason for hiding this comment

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

@10done I honestly don't get what is use of this in JS template can you modify example https://github.com/asyncapi/generator/blob/master/packages/templates/clients/websocket/javascript/example.js to show how this can be useful? Also add screenshot in PR.

Copy link
Copy Markdown

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/components/src/components/SendOperations.js (1)

61-71: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add missing required JSDoc tags on generated async instance send method.

The generated JSDoc here is missing @returns and @async, which are required for public functions in this path. Please update this block and regenerate docs in the same PR.

As per coding guidelines, "Required JSDoc tags for public functions: @param, @returns, and @throws / @async where applicable." and "JSDoc must be regenerated and committed in the same PR ... Use turbo run docs --filter=<pkg> to regenerate."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/components/src/components/SendOperations.js` around lines 61 - 71,
The generated instance send method's JSDoc (the nonStaticMethod block for async
${methodName}(message)) is missing the required `@returns` and `@async` tags; update
that JSDoc to include an `@async` tag and an explicit `@returns` description (e.g.,
Promise<void> or the actual resolved value) alongside the existing `@param` and
`@throws` entries, then regenerate and commit the package docs in the same PR (use
turbo run docs --filter=<pkg>) so the updated JSDoc is reflected in the
committed docs.
🧹 Nitpick comments (1)
packages/templates/clients/websocket/javascript/example.js (1)

17-23: ⚡ Quick win

Replace inline comments with JSDoc for outgoingProcessor.

Please convert this to a proper JSDoc block including parameter type, return type, and any error behavior to keep docs consistent.

As per coding guidelines, "Write clear and consistent JSDoc comments for functions, including parameter types, return values, and error conditions."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/templates/clients/websocket/javascript/example.js` around lines 17 -
23, Replace the inline comment above outgoingProcessor with a proper JSDoc
block: document the function outgoingProcessor(message) with `@param` {any}
message describing the incoming payload, `@returns` {{payload: any, timestamp:
string}} describing the returned processed object, and an `@throws` note that
JSON.stringify may throw (e.g., on circular references); place the JSDoc
directly above the outgoingProcessor function declaration in example.js and keep
the rest of the implementation unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/components/src/components/SendOperations.js`:
- Around line 61-71: The generated instance send method's JSDoc (the
nonStaticMethod block for async ${methodName}(message)) is missing the required
`@returns` and `@async` tags; update that JSDoc to include an `@async` tag and an
explicit `@returns` description (e.g., Promise<void> or the actual resolved value)
alongside the existing `@param` and `@throws` entries, then regenerate and commit
the package docs in the same PR (use turbo run docs --filter=<pkg>) so the
updated JSDoc is reflected in the committed docs.

---

Nitpick comments:
In `@packages/templates/clients/websocket/javascript/example.js`:
- Around line 17-23: Replace the inline comment above outgoingProcessor with a
proper JSDoc block: document the function outgoingProcessor(message) with `@param`
{any} message describing the incoming payload, `@returns` {{payload: any,
timestamp: string}} describing the returned processed object, and an `@throws`
note that JSON.stringify may throw (e.g., on circular references); place the
JSDoc directly above the outgoingProcessor function declaration in example.js
and keep the rest of the implementation unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e4c21e29-2684-4ba8-9108-d7b3c2dfc51e

📥 Commits

Reviewing files that changed from the base of the PR and between e5e5bed and 4ca9d81.

⛔ Files ignored due to path filters (2)
  • packages/components/test/components/__snapshots__/SendOperations.test.js.snap is excluded by !**/*.snap
  • packages/templates/clients/websocket/test/integration-test/__snapshots__/integration.test.js.javascript.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • packages/components/src/components/SendOperations.js
  • packages/templates/clients/websocket/javascript/example.js
  • packages/templates/clients/websocket/javascript/test/components/RegisterOutgoingProcessor.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/templates/clients/websocket/javascript/test/components/RegisterOutgoingProcessor.test.js

@10done
Copy link
Copy Markdown
Contributor Author

10done commented May 27, 2026

@Adi-204 I have updated example.js to demonstrate registerOutgoingProcessor — it intercepts every outgoing message, adds a timestamp, and passes the transformed payload to the send path. Processors are now also wired into the send path in SendOperations.js so they actually run.

I hope this shows how this can be useful. Let me know if you think otherwise.
Screenshot 2026-05-28 at 1 33 09 AM

@10done 10done requested a review from Adi-204 May 27, 2026 20:35
Copy link
Copy Markdown
Member

@Adi-204 Adi-204 left a comment

Choose a reason for hiding this comment

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

@10done have a look at #2101 (comment) nd also run the examples by following the instructions here: https://github.com/asyncapi/generator/blob/master/packages/templates/clients/websocket/javascript/README.md
Thanks for the registerOutgoingProcessor use case it makes sense.

@Adi-204 Adi-204 self-requested a review May 30, 2026 06:14
@Adi-204 Adi-204 self-assigned this May 30, 2026
@10done
Copy link
Copy Markdown
Contributor Author

10done commented May 30, 2026

@Adi-204 Sure i will run the examples.

@10done
Copy link
Copy Markdown
Contributor Author

10done commented May 30, 2026

@Adi-204 These are the screenshots from the examples run

Screenshot 2026-05-30 at 6 39 04 PM Screenshot 2026-05-30 at 6 39 23 PM image

@sonarqubecloud
Copy link
Copy Markdown

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.

Add RegisterOutgoingProcessor to JavaScript WS

3 participants