chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:25:07 +08:00
commit a26e856398
1681 changed files with 296950 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
# ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
# ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
# ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
# ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
# ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
# ┃ Copyright (c) 2017, the Perspective Authors. ┃
# ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
# ┃ This file is part of the Perspective library, distributed under the terms ┃
# ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
[package]
name = "perspective"
version = "4.5.2"
authors = ["Andrew Stein <steinlink@gmail.com>"]
edition = "2024"
description = "A data visualization and analytics component, especially well-suited for large and/or streaming datasets."
repository = "https://github.com/perspective-dev/perspective"
license = "Apache-2.0"
homepage = "https://perspective-dev.github.io"
keywords = []
include = ["src/**/*", "tests/**/*", "Cargo.toml"]
[lib]
path = "src/lib.rs"
[features]
default = []
axum-ws = ["tokio", "axum", "futures"]
external-cpp = [
"perspective-server/external-cpp",
"perspective-client/generate-proto",
"perspective-client/protobuf-src",
]
[dependencies]
async-lock = "2.5.0"
perspective-client = { version = "4.5.2" }
perspective-server = { version = "4.5.2" }
tracing = { version = ">=0.1.36" }
axum = { version = ">=0.7,<0.9", features = ["ws"], optional = true }
fallible-iterator = "0.2.0"
indexmap = "2.12.1"
serde = { version = "1.0" }
serde_json = { version = "1.0.107" }
tokio = { version = "~1", features = ["full"], optional = true }
futures = { version = "~0", optional = true }
[dependencies.prost]
version = "0.12.3"
default-features = false
features = ["prost-derive", "std"]
+41
View File
@@ -0,0 +1,41 @@
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
// ┃ This file is part of the Perspective library, distributed under the terms ┃
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
import { execSync } from "child_process";
let flags = "--release";
if (!!process.env.PSP_DEBUG) {
flags = "";
}
const env = { ...process.env };
// if not windows
if (process.platform !== "win32") {
env.PSP_ROOT_DIR = "../..";
}
let target = "";
if (process.env.PSP_ARCH === "x86_64" && process.platform === "darwin") {
target = "--target=x86_64-apple-darwin";
} else if (
process.env.PSP_ARCH === "aarch64" &&
process.platform === "darwin"
) {
target = "--target=aarch64-apple-darwin";
} else if (process.env.PSP_ARCH === "x86_64" && process.platform === "linux") {
target = "--target=x86_64-unknown-linux-gnu --compatibility manylinux_2_28";
} else if (process.env.PSP_ARCH === "aarch64" && process.platform === "linux") {
target = "--target=aarch64-unknown-linux-gnu";
}
execSync(`cargo build ${flags} ${target}`, { stdio: "inherit", env });
+17
View File
@@ -0,0 +1,17 @@
{
"name": "@perspective-dev/rust",
"version": "4.5.2",
"description": "",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/perspective-dev/perspective"
},
"type": "module",
"license": "Apache-2.0",
"scripts": {
"build": "node build.mjs",
"clean": "cargo clean",
"test": "cargo test"
}
}
+120
View File
@@ -0,0 +1,120 @@
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
// ┃ This file is part of the Perspective library, distributed under the terms ┃
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
use std::net::SocketAddr;
use axum::body::Bytes;
use axum::extract::State;
use axum::extract::connect_info::ConnectInfo;
use axum::extract::ws::{Message, WebSocket, WebSocketUpgrade};
use axum::response::IntoResponse;
use axum::routing::{MethodRouter, get};
use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender, unbounded};
use futures::future::{Either, select};
use futures::{FutureExt, SinkExt, StreamExt};
use crate::client::Session;
use crate::server::{LocalSession, Server, SessionHandler};
/// A local error synonym for this module only.
type PerspectiveWSError = Box<dyn std::error::Error + Send + Sync>;
/// We must share access to the [`WebSocket`] for both sending and receiving
/// messages, a message flow which this enum is used to model. When the
/// client disconnects or the message stream is unrecoverably errored,
/// we must emit an _end_ message as well.
enum PerspectiveWSMessage {
Incoming(Bytes),
Outgoing(Bytes),
End,
}
/// A new-type wrapper for an [`UnboundedSender`], whic bypasses the orphan
/// instance rule allowing us to write a [`SessionHandler`] impl for this
/// struct.
#[derive(Clone)]
struct PerspectiveWSConnection(UnboundedSender<Bytes>);
/// The [`SessionHandler`] implementation provides a method for a
/// [`Session`] to send messages to this
/// [`axum::extract::ws::WebSocket`], which may (or may
/// not) be solicited (e.g. within the async call stack of
/// [`perspective::Session::handle_request`]).
impl SessionHandler for PerspectiveWSConnection {
async fn send_response<'a>(&'a mut self, resp: &'a [u8]) -> Result<(), PerspectiveWSError> {
Ok(self.0.send(Bytes::copy_from_slice(resp)).await?)
}
}
/// The inner message loop handles the full-duplex stream of messages
/// between the [`perspective::Client`] and [`Session`]. When this
/// funciton returns, messages are no longer processed.
async fn process_message_loop(
socket: &mut WebSocket,
receiver: &mut UnboundedReceiver<Bytes>,
session: &mut LocalSession,
) -> Result<(), PerspectiveWSError> {
use Either::*;
use Message::*;
use PerspectiveWSMessage::*;
loop {
let msg = match select(socket.recv().boxed(), receiver.next()).await {
Right((Some(bytes), _)) => Ok(Outgoing(bytes)),
Left((Some(Ok(Binary(bytes))), _)) => Ok(Incoming(bytes)),
Right((None, _)) | Left((None | Some(Ok(Close(_))), _)) => Ok(End),
Left((Some(Ok(_)), _)) => Err("Unexpected message type".to_string()),
Left((Some(Err(err)), _)) => Err(format!("{err}")),
}?;
match msg {
End => break,
Outgoing(bytes) => socket.send(Binary(bytes)).await?,
Incoming(bytes) => {
session.handle_request(&bytes).await?;
},
}
}
Ok(())
}
/// This handler is responsible for the beginning-to-end lifecycle of a
/// single WebSocket connection to an [`axum`] server.
///
/// Messages will come in from the [`axum::extract::ws::WebSocket`] in binary
/// form via [`Message::Binary`], where they'll be routed to
/// [`perspective::Session::handle_request`]. The server may generate
/// one or more responses, which it will then send back to
/// the [`axum::extract::ws::WebSocket::send`] method via its
/// [`SessionHandler`] impl.
pub fn websocket_handler() -> MethodRouter<Server> {
async fn websocket_handler_internal(
ws: WebSocketUpgrade,
State(server): State<Server>,
ConnectInfo(addr): ConnectInfo<SocketAddr>,
) -> impl IntoResponse {
tracing::info!("{addr} Connected.");
ws.on_upgrade(move |mut socket| async move {
let (send, mut receiver) = unbounded::<Bytes>();
let mut session = server.new_session(PerspectiveWSConnection(send)).await;
if let Err(msg) = process_message_loop(&mut socket, &mut receiver, &mut session).await {
tracing::error!("Internal error {}", msg);
}
tracing::info!("{addr} Disconnected.");
session.close().await;
})
}
get(websocket_handler_internal)
}
+66
View File
@@ -0,0 +1,66 @@
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
// ┃ This file is part of the Perspective library, distributed under the terms ┃
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
//! The Rust language bindings for [Perspective](https://perspective-dev.github.io),
//! a high performance data-visualization and analytics component for the web
//! browser.
//!
//! # Examples
//!
//! A simple example which loads an [Apache Arrow](https://arrow.apache.org/) and
//! computes a "Group By" operation, returning a new Arrow.
//!
//! ```rust,no_run
//! use perspective::client::config::ViewConfigUpdate;
//! use perspective::client::{TableInitOptions, UpdateData, ViewWindow};
//! use perspective::server::{LocalClient, Server};
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let server = Server::new(None);
//! let client = LocalClient::new(&server);
//! let arrow_data: Vec<u8> = vec![];
//! let data = UpdateData::Arrow(arrow_data.into());
//! let options = TableInitOptions::default();
//! let table = client.table(data.into(), options).await?;
//! let mut view_config = ViewConfigUpdate::default();
//! view_config.group_by = ["CounterParty", "Security"]
//! .iter()
//! .map(|x| Some(x.to_string()))
//! .collect();
//!
//! let view = table.view(Some(view_config)).await?;
//! let arrow = view.to_arrow(ViewWindow::default()).await?;
//! # Ok(())
//! # }
//! ```
//!
//! # See also
//!
//! - [`perspective-js`](https://docs.rs/perspective-js/latest/) for the
//! JavaScript API.
//! - [`perspective-python`](https://docs.rs/perspective-python/latest/) for the
//! Python API.
//! - [`perspective-server`](https://docs.rs/perspective-server/latest/) for
//! Data Binding details.
//! - [`perspective-client`](https://docs.rs/perspective-client/latest/) for the
//! Rust Client API
//! - [`perspective-viewer`](https://docs.rs/perspective-viewer/latest/) for the
//! WebAssembly `<perspective-viewer>` Custom Element API.
#[cfg(feature = "axum-ws")]
pub mod axum;
#[cfg(feature = "axum-ws")]
pub mod virtual_server;
pub use perspective_client as client;
pub use perspective_client::proto;
pub use perspective_server as server;
+79
View File
@@ -0,0 +1,79 @@
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
// ┃ This file is part of the Perspective library, distributed under the terms ┃
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
use std::net::SocketAddr;
use axum::extract::connect_info::ConnectInfo;
use axum::extract::ws::{Message, WebSocket, WebSocketUpgrade};
use axum::routing::{MethodRouter, get};
use perspective_client::virtual_server::{VirtualServer, VirtualServerHandler};
/// A local error synonym for this module only.
type PerspectiveWSError = Box<dyn std::error::Error + Send + Sync>;
pub type PSPError = Box<dyn std::error::Error + Send + Sync>;
/// The inner message loop handles the full-duplex stream of messages
/// between the [`perspective::Client`] and [`Session`]. When this
/// funciton returns, messages are no longer processed.
async fn process_message_loop(
socket: &mut WebSocket,
handler: impl VirtualServerHandler,
) -> Result<(), PerspectiveWSError> {
use Message::*;
let mut processor = VirtualServer::new(handler);
loop {
match socket.recv().await {
Some(Ok(Binary(msg))) => {
socket
.send(Binary(processor.handle_request(msg).await?))
.await?
},
Some(_) | None => {
tracing::debug!("Unexpected msg");
break;
},
};
}
Ok(())
}
/// This handler is responsible for the beginning-to-end lifecycle of a
/// single WebSocket connection to an [`axum`] server.
///
/// Messages will come in from the [`axum::extract::ws::WebSocket`] in binary
/// form via [`Message::Binary`], where they'll be routed to
/// [`perspective::Session::handle_request`]. The server may generate
/// one or more responses, which it will then send back to
/// the [`axum::extract::ws::WebSocket::send`] method via its
/// [`SessionHandler`] impl.
pub fn custom_websocket_handler<S, T>(handler: T) -> MethodRouter<S>
where
T: VirtualServerHandler + Clone + Send + Sync + 'static,
S: Clone + Send + Sync + 'static,
{
let websocket_handler_internal = async |ws: WebSocketUpgrade,
ConnectInfo(addr): ConnectInfo<SocketAddr>|
-> axum::response::Response {
tracing::info!("{addr} Connected.");
ws.on_upgrade(move |mut socket| async move {
if let Err(msg) = process_message_loop(&mut socket, handler).await {
tracing::error!("Internal error {}", msg);
}
tracing::info!("{addr} Disconnected.");
})
};
get(websocket_handler_internal)
}
+66
View File
@@ -0,0 +1,66 @@
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
// ┃ This file is part of the Perspective library, distributed under the terms ┃
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
#[cfg(feature = "axum-ws")]
mod internal {
// use tokio::sync::Mutex;
use std::error::Error;
use std::sync::Arc;
use perspective_client::{OnUpdateOptions, TableInitOptions, UpdateData, UpdateOptions};
use perspective_server::LocalClient;
use tokio::sync::Mutex;
#[tokio::test]
async fn test_two_sync_clients_receive_messages_on_update() -> Result<(), Box<dyn Error>> {
let server = perspective::server::Server::new(None);
let client1 = LocalClient::new(&server);
let client2 = LocalClient::new(&server);
let table = client1
.table(
UpdateData::Csv("x,y\n1,2\n3,4".to_owned()).into(),
TableInitOptions {
name: Some("Table1".to_owned()),
index: None,
limit: None,
format: None,
},
)
.await?;
let table2 = client2.open_table("Table1".to_owned()).await?;
let view = table2.view(None).await?;
let result = Arc::new(Mutex::new(false));
let _sub = view
.on_update(
{
let result = result.clone();
move |_| {
let result = result.clone();
async move { *result.lock().await = true }
}
},
OnUpdateOptions::default(),
)
.await?;
table
.update(
UpdateData::Csv("x,y\n5,6".to_owned()),
UpdateOptions::default(),
)
.await?;
assert!(*result.lock().await);
Ok(())
}
}