Regression in [email protected] KV SDK: metadata is being stored inside value unexpectedly
Confirm this is a Typescript library issue and not an underlying Cloudflare API issue
- [x] This is an issue with the Typescript library
Describe the bug
🐛 Bug Report
Summary
In [email protected], the kv.namespaces.values.update() method incorrectly stores both metadata and value inside the KV value, rather than keeping metadata separate. This results in unexpected behavior where the stored data is:
{
"metadata": "...",
"value": "{...double-encoded JSON...}"
}
### To Reproduce
## 1. Install the latest SDK:
```bash
npm install [email protected]
2.Run the following code:
import Cloudflare from "cloudflare";
const new Cloudflare({
apiEmail: config?.cloudflare?.email,
apiKey: config?.cloudflare?.access_key,
});
await client.kv.namespaces.values.update('namespace_id', 'my-key', {
account_id: 'my-account-id',
metadata: '{"note": "example"}',
value: JSON.stringify({
ID: "123",
NAME: "Test",
})
});
3.Retrieve the stored value:
const result = await client.kv.namespaces.values.get('namespace_id', 'my-key');
console.log(result);
✅ Expected Behavior
The value stored in KV should be:
{
"ID": "123",
"NAME": "Test"
}
❌ Actual Behavior (in [email protected])
The returned value looks like:
{
"metadata": "",
"value": "{\"ID\":\"123\",\"NAME\":\"Test\"}"
}
This results in:
- Double-encoded JSON.
- TypeScript type mismatches.
- Unexpected data format requiring manual JSON.parse(result.value) to access the actual object.
✅ Works As Expected In
⚠️ Impact
- Breaks backward compatibility.
- Makes KV value unusable without additional parsing.
- Violates expectations based on earlier SDK versions and API documentation.
💡 Suggested Fix
Ensure the value is stored directly as the KV content, and metadata is handled separately at the key level — not embedded into the stored value.
Code snippets
OS
linux
Runtime version
Deno 2.3.1
Library version
v4.2.0
I've opened an internal issue for the team to have a look. Thanks!
Dupe of #2593. This is fixed in https://github.com/cloudflare/cloudflare-typescript/commit/d4ce21e135415971b6b4578151304289f5b7c4ef.