UNPKG

6.46 kBJavaScriptView Raw
1"use strict";
2// Copyright (c) Jupyter Development Team.
3// Distributed under the terms of the Modified BSD License.
4Object.defineProperty(exports, "__esModule", { value: true });
5exports.supportedKernelWebSocketProtocols = exports.isInputReplyMsg = exports.isInputRequestMsg = exports.isDebugReplyMsg = exports.isDebugRequestMsg = exports.isExecuteReplyMsg = exports.isInfoRequestMsg = exports.isCommMsgMsg = exports.isCommCloseMsg = exports.isCommOpenMsg = exports.isDebugEventMsg = exports.isClearOutputMsg = exports.isStatusMsg = exports.isErrorMsg = exports.isExecuteResultMsg = exports.isExecuteInputMsg = exports.isUpdateDisplayDataMsg = exports.isDisplayDataMsg = exports.isStreamMsg = exports.createMessage = void 0;
6const coreutils_1 = require("@lumino/coreutils");
7function createMessage(options) {
8 var _a, _b, _c, _d, _e;
9 return {
10 buffers: (_a = options.buffers) !== null && _a !== void 0 ? _a : [],
11 channel: options.channel,
12 content: options.content,
13 header: {
14 date: new Date().toISOString(),
15 msg_id: (_b = options.msgId) !== null && _b !== void 0 ? _b : coreutils_1.UUID.uuid4(),
16 msg_type: options.msgType,
17 session: options.session,
18 username: (_c = options.username) !== null && _c !== void 0 ? _c : '',
19 version: '5.2'
20 },
21 metadata: (_d = options.metadata) !== null && _d !== void 0 ? _d : {},
22 parent_header: (_e = options.parentHeader) !== null && _e !== void 0 ? _e : {}
23 };
24}
25exports.createMessage = createMessage;
26/**
27 * Test whether a kernel message is a `'stream'` message.
28 */
29function isStreamMsg(msg) {
30 return msg.header.msg_type === 'stream';
31}
32exports.isStreamMsg = isStreamMsg;
33/**
34 * Test whether a kernel message is an `'display_data'` message.
35 */
36function isDisplayDataMsg(msg) {
37 return msg.header.msg_type === 'display_data';
38}
39exports.isDisplayDataMsg = isDisplayDataMsg;
40/**
41 * Test whether a kernel message is an `'update_display_data'` message.
42 */
43function isUpdateDisplayDataMsg(msg) {
44 return msg.header.msg_type === 'update_display_data';
45}
46exports.isUpdateDisplayDataMsg = isUpdateDisplayDataMsg;
47/**
48 * Test whether a kernel message is an `'execute_input'` message.
49 */
50function isExecuteInputMsg(msg) {
51 return msg.header.msg_type === 'execute_input';
52}
53exports.isExecuteInputMsg = isExecuteInputMsg;
54/**
55 * Test whether a kernel message is an `'execute_result'` message.
56 */
57function isExecuteResultMsg(msg) {
58 return msg.header.msg_type === 'execute_result';
59}
60exports.isExecuteResultMsg = isExecuteResultMsg;
61/**
62 * Test whether a kernel message is an `'error'` message.
63 */
64function isErrorMsg(msg) {
65 return msg.header.msg_type === 'error';
66}
67exports.isErrorMsg = isErrorMsg;
68/**
69 * Test whether a kernel message is a `'status'` message.
70 */
71function isStatusMsg(msg) {
72 return msg.header.msg_type === 'status';
73}
74exports.isStatusMsg = isStatusMsg;
75/**
76 * Test whether a kernel message is a `'clear_output'` message.
77 */
78function isClearOutputMsg(msg) {
79 return msg.header.msg_type === 'clear_output';
80}
81exports.isClearOutputMsg = isClearOutputMsg;
82/**
83 * Test whether a kernel message is an experimental `'debug_event'` message.
84 *
85 * @hidden
86 *
87 * #### Notes
88 * Debug messages are experimental messages that are not in the official
89 * kernel message specification. As such, this is *NOT* considered
90 * part of the public API, and may change without notice.
91 */
92function isDebugEventMsg(msg) {
93 return msg.header.msg_type === 'debug_event';
94}
95exports.isDebugEventMsg = isDebugEventMsg;
96/**
97 * Test whether a kernel message is a `'comm_open'` message.
98 */
99function isCommOpenMsg(msg) {
100 return msg.header.msg_type === 'comm_open';
101}
102exports.isCommOpenMsg = isCommOpenMsg;
103/**
104 * Test whether a kernel message is a `'comm_close'` message.
105 */
106function isCommCloseMsg(msg) {
107 return msg.header.msg_type === 'comm_close';
108}
109exports.isCommCloseMsg = isCommCloseMsg;
110/**
111 * Test whether a kernel message is a `'comm_msg'` message.
112 */
113function isCommMsgMsg(msg) {
114 return msg.header.msg_type === 'comm_msg';
115}
116exports.isCommMsgMsg = isCommMsgMsg;
117/**
118 * Test whether a kernel message is a `'kernel_info_request'` message.
119 */
120function isInfoRequestMsg(msg) {
121 return msg.header.msg_type === 'kernel_info_request';
122}
123exports.isInfoRequestMsg = isInfoRequestMsg;
124/**
125 * Test whether a kernel message is an `'execute_reply'` message.
126 */
127function isExecuteReplyMsg(msg) {
128 return msg.header.msg_type === 'execute_reply';
129}
130exports.isExecuteReplyMsg = isExecuteReplyMsg;
131/**
132 * Test whether a kernel message is an experimental `'debug_request'` message.
133 *
134 * @hidden
135 *
136 * #### Notes
137 * Debug messages are experimental messages that are not in the official
138 * kernel message specification. As such, this is *NOT* considered
139 * part of the public API, and may change without notice.
140 */
141function isDebugRequestMsg(msg) {
142 return msg.header.msg_type === 'debug_request';
143}
144exports.isDebugRequestMsg = isDebugRequestMsg;
145/**
146 * Test whether a kernel message is an experimental `'debug_reply'` message.
147 *
148 * @hidden
149 *
150 * #### Notes
151 * Debug messages are experimental messages that are not in the official
152 * kernel message specification. As such, this is *NOT* considered
153 * part of the public API, and may change without notice.
154 */
155function isDebugReplyMsg(msg) {
156 return msg.header.msg_type === 'debug_reply';
157}
158exports.isDebugReplyMsg = isDebugReplyMsg;
159/**
160 * Test whether a kernel message is an `'input_request'` message.
161 */
162function isInputRequestMsg(msg) {
163 return msg.header.msg_type === 'input_request';
164}
165exports.isInputRequestMsg = isInputRequestMsg;
166/**
167 * Test whether a kernel message is an `'input_reply'` message.
168 */
169function isInputReplyMsg(msg) {
170 return msg.header.msg_type === 'input_reply';
171}
172exports.isInputReplyMsg = isInputReplyMsg;
173// ///////////////////////////////////////////////
174// Message (de)serialization
175// ///////////////////////////////////////////////
176/**
177 * The list of supported kernel wire protocols over websocket.
178 */
179var supportedKernelWebSocketProtocols;
180(function (supportedKernelWebSocketProtocols) {
181 supportedKernelWebSocketProtocols["v1KernelWebsocketJupyterOrg"] = "v1.kernel.websocket.jupyter.org";
182})(supportedKernelWebSocketProtocols = exports.supportedKernelWebSocketProtocols || (exports.supportedKernelWebSocketProtocols = {}));
183//# sourceMappingURL=messages.js.map
\No newline at end of file