-
Notifications
You must be signed in to change notification settings - Fork 170
feat(drivers): enhance drivers with typed options for get, set, remove, and list operations via generation
#662
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #662 +/- ##
==========================================
+ Coverage 59.99% 62.45% +2.45%
==========================================
Files 42 43 +1
Lines 3657 3891 +234
Branches 590 660 +70
==========================================
+ Hits 2194 2430 +236
+ Misses 1460 1458 -2
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Docs are currently missing. Will write them once the changes are final 😄 |
… function to ensure type safety of driver options
get, set, remove, and list operations via generation
src/_drivers.ts
Outdated
| } | ||
|
|
||
| export type DriverGetOptions = { | ||
| "deno-kv"?: DenoKVDriver extends { getOptions: infer TGet } ? unknown extends TGet ? {} : TGet : {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not easily doable in runtime to pass { 'deno-kv': { ... opts } }, we should instead use { denoKV: {} } to be easier with JS objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS: We could simplify the interface to the drivers to actually accept a custom option. We can start by denoKV as an example, but then we need to allow actually tOpts.denoKV.*.
Like discussed, inference of name could be in followup PR. This is mainly to document a "bag of possibe options" for get/set/etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for continuously having to ask back.
We could simplify the interface to the drivers to actually accept a custom option
I assume you are talking about another Generic Type Variable?
We can start by denoKV as an example, but then we need to allow actually tOpts.denoKV.*.
The type variable should not be restrained to any type (which makes sense)
Like discussed, inference of name could be in followup PR. This is mainly to document a "bag of possibe options" for get/set/etc
Inference of name in another PR for sure, inference of options in internal drivers via generic type maybe in this?
|
@pi0 is there anything still missing? |
Resolves #660
This is the discussed solution for typed options and would replace PR #661 and should be a very good fit with #610.
A Driver can specify a
<driverName>Driverinterface with set, get, remove and list options typed.This can be used to Infer the complete operation options via the driver name so that we have strongly typed internal driver development.
This Driver is added to the generated _driver.ts and exposes all set, get, remove and list options from all drivers collectively.
Additionally there are now common operation options which all drivers can implement if they support them (like
ttlforset).Please check that get, set, remove and list make sense as common options or if we need to add/remove some.
I added a utility type to mimic thesafeNamefrom thegen-drivers.tsfile. Drivers need to also respect that the options could be passed in via the safe name. I am unsure if this is the best solution. Let me know if you have any suggestions.Please also see the
Storagetype to see how the new types are used.This should not be a breaking changes as we still allow any other untyped properties on the root object like before.
If you have any questions, please feel free to ask right away.