diff --git a/Cargo.lock b/Cargo.lock index 77fd383bdd..d309430487 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1301,6 +1301,7 @@ dependencies = [ "rusqlite", "serde", "serde_json", + "termcolor", "tokio", "url", "uuid", diff --git a/Cargo.toml b/Cargo.toml index 767b9ff5a8..9f5f248683 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -137,6 +137,7 @@ smallvec = "1.8" socket2 = { version = "0.5.3", features = ["all"] } tar = "=0.4.40" tempfile = "3.4.0" +termcolor = "1.1.3" thiserror = "1.0.40" tokio = { version = "1.28.1", features = ["full"] } tokio-metrics = { version = "0.3.0", features = ["rt"] } diff --git a/ext/kv/Cargo.toml b/ext/kv/Cargo.toml index 39901d5949..deaac4db07 100644 --- a/ext/kv/Cargo.toml +++ b/ext/kv/Cargo.toml @@ -29,6 +29,7 @@ reqwest.workspace = true rusqlite.workspace = true serde.workspace = true serde_json.workspace = true +termcolor.workspace = true tokio.workspace = true url.workspace = true uuid = { workspace = true, features = ["serde"] } diff --git a/ext/kv/remote.rs b/ext/kv/remote.rs index 21286fd47f..fc18e4615d 100644 --- a/ext/kv/remote.rs +++ b/ext/kv/remote.rs @@ -1,6 +1,8 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use std::cell::RefCell; +use std::fmt; +use std::io::Write; use std::marker::PhantomData; use std::rc::Rc; use std::sync::Arc; @@ -29,6 +31,10 @@ use deno_core::OpState; use prost::Message; use rand::Rng; use serde::Deserialize; +use termcolor::Ansi; +use termcolor::Color; +use termcolor::ColorSpec; +use termcolor::WriteColor; use tokio::sync::watch; use url::Url; use uuid::Uuid; @@ -272,12 +278,28 @@ impl Database for RemoteDb

{ &self, _state: Rc>, ) -> Result { + let msg = "Deno.Kv.listenQueue is not supported for remote KV databases"; + eprintln!("{}", yellow(msg)); deno_core::futures::future::pending().await } fn close(&self) {} } +fn yellow>(s: S) -> impl fmt::Display { + if std::env::var_os("NO_COLOR").is_some() { + return String::from(s.as_ref()); + } + let mut style_spec = ColorSpec::new(); + style_spec.set_fg(Some(Color::Yellow)); + let mut v = Vec::new(); + let mut ansi_writer = Ansi::new(&mut v); + ansi_writer.set_color(&style_spec).unwrap(); + ansi_writer.write_all(s.as_ref().as_bytes()).unwrap(); + ansi_writer.reset().unwrap(); + String::from_utf8_lossy(&v).into_owned() +} + fn decode_value( value: Vec, encoding: pb::KvValueEncoding,