Skip to content
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

feat(infra): introduce op pattern #8734

Merged
merged 1 commit into from
Nov 9, 2024
Merged

feat(infra): introduce op pattern #8734

merged 1 commit into from
Nov 9, 2024

Conversation

forehalo
Copy link
Member

@forehalo forehalo commented Nov 7, 2024

TL;DR

Introduces a new Operation Pattern RPC framework for cross-tabs, worker, or even client-server communication.

What changed?

  • Introduced a new Operation Pattern RPC framework that enables:
    • Simple function calls between any client and consumer
    • Stream/subscription based communication
    • Support for transferable objects
    • Automatic message handling and routing
    • Built-in timeout and cancellation
  • Added support for multiple transport layers including:
    • Web Workers
    • Shared Workers
    • BroadcastChannel
    • MessagePort

How to test?

  1. Create an operation:
class AddOp extends Op<{ a: number; b: number }, number> {}
  1. Register handler:
const consumer = new OpConsumer(port);
consumer.register(AddOp, ({ a, b }) => a + b);
  1. Call operation:
const client = new OpClient(port);
const result = await client.call(new AddOp({ a: 1, b: 2 })); // 3

Why make this change?

To provide a standardized way of handling communication between different JavaScript contexts (frontend/backend/workers) with:

  • Type-safe RPC calls
  • Built-in error handling
  • Support for streaming data
  • Clean abstraction over different transport mechanisms
  • Reduced boilerplate code compared to raw message passing

Copy link

graphite-app bot commented Nov 7, 2024

Your org has enabled the Graphite merge queue for merging into canary

Add the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

Copy link
Member Author

forehalo commented Nov 7, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @forehalo and the rest of your teammates on Graphite Graphite

@github-actions github-actions bot added mod:infra Environment related issues and discussions docs Improvements or additions to documentation test Related to test cases labels Nov 7, 2024
Copy link

nx-cloud bot commented Nov 7, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 808af0c. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 74.45255% with 35 lines in your changes missing coverage. Please review.

Project coverage is 70.07%. Comparing base (add8c56) to head (808af0c).
Report is 16 commits behind head on canary.

Files with missing lines Patch % Lines
packages/common/infra/src/op/client.ts 70.58% 14 Missing and 6 partials ⚠️
packages/common/infra/src/op/consumer.ts 74.41% 10 Missing and 1 partial ⚠️
packages/common/infra/src/op/message.ts 84.61% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           canary    #8734      +/-   ##
==========================================
+ Coverage   70.05%   70.07%   +0.01%     
==========================================
  Files         546      549       +3     
  Lines       33797    33934     +137     
  Branches     3043     3059      +16     
==========================================
+ Hits        23677    23779     +102     
- Misses       9759     9786      +27     
- Partials      361      369       +8     
Flag Coverage Δ
server-test 77.12% <ø> (ø)
unittest 45.43% <74.45%> (+0.53%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@EYHN EYHN merged commit d6618b6 into canary Nov 9, 2024
46 checks passed
@EYHN EYHN deleted the 61/op branch November 9, 2024 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation mod:infra Environment related issues and discussions test Related to test cases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants