@nteract/messaging
Version:
Messaging mechanics for nteract apps (jupyter spec)
109 lines (108 loc) • 4.73 kB
TypeScript
import { PayloadMessage } from "@nteract/types";
import { Observable } from "rxjs";
import { JupyterMessage, MessageType } from "./types";
export * from "./types";
export interface CreateMessageFields extends Partial<JupyterMessage> {
header?: never;
}
export declare function createMessage<MT extends MessageType>(msg_type: MT, fields?: CreateMessageFields): JupyterMessage<MT>;
/**
* creates a comm open message
* @param {string} comm_id uuid
* @param {string} target_name comm handler
* @param {any} data up to the target handler
* @param {string} target_module [Optional] used to select a module that is responsible for handling the target_name
* @return {jmp.Message} Message ready to send on the shell channel
*/
export declare function createCommOpenMessage(comm_id: string, target_name: string, data: any, target_module: string): JupyterMessage<"comm_open", any>;
/**
* creates a comm message for sending to a kernel
* @param {string} comm_id unique identifier for the comm
* @param {Object} data any data to send for the comm
* @param {Uint8Array} buffers arbitrary binary data to send on the comm
* @return {jmp.Message} jupyter message for comm_msg
*/
export declare function createCommMessage(comm_id: string, data: any, buffers: []): JupyterMessage<"comm_msg", any>;
/**
* creates a comm close message for sending to a kernel
* @param {Object} parent_header header from a parent jupyter message
* @param {string} comm_id unique identifier for the comm
* @param {Object} data any data to send for the comm
* @return {jmp.Message} jupyter message for comm_msg
*/
export declare function createCommCloseMessage(parent_header: any, comm_id: string, data?: any): JupyterMessage<"comm_close", any>;
/**
* operator for getting all messages that declare their parent header as
* parentMessage's header.
*
* @param parentMessage The parent message whose children we should fetch
*
* @returns A function that takes an Observable of kernel messages and returns
* messages that are children of parentMessage.
*/
export declare function childOf(parentMessage: JupyterMessage): (source: Observable<JupyterMessage<MessageType, any>>) => any;
/**
* operator for getting all messages with the given comm id
*
* @param comm_id The comm id that we are filtering by
*
* @returns A function that takes an Observable of kernel messages and returns
* messages that have the given comm id
*/
export declare function withCommId(comm_id: string): (source: Observable<JupyterMessage<MessageType, any>>) => any;
/**
* ofMessageType is an Rx Operator that filters on msg.header.msg_type
* being one of messageTypes.
*
* @param messageTypes The message types to filter on
*
* @returns An Observable containing only messages of the specified types
*/
export declare const ofMessageType: <T extends MessageType>(...messageTypes: (T | [T])[]) => (source: Observable<JupyterMessage>) => Observable<JupyterMessage<T, any>>;
/**
* Create an object that adheres to the jupyter notebook specification.
* http://jupyter-client.readthedocs.io/en/latest/messaging.html
*
* @param msg Message that has content which can be converted to nbformat
*
* @returns Message with the associated output type
*/
export declare function convertOutputMessageToNotebookFormat(msg: JupyterMessage): any;
/**
* Convert raw Jupyter messages that are output messages into nbformat style
* outputs
*
* > o$ = iopub$.pipe(
* childOf(originalMessage),
* outputs()
* )
*/
export declare const outputs: () => (source: Observable<JupyterMessage>) => Observable<any>;
/**
* Get all messages for updating a display output.
*/
export declare const updatedOutputs: () => (source: Observable<JupyterMessage>) => Observable<any>;
/**
* Get all the payload message content from an observable of jupyter messages
*
* > p$ = shell$.pipe(
* childOf(originalMessage),
* payloads()
* )
*/
export declare const payloads: () => (source: Observable<JupyterMessage>) => Observable<PayloadMessage>;
/**
* Get all the execution counts from an observable of jupyter messages
*/
export declare const executionCounts: () => (source: Observable<JupyterMessage>) => Observable<any>;
/**
* Get all statuses of all running kernels.
*/
export declare const kernelStatuses: () => (source: Observable<JupyterMessage>) => Observable<any>;
export declare const inputRequests: () => (source: Observable<JupyterMessage>) => Observable<any>;
export * from "./messages";
import { encode, decode } from "./wire-protocol";
export declare const wireProtocol: {
encode: typeof encode;
decode: typeof decode;
};