UNPKG

4.72 kBTypeScriptView Raw
1import { KernelMessage } from './kernel';
2interface ISerializer {
3 /**
4 * Serialize a kernel message for transport.
5 */
6 serialize(msg: KernelMessage.IMessage, protocol?: string): string | ArrayBuffer;
7 /**
8 * Deserialize and return the unpacked message.
9 */
10 deserialize(data: ArrayBuffer, protocol?: string): KernelMessage.IMessage;
11}
12/**
13 * The namespace for ServerConnection functions.
14 *
15 * #### Notes
16 * This is only intended to manage communication with the Jupyter server.
17 *
18 * The default values can be used in a JupyterLab or Jupyter Notebook context.
19 *
20 * We use `token` authentication if available, falling back on an XSRF
21 * cookie if one has been provided on the `document`.
22 *
23 * A content type of `'application/json'` is added when using authentication
24 * and there is no body data to allow the server to prevent malicious forms.
25 */
26export declare namespace ServerConnection {
27 /**
28 * A Jupyter server settings object.
29 * Note that all of the settings are optional when passed to
30 * [[makeSettings]]. The default settings are given in [[defaultSettings]].
31 */
32 interface ISettings {
33 /**
34 * The base url of the server.
35 */
36 readonly baseUrl: string;
37 /**
38 * The app url of the JupyterLab application.
39 */
40 readonly appUrl: string;
41 /**
42 * The base ws url of the server.
43 */
44 readonly wsUrl: string;
45 /**
46 * The default request init options.
47 */
48 readonly init: RequestInit;
49 /**
50 * The authentication token for requests. Use an empty string to disable.
51 */
52 readonly token: string;
53 /**
54 * Whether to append a token to a Websocket url. The default is `false` in the browser
55 * and `true` in node or jest.
56 */
57 readonly appendToken: boolean;
58 /**
59 * The `fetch` method to use.
60 */
61 readonly fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
62 /**
63 * The `Request` object constructor.
64 */
65 readonly Request: typeof Request;
66 /**
67 * The `Headers` object constructor.
68 */
69 readonly Headers: typeof Headers;
70 /**
71 * The `WebSocket` object constructor.
72 */
73 readonly WebSocket: typeof WebSocket;
74 /**
75 * Serializer used to serialize/deserialize kernel messages.
76 */
77 readonly serializer: ISerializer;
78 }
79 /**
80 * Create a settings object given a subset of options.
81 *
82 * @param options - An optional partial set of options.
83 *
84 * @returns The full settings object.
85 */
86 function makeSettings(options?: Partial<ISettings>): ISettings;
87 /**
88 * Make an request to the notebook server.
89 *
90 * @param url - The url for the request.
91 *
92 * @param init - The initialization options for the request.
93 *
94 * @param settings - The server settings to apply to the request.
95 *
96 * @returns a Promise that resolves with the response.
97 *
98 * @throws If the url of the request is not a notebook server url.
99 *
100 * #### Notes
101 * The `url` must start with `settings.baseUrl`. The `init` settings are
102 * merged with `settings.init`, with `init` taking precedence.
103 * The headers in the two objects are not merged.
104 * If there is no body data, we set the content type to `application/json`
105 * because it is required by the Notebook server.
106 */
107 function makeRequest(url: string, init: RequestInit, settings: ISettings): Promise<Response>;
108 /**
109 * A wrapped error for a fetch response.
110 */
111 class ResponseError extends Error {
112 /**
113 * Create a ResponseError from a response, handling the traceback and message
114 * as appropriate.
115 *
116 * @param response The response object.
117 *
118 * @returns A promise that resolves with a `ResponseError` object.
119 */
120 static create(response: Response): Promise<ResponseError>;
121 /**
122 * Create a new response error.
123 */
124 constructor(response: Response, message?: string, traceback?: string);
125 /**
126 * The response associated with the error.
127 */
128 response: Response;
129 /**
130 * The traceback associated with the error.
131 */
132 traceback: string;
133 private static _defaultMessage;
134 }
135 /**
136 * A wrapped error for a network error.
137 */
138 class NetworkError extends TypeError {
139 /**
140 * Create a new network error.
141 */
142 constructor(original: TypeError);
143 }
144}
145export {};