@jupyterlab/services
Advanced tools
Comparing version 0.44.0 to 0.45.0
@@ -0,1 +1,2 @@ | ||
import { ModelDB } from '@jupyterlab/coreutils'; | ||
import { JSONObject } from '@phosphor/coreutils'; | ||
@@ -144,6 +145,2 @@ import { IDisposable } from '@phosphor/disposable'; | ||
/** | ||
* The server settings of the manager. | ||
*/ | ||
readonly serverSettings: ServerConnection.ISettings; | ||
/** | ||
* A signal emitted when a file operation takes place. | ||
@@ -153,2 +150,12 @@ */ | ||
/** | ||
* Add an `IDrive` to the manager. | ||
*/ | ||
addDrive(drive: IDrive): void; | ||
/** | ||
* Given a path, get a ModelDB.IFactory from the | ||
* relevant backend. Returns `null` if the backend | ||
* does not provide one. | ||
*/ | ||
getModelDBFactory(path: string): ModelDB.IFactory; | ||
/** | ||
* Get a file or directory. | ||
@@ -259,5 +266,137 @@ * | ||
} | ||
/** | ||
* The interface for a network drive that can be mounted | ||
* in the contents manager. | ||
*/ | ||
interface IDrive extends IDisposable { | ||
/** | ||
* The name of the drive, which is used at the leading | ||
* component of file paths. | ||
*/ | ||
readonly name: string; | ||
/** | ||
* The server settings of the manager. | ||
*/ | ||
readonly serverSettings: ServerConnection.ISettings; | ||
/** | ||
* An optional ModelDB.IFactory instance for the | ||
* drive. | ||
*/ | ||
readonly modelDBFactory?: ModelDB.IFactory; | ||
/** | ||
* A signal emitted when a file operation takes place. | ||
*/ | ||
fileChanged: ISignal<IDrive, IChangedArgs>; | ||
/** | ||
* 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. | ||
*/ | ||
get(localPath: string, options?: IFetchOptions): Promise<IModel>; | ||
/** | ||
* Get an encoded download url given a file path. | ||
* | ||
* @param A promise which resolves with the absolute POSIX | ||
* file path on the server. | ||
*/ | ||
getDownloadUrl(localPath: string): Promise<string>; | ||
/** | ||
* 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. | ||
*/ | ||
newUntitled(options?: ICreateOptions): Promise<IModel>; | ||
/** | ||
* Delete a file. | ||
* | ||
* @param localPath - The path to the file. | ||
* | ||
* @returns A promise which resolves when the file is deleted. | ||
*/ | ||
delete(localPath: string): Promise<void>; | ||
/** | ||
* 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 content model when the | ||
* file is renamed. | ||
*/ | ||
rename(oldLocalPath: string, newLocalPath: string): Promise<IModel>; | ||
/** | ||
* Save a file. | ||
* | ||
* @param localPath - The desired file path. | ||
* | ||
* @param options - Optional overrrides to the model. | ||
* | ||
* @returns A promise which resolves with the file content model when the | ||
* file is saved. | ||
*/ | ||
save(localPath: string, options?: IModel): Promise<IModel>; | ||
/** | ||
* Copy a file into a given directory. | ||
* | ||
* @param localPath - The original file path. | ||
* | ||
* @param toLocalDir - The destination directory path. | ||
* | ||
* @returns A promise which resolves with the new content model when the | ||
* file is copied. | ||
*/ | ||
copy(localPath: string, toLocalDir: string): Promise<IModel>; | ||
/** | ||
* 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. | ||
*/ | ||
createCheckpoint(localPath: string): Promise<IModel>; | ||
/** | ||
* 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. | ||
*/ | ||
listCheckpoints(localPath: string): Promise<ICheckpointModel[]>; | ||
/** | ||
* 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. | ||
*/ | ||
restoreCheckpoint(localPath: string, checkpointID: string): Promise<void>; | ||
/** | ||
* 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. | ||
*/ | ||
deleteCheckpoint(localPath: string, checkpointID: string): Promise<void>; | ||
} | ||
} | ||
/** | ||
* A contents manager that passes file operations to the server. | ||
* Multiple servers implementing the `IDrive` interface can be | ||
* attached to the contents manager, so that the same session can | ||
* perform file operations on multiple backends. | ||
* | ||
@@ -278,2 +417,187 @@ * This includes checkpointing with the normal file operations. | ||
/** | ||
* Test whether the manager has been disposed. | ||
*/ | ||
readonly isDisposed: boolean; | ||
/** | ||
* Dispose of the resources held by the manager. | ||
*/ | ||
dispose(): void; | ||
/** | ||
* Add an `IDrive` to the manager. | ||
*/ | ||
addDrive(drive: Contents.IDrive): void; | ||
/** | ||
* Given a path, get a ModelDB.IFactory from the | ||
* relevant backend. Returns `null` if the backend | ||
* does not provide one. | ||
*/ | ||
getModelDBFactory(path: string): ModelDB.IFactory; | ||
/** | ||
* 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. | ||
*/ | ||
get(path: string, options?: Contents.IFetchOptions): Promise<Contents.IModel>; | ||
/** | ||
* 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. | ||
*/ | ||
getDownloadUrl(path: string): Promise<string>; | ||
/** | ||
* 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. | ||
*/ | ||
newUntitled(options?: Contents.ICreateOptions): Promise<Contents.IModel>; | ||
/** | ||
* Delete a file. | ||
* | ||
* @param path - The path to the file. | ||
* | ||
* @returns A promise which resolves when the file is deleted. | ||
*/ | ||
delete(path: string): Promise<void>; | ||
/** | ||
* 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. | ||
*/ | ||
rename(path: string, newPath: string): Promise<Contents.IModel>; | ||
/** | ||
* 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. | ||
*/ | ||
save(path: string, options?: Contents.IModel): Promise<Contents.IModel>; | ||
/** | ||
* 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. | ||
*/ | ||
copy(fromFile: string, toDir: string): Promise<Contents.IModel>; | ||
/** | ||
* 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. | ||
*/ | ||
createCheckpoint(path: string): Promise<Contents.ICheckpointModel>; | ||
/** | ||
* 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. | ||
*/ | ||
listCheckpoints(path: string): Promise<Contents.ICheckpointModel[]>; | ||
/** | ||
* 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. | ||
*/ | ||
restoreCheckpoint(path: string, checkpointID: string): Promise<void>; | ||
/** | ||
* 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. | ||
*/ | ||
deleteCheckpoint(path: string, checkpointID: string): Promise<void>; | ||
/** | ||
* Given a drive and a local path, construct a fully qualified | ||
* path. The inverse of `_driveForPath`. | ||
* | ||
* @param drive: an `IDrive`. | ||
* | ||
* @param localPath: the local path on the drive. | ||
* | ||
* @returns the fully qualified path. | ||
*/ | ||
private _toGlobalPath(drive, localPath); | ||
/** | ||
* Given a path, get the `IDrive 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 `IDrive` object for the path, | ||
* and a local path for that drive. | ||
*/ | ||
private _driveForPath(path); | ||
/** | ||
* 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. | ||
*/ | ||
private _onFileChanged(sender, args); | ||
private _isDisposed; | ||
private _additionalDrives; | ||
private _defaultDrive; | ||
private _fileChanged; | ||
} | ||
/** | ||
* A default implementation for an `IDrive`, talking to the | ||
* server using the Jupyter REST API. | ||
*/ | ||
export declare class Drive implements Contents.IDrive { | ||
/** | ||
* Construct a new contents manager object. | ||
* | ||
* @param options - The options used to initialize the object. | ||
*/ | ||
constructor(options?: Drive.IOptions); | ||
/** | ||
* The name of the drive, which is used at the leading | ||
* component of file paths. | ||
*/ | ||
readonly name: string; | ||
/** | ||
* A signal emitted when a file operation takes place. | ||
*/ | ||
readonly fileChanged: ISignal<this, Contents.IChangedArgs>; | ||
/** | ||
* The server settings of the manager. | ||
@@ -293,3 +617,3 @@ */ | ||
* | ||
* @param path: The path to the file. | ||
* @param localPath: The path to the file. | ||
* | ||
@@ -302,7 +626,7 @@ * @param options: The options used to fetch the file. | ||
*/ | ||
get(path: string, options?: Contents.IFetchOptions): Promise<Contents.IModel>; | ||
get(localPath: string, options?: Contents.IFetchOptions): Promise<Contents.IModel>; | ||
/** | ||
* Get an encoded download url given a file path. | ||
* | ||
* @param path - An absolute POSIX file path on the server. | ||
* @param localPath - An absolute POSIX file path on the server. | ||
* | ||
@@ -312,3 +636,3 @@ * #### Notes | ||
*/ | ||
getDownloadUrl(path: string): Promise<string>; | ||
getDownloadUrl(localPath: string): Promise<string>; | ||
/** | ||
@@ -329,3 +653,3 @@ * Create a new untitled file or directory in the specified directory path. | ||
* | ||
* @param path - The path to the file. | ||
* @param localPath - The path to the file. | ||
* | ||
@@ -337,9 +661,9 @@ * @returns A promise which resolves when the file is deleted. | ||
*/ | ||
delete(path: string): Promise<void>; | ||
delete(localPath: string): Promise<void>; | ||
/** | ||
* Rename a file or directory. | ||
* | ||
* @param path - The original file path. | ||
* @param oldLocalPath - The original file path. | ||
* | ||
* @param newPath - The new file path. | ||
* @param newLocalPath - The new file path. | ||
* | ||
@@ -352,7 +676,7 @@ * @returns A promise which resolves with the new file contents model when | ||
*/ | ||
rename(path: string, newPath: string): Promise<Contents.IModel>; | ||
rename(oldLocalPath: string, newLocalPath: string): Promise<Contents.IModel>; | ||
/** | ||
* Save a file. | ||
* | ||
* @param path - The desired file path. | ||
* @param localPath - The desired file path. | ||
* | ||
@@ -369,7 +693,7 @@ * @param options - Optional overrides to the model. | ||
*/ | ||
save(path: string, options?: Contents.IModel): Promise<Contents.IModel>; | ||
save(localPath: string, options?: Contents.IModel): Promise<Contents.IModel>; | ||
/** | ||
* Copy a file into a given directory. | ||
* | ||
* @param path - The original file path. | ||
* @param localPath - The original file path. | ||
* | ||
@@ -390,3 +714,3 @@ * @param toDir - The destination directory path. | ||
* | ||
* @param path - The path of the file. | ||
* @param localPath - The path of the file. | ||
* | ||
@@ -399,7 +723,7 @@ * @returns A promise which resolves with the new checkpoint model when the | ||
*/ | ||
createCheckpoint(path: string): Promise<Contents.ICheckpointModel>; | ||
createCheckpoint(localPath: string): Promise<Contents.ICheckpointModel>; | ||
/** | ||
* List available checkpoints for a file. | ||
* | ||
* @param path - The path of the file. | ||
* @param localPath - The path of the file. | ||
* | ||
@@ -412,7 +736,7 @@ * @returns A promise which resolves with a list of checkpoint models for | ||
*/ | ||
listCheckpoints(path: string): Promise<Contents.ICheckpointModel[]>; | ||
listCheckpoints(localPath: string): Promise<Contents.ICheckpointModel[]>; | ||
/** | ||
* Restore a file to a known checkpoint state. | ||
* | ||
* @param path - The path of the file. | ||
* @param localPath - The path of the file. | ||
* | ||
@@ -426,7 +750,7 @@ * @param checkpointID - The id of the checkpoint to restore. | ||
*/ | ||
restoreCheckpoint(path: string, checkpointID: string): Promise<void>; | ||
restoreCheckpoint(localPath: string, checkpointID: string): Promise<void>; | ||
/** | ||
* Delete a checkpoint for a file. | ||
* | ||
* @param path - The path of the file. | ||
* @param localPath - The path of the file. | ||
* | ||
@@ -440,3 +764,3 @@ * @param checkpointID - The id of the checkpoint to delete. | ||
*/ | ||
deleteCheckpoint(path: string, checkpointID: string): Promise<void>; | ||
deleteCheckpoint(localPath: string, checkpointID: string): Promise<void>; | ||
/** | ||
@@ -446,2 +770,3 @@ * Get a REST url for a file given a path. | ||
private _getUrl(...args); | ||
private _apiEndpoint; | ||
private _isDisposed; | ||
@@ -459,6 +784,31 @@ private _fileChanged; | ||
/** | ||
* The default drive backend for the contents manager. | ||
*/ | ||
defaultDrive?: Contents.IDrive; | ||
} | ||
} | ||
/** | ||
* A namespace for Drive statics. | ||
*/ | ||
export declare namespace Drive { | ||
/** | ||
* The options used to intialize a `Drive`. | ||
*/ | ||
interface IOptions { | ||
/** | ||
* The name for the `Drive`, which is used in file | ||
* paths to disambiguate it from other drives. | ||
*/ | ||
name?: string; | ||
/** | ||
* The server settings for the server. | ||
*/ | ||
serverSettings?: ServerConnection.ISettings; | ||
/** | ||
* A REST endpoint for drive requests. | ||
* If not given, defaults to the Jupyter | ||
* REST API given by [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents). | ||
*/ | ||
apiEndpoint?: string; | ||
} | ||
} |
"use strict"; | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var coreutils_1 = require("@jupyterlab/coreutils"); | ||
var coreutils_2 = require("@phosphor/coreutils"); | ||
var algorithm_1 = require("@phosphor/algorithm"); | ||
var signaling_1 = require("@phosphor/signaling"); | ||
@@ -11,5 +20,5 @@ var __1 = require(".."); | ||
/** | ||
* The url for the contents service. | ||
* The url for the default drive service. | ||
*/ | ||
var SERVICE_CONTENTS_URL = 'api/contents'; | ||
var SERVICE_DRIVE_URL = 'api/contents'; | ||
/** | ||
@@ -21,2 +30,5 @@ * The url for the file access. | ||
* A contents manager that passes file operations to the server. | ||
* Multiple servers implementing the `IDrive` interface can be | ||
* attached to the contents manager, so that the same session can | ||
* perform file operations on multiple backends. | ||
* | ||
@@ -34,4 +46,7 @@ * This includes checkpointing with the normal file operations. | ||
this._isDisposed = false; | ||
this._additionalDrives = new Map(); | ||
this._defaultDrive = null; | ||
this._fileChanged = new signaling_1.Signal(this); | ||
this.serverSettings = options.serverSettings || __1.ServerConnection.makeSettings(); | ||
this._defaultDrive = options.defaultDrive || new Drive(); | ||
this._defaultDrive.fileChanged.connect(this._onFileChanged, this); | ||
} | ||
@@ -69,2 +84,18 @@ Object.defineProperty(ContentsManager.prototype, "fileChanged", { | ||
/** | ||
* Add an `IDrive` to the manager. | ||
*/ | ||
ContentsManager.prototype.addDrive = function (drive) { | ||
this._additionalDrives.set(drive.name, drive); | ||
drive.fileChanged.connect(this._onFileChanged, this); | ||
}; | ||
/** | ||
* Given a path, get a ModelDB.IFactory from the | ||
* relevant backend. Returns `null` if the backend | ||
* does not provide one. | ||
*/ | ||
ContentsManager.prototype.getModelDBFactory = function (path) { | ||
var drive = this._driveForPath(path)[0]; | ||
return drive.modelDBFactory || null; | ||
}; | ||
/** | ||
* Get a file or directory. | ||
@@ -77,7 +108,312 @@ * | ||
* @returns A promise which resolves with the file content. | ||
*/ | ||
ContentsManager.prototype.get = function (path, options) { | ||
var _this = this; | ||
var _a = this._driveForPath(path), drive = _a[0], localPath = _a[1]; | ||
return drive.get(localPath, options).then(function (contentsModel) { | ||
var listing = []; | ||
if (contentsModel.type === 'directory') { | ||
algorithm_1.each(contentsModel.content, function (item) { | ||
listing.push(__assign({}, item, { path: _this._toGlobalPath(drive, item.path) })); | ||
}); | ||
return __assign({}, contentsModel, { path: _this._toGlobalPath(drive, localPath), content: listing }); | ||
} | ||
else { | ||
return __assign({}, contentsModel, { path: _this._toGlobalPath(drive, localPath) }); | ||
} | ||
}); | ||
}; | ||
/** | ||
* 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. | ||
*/ | ||
ContentsManager.prototype.getDownloadUrl = function (path) { | ||
var _a = this._driveForPath(path), drive = _a[0], localPath = _a[1]; | ||
return drive.getDownloadUrl(localPath); | ||
}; | ||
/** | ||
* 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. | ||
*/ | ||
ContentsManager.prototype.newUntitled = function (options) { | ||
if (options === void 0) { options = {}; } | ||
if (options.path) { | ||
var globalPath_1 = Private.normalize(options.path); | ||
var _a = this._driveForPath(globalPath_1), drive = _a[0], localPath = _a[1]; | ||
return drive.newUntitled(__assign({}, options, { path: localPath })).then(function (contentsModel) { | ||
return __assign({}, contentsModel, { path: coreutils_1.PathExt.join(globalPath_1, contentsModel.name) }); | ||
}); | ||
} | ||
else { | ||
return this._defaultDrive.newUntitled(options); | ||
} | ||
}; | ||
/** | ||
* Delete a file. | ||
* | ||
* @param path - The path to the file. | ||
* | ||
* @returns A promise which resolves when the file is deleted. | ||
*/ | ||
ContentsManager.prototype.delete = function (path) { | ||
var _a = this._driveForPath(path), drive = _a[0], localPath = _a[1]; | ||
return drive.delete(localPath); | ||
}; | ||
/** | ||
* 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. | ||
*/ | ||
ContentsManager.prototype.rename = function (path, newPath) { | ||
var _this = this; | ||
var _a = this._driveForPath(path), drive1 = _a[0], path1 = _a[1]; | ||
var _b = this._driveForPath(newPath), drive2 = _b[0], path2 = _b[1]; | ||
if (drive1 !== drive2) { | ||
throw Error('ContentsManager: renaming files must occur within a Drive'); | ||
} | ||
return drive1.rename(path1, path2).then(function (contentsModel) { | ||
return __assign({}, contentsModel, { path: _this._toGlobalPath(drive1, path2) }); | ||
}); | ||
}; | ||
/** | ||
* 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. | ||
*/ | ||
ContentsManager.prototype.save = function (path, options) { | ||
if (options === void 0) { options = {}; } | ||
var _a = this._driveForPath(path), drive = _a[0], localPath = _a[1]; | ||
return drive.save(localPath, __assign({}, options, { path: localPath })).then(function (contentsModel) { | ||
return __assign({}, contentsModel, { path: Private.normalize(path) }); | ||
}); | ||
}; | ||
/** | ||
* 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. | ||
*/ | ||
ContentsManager.prototype.copy = function (fromFile, toDir) { | ||
var _this = this; | ||
var _a = this._driveForPath(fromFile), drive1 = _a[0], path1 = _a[1]; | ||
var _b = this._driveForPath(toDir), drive2 = _b[0], path2 = _b[1]; | ||
if (drive1 === drive2) { | ||
return drive1.copy(path1, path2).then(function (contentsModel) { | ||
return __assign({}, contentsModel, { path: _this._toGlobalPath(drive1, contentsModel.path) }); | ||
}); | ||
} | ||
else { | ||
throw Error('Copying files between drives is not currently implemented'); | ||
} | ||
}; | ||
/** | ||
* 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. | ||
*/ | ||
ContentsManager.prototype.createCheckpoint = function (path) { | ||
var _a = this._driveForPath(path), drive = _a[0], localPath = _a[1]; | ||
return drive.createCheckpoint(localPath); | ||
}; | ||
/** | ||
* 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. | ||
*/ | ||
ContentsManager.prototype.listCheckpoints = function (path) { | ||
var _a = this._driveForPath(path), drive = _a[0], localPath = _a[1]; | ||
return drive.listCheckpoints(localPath); | ||
}; | ||
/** | ||
* 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. | ||
*/ | ||
ContentsManager.prototype.restoreCheckpoint = function (path, checkpointID) { | ||
var _a = this._driveForPath(path), drive = _a[0], localPath = _a[1]; | ||
return drive.restoreCheckpoint(localPath, checkpointID); | ||
}; | ||
/** | ||
* 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. | ||
*/ | ||
ContentsManager.prototype.deleteCheckpoint = function (path, checkpointID) { | ||
var _a = this._driveForPath(path), drive = _a[0], localPath = _a[1]; | ||
return drive.deleteCheckpoint(localPath, checkpointID); | ||
}; | ||
/** | ||
* Given a drive and a local path, construct a fully qualified | ||
* path. The inverse of `_driveForPath`. | ||
* | ||
* @param drive: an `IDrive`. | ||
* | ||
* @param localPath: the local path on the drive. | ||
* | ||
* @returns the fully qualified path. | ||
*/ | ||
ContentsManager.prototype._toGlobalPath = function (drive, localPath) { | ||
if (drive === this._defaultDrive) { | ||
return coreutils_1.PathExt.removeSlash(localPath); | ||
} | ||
else { | ||
return drive.name + ':' + coreutils_1.PathExt.removeSlash(localPath); | ||
} | ||
}; | ||
/** | ||
* Given a path, get the `IDrive 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 `IDrive` object for the path, | ||
* and a local path for that drive. | ||
*/ | ||
ContentsManager.prototype._driveForPath = function (path) { | ||
// Split the path at ':' | ||
var parts = path.split(':'); | ||
if (parts.length === 1) { | ||
return [this._defaultDrive, path]; | ||
} | ||
else { | ||
var drive = this._additionalDrives.get(parts[0]); | ||
if (!drive) { | ||
throw Error('ContentsManager: cannot find requested drive'); | ||
} | ||
return [drive, Private.normalize(parts[1])]; | ||
} | ||
}; | ||
/** | ||
* 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. | ||
*/ | ||
ContentsManager.prototype._onFileChanged = function (sender, args) { | ||
if (sender === this._defaultDrive) { | ||
this._fileChanged.emit(args); | ||
} | ||
else { | ||
var newValue = null; | ||
var oldValue = null; | ||
if (args.newValue) { | ||
newValue = __assign({}, args.newValue, { path: this._toGlobalPath(sender, args.newValue.path) }); | ||
} | ||
if (args.oldValue) { | ||
oldValue = __assign({}, args.oldValue, { path: this._toGlobalPath(sender, args.oldValue.path) }); | ||
} | ||
this._fileChanged.emit({ | ||
type: args.type, | ||
newValue: newValue, | ||
oldValue: oldValue | ||
}); | ||
} | ||
}; | ||
return ContentsManager; | ||
}()); | ||
exports.ContentsManager = ContentsManager; | ||
/** | ||
* A default implementation for an `IDrive`, talking to the | ||
* server using the Jupyter REST API. | ||
*/ | ||
var Drive = (function () { | ||
/** | ||
* Construct a new contents manager object. | ||
* | ||
* @param options - The options used to initialize the object. | ||
*/ | ||
function Drive(options) { | ||
if (options === void 0) { options = {}; } | ||
this._isDisposed = false; | ||
this._fileChanged = new signaling_1.Signal(this); | ||
this.name = options.name || 'Default'; | ||
this._apiEndpoint = options.apiEndpoint || SERVICE_DRIVE_URL; | ||
this.serverSettings = options.serverSettings || __1.ServerConnection.makeSettings(); | ||
} | ||
Object.defineProperty(Drive.prototype, "fileChanged", { | ||
/** | ||
* A signal emitted when a file operation takes place. | ||
*/ | ||
get: function () { | ||
return this._fileChanged; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Drive.prototype, "isDisposed", { | ||
/** | ||
* Test whether the manager has been disposed. | ||
*/ | ||
get: function () { | ||
return this._isDisposed; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
/** | ||
* Dispose of the resources held by the manager. | ||
*/ | ||
Drive.prototype.dispose = function () { | ||
if (this.isDisposed) { | ||
return; | ||
} | ||
this._isDisposed = true; | ||
signaling_1.Signal.clearData(this); | ||
}; | ||
/** | ||
* 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. | ||
*/ | ||
ContentsManager.prototype.get = function (path, options) { | ||
var url = this._getUrl(path); | ||
Drive.prototype.get = function (localPath, options) { | ||
var url = this._getUrl(localPath); | ||
if (options) { | ||
@@ -113,3 +449,3 @@ // The notebook type cannot take an format option. | ||
* | ||
* @param path - An absolute POSIX file path on the server. | ||
* @param localPath - An absolute POSIX file path on the server. | ||
* | ||
@@ -119,5 +455,5 @@ * #### Notes | ||
*/ | ||
ContentsManager.prototype.getDownloadUrl = function (path) { | ||
Drive.prototype.getDownloadUrl = function (localPath) { | ||
var baseUrl = this.serverSettings.baseUrl; | ||
return Promise.resolve(coreutils_1.URLExt.join(baseUrl, FILES_URL, coreutils_1.URLExt.encodeParts(path))); | ||
return Promise.resolve(coreutils_1.URLExt.join(baseUrl, FILES_URL, coreutils_1.URLExt.encodeParts(localPath))); | ||
}; | ||
@@ -135,3 +471,3 @@ /** | ||
*/ | ||
ContentsManager.prototype.newUntitled = function (options) { | ||
Drive.prototype.newUntitled = function (options) { | ||
var _this = this; | ||
@@ -173,3 +509,3 @@ if (options === void 0) { options = {}; } | ||
* | ||
* @param path - The path to the file. | ||
* @param localPath - The path to the file. | ||
* | ||
@@ -181,6 +517,6 @@ * @returns A promise which resolves when the file is deleted. | ||
*/ | ||
ContentsManager.prototype.delete = function (path) { | ||
Drive.prototype.delete = function (localPath) { | ||
var _this = this; | ||
var request = { | ||
url: this._getUrl(path), | ||
url: this._getUrl(localPath), | ||
method: 'DELETE' | ||
@@ -194,3 +530,3 @@ }; | ||
type: 'delete', | ||
oldValue: { path: path }, | ||
oldValue: { path: localPath }, | ||
newValue: null | ||
@@ -214,5 +550,5 @@ }); | ||
* | ||
* @param path - The original file path. | ||
* @param oldLocalPath - The original file path. | ||
* | ||
* @param newPath - The new file path. | ||
* @param newLocalPath - The new file path. | ||
* | ||
@@ -225,8 +561,8 @@ * @returns A promise which resolves with the new file contents model when | ||
*/ | ||
ContentsManager.prototype.rename = function (path, newPath) { | ||
Drive.prototype.rename = function (oldLocalPath, newLocalPath) { | ||
var _this = this; | ||
var request = { | ||
url: this._getUrl(path), | ||
url: this._getUrl(oldLocalPath), | ||
method: 'PATCH', | ||
data: JSON.stringify({ path: newPath }) | ||
data: JSON.stringify({ path: newLocalPath }) | ||
}; | ||
@@ -246,3 +582,3 @@ return __1.ServerConnection.makeRequest(request, this.serverSettings).then(function (response) { | ||
type: 'rename', | ||
oldValue: { path: path }, | ||
oldValue: { path: oldLocalPath }, | ||
newValue: data | ||
@@ -256,3 +592,3 @@ }); | ||
* | ||
* @param path - The desired file path. | ||
* @param localPath - The desired file path. | ||
* | ||
@@ -269,7 +605,7 @@ * @param options - Optional overrides to the model. | ||
*/ | ||
ContentsManager.prototype.save = function (path, options) { | ||
Drive.prototype.save = function (localPath, options) { | ||
var _this = this; | ||
if (options === void 0) { options = {}; } | ||
var request = { | ||
url: this._getUrl(path), | ||
url: this._getUrl(localPath), | ||
method: 'PUT', | ||
@@ -302,3 +638,3 @@ cache: false, | ||
* | ||
* @param path - The original file path. | ||
* @param localPath - The original file path. | ||
* | ||
@@ -315,3 +651,3 @@ * @param toDir - The destination directory path. | ||
*/ | ||
ContentsManager.prototype.copy = function (fromFile, toDir) { | ||
Drive.prototype.copy = function (fromFile, toDir) { | ||
var _this = this; | ||
@@ -345,3 +681,3 @@ var request = { | ||
* | ||
* @param path - The path of the file. | ||
* @param localPath - The path of the file. | ||
* | ||
@@ -354,5 +690,5 @@ * @returns A promise which resolves with the new checkpoint model when the | ||
*/ | ||
ContentsManager.prototype.createCheckpoint = function (path) { | ||
Drive.prototype.createCheckpoint = function (localPath) { | ||
var request = { | ||
url: this._getUrl(path, 'checkpoints'), | ||
url: this._getUrl(localPath, 'checkpoints'), | ||
method: 'POST' | ||
@@ -377,3 +713,3 @@ }; | ||
* | ||
* @param path - The path of the file. | ||
* @param localPath - The path of the file. | ||
* | ||
@@ -386,5 +722,5 @@ * @returns A promise which resolves with a list of checkpoint models for | ||
*/ | ||
ContentsManager.prototype.listCheckpoints = function (path) { | ||
Drive.prototype.listCheckpoints = function (localPath) { | ||
var request = { | ||
url: this._getUrl(path, 'checkpoints'), | ||
url: this._getUrl(localPath, 'checkpoints'), | ||
method: 'GET', | ||
@@ -414,3 +750,3 @@ cache: false | ||
* | ||
* @param path - The path of the file. | ||
* @param localPath - The path of the file. | ||
* | ||
@@ -424,5 +760,5 @@ * @param checkpointID - The id of the checkpoint to restore. | ||
*/ | ||
ContentsManager.prototype.restoreCheckpoint = function (path, checkpointID) { | ||
Drive.prototype.restoreCheckpoint = function (localPath, checkpointID) { | ||
var request = { | ||
url: this._getUrl(path, 'checkpoints', checkpointID), | ||
url: this._getUrl(localPath, 'checkpoints', checkpointID), | ||
method: 'POST' | ||
@@ -439,3 +775,3 @@ }; | ||
* | ||
* @param path - The path of the file. | ||
* @param localPath - The path of the file. | ||
* | ||
@@ -449,5 +785,5 @@ * @param checkpointID - The id of the checkpoint to delete. | ||
*/ | ||
ContentsManager.prototype.deleteCheckpoint = function (path, checkpointID) { | ||
Drive.prototype.deleteCheckpoint = function (localPath, checkpointID) { | ||
var request = { | ||
url: this._getUrl(path, 'checkpoints', checkpointID), | ||
url: this._getUrl(localPath, 'checkpoints', checkpointID), | ||
method: 'DELETE' | ||
@@ -464,3 +800,3 @@ }; | ||
*/ | ||
ContentsManager.prototype._getUrl = function () { | ||
Drive.prototype._getUrl = function () { | ||
var args = []; | ||
@@ -472,7 +808,7 @@ for (var _i = 0; _i < arguments.length; _i++) { | ||
var baseUrl = this.serverSettings.baseUrl; | ||
return coreutils_1.URLExt.join.apply(coreutils_1.URLExt, [baseUrl, SERVICE_CONTENTS_URL].concat(parts)); | ||
return coreutils_1.URLExt.join.apply(coreutils_1.URLExt, [baseUrl, this._apiEndpoint].concat(parts)); | ||
}; | ||
return ContentsManager; | ||
return Drive; | ||
}()); | ||
exports.ContentsManager = ContentsManager; | ||
exports.Drive = Drive; | ||
/** | ||
@@ -495,2 +831,20 @@ * A namespace for module private data. | ||
Private.normalizeExtension = normalizeExtension; | ||
/** | ||
* 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. | ||
*/ | ||
function normalize(path) { | ||
var parts = path.split(':'); | ||
if (parts.length === 1) { | ||
return coreutils_1.PathExt.normalize(path); | ||
} | ||
else if (parts.length === 2) { | ||
return parts[0] + ':' + coreutils_1.PathExt.normalize(parts[1]); | ||
} | ||
else { | ||
throw Error('Malformed path: ' + path); | ||
} | ||
} | ||
Private.normalize = normalize; | ||
})(Private || (Private = {})); |
@@ -302,2 +302,6 @@ import { IDisposable } from '@phosphor/disposable'; | ||
/** | ||
* Clear the socket state. | ||
*/ | ||
private _clearSocket(); | ||
/** | ||
* Handle status iopub messages from the kernel. | ||
@@ -334,2 +338,3 @@ */ | ||
private _clientId; | ||
private _wsStopped; | ||
private _ws; | ||
@@ -336,0 +341,0 @@ private _username; |
@@ -44,2 +44,3 @@ "use strict"; | ||
this._clientId = ''; | ||
this._wsStopped = false; | ||
this._ws = null; | ||
@@ -239,6 +240,3 @@ this._username = ''; | ||
this._status = 'dead'; | ||
if (this._ws !== null) { | ||
this._ws.close(); | ||
} | ||
this._ws = null; | ||
this._clearSocket(); | ||
this._futures.forEach(function (future, key) { | ||
@@ -290,3 +288,3 @@ future.dispose(); | ||
_this._futures.delete(msg.header.msg_id); | ||
}, msg, expectReply, disposeOnDone); | ||
}, msg, expectReply, disposeOnDone, this); | ||
this._futures.set(msg.header.msg_id, future); | ||
@@ -367,3 +365,2 @@ return future; | ||
DefaultKernel.prototype.shutdown = function () { | ||
var _this = this; | ||
if (this.status === 'dead') { | ||
@@ -373,5 +370,4 @@ return Promise.reject(new Error('Kernel is dead')); | ||
this._clearState(); | ||
return this.ready.then(function () { | ||
return Private.shutdownKernel(_this.id, _this.serverSettings); | ||
}); | ||
this._clearSocket(); | ||
return Private.shutdownKernel(this.id, this.serverSettings); | ||
}; | ||
@@ -642,2 +638,3 @@ /** | ||
this._connectionPromise = new coreutils_2.PromiseDelegate(); | ||
this._wsStopped = false; | ||
this._ws = settings.wsFactory(url); | ||
@@ -671,3 +668,3 @@ // Ensure incoming binary messages are not Blobs | ||
DefaultKernel.prototype._onWSMessage = function (evt) { | ||
if (this.status === 'dead') { | ||
if (this._wsStopped) { | ||
// If the socket is being closed, ignore any messages | ||
@@ -722,3 +719,3 @@ return; | ||
DefaultKernel.prototype._onWSClose = function (evt) { | ||
if (this.status === 'dead') { | ||
if (this._wsStopped) { | ||
return; | ||
@@ -743,2 +740,12 @@ } | ||
/** | ||
* Clear the socket state. | ||
*/ | ||
DefaultKernel.prototype._clearSocket = function () { | ||
this._wsStopped = true; | ||
if (this._ws !== null) { | ||
this._ws.close(); | ||
} | ||
this._ws = null; | ||
}; | ||
/** | ||
* Handle status iopub messages from the kernel. | ||
@@ -809,2 +816,5 @@ */ | ||
var content = msg.content; | ||
if (this.isDisposed) { | ||
return; | ||
} | ||
var promise = Private.loadObject(content.target_name, content.target_module, this._targetRegistry).then(function (target) { | ||
@@ -822,2 +832,5 @@ var comm = new comm_1.CommHandler(content.target_name, content.comm_id, _this, function () { _this._unregisterComm(content.comm_id); }); | ||
return Promise.resolve(response).then(function () { | ||
if (_this.isDisposed) { | ||
return; | ||
} | ||
_this._commPromises.delete(comm.commId); | ||
@@ -824,0 +837,0 @@ _this._comms.set(comm.commId, comm); |
@@ -11,3 +11,3 @@ import { DisposableDelegate } from '@phosphor/disposable'; | ||
*/ | ||
constructor(cb: () => void, msg: KernelMessage.IShellMessage, expectShell: boolean, disposeOnDone: boolean); | ||
constructor(cb: () => void, msg: KernelMessage.IShellMessage, expectShell: boolean, disposeOnDone: boolean, kernel: Kernel.IKernel); | ||
/** | ||
@@ -18,5 +18,5 @@ * Get the original outgoing message. | ||
/** | ||
* Check for message done state. | ||
* A promise that resolves when the future is done. | ||
*/ | ||
readonly isDone: boolean; | ||
readonly done: Promise<KernelMessage.IShellMessage>; | ||
/** | ||
@@ -37,9 +37,2 @@ * Get the reply handler. | ||
/** | ||
* Get the done handler. | ||
*/ | ||
/** | ||
* Set the done handler. | ||
*/ | ||
onDone: () => void; | ||
/** | ||
* Get the stdin handler. | ||
@@ -75,2 +68,6 @@ */ | ||
/** | ||
* Send an `input_reply` message. | ||
*/ | ||
sendInputReply(content: KernelMessage.IInputReply): void; | ||
/** | ||
* Dispose and unregister the future. | ||
@@ -101,4 +98,6 @@ */ | ||
private _done; | ||
private _replyMsg; | ||
private _hooks; | ||
private _disposeOnDone; | ||
private _kernel; | ||
} |
@@ -15,2 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var coreutils_1 = require("@phosphor/coreutils"); | ||
var disposable_1 = require("@phosphor/disposable"); | ||
@@ -26,3 +27,3 @@ var messages_1 = require("./messages"); | ||
*/ | ||
function KernelFutureHandler(cb, msg, expectShell, disposeOnDone) { | ||
function KernelFutureHandler(cb, msg, expectShell, disposeOnDone, kernel) { | ||
var _this = _super.call(this, cb) || this; | ||
@@ -34,3 +35,3 @@ _this._msg = null; | ||
_this._reply = null; | ||
_this._done = null; | ||
_this._done = new coreutils_1.PromiseDelegate(); | ||
_this._hooks = new Private.HookList(); | ||
@@ -43,2 +44,3 @@ _this._disposeOnDone = true; | ||
_this._disposeOnDone = disposeOnDone; | ||
_this._kernel = kernel; | ||
return _this; | ||
@@ -56,8 +58,8 @@ } | ||
}); | ||
Object.defineProperty(KernelFutureHandler.prototype, "isDone", { | ||
Object.defineProperty(KernelFutureHandler.prototype, "done", { | ||
/** | ||
* Check for message done state. | ||
* A promise that resolves when the future is done. | ||
*/ | ||
get: function () { | ||
return this._testFlag(Private.KernelFutureFlag.IsDone); | ||
return this._done.promise; | ||
}, | ||
@@ -99,18 +101,2 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(KernelFutureHandler.prototype, "onDone", { | ||
/** | ||
* Get the done handler. | ||
*/ | ||
get: function () { | ||
return this._done; | ||
}, | ||
/** | ||
* Set the done handler. | ||
*/ | ||
set: function (cb) { | ||
this._done = cb; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(KernelFutureHandler.prototype, "onStdin", { | ||
@@ -163,2 +149,8 @@ /** | ||
/** | ||
* Send an `input_reply` message. | ||
*/ | ||
KernelFutureHandler.prototype.sendInputReply = function (content) { | ||
this._kernel.sendInputReply(content); | ||
}; | ||
/** | ||
* Dispose and unregister the future. | ||
@@ -176,2 +168,3 @@ */ | ||
this._hooks = null; | ||
this._kernel = null; | ||
_super.prototype.dispose.call(this); | ||
@@ -200,2 +193,3 @@ }; | ||
} | ||
this._replyMsg = msg; | ||
this._setFlag(Private.KernelFutureFlag.GotReply); | ||
@@ -227,10 +221,7 @@ if (this._testFlag(Private.KernelFutureFlag.GotIdle)) { | ||
KernelFutureHandler.prototype._handleDone = function () { | ||
if (this.isDone) { | ||
if (this._testFlag(Private.KernelFutureFlag.IsDone)) { | ||
return; | ||
} | ||
this._setFlag(Private.KernelFutureFlag.IsDone); | ||
var done = this._done; | ||
if (done) | ||
done(); | ||
this._done = null; | ||
this._done.resolve(this._replyMsg); | ||
if (this._disposeOnDone) { | ||
@@ -237,0 +228,0 @@ this.dispose(); |
@@ -567,5 +567,7 @@ import { IIterator } from '@phosphor/algorithm'; | ||
/** | ||
* Whether the future is done. | ||
* A promise that resolves when the future is done. | ||
* | ||
* The contents of the promise is the reply message. | ||
*/ | ||
readonly isDone: boolean; | ||
readonly done: Promise<KernelMessage.IShellMessage>; | ||
/** | ||
@@ -584,6 +586,2 @@ * The reply handler for the kernel future. | ||
/** | ||
* The done handler for the kernel future. | ||
*/ | ||
onDone: () => void; | ||
/** | ||
* Register hook for IOPub messages. | ||
@@ -611,2 +609,6 @@ * | ||
removeMessageHook(hook: (msg: KernelMessage.IIOPubMessage) => boolean): void; | ||
/** | ||
* Send an `input_reply` message. | ||
*/ | ||
sendInputReply(content: KernelMessage.IInputReply): void; | ||
} | ||
@@ -613,0 +615,0 @@ /** |
@@ -481,2 +481,6 @@ import { nbformat } from '@jupyterlab/coreutils'; | ||
/** | ||
* Test whether a kernel message is an `'execute_reply'` message. | ||
*/ | ||
function isExecuteReplyMsg(msg: IMessage): msg is IExecuteReplyMsg; | ||
/** | ||
* An `'input_request'` message on the `'stdin'` channel. | ||
@@ -483,0 +487,0 @@ * |
@@ -115,2 +115,9 @@ "use strict"; | ||
KernelMessage.isCommMsgMsg = isCommMsgMsg; | ||
/** | ||
* Test whether a kernel message is an `'execute_reply'` message. | ||
*/ | ||
function isExecuteReplyMsg(msg) { | ||
return msg.header.msg_type === 'execute_reply'; | ||
} | ||
KernelMessage.isExecuteReplyMsg = isExecuteReplyMsg; | ||
; | ||
@@ -117,0 +124,0 @@ /** |
@@ -36,5 +36,5 @@ import { ISignal, Signal } from '@phosphor/signaling'; | ||
/** | ||
* A signal emitted when the session path changes. | ||
* A signal emitted when a session property changes. | ||
*/ | ||
readonly pathChanged: ISignal<this, string>; | ||
readonly propertyChanged: ISignal<this, 'path' | 'name' | 'type'>; | ||
/** | ||
@@ -58,2 +58,10 @@ * Get the session id. | ||
/** | ||
* Get the session type. | ||
*/ | ||
readonly type: string; | ||
/** | ||
* Get the session name. | ||
*/ | ||
readonly name: string; | ||
/** | ||
* Get the model associated with the session. | ||
@@ -94,2 +102,4 @@ */ | ||
* | ||
* @returns A promise that resolves when the session has renamed. | ||
* | ||
* #### Notes | ||
@@ -99,4 +109,12 @@ * This uses the Jupyter REST API, and the response is validated. | ||
*/ | ||
rename(path: string): Promise<void>; | ||
setPath(path: string): Promise<void>; | ||
/** | ||
* Change the session name. | ||
*/ | ||
setName(name: string): Promise<void>; | ||
/** | ||
* Change the session type. | ||
*/ | ||
setType(type: string): Promise<void>; | ||
/** | ||
* Change the kernel. | ||
@@ -141,4 +159,10 @@ * | ||
private _patch(data); | ||
/** | ||
* Handle a change to the model. | ||
*/ | ||
private _handleModelChange(oldModel); | ||
private _id; | ||
private _path; | ||
private _name; | ||
private _type; | ||
private _kernel; | ||
@@ -152,3 +176,3 @@ private _uuid; | ||
private _unhandledMessage; | ||
private _pathChanged; | ||
private _propertyChanged; | ||
} | ||
@@ -155,0 +179,0 @@ /** |
@@ -27,2 +27,4 @@ "use strict"; | ||
this._path = ''; | ||
this._name = ''; | ||
this._type = ''; | ||
this._kernel = null; | ||
@@ -36,5 +38,7 @@ this._uuid = ''; | ||
this._unhandledMessage = new signaling_1.Signal(this); | ||
this._pathChanged = new signaling_1.Signal(this); | ||
this._propertyChanged = new signaling_1.Signal(this); | ||
this._id = id; | ||
this._path = options.path; | ||
this._type = options.type; | ||
this._name = options.name; | ||
this.serverSettings = options.serverSettings || __1.ServerConnection.makeSettings(); | ||
@@ -86,8 +90,8 @@ this._uuid = coreutils_1.uuid(); | ||
}); | ||
Object.defineProperty(DefaultSession.prototype, "pathChanged", { | ||
Object.defineProperty(DefaultSession.prototype, "propertyChanged", { | ||
/** | ||
* A signal emitted when the session path changes. | ||
* A signal emitted when a session property changes. | ||
*/ | ||
get: function () { | ||
return this._pathChanged; | ||
return this._propertyChanged; | ||
}, | ||
@@ -132,2 +136,22 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(DefaultSession.prototype, "type", { | ||
/** | ||
* Get the session type. | ||
*/ | ||
get: function () { | ||
return this._type; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(DefaultSession.prototype, "name", { | ||
/** | ||
* Get the session name. | ||
*/ | ||
get: function () { | ||
return this._name; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(DefaultSession.prototype, "model", { | ||
@@ -141,5 +165,5 @@ /** | ||
kernel: this.kernel.model, | ||
notebook: { | ||
path: this.path | ||
} | ||
path: this._path, | ||
type: this._type, | ||
name: this._name | ||
}; | ||
@@ -194,4 +218,6 @@ }, | ||
} | ||
var oldPath = this._path; | ||
var newPath = this._path = model.notebook.path; | ||
var oldModel = this.model; | ||
this._path = model.path; | ||
this._name = model.name; | ||
this._type = model.type; | ||
if (this._kernel.isDisposed || model.kernel.id !== this._kernel.id) { | ||
@@ -201,10 +227,6 @@ return kernel_1.Kernel.connectTo(model.kernel.id, this.serverSettings).then(function (kernel) { | ||
_this._kernelChanged.emit(kernel); | ||
if (oldPath !== newPath) { | ||
_this._pathChanged.emit(newPath); | ||
} | ||
_this._handleModelChange(oldModel); | ||
}); | ||
} | ||
else if (oldPath !== newPath) { | ||
this._pathChanged.emit(newPath); | ||
} | ||
this._handleModelChange(oldModel); | ||
return Promise.resolve(void 0); | ||
@@ -232,2 +254,4 @@ }; | ||
* | ||
* @returns A promise that resolves when the session has renamed. | ||
* | ||
* #### Notes | ||
@@ -237,12 +261,30 @@ * This uses the Jupyter REST API, and the response is validated. | ||
*/ | ||
DefaultSession.prototype.rename = function (path) { | ||
DefaultSession.prototype.setPath = function (path) { | ||
if (this.isDisposed) { | ||
return Promise.reject(new Error('Session is disposed')); | ||
} | ||
var data = JSON.stringify({ | ||
notebook: { path: path } | ||
}); | ||
var data = JSON.stringify({ path: path }); | ||
return this._patch(data).then(function () { return void 0; }); | ||
}; | ||
/** | ||
* Change the session name. | ||
*/ | ||
DefaultSession.prototype.setName = function (name) { | ||
if (this.isDisposed) { | ||
return Promise.reject(new Error('Session is disposed')); | ||
} | ||
var data = JSON.stringify({ name: name }); | ||
return this._patch(data).then(function () { return void 0; }); | ||
}; | ||
/** | ||
* Change the session type. | ||
*/ | ||
DefaultSession.prototype.setType = function (type) { | ||
if (this.isDisposed) { | ||
return Promise.reject(new Error('Session is disposed')); | ||
} | ||
var data = JSON.stringify({ type: type }); | ||
return this._patch(data).then(function () { return void 0; }); | ||
}; | ||
/** | ||
* Change the kernel. | ||
@@ -280,11 +322,5 @@ * | ||
DefaultSession.prototype.shutdown = function () { | ||
var _this = this; | ||
if (this.isDisposed) { | ||
return Promise.reject(new Error('Session is disposed')); | ||
} | ||
if (this._kernel) { | ||
return this._kernel.ready.then(function () { | ||
return Private.shutdownSession(_this.id, _this.serverSettings); | ||
}); | ||
} | ||
return Private.shutdownSession(this.id, this.serverSettings); | ||
@@ -350,2 +386,16 @@ }; | ||
}; | ||
/** | ||
* Handle a change to the model. | ||
*/ | ||
DefaultSession.prototype._handleModelChange = function (oldModel) { | ||
if (oldModel.name !== this._name) { | ||
this._propertyChanged.emit('name'); | ||
} | ||
if (oldModel.type !== this._type) { | ||
this._propertyChanged.emit('type'); | ||
} | ||
if (oldModel.path !== this._path) { | ||
this._propertyChanged.emit('path'); | ||
} | ||
}; | ||
return DefaultSession; | ||
@@ -455,3 +505,5 @@ }()); | ||
return new DefaultSession({ | ||
path: model.notebook.path, | ||
path: model.path, | ||
type: model.type, | ||
name: model.name, | ||
serverSettings: settings | ||
@@ -492,3 +544,3 @@ }, model.id, kernel); | ||
var model = algorithm_1.find(models, function (value) { | ||
return value.notebook.path === path; | ||
return value.path === path; | ||
}); | ||
@@ -638,3 +690,5 @@ if (model) { | ||
kernel: { name: options.kernelName, id: options.kernelId }, | ||
notebook: { path: options.path } | ||
path: options.path, | ||
type: options.type || '', | ||
name: options.name || '' | ||
}; | ||
@@ -641,0 +695,0 @@ var request = { |
@@ -181,3 +181,3 @@ "use strict"; | ||
return session_1.Session.listRunning(this.serverSettings).then(function (sessions) { | ||
var matches = sessions.filter(function (value) { return value.notebook.path === path; }); | ||
var matches = sessions.filter(function (value) { return value.path === path; }); | ||
if (matches.length === 1) { | ||
@@ -244,3 +244,3 @@ var id = matches[0].id; | ||
}); | ||
session.pathChanged.connect(function () { | ||
session.propertyChanged.connect(function () { | ||
_this._onChanged(session.model); | ||
@@ -247,0 +247,0 @@ }); |
@@ -28,5 +28,5 @@ import { IIterator } from '@phosphor/algorithm'; | ||
/** | ||
* A signal emitted when the session path changes. | ||
* A signal emitted when a session property changes. | ||
*/ | ||
pathChanged: ISignal<ISession, string>; | ||
readonly propertyChanged: ISignal<this, 'path' | 'name' | 'type'>; | ||
/** | ||
@@ -45,6 +45,14 @@ * A signal emitted for iopub kernel messages. | ||
/** | ||
* The path associated with the session. | ||
* The current path associated with the sesssion. | ||
*/ | ||
readonly path: string; | ||
/** | ||
* The current name associated with the sesssion. | ||
*/ | ||
readonly name: string; | ||
/** | ||
* The type of the session. | ||
*/ | ||
readonly type: string; | ||
/** | ||
* The server settings of the session. | ||
@@ -82,4 +90,12 @@ */ | ||
*/ | ||
rename(path: string): Promise<void>; | ||
setPath(path: string): Promise<void>; | ||
/** | ||
* Change the session name. | ||
*/ | ||
setName(name: string): Promise<void>; | ||
/** | ||
* Change the session type. | ||
*/ | ||
setType(type: string): Promise<void>; | ||
/** | ||
* Change the kernel. | ||
@@ -224,2 +240,10 @@ * | ||
/** | ||
* The name of the session. | ||
*/ | ||
name?: string; | ||
/** | ||
* The type of the session. | ||
*/ | ||
type?: string; | ||
/** | ||
* The type of kernel (e.g. python3). | ||
@@ -372,8 +396,7 @@ */ | ||
readonly id: string; | ||
readonly notebook?: { | ||
[key: string]: string; | ||
path: string; | ||
}; | ||
readonly name: string; | ||
readonly path: string; | ||
readonly type: string; | ||
readonly kernel?: Kernel.IModel; | ||
} | ||
} |
@@ -37,7 +37,8 @@ "use strict"; | ||
validateProperty(model, 'id', 'string'); | ||
validateProperty(model, 'notebook', 'object'); | ||
validateProperty(model, 'path', 'string'); | ||
validateProperty(model, 'type', 'string'); | ||
validateProperty(model, 'name', 'string'); | ||
validateProperty(model, 'kernel', 'object'); | ||
validate_1.validateModel(model.kernel); | ||
validateProperty(model.notebook, 'path', 'string'); | ||
} | ||
exports.validateModel = validateModel; |
{ | ||
"name": "@jupyterlab/services", | ||
"version": "0.44.0", | ||
"version": "0.45.0", | ||
"description": "Client APIs for the Jupyter services REST APIs", | ||
@@ -8,3 +8,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@jupyterlab/coreutils": "^0.5.0", | ||
"@jupyterlab/coreutils": "^0.6.0", | ||
"@phosphor/algorithm": "^1.1.0", | ||
@@ -14,7 +14,3 @@ "@phosphor/coreutils": "^1.1.0", | ||
"@phosphor/signaling": "^1.2.0", | ||
"@types/minimist": "^1.2.0", | ||
"@types/text-encoding": "0.0.30", | ||
"minimist": "^1.2.0", | ||
"path-posix": "^1.0.0", | ||
"url-parse": "^1.1.8" | ||
"@types/text-encoding": "0.0.30" | ||
}, | ||
@@ -43,3 +39,3 @@ "devDependencies": { | ||
"test:integration": "cd test && python integration_test.py", | ||
"test:devtool": "devtool node_modules/.bin/_mocha -qc ttest/build/**/*.spec.js test/build/*.spec.js --jupyter-config-data=./test/config.json --timeout=50000", | ||
"test:devtool": "devtool node_modules/.bin/_mocha -qc test/build/**/*.spec.js test/build/*.spec.js --jupyter-config-data=./test/config.json --timeout=50000", | ||
"test:debug": "mocha test/build/**/*.spec.js test/build/*.spec.js --jupyter-config-data=./test/config.json --debug-brk", | ||
@@ -46,0 +42,0 @@ "test": "mocha --retries 3 test/build/**/*.spec.js test/build/*.spec.js --jupyter-config-data=./test/config.json" |
@@ -23,3 +23,3 @@ JupyterLab Services | ||
npm install --save @jupyterlab/services | ||
conda install notebook # notebook 4.2+ required | ||
conda install notebook # notebook 4.3+ required | ||
``` | ||
@@ -41,3 +41,3 @@ | ||
npm run build | ||
conda install notebook # notebook 4.2+ required | ||
conda install notebook # notebook 4.3+ required | ||
``` | ||
@@ -44,0 +44,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
367632
6
10566
+ Added@jupyterlab/coreutils@0.6.0(transitive)
- Removed@types/minimist@^1.2.0
- Removedminimist@^1.2.0
- Removedpath-posix@^1.0.0
- Removedurl-parse@^1.1.8
- Removed@jupyterlab/coreutils@0.5.0(transitive)
- Removed@types/minimist@1.2.5(transitive)
Updated@jupyterlab/coreutils@^0.6.0