diff options
author | Trevor Manz <trevor.j.manz@gmail.com> | 2023-09-29 18:24:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-30 00:24:09 +0200 |
commit | 7bcf1211a1494c188c9de83670d328c0492de98a (patch) | |
tree | 712e92f5cb5bbf32867474f272ca24c2228df2b5 /cli | |
parent | 2d1af0cf51bac446f1c92e8a12db9b5052e37e12 (diff) |
feat(jupyter): send Jupyter messaging metadata with `Deno.jupyter.broadcast` (#20714)
Exposes
[`metadata`](https://jupyter-client.readthedocs.io/en/latest/messaging.html#metadata)
to the `Deno.jupyter.broadcast` API.
```js
await Deno.jupyter.broadcast(msgType, content, metadata);
```
The metadata is required for
[`"comm_open"`](https://github.com/jupyter-widgets/ipywidgets/blob/main/packages/schema/messages.md#instantiating-a-widget-object-1)
for with `jupyter.widget` target.
Diffstat (limited to 'cli')
-rw-r--r-- | cli/js/40_jupyter.js | 4 | ||||
-rw-r--r-- | cli/ops/jupyter.rs | 2 | ||||
-rw-r--r-- | cli/tools/jupyter/jupyter_msg.rs | 8 | ||||
-rw-r--r-- | cli/tsc/dts/lib.deno.unstable.d.ts | 3 |
4 files changed, 15 insertions, 2 deletions
diff --git a/cli/js/40_jupyter.js b/cli/js/40_jupyter.js index ae257f1c1..10dbccf4c 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 765b062e5..12d19fab5 100644 --- a/cli/ops/jupyter.rs +++ b/cli/ops/jupyter.rs @@ -36,6 +36,7 @@ pub async fn op_jupyter_broadcast( state: Rc<RefCell<OpState>>, #[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 c28dd3b48..beb9f34e4 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<S: zeromq::SocketSend>( &self, connection: &mut Connection<S>, diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts index 9f9a4914b..11510d144 100644 --- a/cli/tsc/dts/lib.deno.unstable.d.ts +++ b/cli/tsc/dts/lib.deno.unstable.d.ts @@ -1978,6 +1978,9 @@ declare namespace Deno { export function broadcast( msgType: string, content: Record<string, unknown>, + extra?: { + metadata?: Record<string, unknown>; + }, ): Promise<void>; } } |