Skip to content

Commit

Permalink
feat: remote client
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato committed Oct 30, 2023
1 parent ba84c38 commit 627c93f
Show file tree
Hide file tree
Showing 8 changed files with 1,209 additions and 12 deletions.
553 changes: 549 additions & 4 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["proto", "sqlite"]
members = ["proto", "remote", "sqlite"]
resolver = "2"

[workspace.package]
Expand All @@ -25,3 +25,6 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1.0.107"
tokio = { version = "1.33.0", features = ["full"] }
uuid = { version = "1.4.1", features = ["v4", "serde"] }
url = "2"
reqwest = { version = "0.11", features = ["json"] }
bytes = "1"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This repository contains two crates:
- `denokv_proto` (`/proto`): Shared interfaces backing KV, like definitions of
`Key`, `Database`, and `Value`.
- `denokv_sqlite` (`/sqlite`): An implementation of `Database` backed by SQLite.
- `denokv_remote` (`/remote`): An implementation of `Database` backed by a
remote KV database, acessible via the KV Connect protocol.

These crates are used by the `deno_kv` crate in the Deno repository to provide a
JavaScript API for interacting with Deno KV.
Expand Down
8 changes: 7 additions & 1 deletion proto/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,16 @@ pub struct CommitResult {
pub versionstamp: Versionstamp,
}

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MetadataExchangeRequest {
#[serde(default)]
pub supported_versions: Vec<u64>,
}

/// The database metadata that is returned by the KV Connect metadata endpoint.
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct DatabaseMetadata {
pub version: u64,
pub database_id: Uuid,
Expand Down
9 changes: 5 additions & 4 deletions proto/kv-connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ exponential backoff strategy with unlimited retries.
The client MUST verify that the response is a 200 OK, 3xx class redirect
response, or 4xx class HTTP status response. If the response is a 3xx class
redirect response, the client MUST follow the redirect and perform the metadata
exchange with the new URL as the base URL. If the response is a 4xx class HTTP
status response, the client MUST fatally abort the metadata exchange and display
the error message to the user. If the response is a 200 OK response, the client
MUST verify that the response body adheres to the JSON schema defined in the
exchange with the new URL as the base URL (the client MAY impose a maximum
redirect depth). If the response is a 4xx class HTTP status response, the client
MUST fatally abort the metadata exchange and display the error message to the
user. If the response is a 200 OK response, the client MUST verify that the
response body adheres to the JSON schema defined in the
`schema/kv-metadata-exchange-response.v<protocolversion>.json` file. If the
response body is invalid, the client MUST fatally abort the metadata exchange
and display the error message to the user.
Expand Down
4 changes: 2 additions & 2 deletions proto/schema/datapath.proto
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ enum MutationType {
M_UNSPECIFIED = 0;
// Set the value.
M_SET = 1;
// Clear the value.
M_CLEAR = 2;
// Delete the value.
M_DELETE = 2;
// Sum the stored value with the new value. Both values must be LE64 encoded.
M_SUM = 3;
// Min the stored value with the new value. Both values must be LE64 encoded.
Expand Down
29 changes: 29 additions & 0 deletions remote/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "denokv_remote"
description = "Remote (KV Connect) backend for Deno KV"
version = "0.1.0"
edition.workspace = true
license.workspace = true
repository.workspace = true
authors.workspace = true

[lib]
path = "lib.rs"

[dependencies]
anyhow.workspace = true
async-trait.workspace = true
chrono.workspace = true
denokv_proto.workspace = true
futures.workspace = true
log.workspace = true
num-bigint.workspace = true
rand.workspace = true
serde_json.workspace = true
tokio.workspace = true
uuid.workspace = true
url.workspace = true
reqwest.workspace = true
serde.workspace = true
prost.workspace = true
bytes.workspace = true
Loading

0 comments on commit 627c93f

Please sign in to comment.