-
Notifications
You must be signed in to change notification settings - Fork 144
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: strongly type extended drivers #554
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #554 +/- ##
==========================================
- Coverage 65.05% 58.76% -6.30%
==========================================
Files 39 43 +4
Lines 4055 3664 -391
Branches 487 587 +100
==========================================
- Hits 2638 2153 -485
- Misses 1408 1507 +99
+ Partials 9 4 -5 ☔ View full report in Codecov by Sentry. |
Currently, a driver can define its own method signatures but they will be lost thanks to `DriverFactory` returning a `Driver` rather than the original type. This means things like the netlify driver never actually exposed their extended types (e.g. special options in `getKeys`). With these changes, a driver can implement `Driver` but add its own types on top which are then exposed.
I think we should do this for the repo in its current state But given what you said in #555 , it made me wonder about what the right interface is I wonder if in v2, we should actually have a fixed interface (like before this change). And an option which contains driver specific options, instead of merging the two getItem("key", {
driverOptions: {
somethingDriverSpecific: true
}
}) |
...localstorage({ | ||
windowKey: "sessionStorage", | ||
...opts, | ||
}), | ||
name: DRIVER_NAME, |
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.
Reminder this another valid fix
Appreciate your work on this PR ❤️
In v2, it shall be a global namespace interface with explicit keys for each driver (which is, unfortunately, a breaking change for v1 as we used top-level mixed keys) {
ttl: 1200, // Generic
http: { headers: { } } // driver specific
} |
The netlify driver specifies it's own types which currently have no use, since we only expose a Was that intentional too? That's mostly why I did this change e.g we specify that it can take a |
Indeed, they are only usable internally now for those drivers. Also consider, that passing driver-specific options to each transaction is something more of an escape hatch / advanced purpose. The key point of using unstorage abstraction is that an operation works regardless of the underlying driver. Only standard keys such as |
I see, it was just there to help with the internal types And yes, I would much rather it return a Then if we must, have an option in there that is passed through to the underlying driver. Instead of changing the method signature |
(lets discuss it later) |
Currently, a driver can define its own method signatures but they will be lost thanks to
DriverFactory
returning aDriver
rather than the original type.This means things like the netlify driver never actually exposed their extended types (e.g. special options in
getKeys
).With these changes, a driver can implement
Driver
but add its own types on top which are then exposed.