mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
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.
This commit is contained in:
parent
2d1af0cf51
commit
7bcf1211a1
4 changed files with 15 additions and 2 deletions
|
@ -9,8 +9,8 @@ function enableJupyter() {
|
||||||
} = core.ensureFastOps();
|
} = core.ensureFastOps();
|
||||||
|
|
||||||
globalThis.Deno.jupyter = {
|
globalThis.Deno.jupyter = {
|
||||||
async broadcast(msgType, content) {
|
async broadcast(msgType, content, { metadata = {} } = {}) {
|
||||||
await op_jupyter_broadcast(msgType, content);
|
await op_jupyter_broadcast(msgType, content, metadata);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ pub async fn op_jupyter_broadcast(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
#[string] message_type: String,
|
#[string] message_type: String,
|
||||||
#[serde] content: serde_json::Value,
|
#[serde] content: serde_json::Value,
|
||||||
|
#[serde] metadata: serde_json::Value,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let (iopub_socket, last_execution_request) = {
|
let (iopub_socket, last_execution_request) = {
|
||||||
let s = state.borrow();
|
let s = state.borrow();
|
||||||
|
@ -52,6 +53,7 @@ pub async fn op_jupyter_broadcast(
|
||||||
last_request
|
last_request
|
||||||
.new_message(&message_type)
|
.new_message(&message_type)
|
||||||
.with_content(content)
|
.with_content(content)
|
||||||
|
.with_metadata(metadata)
|
||||||
.send(&mut *iopub_socket.lock().await)
|
.send(&mut *iopub_socket.lock().await)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,6 +206,14 @@ impl JupyterMessage {
|
||||||
self
|
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>(
|
pub(crate) async fn send<S: zeromq::SocketSend>(
|
||||||
&self,
|
&self,
|
||||||
connection: &mut Connection<S>,
|
connection: &mut Connection<S>,
|
||||||
|
|
3
cli/tsc/dts/lib.deno.unstable.d.ts
vendored
3
cli/tsc/dts/lib.deno.unstable.d.ts
vendored
|
@ -1978,6 +1978,9 @@ declare namespace Deno {
|
||||||
export function broadcast(
|
export function broadcast(
|
||||||
msgType: string,
|
msgType: string,
|
||||||
content: Record<string, unknown>,
|
content: Record<string, unknown>,
|
||||||
|
extra?: {
|
||||||
|
metadata?: Record<string, unknown>;
|
||||||
|
},
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue