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
Add transformer option #50
Conversation
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.
I think the test is good but there was a bug in your implementation.
src/cache.js
Outdated
@@ -334,10 +341,16 @@ class Wrapper { | |||
} | |||
|
|||
async get (key) { | |||
if (this.transformer) { | |||
return this.transformer.deserialize(this.storage.get(key)) |
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.
return this.transformer.deserialize(this.storage.get(key)) | |
return this.transformer.deserialize(await this.storage.get(key)) |
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.
Good catch, thanks! I changed this, but sadly the error remains. I've also added documentation and an example to the README.
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.
Okay, I've managed to fix all the errors. There actually was another bug in the implementation.
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.
lgtm
Apparently the code coverage is too low: https://github.com/mcollina/async-cache-dedupe/actions/runs/4162364135/jobs/7203097232#step:6:1656 |
Fixed it! |
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.
lgtm
This implements #46.
This allows passing a transformer library like
superjson
to serialize data types that are not supported byJSON.stringify
.The API for this option was inspired by https://trpc.io/docs/data-transformers#using-superjson.
You can use a transformer like this on a per-cache basis:
Alternatively, a transformer can be added for a specific function:
I've tried creating tests for this, but the test are failing without any error message.
Since I'm not too familiar with tap for testing, I was hoping somebody could look into this.
I hope this is helpful!