@jupyterlab/services
Version:
Client APIs for the Jupyter services REST APIs
184 lines • 6.05 kB
JavaScript
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.supportedKernelWebSocketProtocols = void 0;
exports.createMessage = createMessage;
exports.isStreamMsg = isStreamMsg;
exports.isDisplayDataMsg = isDisplayDataMsg;
exports.isUpdateDisplayDataMsg = isUpdateDisplayDataMsg;
exports.isExecuteInputMsg = isExecuteInputMsg;
exports.isExecuteResultMsg = isExecuteResultMsg;
exports.isErrorMsg = isErrorMsg;
exports.isStatusMsg = isStatusMsg;
exports.isClearOutputMsg = isClearOutputMsg;
exports.isDebugEventMsg = isDebugEventMsg;
exports.isCommOpenMsg = isCommOpenMsg;
exports.isCommCloseMsg = isCommCloseMsg;
exports.isCommMsgMsg = isCommMsgMsg;
exports.isInfoRequestMsg = isInfoRequestMsg;
exports.isExecuteReplyMsg = isExecuteReplyMsg;
exports.isDebugRequestMsg = isDebugRequestMsg;
exports.isDebugReplyMsg = isDebugReplyMsg;
exports.isInputRequestMsg = isInputRequestMsg;
exports.isInputReplyMsg = isInputReplyMsg;
const coreutils_1 = require("@lumino/coreutils");
function createMessage(options) {
var _a, _b, _c, _d, _e, _f;
return {
buffers: (_a = options.buffers) !== null && _a !== void 0 ? _a : [],
channel: options.channel,
content: options.content,
header: {
date: new Date().toISOString(),
msg_id: (_b = options.msgId) !== null && _b !== void 0 ? _b : coreutils_1.UUID.uuid4(),
msg_type: options.msgType,
session: options.session,
username: (_c = options.username) !== null && _c !== void 0 ? _c : '',
subshell_id: (_d = options.subshellId) !== null && _d !== void 0 ? _d : null,
version: '5.2'
},
metadata: (_e = options.metadata) !== null && _e !== void 0 ? _e : {},
parent_header: (_f = options.parentHeader) !== null && _f !== void 0 ? _f : {}
};
}
/**
* Test whether a kernel message is a `'stream'` message.
*/
function isStreamMsg(msg) {
return msg.header.msg_type === 'stream';
}
/**
* Test whether a kernel message is an `'display_data'` message.
*/
function isDisplayDataMsg(msg) {
return msg.header.msg_type === 'display_data';
}
/**
* Test whether a kernel message is an `'update_display_data'` message.
*/
function isUpdateDisplayDataMsg(msg) {
return msg.header.msg_type === 'update_display_data';
}
/**
* Test whether a kernel message is an `'execute_input'` message.
*/
function isExecuteInputMsg(msg) {
return msg.header.msg_type === 'execute_input';
}
/**
* Test whether a kernel message is an `'execute_result'` message.
*/
function isExecuteResultMsg(msg) {
return msg.header.msg_type === 'execute_result';
}
/**
* Test whether a kernel message is an `'error'` message.
*/
function isErrorMsg(msg) {
return msg.header.msg_type === 'error';
}
/**
* Test whether a kernel message is a `'status'` message.
*/
function isStatusMsg(msg) {
return msg.header.msg_type === 'status';
}
/**
* Test whether a kernel message is a `'clear_output'` message.
*/
function isClearOutputMsg(msg) {
return msg.header.msg_type === 'clear_output';
}
/**
* Test whether a kernel message is an experimental `'debug_event'` message.
*
* @hidden
*
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, this is *NOT* considered
* part of the public API, and may change without notice.
*/
function isDebugEventMsg(msg) {
return msg.header.msg_type === 'debug_event';
}
/**
* Test whether a kernel message is a `'comm_open'` message.
*/
function isCommOpenMsg(msg) {
return msg.header.msg_type === 'comm_open';
}
/**
* Test whether a kernel message is a `'comm_close'` message.
*/
function isCommCloseMsg(msg) {
return msg.header.msg_type === 'comm_close';
}
/**
* Test whether a kernel message is a `'comm_msg'` message.
*/
function isCommMsgMsg(msg) {
return msg.header.msg_type === 'comm_msg';
}
/**
* Test whether a kernel message is a `'kernel_info_request'` message.
*/
function isInfoRequestMsg(msg) {
return msg.header.msg_type === 'kernel_info_request';
}
/**
* Test whether a kernel message is an `'execute_reply'` message.
*/
function isExecuteReplyMsg(msg) {
return msg.header.msg_type === 'execute_reply';
}
/**
* Test whether a kernel message is an experimental `'debug_request'` message.
*
* @hidden
*
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, this is *NOT* considered
* part of the public API, and may change without notice.
*/
function isDebugRequestMsg(msg) {
return msg.header.msg_type === 'debug_request';
}
/**
* Test whether a kernel message is an experimental `'debug_reply'` message.
*
* @hidden
*
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, this is *NOT* considered
* part of the public API, and may change without notice.
*/
function isDebugReplyMsg(msg) {
return msg.header.msg_type === 'debug_reply';
}
/**
* Test whether a kernel message is an `'input_request'` message.
*/
function isInputRequestMsg(msg) {
return msg.header.msg_type === 'input_request';
}
/**
* Test whether a kernel message is an `'input_reply'` message.
*/
function isInputReplyMsg(msg) {
return msg.header.msg_type === 'input_reply';
}
// ///////////////////////////////////////////////
// Message (de)serialization
// ///////////////////////////////////////////////
/**
* The list of supported kernel wire protocols over websocket.
*/
var supportedKernelWebSocketProtocols;
(function (supportedKernelWebSocketProtocols) {
supportedKernelWebSocketProtocols["v1KernelWebsocketJupyterOrg"] = "v1.kernel.websocket.jupyter.org";
})(supportedKernelWebSocketProtocols || (exports.supportedKernelWebSocketProtocols = supportedKernelWebSocketProtocols = {}));
//# sourceMappingURL=messages.js.map
;