1 | /**
|
2 | * This module defines shims for @jupyterlab/services that allows you to use the
|
3 | * old comm API. Use this, @jupyterlab/services, and the widget base manager to
|
4 | * embed live widgets in a context outside of the notebook.
|
5 | */
|
6 | import { Kernel, KernelMessage } from '@jupyterlab/services';
|
7 | import type { JSONValue, JSONObject } from '@lumino/coreutils';
|
8 | /**
|
9 | * Callbacks for services shim comms.
|
10 | */
|
11 | export interface ICallbacks {
|
12 | shell?: {
|
13 | [key: string]: (msg: KernelMessage.IShellMessage) => void;
|
14 | };
|
15 | iopub?: {
|
16 | [key: string]: (msg: KernelMessage.IIOPubMessage) => void;
|
17 | };
|
18 | input?: (msg: KernelMessage.IStdinMessage) => void;
|
19 | }
|
20 | export interface IClassicComm {
|
21 | /**
|
22 | * Comm id
|
23 | * @return {string}
|
24 | */
|
25 | comm_id: string;
|
26 | /**
|
27 | * Target name
|
28 | * @return {string}
|
29 | */
|
30 | target_name: string;
|
31 | /**
|
32 | * Opens a sibling comm in the backend
|
33 | * @param data
|
34 | * @param callbacks
|
35 | * @param metadata
|
36 | * @param buffers
|
37 | * @return msg id
|
38 | */
|
39 | open(data: JSONValue, callbacks?: ICallbacks, metadata?: JSONObject, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
|
40 | /**
|
41 | * Sends a message to the sibling comm in the backend
|
42 | * @param data
|
43 | * @param callbacks
|
44 | * @param metadata
|
45 | * @param buffers
|
46 | * @return message id
|
47 | */
|
48 | send(data: JSONValue, callbacks?: ICallbacks, metadata?: JSONObject, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
|
49 | /**
|
50 | * Closes the sibling comm in the backend
|
51 | * @param data
|
52 | * @param callbacks
|
53 | * @param metadata
|
54 | * @param buffers
|
55 | * @return msg id
|
56 | */
|
57 | close(data?: JSONValue, callbacks?: ICallbacks, metadata?: JSONObject, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
|
58 | /**
|
59 | * Register a message handler
|
60 | * @param callback, which is given a message
|
61 | */
|
62 | on_msg(callback: (x: any) => void): void;
|
63 | /**
|
64 | * Register a handler for when the comm is closed by the backend
|
65 | * @param callback, which is given a message
|
66 | */
|
67 | on_close(callback: (x: any) => void): void;
|
68 | }
|
69 | export declare namespace shims {
|
70 | namespace services {
|
71 | /**
|
72 | * Public constructor
|
73 | * @param jsServicesKernel - @jupyterlab/services Kernel.IKernel instance
|
74 | */
|
75 | class CommManager {
|
76 | constructor(jsServicesKernel: Kernel.IKernelConnection);
|
77 | /**
|
78 | * Hookup kernel events.
|
79 | * @param {Kernel.IKernel} jsServicesKernel - /services Kernel.IKernel instance
|
80 | */
|
81 | init_kernel(jsServicesKernel: Kernel.IKernelConnection): void;
|
82 | /**
|
83 | * Creates a new connected comm
|
84 | */
|
85 | new_comm(target_name: string, data: any, callbacks: any, metadata: any, comm_id: string, buffers?: ArrayBuffer[] | ArrayBufferView[]): Promise<Comm>;
|
86 | /**
|
87 | * Register a comm target
|
88 | * @param {string} target_name
|
89 | * @param {(Comm, object) => void} f - callback that is called when the
|
90 | * comm is made. Signature of f(comm, msg).
|
91 | */
|
92 | register_target(target_name: string, f: (comm: Comm, object: KernelMessage.IMessage) => void): void;
|
93 | /**
|
94 | * Unregisters a comm target
|
95 | * @param {string} target_name
|
96 | */
|
97 | unregister_target(target_name: string, f: (comm: Comm, object: KernelMessage.IMessage) => void): void;
|
98 | /**
|
99 | * Register a comm in the mapping
|
100 | */
|
101 | register_comm(comm: Comm): string;
|
102 | targets: any;
|
103 | comms: any;
|
104 | kernel: Kernel.IKernelConnection;
|
105 | jsServicesKernel: Kernel.IKernelConnection;
|
106 | }
|
107 | /**
|
108 | * Public constructor
|
109 | * @param {IComm} jsServicesComm - @jupyterlab/services IComm instance
|
110 | */
|
111 | class Comm implements IClassicComm {
|
112 | constructor(jsServicesComm: Kernel.IComm);
|
113 | /**
|
114 | * Comm id
|
115 | * @return {string}
|
116 | */
|
117 | get comm_id(): string;
|
118 | /**
|
119 | * Target name
|
120 | * @return {string}
|
121 | */
|
122 | get target_name(): string;
|
123 | /**
|
124 | * Opens a sibling comm in the backend
|
125 | * @param data
|
126 | * @param callbacks
|
127 | * @param metadata
|
128 | * @return msg id
|
129 | */
|
130 | open(data: JSONValue, callbacks?: ICallbacks, metadata?: JSONObject, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
|
131 | /**
|
132 | * Sends a message to the sibling comm in the backend
|
133 | * @param data
|
134 | * @param callbacks
|
135 | * @param metadata
|
136 | * @param buffers
|
137 | * @return message id
|
138 | */
|
139 | send(data: JSONValue, callbacks?: ICallbacks, metadata?: JSONObject, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
|
140 | /**
|
141 | * Closes the sibling comm in the backend
|
142 | * @param data
|
143 | * @param callbacks
|
144 | * @param metadata
|
145 | * @return msg id
|
146 | */
|
147 | close(data?: JSONValue, callbacks?: ICallbacks, metadata?: JSONObject, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
|
148 | /**
|
149 | * Register a message handler
|
150 | * @param callback, which is given a message
|
151 | */
|
152 | on_msg(callback: (x: any) => void): void;
|
153 | /**
|
154 | * Register a handler for when the comm is closed by the backend
|
155 | * @param callback, which is given a message
|
156 | */
|
157 | on_close(callback: (x: any) => void): void;
|
158 | /**
|
159 | * Hooks callback object up with @jupyterlab/services IKernelFuture
|
160 | * @param @jupyterlab/services IKernelFuture instance
|
161 | * @param callbacks
|
162 | */
|
163 | _hookupCallbacks(future: Kernel.IShellFuture, callbacks?: ICallbacks): void;
|
164 | jsServicesComm: Kernel.IComm;
|
165 | kernel: Kernel.IKernelConnection;
|
166 | }
|
167 | }
|
168 | }
|
169 | //# sourceMappingURL=services-shim.d.ts.map |
\ | No newline at end of file |