Skip to content
LogoLogo

Kv.from

Wraps an existing Kv-shaped object so the SDK accepts it as a Kv. Useful when adapting a custom backend (Redis, DynamoDB, Postgres, an internal cache) — implement the four-method interface and pass the result through Kv.from.

Kv.from is a structural pass-through — it returns the input unchanged. It exists so callers can opt into the Kv type without an explicit as cast and so future evolutions of the interface stay compatible.

Usage

const  = .({
  async () {
    const  = await .()
    return  ? .() : 
  },
  async (, , ) {
    if (?.) await .(, .(), 'EX', .)
    else await .(, .())
  },
  async () {
    await .()
  },
})

Parameters

kv

  • Type: Kv
  • Required

A Kv-shaped object. Must implement get, set, and delete. Optionally implement take for atomic read-and-delete semantics — handlers that require it (e.g. Handler.auth on multi-instance deployments) refuse stores without it.

import {  } from 'accounts/server'
 
const  = .({
  async () { /* ... */ return  },
  async (, , ) { /* ... */ },
  async () { /* ... */ },
  async () { /* ... */ return  }, 
})

Return Type

The same Kv instance passed in, typed as Kv.