From 675603a4e5fbb74373e49092d4f0daf737a2219d Mon Sep 17 00:00:00 2001 From: Trevor Manz Date: Wed, 27 Sep 2023 14:34:42 -0400 Subject: [PATCH] feat(unstable): add `metadata` to `Deno.jupyter.broadcast`. --- cli/js/40_jupyter.js | 4 ++-- cli/ops/jupyter.rs | 2 ++ cli/tools/jupyter/jupyter_msg.rs | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cli/js/40_jupyter.js b/cli/js/40_jupyter.js index ae257f1c1f54fb..59a39783496b44 100644 --- a/cli/js/40_jupyter.js +++ b/cli/js/40_jupyter.js @@ -9,8 +9,8 @@ function enableJupyter() { } = core.ensureFastOps(); globalThis.Deno.jupyter = { - async broadcast(msgType, content) { - await op_jupyter_broadcast(msgType, content); + async broadcast(msgType, content, metadata = {}) { + await op_jupyter_broadcast(msgType, content, metadata); }, }; } diff --git a/cli/ops/jupyter.rs b/cli/ops/jupyter.rs index 765b062e5c7128..12d19fab5099ab 100644 --- a/cli/ops/jupyter.rs +++ b/cli/ops/jupyter.rs @@ -36,6 +36,7 @@ pub async fn op_jupyter_broadcast( state: Rc>, #[string] message_type: String, #[serde] content: serde_json::Value, + #[serde] metadata: serde_json::Value, ) -> Result<(), AnyError> { let (iopub_socket, last_execution_request) = { let s = state.borrow(); @@ -52,6 +53,7 @@ pub async fn op_jupyter_broadcast( last_request .new_message(&message_type) .with_content(content) + .with_metadata(metadata) .send(&mut *iopub_socket.lock().await) .await?; } diff --git a/cli/tools/jupyter/jupyter_msg.rs b/cli/tools/jupyter/jupyter_msg.rs index c28dd3b485f66d..beb9f34e4ae57a 100644 --- a/cli/tools/jupyter/jupyter_msg.rs +++ b/cli/tools/jupyter/jupyter_msg.rs @@ -206,6 +206,14 @@ impl JupyterMessage { self } + pub(crate) fn with_metadata( + mut self, + metadata: serde_json::Value, + ) -> JupyterMessage { + self.metadata = metadata; + self + } + pub(crate) async fn send( &self, connection: &mut Connection,