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

Client refactor #85

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft

Client refactor #85

wants to merge 29 commits into from

Conversation

doseofted
Copy link
Owner

@doseofted doseofted commented Mar 18, 2024

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.
  • Separation of proxy-related and RPC-related functions in client (needed for method chaining)
  • Properly typed options based on provided module
  • Provide error codes with each message (and keep messages short)

New features (non-breaking):

  • It's now easier to return synchronously from the client when needed (with reflection on types)
  • Form data can now also be automatically transformed for locally-provided, partial modules
  • 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)
  • Error handling hook on client
  • 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):

  • 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
  • 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
  • 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)

…y for easier organization

This will also be useful for starting work with chaining methods in RPC
Copy link

changeset-bot bot commented Mar 18, 2024

⚠️ No Changeset found

Latest commit: 73dc2a1

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

Copy link

vercel bot commented Mar 18, 2024

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

…al modules, either given as dynamic or static import)
… returning dynamic import

This should allow proper type definitions in module option of client when provided a partial module
…rt partial modules

This is useful when part of a module is available client-side and a call can be made synchronously.
Now, type definitions can optionally reflect when that module is available and avoid wrapping the return result
in a Promise. The default remains the same, and the Module type parameter goes through transformations to reflect
the transport of function data from a remote location (wrapping it in a Promise and adding support for HTML forms).

Currently, the client needs this type parameter passed explicitly (passing partial module to `.module` option alone
isn't enough but I'm unsure how to work around that).
…adding tests for types

Also added more options for PromisifiedModule type (types still need to be reorganized and thought out)
…terfaces (being utilized in rewritten client)
…ot full support but useful for supporting them)

Iterator methods and properties given on the client can now be intercepted to potentially support generators.
This would need support from both the server and client to return and transform into async generators from
the server.
…tests too (I won't even pretend to understand this one)

Previously type tests stalled forever and typedoc generation failed, now it doesn't. I'm not sure which upgrade
actually fixed the problem but I won't complain.
Build time for typedocs are incredibly slow and type tests are also slow
but they do seem to work locally (unsure of what impact on types in IDE
will be)
These should be much easier to work with in the new client. The old client's utilities have been updated to make use of
the new utilities in the meantime (and those temporary, old functions have been marked deprecated).
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