prim-rpc icon indicating copy to clipboard operation
prim-rpc copied to clipboard

Client refactor

Open doseofted opened this issue 1 year ago • 2 comments

As part of the 1.0 release, the code should be easier to read, debug, and contribute. As part of this refactor, I also plan to consider what method chaining looks like in the library for the future. While this PR does not include method chaining, it should include changes that make it possible.

Changes:

  • [ ] Easier-to-read code
  • [ ] Separation of responsibilities between methods/callbacks/blobs/batching/etc.
  • [x] Separation of proxy-related and RPC-related functions in client (needed for method chaining)
  • [x] Properly typed options based on provided module
  • [ ] Provide error codes with each message (and keep messages short)

New features (non-breaking):

  • [x] It's now easier to return synchronously from the client when needed (with reflection on types)
  • [x] Form data can now also be automatically transformed for locally-provided, partial modules
  • [x] Make form handling (and possibly reflection on final Module type) optional
  • [ ] Method plugin can return synchronously (avoids extra Promise in event that a result is cached client-side)
  • [x] Error handling hook on client
  • [x] Files on a result or parameters now have an optimized merging strategy for better performance on large objects in parameters or return values (for small objects, this will probably go unnoticed)

Breaking changes (and new features):

  • [x] Files, blobs, callbacks, and promises no longer have to be located at the top-level of arguments or return values: they can be set up to a specified, maximum depth
  • [x] Client can now make use of options.module types with provided ModuleType type parameter
    • This feature is optional and only activates when ModuleType is not provided or when both type parameters are provided. When only the ModuleType is provided (as in previous version), behavior remains the same.
    • Note: types of options.module will only be reflected if options type is also provided as a generic, otherwise ModuleType will be utilized (as expected)
    • When this feature is utilized, options should be cast as const so type parameter can pick up on selected options
  • [x] options.postRequest now takes three arguments: (args, result, name) => unknown (args have been added)
  • [ ] Consider what streaming results in method plugin looks like (with HTTP streaming, precursor to support for generator functions and multiple Promises in a function's result)

doseofted avatar Mar 18 '24 02:03 doseofted

⚠️ No Changeset found

Latest commit: 73dc2a13f68dfc1b9525f0e54aa65a9b917a65a8

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

changeset-bot[bot] avatar Mar 18 '24 02:03 changeset-bot[bot]

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
prim-rpc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 7, 2024 4:28pm

vercel[bot] avatar Mar 18 '24 02:03 vercel[bot]