-
Notifications
You must be signed in to change notification settings - Fork 135
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
getItems
does not work with prefixStorage
#396
Comments
Can you please make a sandbox ideally with unstorage only? 🙏🏼 |
Yes, sorry thought it was clear enough. Here is a repro: https://stackblitz.com/edit/stackblitz-starters-rrstqp?file=index.js Would be great to add a starter to readme for quickly spinning one up. |
getItems
does not work with a storage basegetItems
does not work with prefixStorage
useStorage('namespace').clear() also not working with namespace |
I think I found the bug, the cause of the issue is the function prefixStorage. export function prefixStorage<T extends StorageValue>(
storage: Storage<T>,
base: string
): Storage<T> {
base = normalizeBaseKey(base);
if (!base) {
return storage;
}
const nsStorage: Storage = { ...storage };
for (const property of storageKeyProperties) {
// @ts-ignore
nsStorage[property] = (key = "", ...args) =>
// @ts-ignore
storage[property](base + key, ...args);
}
nsStorage.getKeys = (key = "", ...arguments_) =>
storage
.getKeys(base + key, ...arguments_)
// Remove Prefix
.then((keys) => keys.map((key) => key.slice(base.length)));
return nsStorage;
} In this code it tries to iterate through the storageKeyProperties to splice the base for each key, but in fact the storageKeyProperties does not contain the getItems and setItems strings, and this splice step is not implemented in runBatch. This means that when traversing the asyncCall in getItems, the key in the argument does not actually contain a namespace. Additionally, since the traversal code here can't handle more complex cases, the function getKeys is also handled separately, which may be another reason why the issue arose. All in all, I'm trying to deal with the current issue and will bring up a pr when I'm done. (The above is from a translation tool, please understand that it may be misleading) |
Same issue here. |
Environment
1.10.1
Reproduction
https://stackblitz.com/edit/stackblitz-starters-rrstqp?file=index.js
Describe the bug
Working
Not Working
It seems to switch back to the default driver (
memory
). I'm guessing this is because the mount is being discovered from the input key, without the base being applied first.Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: