Notes ·
kvport: moving Deno KV code to Cloudflare, with real Deno as the specification
If your app uses Deno KV and kv.atomic().check(...), the obvious Cloudflare target, Workers KV, will not take that code unchanged: it is eventually consistent. kvport puts a Deno.Kv-compatible API on a SQLite-backed Durable Object, so the same calls run on a strongly consistent store, and a CLI exports, imports and verifies your data. It is alpha. I built it as one person directing AI coding agents, with tests and review by a separate AI agent as the checks.
The problem
The README cites Deno's announcement that Deno Deploy shuts down about six months after 2026-10-09, which takes Deno KV with it. Cloudflare's own documentation says Workers KV is "not ideal for applications where you need support for atomic operations", and Durable Object SQLite storage is described as transactional and strongly consistent. So the job is a migration path, not a new database: keep the API, change the store. kvport only covers what Deno KV does; COMPAT.md lists every known difference.
What it does
Worker --openKv(env.KVPORT)--> KvPort client --RPC--> KvPortDO (SQLite)
CLI (Deno) --NDJSON over HTTP, admin token--> /__kvport/import, /__kvport/digest --> KvPortDO get, getMany, set, delete, list, atomic() with check, set, delete, sum, min, max, expireIn, queues and watch work as in Deno. Deno.cron becomes cron.register. The Durable Object's alarm drives expiry, queue delivery and cron retries.
The design decision I would defend: real Deno is the specification. Before writing the client I probed Deno.openKv(":memory:"), and my assumptions about key order, limit errors and which errors throw synchronously turned out wrong in several places. The same conformance cases now run against two targets, real Deno and kvport inside workerd, and where they disagreed the oracle won and the case encodes Deno's behaviour. The trade-off is that the spec is one Deno version (2.9.8 per COMPAT.md), and the oracle only knows what Deno actually does. It is silent where Deno does not validate, for example keysIfUndelivered, which Deno accepts unchecked; there kvport had to choose its own limits and document them.
How it is tested
Measured on 2026-11-30: deno test 268 passed; npx vitest run 212 passed; the end-to-end script passes with equal digests for 5,000 entries; 153 conformance cases run on both real Deno and workerd.
npm ci
deno test -A --unstable-kv tests/ # oracle + Deno-side unit tests
npx vitest run # workerd
bash scripts/e2e.sh # 5000 entries end to end scripts/e2e.sh seeds 5,000 entries into a Deno KV file, exports, imports into wrangler dev --local, compares SHA-256 digests of both sides, then corrupts one line and checks that verify exits non-zero. I also ran the shortlinks example on a real Cloudflare account on 2026-11-30: 5,000 links (16,250 entries) imported in about 2 s, digests equal, a corrupted copy rejected, wrong admin token answered 401, and a click counted through the queue. The test Worker was deleted afterwards.
What these numbers do not show: cron and kv.watch were not tested on real Cloudflare (the cron trigger was not waited for), and I have not run an export against a real remote Deno Deploy database, only local files.
What the security audit found
Four problems, all fixed:
- A byte-order mark was lost on read. A key part starting with U+FEFF was stored with it but read back without it, so
listreported a different key than the one stored. Real Deno keeps the BOM. The decoder now setsignoreBOM: true, and a test intests/do.test.tschecks the round trip. - Import accepted non-canonical key encodings. The integer 5 can be encoded in more than one way at the byte level; only one is what Deno writes. The admin route and the CLI now re-encode and compare, and reject a mismatch.
- The export temp file followed a planted symlink. Export now creates its temp file exclusively (
createNew, O_EXCL) and refuses an existing file or symlink; a test plants one and checks that nothing is written. - Scanned text reached the terminal unfiltered.
scanandcron extractprint text from the code they read, which is untrusted. Control characters, including ANSI escapes, are now dropped before printing.
The BOM case is a good argument for the oracle approach: the correct behaviour was confirmed against real Deno, not argued from the spec.
Limits and what is not done
exportpages throughlist, so it is not a snapshot: stop writes first. TTLs are dropped and versionstamps are reassigned on import, so savedcheck()stamps are invalid after the move.importoverwrites existing keys unconditionally. Messages still queued in Deno are not exported.- One Durable Object per database: 10 GB on Workers Paid, 1 GB on Free, and the throughput of one object. Every call is an RPC that may cross regions.
- Queue delivery is at least once, so handlers must be idempotent.
- Alpha: one real-Cloudflare run so far, and the package name is not decided.
Code: https://github.com/basartuncay/kvport
Türkçe özet
kvport, Deno KV kullanan uygulamaların kv.atomic().check(...) gibi çağrılarını değiştirmeden Cloudflare'e taşımak için SQLite tabanlı bir Durable Object üzerinde Deno.Kv uyumlu bir API sunuyor; CLI ile veriyi dışa aktarıp içe aktarıyor ve doğruluyor. Temel tasarım kararı, gerçek Deno'yu belirtim olarak kullanmak: aynı uyumluluk senaryoları hem Deno'da hem workerd'de çalışıyor (268 deno test, 212 vitest, 5.000 kayıtlık uçtan uca betik geçiyor) ve fark çıkınca Deno'nun davranışı kazanıyor. Gerçek Cloudflare hesabında yalnızca bir kez denendi; cron ve watch orada sınanmadı. Güvenlik denetimi bayt sırası işaretiyle başlayan anahtarın okunurken kaybolmasını, kanonik olmayan anahtar kodlamalarının kabul edilmesini, dışa aktarma geçici dosyasının sembolik bağı izlemesini ve taranan metnin terminale süzülmeden yazılmasını buldu; hepsi düzeltildi. Proje alfa aşamasında.