Refs #603
Environment
unstorage: 2.0.0-alpha.7
- Runtime: Cloudflare Workers
- Consumer observed through Nitro 3 cached handlers using the
cache storage mount
Reproduction
In a Cloudflare Worker runtime:
import { createStorage } from "unstorage";
import cloudflareCacheBinding from "unstorage/drivers/cloudflare-cache-binding";
export default {
async fetch() {
const storage = createStorage();
storage.mount("cache", cloudflareCacheBinding({ base: "nitro-cache" }));
await storage.setItem("cache:test", { ok: true }, { ttl: 60 });
return new Response("ok");
},
};
Actual behavior
The write fails with:
TypeError: Cannot read properties of undefined (reading 'setItemRaw')
I observed this in a real Nitro Worker deployment when defineCachedHandler tried to write its cache entry:
[cache] TypeError: Cannot read properties of undefined (reading 'setItemRaw')
Expected behavior
storage.setItem(...) should write through the Cloudflare Cache API driver successfully.
Suspected cause
src/drivers/cloudflare-cache-binding.ts currently implements setItem() as:
async setItem(key, value, tOptions) {
return this.setItemRaw!(key, value, tOptions);
}
When unstorage calls driver methods, the method appears to be invoked without binding the driver object as this. In ESM strict mode, this is undefined, so this.setItemRaw throws before the Cache API write happens.
Notes
This is not caused by name or base configuration. The driver resolves caches.default correctly when name is omitted, and the failure happens before/while dispatching from setItem() to setItemRaw().
Refs #603
Environment
unstorage:2.0.0-alpha.7cachestorage mountReproduction
In a Cloudflare Worker runtime:
Actual behavior
The write fails with:
I observed this in a real Nitro Worker deployment when
defineCachedHandlertried to write its cache entry:Expected behavior
storage.setItem(...)should write through the Cloudflare Cache API driver successfully.Suspected cause
src/drivers/cloudflare-cache-binding.tscurrently implementssetItem()as:When unstorage calls driver methods, the method appears to be invoked without binding the driver object as
this. In ESM strict mode,thisisundefined, sothis.setItemRawthrows before the Cache API write happens.Notes
This is not caused by
nameorbaseconfiguration. The driver resolvescaches.defaultcorrectly whennameis omitted, and the failure happens before/while dispatching fromsetItem()tosetItemRaw().