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

Use string literal type for path #69

Merged
merged 2 commits into from
Sep 19, 2020
Merged

Conversation

smolijar
Copy link
Contributor

I kept the two commits in the same PR. Though they are not directly semantically related, they change the same lines and would trigger conflicts. If it is desirable as two PRs, I can update it.

Use type literal for path

Using string literal type should not break anything (tested on a
larger project) since it is a subtype of string.

Using literal instead of generic string allows to do type-safe
RPC matching, for example it generic middlewares for cache, ACL etc.
Without it we need to match a string for path (long, prone to errors) or
method names (ambiguous) and have no way to check, wheather the matching
is correct or not.

With literals, we can extract all paths from generated stubs with
meta-typing and use it in these occasions.

Fix path composition on missing package

Correct RPC paths (also aligned with the grpc implementation) are

  • /Package.Service/Method
  • /Service/Method (undefined package)

Currently the template does not handle well services without package

  • /Package.Service/Method white_check_mark
  • /.Service/Method x (extra dot)

This commit adds the dot conditionally only if Package is not falsy

Correct RPC paths (also aligned with the grpc implementation) are
- `/Package.Service/Method`
- `/Service/Method` (undefined package)

Currently the template does not handle well services without package
- `/Package.Service/Method` ✅
- `/.Service/Method` ❌ (extra dot)

This commit adds the dot conditionally only if Package is not falsy
Using string literal type _should_ not break anything (tested on a
larger project) since it is a subtype of string.

Using literal instead of generic string allows to do type-safe
RPC matching, for example it generic middlewares for cache, ACL etc.
Without it we need to match a string for path (long, prone to errors) or
method names (ambiguous) and have no way to check, wheather the matching
is correct or not.

With literals, we can extract all paths from generated stubs with
meta-typing and use it in these occasions.
@agreatfool
Copy link
Owner

Gotcha, thanks for the PR. I would check & merge asap.

@agreatfool agreatfool merged commit 1a002f6 into agreatfool:master Sep 19, 2020
@agreatfool
Copy link
Owner

Done. New version 4.1.5 has been published. Thanks again.

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