Rust bindings to Cloudflare Worker KV Stores using wasm-bindgen and js-sys.

Overview

worker-kv

Docs.rs Crates.io MIT Apache 2

Rust bindings to Cloudflare Worker KV Stores using wasm-bindgen and js-sys.

Example

>("example_key").await?; ">
let kv = KvStore::create("Example")?; // or KvStore::from_this(&this, "Example") if using modules format Workers

// Insert a new entry into the kv.
kv.put("example_key", "example_value")?
    .metadata(vec![1, 2, 3, 4]) // Use some arbitrary serialiazable metadata
    .execute()
    .await?;

// NOTE: kv changes can take a minute to become visible to other workers.
// Get that same metadata.
let (value, metdata) = kv.get_with_metadata::<Vec<usize>>("example_key").await?;

For a more complete example check out the full example.

How do I use futures in WebAssembly?

There currently is not a way to use a Future natively from WebAssembly but with the future_to_promise function from wasm_bindgen_futures we can convert it to a standard JavaScript promise, which can be awaited in the regular JavaScript context.

Comments
  • feat: add KvStore.put_slice method

    feat: add KvStore.put_slice method

    This PR adds a method to put a slice of bytes into a KV store, which is not possible with the existing methods as a slice does not implement the necessary trait bounds.

    opened by fkettelhoit 5
  • Fixed cyclic reference in cargo.

    Fixed cyclic reference in cargo.

    This changes worker to use serde-wasm-bindgen package, rather than relying on the deprecated serde option in wasm-bindgen.

    Description of the cyclic reference issue that I was hitting is here: https://github.com/tkaitchuck/aHash/issues/95

    wasm_bindgen::JsValue::from_serde and wasm_bindgen::JsValue::into_serde are deprecated here (citing the cyclic reference issue that I encountered). https://github.com/rustwasm/wasm-bindgen/pull/3031

    Also, additional description of serde-wasm-bindgen is found here (turns out that it was written by Cloudflare). https://github.com/rustwasm/wasm-bindgen/issues/1258

    This patch replaces the usage of wasm_bindgen::JsValue::from_serde and wasm_bindgen::JsValue::into_serde with serde_wasm_bindgen::from_value() and serde_wasm_bindgen::to_value() equivalents..

    opened by CMoore-Darwinium 3
  • support new Workers modules syntax and relicense for optimal compatibility

    support new Workers modules syntax and relicense for optimal compatibility

    This PR enables worker-kv to be used within the new Workers modules syntax (e.g. here), which is also required when using a Durable Object.

    Also, I've taken the liberty to re-license the repository as dual MIT OR Apache 2, which is common amongst Rust crates. It is also more compatible with many organizations' copyright policies for open source. I hope that is OK! If not, let me know and I can revert. I'd highly recommend this licensing strategy though :)

    opened by nilslice 3
  • Use gloo_utils instead of the serde feature in wasm_bindgen to convert objects.

    Use gloo_utils instead of the serde feature in wasm_bindgen to convert objects.

    This changes worker to use gloo_utils package, rather than relying on the deprecated serde option in wasm-bindgen.

    Description of the cyclic reference issue that I was hitting is here: https://github.com/tkaitchuck/aHash/issues/95

    wasm_bindgen::JsValue::from_serde and wasm_bindgen::JsValue::into_serde are deprecated here (citing the cyclic reference issue that I encountered). https://github.com/rustwasm/wasm-bindgen/pull/3031

    This patch replaces the usage of wasm_bindgen::JsValue::from_serde and wasm_bindgen::JsValue::into_serde with gloo_utils::format::JsValueSerdeExt::from_serde and gloo_utils::format::JsValueSerdeExt::into_serde respectively.

    opened by CMoore-Darwinium 0
  • Rewrite integration tests

    Rewrite integration tests

    Currently worker-kv uses an actual KV for it's integration testing which makes testing incredibly slow as we need to give it time to propagate changes made to the store. This project might be a better alternative for integration testing.

    enhancement 
    opened by zebp 0
  • HTTP implementation

    HTTP implementation

    Potentially have a feature to use an HTTP implementation using the workers kv rest api. This might not map well onto the current api, so if this can be done without breaking changes is unknown at this point.

    enhancement 
    opened by zebp 0
Releases(v0.4.0)
  • v0.4.0(Oct 1, 2021)

Owner
Zeb Piasecki
Zeb Piasecki
Cloudflare worker for embedding polls anywhere.

poll.fizzy.wtf Cloudflare worker for embedding polls anywhere. ?? Pineapple on pizza? ?? Yes ?? No ?? Total Features Unlimited polls and unlimited opt

Valentin Berlier 39 Dec 10, 2022
🥅 Dead simple webhook worker for Sentry to output events in a Discord channel

