-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
Storage Item Serialization and Validation #1173
Comments
Would be nice with arktype |
Hadn't heard of that one before... I'll give it a go sometime, looks really cool! I see you're a sponsor 😉 Should be easy enough to support, just a function, or if something goes terribly wrong, we can always use the assert function they show integrating with tRPC. type StorageItemSchema<TValue, TStored> =
// Manual serialization functions
| { serialize(value: TValue): TStored, deserialize(stored: TStored): TValue }
// Zod
| { parse(stored: TStored): TValue }
// Arktypes & Typebox
| (stored: TStored) => TValue |
Will also need to decide what happens when validation fails... Do we do nothing? Return the default value? Throw the error? Overwrite the bad value or leave it as-is? How do we integrate a logger for error reporters to hook into? Some questions to answer... |
Not quite sure how you'd design the api around it but might be nice to have the option to decide what happens, like either hook into an event and if it's not hooked into we reset it or something? |
I love arktype, it's super fast and gives the best usable types in the editor imo haha |
One more addition: an alternative to Plasmo's secure storage. I don't think calling it "secure" is the right move, in reality, it's just 2-way encoded with a "secret" key that's shipped with the extension. So we could easily add an equivalent API: const encodeAtRest = createStorageEncoder("key");
export const example = defineStorageItem("local:example", {
schema: encodeAtRest(z.String())
}); Doesn't need to be apart of the initial feature, and that's just an idea of what the API might look like. Could be a separate field unrelated to |
Feature Request
When defineing storage items, getting values, or setting values, we should support serialization options for converting storage to and from a specific data type:
A natural extension to this is to support various other popular data serialization and validation libraries, like Zod and TypeBox.
Is your feature request related to a bug?
#1123
What are the alternatives?
Write a wrapper around
storage.defineItem
yourself.Additional context
N/A
The text was updated successfully, but these errors were encountered: