-
Notifications
You must be signed in to change notification settings - Fork 72
Open
Description
Confirm this is a Typescript library issue and not an underlying Cloudflare API issue
- This is an issue with the Typescript library
Describe the bug
When I set a KV value with
await cf.kv.namespaces.values.update(env.CF_NAMESPACE_ID, "key1", {
account_id: env.CF_ACCOUNT_ID,
metadata: "", // why is metadata mandatory ?
value: JSON.stringify({
hello:"world"
})
})
It actually sets the KV to {metadata:"", value:{hello:"world"}}
So now in a worker if I try to get the value with
const value = await c.env.KV.get<{hello: string}>("key1", "json");
I expect the get back the object {hello:'world'} but instead I get {metadata:'', value:"{'hello':'world'}"}
So to fix this weird behavior I need to do
const value = await c.env.KV.get<{value:string}>("key1", 'json');
const parsedValue = JSON.parse(value.value)
I can see the metadata on the Cloudflare KV web UI (in the value column), which is not the case for KV set from Cloudflare Workers with KV binding
To Reproduce
- Set a KV value with the Cloudflare typescript library
await cf.kv.namespaces.values.update(env.CF_NAMESPACE_ID, "key1", {
account_id: env.CF_ACCOUNT_ID,
metadata: "", // why is metadata mandatory ?
value: "value1"
})
- Get the KV in worker with KV binding
const value = await c.env.KV.get("key1");
Instead of getting back "value1", I get back "{'metadata':'','value':'value1'}"
Code snippets
OS
macOS
Runtime version
^5
Library version
v4.2.0
Metadata
Metadata
Assignees
Labels
No labels