?? Sentry Webhook Dead simple webhook worker for Sentry to output events in a Discord channel Why? This is just a simple Rust HTTP service to do so, t

Noel 5 Nov 7, 2022
Pass cloudflare IUAM using headless chrome without hassle.

FlarelessHeadlessChrome Pass cloudflare turnstile challenge using patched chrome binary (Windows/Linux x64). How it works Currently, with new headless

makin 3 Oct 24, 2023
Log your spending in seconds with short text snippets. Powered by Rust, Cloudflare Workers and Svelte.

FastSpend Log your daily spending lightning fast with short text snippets! FastSpend is a tool to log your spending in seconds, powered by a lightning

Phoomparin Mano 24 Sep 13, 2022
A pure-Rust serverless discord chatbot hosted on Cloudflare Workers.

About A pure-Rust serverless discord chatbot hosted on Cloudflare Workers. With a free account you have up to 100k requests per day. For storing state

Mike Dallas 31 Nov 21, 2022
Write Cloudflare Workers in 100% Rust via WebAssembly. (A fork of workers-rs)

Note: This is a fork to workers-rs. Work-in-progress ergonomic Rust bindings to Cloudflare Workers environment. Write your entire worker in Rust! Read

Abid Omar 7 Jan 11, 2023
Telegram Bot Template with Cloudflare Workers

cf-workers-telegram-bot-template Usage This template starts you off with a src/lib.rs file, acting as an entrypoint for requests hitting your Worker.

Lee Taehoon 2 Sep 23, 2021
Blueboat is an open-source alternative to Cloudflare Workers. The monolithic engine for serverless web apps.

Blueboat Blueboat is an open-source alternative to Cloudflare Workers. Blueboat aims to be a developer-friendly, multi-tenant platform for serverless

Heyang Zhou 1.8k Jan 9, 2023
Verify Discord interactions on Cloudflare Workers with Twilight

twilight-cloudflare-workers Verify Discord interactions on Cloudflare Workers with Twilight. API The primary function in the API is process. It takes

Zeyla 5 Jun 6, 2022
Edgelord is a library for Cloudflare Workers. You can scaffold a basic bot for discord, slack, etc.

Edge Computing + chūnibyō = Edgelord ✨ ?? Edgelord Edgelord is now working. You can contribute for it. Edgelord is a Rust library for cloudflare worke

null 23 Dec 26, 2022
CLI to create redirections in CloudFlare to Zoom meetings.

boteco boteco is a CLI to create redirections in CloudFlare to Zoom meetings. Requirements CloudFlare page rules In the domain you want to use, you ne

Eduardo Cuducos 3 Jan 3, 2023
CFD is a tool that allows you to check one or more domains to see if they are protected by CloudFlare or not.

CFD is a tool that allows you to check one or more domains to see if they are protected by CloudFlare or not. The check is carried out based on five criteria: 3 headers in the HTTP response, IP, and SSL certificate issuer. The check result can be displayed on the screen or saved to a file.

Airat Galiullin 13 Apr 7, 2023
🦀 CLI for Cloudflare API 🦀

?? CLI️ to interact with Cloudflare APIs ?? An excuse to write some Rust ?? Under heavy development Setup Install Rust ?? curl --proto '=https' --tlsv

Dave Miller 3 Dec 15, 2023
Scan all IP nodes of CloudFlare to find the fastest IP node.

中文版 | English ?? Introduction Scan all IP nodes of CloudFlare to find the fastest IP node. ⚡️ Get Started ??️ Build git clone https://github.com/golan

golangboy 47 Mar 19, 2024
Rust bindings to llama.cpp, using metal on macOS

llama-rs Rust bindings to llama.cpp, for macOS, with metal support, for testing and evaluating whether it would be worthwhile to run an Llama model lo

Max Brunsfeld 7 Aug 31, 2023
Gun port in rust & wasm

rusty-gun Rust & WASM port of Gun. Example (source) Use npm install rusty-gun import { Node as Gun } from "rusty-gun" const gun = new Gun('ws://localh

Martti Malmi 39 Dec 19, 2022
High-level PortMidi bindings and wrappers for Rust

High-level PortMidi bindings and wrappers for Rust

Philippe Delrieu 69 Dec 1, 2022
Rust bindings for the WebView2 COM APIs

webview2-rs Rust bindings for the WebView2 COM APIs Crates in this repo The root of this repo defines a virtual workspace in Cargo.toml which includes

Bill Avery 24 Dec 15, 2022
Rust bindings for the KING OF TIME API

Rust bindings for the KING OF TIME API Example Prints if you are at work or not at work. $ cargo run --example tc -- status Record the time you start

Idein Inc. 2 Oct 11, 2021