repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
libro | github_2023 | weavefox | typescript | WidgetView.toJSON | toJSON(): string {
return this.toModelKey();
} | /**
* Serialize the model. See the deserialization function at the top of this file
* and the kernel-side serializer/deserializer.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-jupyter/src/widget/widget-view.tsx#L222-L224 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | InstancesProgressWidget.handleCommMsg | override handleCommMsg(msg: KernelMessage.ICommMsgMsg): Promise<void> {
const data = msg.content.data as any;
const method = data.method;
switch (method) {
case 'update':
if (data.state.prefix) {
this.prefix = data.state.prefix;
}
if (data.state.suffix) {
this.suffix = data.state.suffix;
}
// eslint-disable-next-line no-fallthrough
case 'custom':
// eslint-disable-next-line no-case-declarations
const customMsg = data.content;
if (customMsg) {
// message format: '{"action": "action", content: ["content1", "content2"]}'
const msgObj: { action: 'update' | 'delete' | 'clear'; content: string[] } =
JSON.parse(customMsg);
const action: string = msgObj.action;
const content: string[] = [];
if (msgObj.content) {
content.push(...msgObj.content);
}
switch (action) {
case 'update':
content.forEach((groupJson) => {
const parsedProgressItem: ProgressItem = JSON.parse(groupJson);
if (!this.progressMap[parsedProgressItem.key]) {
this.workingProgressKeys.push(parsedProgressItem.key);
}
this.progressMap[parsedProgressItem.key] = parsedProgressItem;
this.updateRecords(parsedProgressItem.key);
});
// ? TODO: 发出一个更新 modal signal 的信号,这里需要取到之前的 key
break;
case 'delete':
content.forEach((groupKey: string) => {
if (!this.progressMap[groupKey]) {
return;
}
const i = this.workingProgressKeys.indexOf(groupKey);
if (i >= 0) {
this.workingProgressKeys.splice(i, 1);
}
});
break;
case 'clear':
this.progressMap = {};
this.workingProgressKeys = [];
// ? TODO: 发出更新 overview 以及 modal 的 signal
break;
default:
}
}
}
return Promise.resolve();
} | /**
* Handle incoming comm msg.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-jupyter/src/widget/instance-progress/view.tsx#L96-L154 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | BaseManager.onDisposed | get onDisposed(): ManaEvent<void> {
return this.onDisposedEmitter.event;
} | /**
* A signal emitted when the delegate is disposed.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/basemanager.ts#L57-L59 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | BaseManager.connectionFailure | get connectionFailure(): ManaEvent<Error> {
return this.connectionFailureEmitter.event;
} | /**
* A signal emitted when there is a connection failure.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/basemanager.ts#L64-L66 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | BaseManager.isDisposed | get isDisposed(): boolean {
return this._isDisposed;
} | /**
* Test whether the delegate has been disposed.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/basemanager.ts#L71-L73 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | BaseManager.isReady | get isReady(): boolean {
return this._isReady;
} | /**
* Test whether the manager is ready.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/basemanager.ts#L78-L80 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | BaseManager.ready | get ready(): Promise<void> {
return this._ready;
} | /**
* A promise that fulfills when the manager is ready.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/basemanager.ts#L85-L87 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | BaseManager.isActive | get isActive(): boolean {
return true;
} | /**
* Whether the manager is active.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/basemanager.ts#L92-L94 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | BaseManager.dispose | dispose(): void {
if (this.isDisposed) {
return;
}
this.onDisposedEmitter.fire(undefined);
this.onDisposedEmitter.dispose();
} | /**
* Dispose of the delegate and invoke the callback function.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/basemanager.ts#L99-L105 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | PageConfig.getBodyData | static getBodyData(key: string): string {
if (typeof document === 'undefined' || !document.body) {
return '';
}
const val = document.body.dataset[key];
if (typeof val === 'undefined') {
return '';
}
return decodeURIComponent(val);
} | /**
* Get a url-encoded item from `body.data` and decode it
* We should never have any encoded URLs anywhere else in code
* until we are building an actual request.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/page-config.ts#L16-L25 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | PageConfig.setOption | static setOption(name: string, value: string): string {
const last = PageConfig.getOption(name);
configData![name] = value;
return last;
} | /**
* Set global configuration data for the Jupyter application.
*
* @param name - The name of the configuration option.
* @param value - The value to set the option to.
*
* @returns The last config value or an empty string if it doesn't exist.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/page-config.ts#L60-L65 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | PageConfig.getBaseUrl | static getBaseUrl(): string {
return URL.normalize(PageConfig.getOption('baseUrl') || '/');
} | /**
* Get the base url for a Jupyter application, or the base url of the page.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/page-config.ts#L70-L72 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | PageConfig.getWsUrl | static getWsUrl(baseUrl?: string): string {
let wsUrl = PageConfig.getOption('wsUrl');
if (!wsUrl) {
baseUrl = baseUrl ? URL.normalize(baseUrl) : PageConfig.getBaseUrl();
if (baseUrl.indexOf('http') !== 0) {
return '';
}
wsUrl = 'ws' + baseUrl.slice(4);
}
return URL.normalize(wsUrl);
} | /**
* Get the base websocket url for a Jupyter application, or an empty string.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/page-config.ts#L77-L87 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | PageConfig.getToken | static getToken(): string {
return PageConfig.getOption('token') || PageConfig.getBodyData('jupyterApiToken');
} | /**
* Get the authorization token for a Jupyter application.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/page-config.ts#L92-L94 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | PageConfig.getNotebookVersion | static getNotebookVersion(): [number, number, number] {
const notebookVersion = PageConfig.getOption('notebookVersion');
if (notebookVersion === '') {
return [0, 0, 0];
}
return JSON.parse(notebookVersion);
} | /**
* Get the Notebook version info [major, minor, patch].
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/page-config.ts#L99-L105 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Drive.constructor | constructor() {
this.apiEndpoint = SERVICE_DRIVE_URL;
} | /**
* Construct a new contents manager object.
*
* @param options - The options used to initialize the object.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-drive.ts#L52-L54 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Drive.fileChanged | get fileChanged(): ManaEvent<IContentsChangedArgs> {
return this.fileChangedEmitter.event;
} | /**
* A signal emitted when a file operation takes place.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-drive.ts#L65-L67 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Drive.isDisposed | get isDisposed(): boolean {
return this._isDisposed;
} | /**
* Test whether the manager has been disposed.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-drive.ts#L77-L79 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Drive.dispose | dispose(): void {
if (this.isDisposed) {
return;
}
this._isDisposed = true;
this.fileChangedEmitter.dispose();
} | /**
* Dispose of the resources held by the manager.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-drive.ts#L84-L90 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Drive.get | async get(
localPath: string,
options?: IContentsFetchOptions,
): Promise<IContentsModel> {
let url = this.getUrl(options?.baseUrl, localPath);
const settings = this._getSettings(options?.baseUrl);
if (options) {
// The notebook type cannot take an format option.
if (options.type === 'notebook') {
delete options.format;
}
if (options.baseUrl) {
delete options.baseUrl;
}
const content = options.content ? '1' : '0';
const params: PartialJSONObject = { ...options, content };
url += `?${qs.stringify(params)}`;
}
const response = await this.serverConnection.makeRequest(url, {}, settings);
if (response.status !== 200) {
const err = await createResponseError(response);
throw err;
}
const data = await response.json();
validate.validateContentsModel(data);
return data;
} | /**
* Get a file or directory.
*
* @param localPath: The path to the file.
*
* @param options: The options used to fetch the file.
*
* @returns A promise which resolves with the file content.
*
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-drive.ts#L103-L131 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Drive.getDownloadUrl | getDownloadUrl(
localPath: string,
options?: IContentsRequestOptions,
): Promise<string> {
const baseUrl = options?.baseUrl || this.serverConnection.settings.baseUrl;
let url = URLUtil.join(baseUrl, FILES_URL, URLUtil.encodeParts(localPath));
const xsrfTokenMatch = document.cookie.match('\\b_xsrf=([^;]*)\\b');
if (xsrfTokenMatch) {
const fullUrl = new URL(url);
fullUrl.searchParams.append('_xsrf', xsrfTokenMatch[1]);
url = fullUrl.toString();
}
return Promise.resolve(url);
} | /**
* Get an encoded download url given a file path.
*
* @param localPath - An absolute POSIX file path on the server.
*
* #### Notes
* It is expected that the path contains no relative paths.
*
* The returned URL may include a query parameter.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-drive.ts#L143-L156 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Drive.newUntitled | async newUntitled(options: IContentsCreateOptions = {}): Promise<IContentsModel> {
let body = '{}';
const url = this.getUrl(options.baseUrl, options.path ?? '');
const settings = this._getSettings(options.baseUrl);
if (options) {
if (options.ext) {
options.ext = normalizeExtension(options.ext);
}
if (options.baseUrl) {
delete options.baseUrl;
}
body = JSON.stringify(options);
}
const init = {
method: 'POST',
body,
};
const response = await this.serverConnection.makeRequest(url, init, settings);
if (response.status !== 201) {
const err = await createResponseError(response);
throw err;
}
const data = await response.json();
validate.validateContentsModel(data);
this.fileChangedEmitter.fire({
type: 'new',
oldValue: null,
newValue: data,
});
return data;
} | /**
* Create a new untitled file or directory in the specified directory path.
*
* @param options: The options used to create the file.
*
* @returns A promise which resolves with the created file content when the
* file is created.
*
* #### Notes
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-drive.ts#L169-L201 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Drive.delete | async delete(localPath: string, options?: IContentsRequestOptions): Promise<void> {
const url = this.getUrl(options?.baseUrl, localPath);
const init = { method: 'DELETE' };
const settings = this._getSettings(options?.baseUrl);
const response = await this.serverConnection.makeRequest(url, init, settings);
// TODO: update IPEP27 to specify errors more precisely, so
// that error types can be detected here with certainty.
if (response.status !== 204) {
const err = await createResponseError(response);
throw err;
}
this.fileChangedEmitter.fire({
type: 'delete',
oldValue: { path: localPath },
newValue: null,
});
} | /**
* Delete a file.
*
* @param localPath - The path to the file.
*
* @returns A promise which resolves when the file is deleted.
*
* #### Notes
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents).
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-drive.ts#L213-L229 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Drive.rename | async rename(
oldLocalPath: string,
newLocalPath: string,
options?: IContentsRequestOptions,
): Promise<IContentsModel> {
const url = this.getUrl(options?.baseUrl, oldLocalPath);
const init = {
method: 'PATCH',
body: JSON.stringify({ path: newLocalPath }),
};
const settings = this._getSettings(options?.baseUrl);
const response = await this.serverConnection.makeRequest(url, init, settings);
if (response.status !== 200) {
const err = await createResponseError(response);
throw err;
}
const data = await response.json();
validate.validateContentsModel(data);
this.fileChangedEmitter.fire({
type: 'rename',
oldValue: { path: oldLocalPath },
newValue: data,
});
return data;
} | /**
* Rename a file or directory.
*
* @param oldLocalPath - The original file path.
*
* @param newLocalPath - The new file path.
*
* @returns A promise which resolves with the new file contents model when
* the file is renamed.
*
* #### Notes
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-drive.ts#L244-L268 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Drive.save | async save(
localPath: string,
options: Partial<IContentsModel> = {},
): Promise<IContentsModel> {
const url = this.getUrl(options.baseUrl, localPath);
const settings = this._getSettings(options.baseUrl);
if (options) {
if (options.baseUrl) {
delete options.baseUrl;
}
}
const init = {
method: 'PUT',
body: JSON.stringify(options),
};
const response = await this.serverConnection.makeRequest(url, init, settings);
// will return 200 for an existing file and 201 for a new file
if (response.status !== 200 && response.status !== 201) {
const err = await createResponseError(response);
throw err;
}
const data = await response.json();
validate.validateContentsModel(data);
this.fileChangedEmitter.fire({
type: 'save',
oldValue: null,
newValue: data,
});
return data;
} | /**
* Save a file.
*
* @param localPath - The desired file path.
*
* @param options - Optional overrides to the model.
*
* @returns A promise which resolves with the file content model when the
* file is saved.
*
* #### Notes
* Ensure that `model.content` is populated for the file.
*
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-drive.ts#L285-L316 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Drive.copy | async copy(
fromFile: string,
toDir: string,
options?: IContentsRequestOptions,
): Promise<IContentsModel> {
const url = this.getUrl(options?.baseUrl, toDir);
const init = {
method: 'POST',
body: JSON.stringify({ copy_from: fromFile }),
};
const settings = this._getSettings(options?.baseUrl);
const response = await this.serverConnection.makeRequest(url, init, settings);
if (response.status !== 201) {
const err = await createResponseError(response);
throw err;
}
const data = await response.json();
validate.validateContentsModel(data);
this.fileChangedEmitter.fire({
type: 'new',
oldValue: null,
newValue: data,
});
return data;
} | /**
* Copy a file into a given directory.
*
* @param localPath - The original file path.
*
* @param toDir - The destination directory path.
*
* @returns A promise which resolves with the new contents model when the
* file is copied.
*
* #### Notes
* The server will select the name of the copied file.
*
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-drive.ts#L333-L357 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Drive.createCheckpoint | async createCheckpoint(
localPath: string,
options?: IContentsRequestOptions,
): Promise<IContentsCheckpointModel> {
const url = this.getUrl(options?.baseUrl, localPath, 'checkpoints');
const init = { method: 'POST' };
const settings = this._getSettings(options?.baseUrl);
const response = await this.serverConnection.makeRequest(url, init, settings);
if (response.status !== 201) {
const err = await createResponseError(response);
throw err;
}
const data = await response.json();
validate.validateCheckpointModel(data);
return data;
} | /**
* Create a checkpoint for a file.
*
* @param localPath - The path of the file.
*
* @returns A promise which resolves with the new checkpoint model when the
* checkpoint is created.
*
* #### Notes
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-drive.ts#L370-L385 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Drive.listCheckpoints | async listCheckpoints(
localPath: string,
options?: IContentsRequestOptions,
): Promise<IContentsCheckpointModel[]> {
const url = this.getUrl(options?.baseUrl, localPath, 'checkpoints');
const settings = this._getSettings(options?.baseUrl);
const response = await this.serverConnection.makeRequest(url, {}, settings);
if (response.status !== 200) {
const err = await createResponseError(response);
throw err;
}
const data = await response.json();
if (!Array.isArray(data)) {
throw new Error('Invalid Checkpoint list');
}
for (let i = 0; i < data.length; i++) {
validate.validateCheckpointModel(data[i]);
}
return data;
} | /**
* List available checkpoints for a file.
*
* @param localPath - The path of the file.
*
* @returns A promise which resolves with a list of checkpoint models for
* the file.
*
* #### Notes
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-drive.ts#L398-L417 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Drive.restoreCheckpoint | async restoreCheckpoint(
localPath: string,
checkpointID: string,
options?: IContentsRequestOptions,
): Promise<void> {
const url = this.getUrl(options?.baseUrl, localPath, 'checkpoints', checkpointID);
const settings = this._getSettings(options?.baseUrl);
const init = { method: 'POST' };
const response = await this.serverConnection.makeRequest(url, init, settings);
if (response.status !== 204) {
const err = await createResponseError(response);
throw err;
}
} | /**
* Restore a file to a known checkpoint state.
*
* @param localPath - The path of the file.
*
* @param checkpointID - The id of the checkpoint to restore.
*
* @returns A promise which resolves when the checkpoint is restored.
*
* #### Notes
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents).
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-drive.ts#L431-L444 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Drive.deleteCheckpoint | async deleteCheckpoint(
localPath: string,
checkpointID: string,
options?: IContentsRequestOptions,
): Promise<void> {
const url = this.getUrl(options?.baseUrl, localPath, 'checkpoints', checkpointID);
const init = { method: 'DELETE' };
const settings = this._getSettings(options?.baseUrl);
const response = await this.serverConnection.makeRequest(url, init, settings);
if (response.status !== 204) {
const err = await createResponseError(response);
throw err;
}
} | /**
* Delete a checkpoint for a file.
*
* @param localPath - The path of the file.
*
* @param checkpointID - The id of the checkpoint to delete.
*
* @returns A promise which resolves when the checkpoint is deleted.
*
* #### Notes
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents).
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-drive.ts#L458-L471 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Drive.getUrl | protected getUrl(base?: string, ...args: string[]): string {
let baseUrl = base;
if (!baseUrl) {
baseUrl = this.serverConnection.settings.baseUrl;
}
const parts = args.map((path) => URLUtil.encodeParts(path));
return URLUtil.join(baseUrl!, this.apiEndpoint, ...parts);
} | /**
* Get a REST url for a file given a path.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-drive.ts#L476-L483 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.fileChanged | get fileChanged(): ManaEvent<IContentsChangedArgs> {
// return this._fileChanged;
return this.fileChangedEmitter.event;
} | /**
* A signal emitted when a file operation takes place.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L43-L46 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.isDisposed | get isDisposed(): boolean {
return this._isDisposed;
} | /**
* Test whether the manager has been disposed.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L51-L53 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.dispose | dispose(): void {
if (this.isDisposed) {
return;
}
this._isDisposed = true;
this.fileChangedEmitter.dispose();
} | /**
* Dispose of the resources held by the manager.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L58-L64 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.addDrive | addDrive(drive: IContentsDrive): void {
this.additionalDrives.set(drive.name, drive);
drive.fileChanged((args) => this.onFileChanged(drive, args));
} | /**
* Add an `IContentsDrive` to the manager.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L69-L72 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.localPath | localPath(path: string): string {
const parts = path.split('/');
const firstParts = parts[0].split(':');
if (firstParts.length === 1 || !this.additionalDrives.has(firstParts[0])) {
return PathExt.removeSlash(path);
}
return PathExt.join(firstParts.slice(1).join(':'), ...parts.slice(1));
} | /**
* Given a path of the form `drive:local/portion/of/it.txt`
* get the local part of it.
*
* @param path: the path.
*
* @returns The local part of the path.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L92-L99 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.normalize | normalize(path: string): string {
const parts = path.split(':');
if (parts.length === 1) {
return PathExt.normalize(path);
}
return `${parts[0]}:${PathExt.normalize(parts.slice(1).join(':'))}`;
} | /**
* Normalize a global path. Reduces '..' and '.' parts, and removes
* leading slashes from the local part of the path, while retaining
* the drive name if it exists.
*
* @param path: the path.
*
* @returns The normalized path.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L110-L116 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.resolvePath | resolvePath(root: string, path: string): string {
const driveName = this.driveName(root);
const localPath = this.localPath(root);
const resolved = PathExt.resolve('/', localPath, path);
return driveName ? `${driveName}:${resolved}` : resolved;
} | /**
* Resolve a global path, starting from the root path. Behaves like
* posix-path.resolve, with 3 differences:
* - will never prepend cwd
* - if root has a drive name, the result is prefixed with "<drive>:"
* - before adding drive name, leading slashes are removed
*
* @param path: the path.
*
* @returns The normalized path.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L129-L134 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.driveName | driveName(path: string): string {
const parts = path.split('/');
const firstParts = parts[0].split(':');
if (firstParts.length === 1) {
return '';
}
if (this.additionalDrives.has(firstParts[0])) {
return firstParts[0];
}
return '';
} | /**
* Given a path of the form `drive:local/portion/of/it.txt`
* get the name of the drive. If the path is missing
* a drive portion, returns an empty string.
*
* @param path: the path.
*
* @returns The drive name for the path, or the empty string.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L145-L155 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.get | get(path: string, options?: IContentsFetchOptions): Promise<IContentsModel> {
const [drive, localPath] = this.driveForPath(path);
return drive.get(localPath, options).then((contentsModel) => {
const listing: IContentsModel[] = [];
if (contentsModel.type === 'directory' && contentsModel.content) {
for (const item of contentsModel.content) {
listing.push({ ...item, path: this.toGlobalPath(drive, item.path) });
}
return {
...contentsModel,
path: this.toGlobalPath(drive, localPath),
content: listing,
} as IContentsModel;
} else {
return {
...contentsModel,
path: this.toGlobalPath(drive, localPath),
} as IContentsModel;
}
});
} | /**
* Get a file or directory.
*
* @param path: The path to the file.
*
* @param options: The options used to fetch the file.
*
* @returns A promise which resolves with the file content.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L166-L186 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.getDownloadUrl | getDownloadUrl(path: string, options?: IContentsRequestOptions): Promise<string> {
const [drive, localPath] = this.driveForPath(path);
return drive.getDownloadUrl(localPath, options);
} | /**
* Get an encoded download url given a file path.
*
* @param path - An absolute POSIX file path on the server.
*
* #### Notes
* It is expected that the path contains no relative paths.
*
* The returned URL may include a query parameter.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L198-L201 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.newUntitled | newUntitled(options: IContentsCreateOptions = {}): Promise<IContentsModel> {
if (options.path) {
const globalPath = this.normalize(options.path);
const [drive, localPath] = this.driveForPath(globalPath);
return drive
.newUntitled({ ...options, path: localPath })
.then((contentsModel) => {
return {
...contentsModel,
path: PathExt.join(globalPath, contentsModel.name),
} as IContentsModel;
});
} else {
return this.defaultDrive.newUntitled(options);
}
} | /**
* Create a new untitled file or directory in the specified directory path.
*
* @param options: The options used to create the file.
*
* @returns A promise which resolves with the created file content when the
* file is created.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L211-L226 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.delete | delete(path: string, options?: IContentsRequestOptions): Promise<void> {
const [drive, localPath] = this.driveForPath(path);
return drive.delete(localPath, options);
} | /**
* Delete a file.
*
* @param path - The path to the file.
*
* @returns A promise which resolves when the file is deleted.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L235-L238 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.rename | rename(
path: string,
newPath: string,
options?: IContentsRequestOptions,
): Promise<IContentsModel> {
const [drive1, path1] = this.driveForPath(path);
const [drive2, path2] = this.driveForPath(newPath);
if (drive1 !== drive2) {
throw Error('ContentsManager: renaming files must occur within a Drive');
}
return drive1.rename(path1, path2, options).then((contentsModel) => {
return {
...contentsModel,
path: this.toGlobalPath(drive1, path2),
} as IContentsModel;
});
} | /**
* Rename a file or directory.
*
* @param path - The original file path.
*
* @param newPath - The new file path.
*
* @returns A promise which resolves with the new file contents model when
* the file is renamed.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L250-L266 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.save | save(path: string, options: Partial<IContentsModel> = {}): Promise<IContentsModel> {
const globalPath = this.normalize(path);
const [drive, localPath] = this.driveForPath(path);
return drive
.save(localPath, { ...options, path: localPath })
.then((contentsModel) => {
return { ...contentsModel, path: globalPath } as IContentsModel;
});
} | /**
* Save a file.
*
* @param path - The desired file path.
*
* @param options - Optional overrides to the model.
*
* @returns A promise which resolves with the file content model when the
* file is saved.
*
* #### Notes
* Ensure that `model.content` is populated for the file.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L281-L289 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.copy | copy(
fromFile: string,
toDir: string,
options?: IContentsRequestOptions,
): Promise<IContentsModel> {
const [drive1, path1] = this.driveForPath(fromFile);
const [drive2, path2] = this.driveForPath(toDir);
if (drive1 === drive2) {
return drive1.copy(path1, path2, options).then((contentsModel) => {
return {
...contentsModel,
path: this.toGlobalPath(drive1, contentsModel.path),
} as IContentsModel;
});
} else {
throw Error('Copying files between drives is not currently implemented');
}
} | /**
* Copy a file into a given directory.
*
* @param path - The original file path.
*
* @param toDir - The destination directory path.
*
* @returns A promise which resolves with the new contents model when the
* file is copied.
*
* #### Notes
* The server will select the name of the copied file.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L304-L321 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.createCheckpoint | createCheckpoint(
path: string,
options?: IContentsRequestOptions,
): Promise<IContentsCheckpointModel> {
const [drive, localPath] = this.driveForPath(path);
return drive.createCheckpoint(localPath, options);
} | /**
* Create a checkpoint for a file.
*
* @param path - The path of the file.
*
* @returns A promise which resolves with the new checkpoint model when the
* checkpoint is created.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L331-L337 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.listCheckpoints | listCheckpoints(
path: string,
options?: IContentsRequestOptions,
): Promise<IContentsCheckpointModel[]> {
const [drive, localPath] = this.driveForPath(path);
return drive.listCheckpoints(localPath, options);
} | /**
* List available checkpoints for a file.
*
* @param path - The path of the file.
*
* @returns A promise which resolves with a list of checkpoint models for
* the file.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L347-L353 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.restoreCheckpoint | restoreCheckpoint(
path: string,
checkpointID: string,
options?: IContentsRequestOptions,
): Promise<void> {
const [drive, localPath] = this.driveForPath(path);
return drive.restoreCheckpoint(localPath, checkpointID, options);
} | /**
* Restore a file to a known checkpoint state.
*
* @param path - The path of the file.
*
* @param checkpointID - The id of the checkpoint to restore.
*
* @returns A promise which resolves when the checkpoint is restored.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L364-L371 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.deleteCheckpoint | deleteCheckpoint(
path: string,
checkpointID: string,
options?: IContentsRequestOptions,
): Promise<void> {
const [drive, localPath] = this.driveForPath(path);
return drive.deleteCheckpoint(localPath, checkpointID, options);
} | /**
* Delete a checkpoint for a file.
*
* @param path - The path of the file.
*
* @param checkpointID - The id of the checkpoint to delete.
*
* @returns A promise which resolves when the checkpoint is deleted.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L382-L389 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.toGlobalPath | protected toGlobalPath(drive: IContentsDrive, localPath: string): string {
if (drive === this.defaultDrive) {
return PathExt.removeSlash(localPath);
} else {
return `${drive.name}:${PathExt.removeSlash(localPath)}`;
}
} | /**
* Given a drive and a local path, construct a fully qualified
* path. The inverse of `driveForPath`.
*
* @param drive: an `IContentsDrive`.
*
* @param localPath: the local path on the drive.
*
* @returns the fully qualified path.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L401-L407 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.driveForPath | protected driveForPath(path: string): [IContentsDrive, string] {
const driveName = this.driveName(path);
const localPath = this.localPath(path);
if (driveName) {
return [this.additionalDrives.get(driveName)!, localPath];
} else {
return [this.defaultDrive, localPath];
}
} | /**
* Given a path, get the `IContentsDrive to which it refers,
* where the path satisfies the pattern
* `'driveName:path/to/file'`. If there is no `driveName`
* prepended to the path, it returns the default drive.
*
* @param path: a path to a file.
*
* @returns A tuple containing an `IContentsDrive` object for the path,
* and a local path for that drive.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L420-L428 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ContentsManager.onFileChanged | protected onFileChanged(sender: IContentsDrive, args: IContentsChangedArgs) {
if (sender === this.defaultDrive) {
this.fileChangedEmitter.fire(args);
} else {
let newValue: Partial<IContentsModel> | null = null;
let oldValue: Partial<IContentsModel> | null = null;
if (args.newValue?.path) {
newValue = {
...args.newValue,
path: this.toGlobalPath(sender, args.newValue.path),
};
}
if (args.oldValue?.path) {
oldValue = {
...args.oldValue,
path: this.toGlobalPath(sender, args.oldValue.path),
};
}
this.fileChangedEmitter.fire({
type: args.type,
newValue,
oldValue,
});
}
} | /**
* Respond to fileChanged signals from the drives attached to
* the manager. This prepends the drive name to the path if necessary,
* and then forwards the signal.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/contents/contents-manager.ts#L435-L459 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CommHandler.constructor | constructor(
target: string,
id: string,
kernel: IKernelConnection,
disposeCb: () => void,
) {
this.disposeCb = disposeCb;
this._id = id;
this._target = target;
this._kernel = kernel;
} | /**
* Construct a new comm channel.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/comm.ts#L28-L38 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CommHandler.commId | get commId(): string {
return this._id;
} | /**
* The unique id for the comm channel.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/comm.ts#L47-L49 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CommHandler.targetName | get targetName(): string {
return this._target;
} | /**
* The target name for the comm channel.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/comm.ts#L54-L56 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CommHandler.onClose | get onClose(): (msg: KernelMessage.ICommCloseMsg) => void | PromiseLike<void> {
return this._onClose;
} | /**
* Get the callback for a comm close event.
*
* #### Notes
* This is called when the comm is closed from either the server or client.
*
* **See also:** [[ICommClose]], [[close]]
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/comm.ts#L66-L68 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CommHandler.onClose | set onClose(cb: (msg: KernelMessage.ICommCloseMsg) => void | PromiseLike<void>) {
this._onClose = cb;
} | /**
* Set the callback for a comm close event.
*
* #### Notes
* This is called when the comm is closed from either the server or client. If
* the function returns a promise, and the kernel was closed from the server,
* kernel message processing will pause until the returned promise is
* fulfilled.
*
* **See also:** [[close]]
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/comm.ts#L81-L83 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CommHandler.onMsg | get onMsg(): (msg: KernelMessage.ICommMsgMsg) => void | PromiseLike<void> {
return this._onMsg;
} | /**
* Get the callback for a comm message received event.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/comm.ts#L88-L90 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CommHandler.onMsg | set onMsg(cb: (msg: KernelMessage.ICommMsgMsg) => void | PromiseLike<void>) {
this._onMsg = cb;
} | /**
* Set the callback for a comm message received event.
*
* #### Notes
* This is called when a comm message is received. If the function returns a
* promise, kernel message processing will pause until it is fulfilled.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/comm.ts#L99-L101 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CommHandler.open | open(
data?: JSONObject,
metadata?: JSONObject,
buffers: (ArrayBuffer | ArrayBufferView)[] = [],
): IShellFuture {
if (this.disposed || this._kernel.disposed) {
throw new Error('Cannot open');
}
const msg = KernelMessage.createMessage({
msgType: 'comm_open',
channel: 'shell',
username: this._kernel.username,
session: this._kernel.clientId,
content: {
comm_id: this._id,
target_name: this._target,
data: data ?? {},
},
metadata,
buffers,
});
return this._kernel.sendShellMessage(msg, false, true);
} | /**
* Open a comm with optional data and metadata.
*
* #### Notes
* This sends a `comm_open` message to the server.
*
* **See also:** [[ICommOpen]]
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/comm.ts#L111-L133 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CommHandler.send | send(
data: JSONObject,
metadata?: JSONObject,
buffers: (ArrayBuffer | ArrayBufferView)[] = [],
disposeOnDone = true,
): IShellFuture {
if (this.disposed || this._kernel.disposed) {
throw new Error('Cannot send');
}
const msg = KernelMessage.createMessage({
msgType: 'comm_msg',
channel: 'shell',
username: this._kernel.username,
session: this._kernel.clientId,
content: {
comm_id: this._id,
data: data,
},
metadata,
buffers,
});
return this._kernel.sendShellMessage(msg, false, disposeOnDone);
} | /**
* Send a `comm_msg` message to the kernel.
*
* #### Notes
* This is a no-op if the comm has been closed.
*
* **See also:** [[ICommMsg]]
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/comm.ts#L143-L165 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CommHandler.close | close(
data?: JSONObject,
metadata?: JSONObject,
buffers: (ArrayBuffer | ArrayBufferView)[] = [],
): IShellFuture {
if (this.disposed || this._kernel.disposed) {
throw new Error('Cannot close');
}
const msg = KernelMessage.createMessage({
msgType: 'comm_close',
channel: 'shell',
username: this._kernel.username,
session: this._kernel.clientId,
content: {
comm_id: this._id,
data: data ?? {},
},
metadata,
buffers,
});
const future = this._kernel.sendShellMessage(msg, false, true);
const onClose = this._onClose;
if (onClose) {
const ioMsg = KernelMessage.createMessage({
msgType: 'comm_close',
channel: 'iopub',
username: this._kernel.username,
session: this._kernel.clientId,
content: {
comm_id: this._id,
data: data ?? {},
},
metadata,
buffers,
});
// In the future, we may want to communicate back to the user the possible
// promise returned from onClose.
void onClose(ioMsg);
}
this.dispose();
return future;
} | /**
* Close the comm.
*
* #### Notes
* This will send a `comm_close` message to the kernel, and call the
* `onClose` callback if set.
*
* This is a no-op if the comm is already closed.
*
* **See also:** [[ICommClose]], [[onClose]]
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/comm.ts#L178-L219 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | HookList.add | add(hook: (msg: T) => boolean | PromiseLike<boolean>): void {
this.remove(hook);
this._hooks.push(hook);
} | /**
* Register a hook.
*
* @param hook - The callback to register.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/future.ts#L42-L45 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | HookList.remove | remove(hook: (msg: T) => boolean | PromiseLike<boolean>): void {
const index = this._hooks.indexOf(hook);
if (index >= 0) {
this._hooks[index] = null;
this._scheduleCompact();
}
} | /**
* Remove a hook, if it exists in the hook list.
*
* @param hook - The callback to remove.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/future.ts#L52-L58 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | HookList.process | async process(msg: T): Promise<boolean> {
// Wait until we can start a new process run.
await this._processing;
// Start the next process run.
const processing = new Deferred<void>();
this._processing = processing.promise;
let continueHandling: boolean;
// Call the end hook (most recently-added) first. Starting at the end also
// guarantees that hooks added during the processing will not be run in
// this process run.
for (let i = this._hooks.length - 1; i >= 0; i--) {
const hook = this._hooks[i];
// If the hook has been removed, continue to the next one.
if (hook === null) {
continue;
}
// Execute the hook and log any errors.
try {
// tslint:disable-next-line:await-promise
continueHandling = await hook(msg);
} catch (err) {
continueHandling = true;
console.error(err);
}
// If the hook resolved to false, stop processing and return.
if (continueHandling === false) {
processing.resolve(undefined);
return false;
}
}
// All hooks returned true (or errored out), so return true.
processing.resolve(undefined);
return true;
} | /**
* Process a message through the hooks.
*
* @returns a promise resolving to false if any hook resolved as false,
* otherwise true
*
* #### Notes
* The most recently registered hook is run first. A hook can return a
* boolean or a promise to a boolean, in which case processing pauses until
* the promise is fulfilled. If a hook return value resolves to false, any
* later hooks will not run and the function will return a promise resolving
* to false. If a hook throws an error, the error is logged to the console
* and the next hook is run. If a hook is registered during the hook
* processing, it will not run until the next message. If a hook is removed
* during the hook processing, it will be deactivated immediately.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/future.ts#L76-L116 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | HookList._scheduleCompact | protected _scheduleCompact(): void {
if (!this._compactScheduled) {
this._compactScheduled = true;
// Schedule a compaction in between processing runs. We do the
// scheduling in an animation frame to rate-limit our compactions. If we
// need to compact more frequently, we can change this to directly
// schedule the compaction.
defer(() => {
this._processing = this._processing.then(() => {
this._compactScheduled = false;
this._compact();
return;
});
});
}
} | /**
* Schedule a cleanup of the list, removing any hooks that have been nulled out.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/future.ts#L121-L137 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | HookList._compact | protected _compact(): void {
let numNulls = 0;
for (let i = 0, len = this._hooks.length; i < len; i++) {
const hook = this._hooks[i];
if (this._hooks[i] === null) {
numNulls++;
} else {
this._hooks[i - numNulls] = hook;
}
}
this._hooks.length -= numNulls;
} | /**
* Compact the list, removing any nulls.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/future.ts#L142-L153 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.constructor | constructor(
@inject(KernelConnectionOptions) options: KernelConnectionOptions,
@inject(ServerConnection) serverConnection: ServerConnection,
) {
this.serverSettings = { ...serverConnection.settings, ...options.serverSettings };
this._name = options.model.name;
this._id = options.model.id;
this._clientId = options.clientId ?? v4();
this._username = options.username ?? '';
this.handleComms = options.handleComms ?? true;
this._createSocket();
} | /**
* Construct a kernel object.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L162-L175 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.statusChanged | get statusChanged(): ManaEvent<KernelMessage.Status> {
return this.statusChangedEmitter.event;
} | /**
* A signal emitted when the kernel status changes.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L205-L207 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.connectionStatusChanged | get connectionStatusChanged(): ManaEvent<ConnectionStatus> {
return this.connectionStatusChangedEmitter.event;
} | /**
* A signal emitted when the kernel status changes.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L212-L214 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.iopubMessage | get iopubMessage(): ManaEvent<KernelMessage.IIOPubMessage> {
return this.iopubMessageEmitter.event;
} | /**
* A signal emitted for iopub kernel messages.
*
* #### Notes
* This signal is emitted after the iopub message is handled asynchronously.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L222-L224 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.unhandledMessage | get unhandledMessage(): ManaEvent<KernelMessage.IMessage> {
return this.unhandledMessageEmitter.event;
} | /**
* A signal emitted for unhandled kernel message.
*
* #### Notes
* This signal is emitted for a message that was not handled. It is emitted
* during the asynchronous message handling code.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L237-L239 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.model | get model(): IKernelModel {
return (
this._model || {
id: this.id,
name: this.name,
reason: this._reason,
}
);
} | /**
* The kernel model
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L244-L252 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.anyMessage | get anyMessage(): ManaEvent<IAnyMessageArgs> {
return this.anyMessageEmitter.event;
} | /**
* A signal emitted for any kernel message.
*
* #### Notes
* This signal is emitted when a message is received, before it is handled
* asynchronously.
*
* This message is emitted when a message is queued for sending (either in
* the websocket buffer, or our own pending message buffer). The message may
* actually be sent across the wire at a later time.
*
* The message emitted in this signal should not be modified in any way.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L267-L269 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.pendingInput | get pendingInput(): ManaEvent<boolean> {
return this.pendingInputEmitter.event;
} | /**
* A signal emitted when a kernel has pending inputs from the user.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L274-L276 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.id | get id(): string {
return this._id;
} | /**
* The id of the server-side kernel.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L281-L283 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.name | get name(): string {
return this._name;
} | /**
* The name of the server-side kernel.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L288-L290 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.username | get username(): string {
return this._username;
} | /**
* The client username.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L295-L297 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.clientId | get clientId(): string {
return this._clientId;
} | /**
* The client unique id.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L302-L304 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.status | get status(): KernelMessage.Status {
return this._status;
} | /**
* The current status of the kernel.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L309-L311 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.connectionStatus | get connectionStatus(): ConnectionStatus {
return this._connectionStatus;
} | /**
* The current connection status of the kernel connection.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L316-L318 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.isDisposed | get isDisposed(): boolean {
return this._isDisposed;
} | /**
* Test whether the kernel has been disposed.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L323-L325 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.info | get info(): Promise<KernelMessage.IInfoReply> {
return this._info.promise;
} | /**
* The cached kernel info.
*
* @returns A promise that resolves to the kernel info.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L332-L334 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.spec | get spec(): Promise<ISpecModel | undefined> {
if (this._specPromise) {
return this._specPromise;
}
this._specPromise = this.kernelSpecRestAPI
.getSpecs(this.serverSettings)
.then((specs) => {
return specs.kernelspecs[this._name];
});
return this._specPromise;
} | /**
* The kernel spec.
*
* @returns A promise that resolves to the kernel spec.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L341-L351 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.clone | clone(
options: Pick<
KernelConnectionOptions,
'clientId' | 'username' | 'handleComms'
> = {},
): IKernelConnection {
return this.libroKernelConnectionFactory({
model: this.model,
username: this.username,
// handleComms defaults to false since that is safer
handleComms: false,
...options,
});
} | /**
* Clone the current kernel with a new clientId.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L356-L369 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.dispose | dispose(): void {
if (this.isDisposed) {
return;
}
this.onDisposedEmitter.fire();
this._updateConnectionStatus('disconnected');
this._clearKernelState();
this._pendingMessages = [];
this._clearSocket();
this.connectionStatusChangedEmitter.dispose();
this.statusChangedEmitter.dispose();
this.onDisposedEmitter.dispose();
this.iopubMessageEmitter.dispose();
this.futureMessageEmitter.dispose();
this.anyMessageEmitter.dispose();
this.pendingInputEmitter.dispose();
this.unhandledMessageEmitter.dispose();
this._isDisposed = true;
} | /**
* Dispose of the resources held by the kernel.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L374-L394 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.sendShellMessage | sendShellMessage<T extends KernelMessage.ShellMessageType>(
msg: KernelMessage.IShellMessage<T>,
expectReply = false,
disposeOnDone = true,
): IShellFuture<KernelMessage.IShellMessage<T>> {
return this._sendKernelShellControl(
KernelShellFutureHandler as any,
msg,
expectReply,
disposeOnDone,
) as IShellFuture<KernelMessage.IShellMessage<T>>;
} | /**
* Send a shell message to the kernel.
*
* #### Notes
* Send a message to the kernel's shell channel, yielding a future object
* for accepting replies.
*
* If `expectReply` is given and `true`, the future is disposed when both a
* shell reply and an idle status message are received. If `expectReply`
* is not given or is `false`, the future is resolved when an idle status
* message is received.
* If `disposeOnDone` is not given or is `true`, the Future is disposed at this point.
* If `disposeOnDone` is given and `false`, it is up to the caller to dispose of the Future.
*
* All replies are validated as valid kernel messages.
*
* If the kernel status is `dead`, this will throw an error.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L414-L425 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.sendControlMessage | sendControlMessage<T extends KernelMessage.ControlMessageType>(
msg: KernelMessage.IControlMessage<T>,
expectReply = false,
disposeOnDone = true,
): IControlFuture<KernelMessage.IControlMessage<T>> {
return this._sendKernelShellControl(
KernelControlFutureHandler as any,
msg,
expectReply,
disposeOnDone,
) as IControlFuture<KernelMessage.IControlMessage<T>>;
} | /**
* Send a control message to the kernel.
*
* #### Notes
* Send a message to the kernel's control channel, yielding a future object
* for accepting replies.
*
* If `expectReply` is given and `true`, the future is disposed when both a
* control reply and an idle status message are received. If `expectReply`
* is not given or is `false`, the future is resolved when an idle status
* message is received.
* If `disposeOnDone` is not given or is `true`, the Future is disposed at this point.
* If `disposeOnDone` is given and `false`, it is up to the caller to dispose of the Future.
*
* All replies are validated as valid kernel messages.
*
* If the kernel status is `dead`, this will throw an error.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L445-L456 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection._sendMessage | protected _sendMessage(msg: KernelMessage.IMessage, queue = true) {
if (this.status === 'dead') {
throw new Error('Kernel is dead');
}
// If we have a kernel_info_request and we are starting or restarting, send the
// kernel_info_request immediately if we can, and if not throw an error so
// we can retry later. On restarting we do this because we must get at least one message
// from the kernel to reset the kernel session (thus clearing the restart
// status sentinel).
if (
(this._kernelSession === STARTING_KERNEL_SESSION ||
this._kernelSession === RESTARTING_KERNEL_SESSION) &&
isInfoRequestMsg(msg)
) {
if (this.connectionStatus === 'connected') {
this._ws!.send(serialize(msg, this._ws!.protocol));
return;
} else {
throw new Error('Could not send message: status is not connected');
}
}
// If there are pending messages, add to the queue so we keep messages in order
if (queue && this._pendingMessages.length > 0) {
this._pendingMessages.push(msg);
return;
}
// Send if the ws allows it, otherwise queue the message.
if (
this.connectionStatus === 'connected' &&
this._kernelSession !== RESTARTING_KERNEL_SESSION
) {
this._ws!.send(serialize(msg, this._ws!.protocol));
} else if (queue) {
this._pendingMessages.push(msg);
} else {
throw new Error('Could not send message');
}
} | /**
* Send a message on the websocket.
*
* If queue is true, queue the message for later sending if we cannot send
* now. Otherwise throw an error.
*
* #### Notes
* As an exception to the queueing, if we are sending a kernel_info_request
* message while we think the kernel is restarting, we send the message
* immediately without queueing. This is so that we can trigger a message
* back, which will then clear the kernel restarting state.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L519-L559 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.interrupt | async interrupt(): Promise<void> {
this.hasPendingInput = false;
if (this.status === 'dead') {
throw new Error('Kernel is dead');
}
return this.kernelRestAPI.interruptKernel(this.id, this.serverSettings);
} | /**
* Interrupt a kernel.
*
* #### Notes
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/kernels).
*
* The promise is fulfilled on a valid response and rejected otherwise.
*
* It is assumed that the API call does not mutate the kernel id or name.
*
* The promise will be rejected if the kernel status is `Dead` or if the
* request fails or the response is invalid.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L574-L580 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.restart | async restart(): Promise<void> {
if (this.status === 'dead') {
throw new Error('Kernel is dead');
}
this._updateStatus('restarting');
this._clearKernelState();
this._kernelSession = RESTARTING_KERNEL_SESSION;
await this.kernelRestAPI.restartKernel(this.id, this.serverSettings);
// Reconnect to the kernel to address cases where kernel ports
// have changed during the restart.
await this.reconnect();
this.hasPendingInput = false;
} | /**
* Request a kernel restart.
*
* #### Notes
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/kernels)
* and validates the response model.
*
* Any existing Future or Comm objects are cleared once the kernel has
* actually be restarted.
*
* The promise is fulfilled on a valid server response (after the kernel restarts)
* and rejected otherwise.
*
* It is assumed that the API call does not mutate the kernel id or name.
*
* The promise will be rejected if the request fails or the response is
* invalid.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L600-L612 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.reconnect | reconnect(): Promise<void> {
this._errorIfDisposed();
const result = new Deferred<void>();
let toDispose: Disposable | undefined = undefined;
// Set up a listener for the connection status changing, which accepts or
// rejects after the retries are done.
const fulfill = (status: ConnectionStatus) => {
if (status === 'connected') {
result.resolve();
if (toDispose) {
toDispose.dispose();
toDispose = undefined;
}
} else if (status === 'disconnected') {
result.reject(new Error('Kernel connection disconnected'));
if (toDispose) {
toDispose.dispose();
toDispose = undefined;
}
}
};
toDispose = this.connectionStatusChanged(fulfill);
// Reset the reconnect limit so we start the connection attempts fresh
this._reconnectAttempt = 0;
// Start the reconnection process, which will also clear any existing
// connection.
this._reconnect();
// Return the promise that should resolve on connection or reject if the
// retries don't work.
return result.promise;
} | /**
* Reconnect to a kernel.
*
* #### Notes
* This may try multiple times to reconnect to a kernel, and will sever any
* existing connection.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L621-L655 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | fulfill | const fulfill = (status: ConnectionStatus) => {
if (status === 'connected') {
result.resolve();
if (toDispose) {
toDispose.dispose();
toDispose = undefined;
}
} else if (status === 'disconnected') {
result.reject(new Error('Kernel connection disconnected'));
if (toDispose) {
toDispose.dispose();
toDispose = undefined;
}
}
}; | // Set up a listener for the connection status changing, which accepts or | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L628-L642 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.shutdown | async shutdown(): Promise<void> {
if (this.status !== 'dead') {
await this.kernelRestAPI.shutdownKernel(this.id, this.serverSettings);
}
this.handleShutdown();
} | /**
* Shutdown a kernel.
*
* #### Notes
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/kernels).
*
* The promise is fulfilled on a valid response and rejected otherwise.
*
* On a valid response, disposes this kernel connection.
*
* If the kernel is already `dead`, disposes this kernel connection without
* a server request.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L670-L675 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.handleShutdown | handleShutdown(): void {
this._updateStatus('dead');
this.dispose();
} | /**
* Handles a kernel shutdown.
*
* #### Notes
* This method should be called if we know from outside information that a
* kernel is dead (for example, we cannot find the kernel model on the
* server).
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L685-L688 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.requestKernelInfo | async requestKernelInfo(): Promise<KernelMessage.IInfoReplyMsg | undefined> {
const msg = KernelMessage.createMessage({
msgType: 'kernel_info_request',
channel: 'shell',
username: this._username,
session: this._clientId,
content: {},
});
let reply: KernelMessage.IInfoReplyMsg | undefined;
try {
reply = (await Private.handleShellMessage(this, msg)) as
| KernelMessage.IInfoReplyMsg
| undefined;
} catch (e) {
// If we rejected because the future was disposed, ignore and return.
if (this.isDisposed) {
return;
} else {
throw e;
}
}
this._errorIfDisposed();
if (!reply) {
return;
}
// Kernels sometimes do not include a status field on kernel_info_reply
// messages, so set a default for now.
// See https://github.com/jupyterlab/jupyterlab/issues/6760
if (reply.content.status === undefined) {
(reply.content as any).status = 'ok';
}
if (reply.content.status !== 'ok') {
this._info.reject('Kernel info reply errored');
return reply;
}
this._info.resolve(reply.content);
this._kernelSession = reply.header.session;
return reply;
} | /**
* Send a `kernel_info_request` message.
*
* #### Notes
* See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#kernel-info).
*
* Fulfills with the `kernel_info_response` content when the shell reply is
* received and validated.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L699-L743 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.requestComplete | requestComplete(
content: KernelMessage.ICompleteRequestMsg['content'],
): Promise<KernelMessage.ICompleteReplyMsg> {
const msg = KernelMessage.createMessage({
msgType: 'complete_request',
channel: 'shell',
username: this._username,
session: this._clientId,
content,
});
return Private.handleShellMessage(
this,
msg,
) as Promise<KernelMessage.ICompleteReplyMsg>;
} | /**
* Send a `complete_request` message.
*
* #### Notes
* See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#completion).
*
* Fulfills with the `complete_reply` content when the shell reply is
* received and validated.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L754-L768 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.requestInspect | requestInspect(
content: KernelMessage.IInspectRequestMsg['content'],
): Promise<KernelMessage.IInspectReplyMsg> {
const msg = KernelMessage.createMessage({
msgType: 'inspect_request',
channel: 'shell',
username: this._username,
session: this._clientId,
content: content,
});
return Private.handleShellMessage(
this,
msg,
) as Promise<KernelMessage.IInspectReplyMsg>;
} | /**
* Send an `inspect_request` message.
*
* #### Notes
* See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#introspection).
*
* Fulfills with the `inspect_reply` content when the shell reply is
* received and validated.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L779-L793 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | KernelConnection.requestHistory | requestHistory(
content: KernelMessage.IHistoryRequestMsg['content'],
): Promise<KernelMessage.IHistoryReplyMsg> {
const msg = KernelMessage.createMessage({
msgType: 'history_request',
channel: 'shell',
username: this._username,
session: this._clientId,
content,
});
return Private.handleShellMessage(
this,
msg,
) as Promise<KernelMessage.IHistoryReplyMsg>;
} | /**
* Send a `history_request` message.
*
* #### Notes
* See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#history).
*
* Fulfills with the `history_reply` content when the shell reply is
* received and validated.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-kernel/src/kernel/kernel-connection.ts#L804-L818 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.