diff options
author | Igor Zinkovsky <igor@deno.com> | 2023-09-03 17:47:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-03 17:47:52 -0700 |
commit | 1dc5d421149903f4e963e735755026d07022ac33 (patch) | |
tree | c0aefedee92ab93361fd539250b60a096e36bc0c /ext/kv/remote.rs | |
parent | d6c49353c3f545bfd2af8711197d23e41dd5e378 (diff) |
fix(ext/kv): add a warning for listenQueue if used with remote KV (#20341)
Diffstat (limited to 'ext/kv/remote.rs')
-rw-r--r-- | ext/kv/remote.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/ext/kv/remote.rs b/ext/kv/remote.rs index 21286fd47..fc18e4615 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<P: RemoteDbHandlerPermissions> Database for RemoteDb<P> { &self, _state: Rc<RefCell<OpState>>, ) -> Result<Self::QMH, AnyError> { + 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: AsRef<str>>(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<u8>, encoding: pb::KvValueEncoding, |