jupyter-js-services
Advanced tools
Comparing version 0.6.6 to 0.7.1
@@ -32,3 +32,3 @@ import { IAjaxSettings } from 'jupyter-js-utils'; | ||
*/ | ||
export declare function getConfigSection(sectionName: string, baseUrl: string, ajaxSettings?: IAjaxSettings): Promise<IConfigSection>; | ||
export declare function getConfigSection(sectionName: string, baseUrl?: string, ajaxSettings?: IAjaxSettings): Promise<IConfigSection>; | ||
/** | ||
@@ -35,0 +35,0 @@ * Configurable object with defaults. |
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
"use strict"; | ||
var utils = require('jupyter-js-utils'); | ||
@@ -14,3 +15,2 @@ /** | ||
function getConfigSection(sectionName, baseUrl, ajaxSettings) { | ||
baseUrl = baseUrl || utils.getBaseUrl(); | ||
var section = new ConfigSection(sectionName, baseUrl, ajaxSettings); | ||
@@ -28,3 +28,3 @@ return section.load(); | ||
function ConfigSection(sectionName, baseUrl, ajaxSettings) { | ||
this._url = "unknown"; | ||
this._url = 'unknown'; | ||
this._data = {}; | ||
@@ -117,3 +117,3 @@ this._ajaxSettings = '{}'; | ||
return ConfigSection; | ||
})(); | ||
}()); | ||
/** | ||
@@ -129,3 +129,3 @@ * Configurable object with defaults. | ||
this._defaults = null; | ||
this._className = "unknown"; | ||
this._className = 'unknown'; | ||
this._section = section; | ||
@@ -179,3 +179,3 @@ this._defaults = defaults; | ||
return ConfigWithDefaults; | ||
})(); | ||
}()); | ||
exports.ConfigWithDefaults = ConfigWithDefaults; |
@@ -245,3 +245,3 @@ import { IAjaxSettings } from 'jupyter-js-utils'; | ||
*/ | ||
constructor(baseUrl: string, ajaxSettings?: IAjaxSettings); | ||
constructor(baseUrl?: string, ajaxSettings?: IAjaxSettings); | ||
/** | ||
@@ -248,0 +248,0 @@ * Get a copy of the default ajax settings for the contents manager. |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var utils = require('jupyter-js-utils'); | ||
@@ -21,3 +22,3 @@ var validate = require('./validate'); | ||
function ContentsManager(baseUrl, ajaxSettings) { | ||
this._apiUrl = "unknown"; | ||
this._apiUrl = 'unknown'; | ||
this._ajaxSettings = '{}'; | ||
@@ -367,3 +368,3 @@ baseUrl = baseUrl || utils.getBaseUrl(); | ||
return ContentsManager; | ||
})(); | ||
}()); | ||
exports.ContentsManager = ContentsManager; |
@@ -654,2 +654,6 @@ import { IDisposable } from 'phosphor-disposable'; | ||
/** | ||
* Find a kernel by id. | ||
*/ | ||
findById(id: string, options?: IKernelOptions): Promise<IKernelId>; | ||
/** | ||
* Connect to an existing kernel. | ||
@@ -656,0 +660,0 @@ */ |
@@ -8,3 +8,3 @@ // Copyright (c) Jupyter Development Team. | ||
function isStreamMessage(msg) { | ||
return msg.header.msg_type === "stream"; | ||
return msg.header.msg_type === 'stream'; | ||
} | ||
@@ -16,3 +16,3 @@ exports.isStreamMessage = isStreamMessage; | ||
function isDisplayDataMessage(msg) { | ||
return msg.header.msg_type === "display_data"; | ||
return msg.header.msg_type === 'display_data'; | ||
} | ||
@@ -24,3 +24,3 @@ exports.isDisplayDataMessage = isDisplayDataMessage; | ||
function isExecuteInputMessage(msg) { | ||
return msg.header.msg_type === "execute_input"; | ||
return msg.header.msg_type === 'execute_input'; | ||
} | ||
@@ -32,3 +32,3 @@ exports.isExecuteInputMessage = isExecuteInputMessage; | ||
function isExecuteResultMessage(msg) { | ||
return msg.header.msg_type === "execute_result"; | ||
return msg.header.msg_type === 'execute_result'; | ||
} | ||
@@ -40,3 +40,3 @@ exports.isExecuteResultMessage = isExecuteResultMessage; | ||
function isErrorMessage(msg) { | ||
return msg.header.msg_type === "error"; | ||
return msg.header.msg_type === 'error'; | ||
} | ||
@@ -48,3 +48,3 @@ exports.isErrorMessage = isErrorMessage; | ||
function isStatusMessage(msg) { | ||
return msg.header.msg_type === "status"; | ||
return msg.header.msg_type === 'status'; | ||
} | ||
@@ -56,3 +56,3 @@ exports.isStatusMessage = isStatusMessage; | ||
function isClearOutputMessage(msg) { | ||
return msg.header.msg_type === "clear_output"; | ||
return msg.header.msg_type === 'clear_output'; | ||
} | ||
@@ -64,3 +64,3 @@ exports.isClearOutputMessage = isClearOutputMessage; | ||
function isCommOpenMessage(msg) { | ||
return msg.header.msg_type === "comm_open"; | ||
return msg.header.msg_type === 'comm_open'; | ||
} | ||
@@ -67,0 +67,0 @@ exports.isCommOpenMessage = isCommOpenMessage; |
@@ -10,4 +10,3 @@ // Copyright (c) Jupyter Development Team. | ||
__export(require('./ikernel')); | ||
__export(require('./isession')); | ||
__export(require('./kernel')); | ||
__export(require('./session')); |
@@ -76,2 +76,10 @@ import { IDisposable } from 'phosphor-disposable'; | ||
/** | ||
* Find a session by id. | ||
*/ | ||
findById(id: string, options?: ISessionOptions): Promise<ISessionId>; | ||
/** | ||
* Find a session by notebook path. | ||
*/ | ||
findByPath(id: string, options?: ISessionOptions): Promise<ISessionId>; | ||
/** | ||
* Connect to a running notebook session. | ||
@@ -78,0 +86,0 @@ */ |
@@ -11,3 +11,3 @@ import { IKernel, IKernelId, IKernelManager, IKernelMessage, IKernelMessageOptions, IKernelOptions, IKernelSpecIds } from './ikernel'; | ||
*/ | ||
constructor(options: IKernelOptions); | ||
constructor(options?: IKernelOptions); | ||
/** | ||
@@ -32,2 +32,8 @@ * Get the kernel specs. See also [[getKernelSpecs]]. | ||
/** | ||
* Find a kernel by id. | ||
* | ||
* @param options - Overrides for the default options. | ||
*/ | ||
findById(id: string, options?: IKernelOptions): Promise<IKernelId>; | ||
/** | ||
* Connect to a running kernel. See also [[connectToKernel]]. | ||
@@ -45,2 +51,15 @@ * | ||
/** | ||
* Find a kernel by id. | ||
* | ||
* #### Notes | ||
* If the kernel was already started via `startNewKernel`, the existing | ||
* IKernel object is used as the fulfillment value. | ||
* | ||
* Otherwise, if `options` are given, we attempt to find to the existing | ||
* kernel. | ||
* The promise is fulfilled when the kernel is found, | ||
* otherwise the promise is rejected. | ||
*/ | ||
export declare function findKernelById(id: string, options?: IKernelOptions): Promise<IKernelId>; | ||
/** | ||
* Fetch the kernel specs. | ||
@@ -51,3 +70,3 @@ * | ||
*/ | ||
export declare function getKernelSpecs(options: IKernelOptions): Promise<IKernelSpecIds>; | ||
export declare function getKernelSpecs(options?: IKernelOptions): Promise<IKernelSpecIds>; | ||
/** | ||
@@ -61,3 +80,3 @@ * Fetch the running kernels. | ||
*/ | ||
export declare function listRunningKernels(options: IKernelOptions): Promise<IKernelId[]>; | ||
export declare function listRunningKernels(options?: IKernelOptions): Promise<IKernelId[]>; | ||
/** | ||
@@ -69,6 +88,9 @@ * Start a new kernel. | ||
* | ||
* If no options are given or the kernel name is not given, the | ||
* default kernel will by started by the server. | ||
* | ||
* Wraps the result in a Kernel object. The promise is fulfilled | ||
* when the kernel is started by the server, otherwise the promise is rejected. | ||
*/ | ||
export declare function startNewKernel(options: IKernelOptions): Promise<IKernel>; | ||
export declare function startNewKernel(options?: IKernelOptions): Promise<IKernel>; | ||
/** | ||
@@ -75,0 +97,0 @@ * Connect to a running kernel. |
@@ -24,6 +24,2 @@ // Copyright (c) Jupyter Development Team. | ||
/** | ||
* The error message to send when the kernel is not ready. | ||
*/ | ||
var KERNEL_NOT_READY_MSG = 'Kernel is not ready to send a message'; | ||
/** | ||
* An implementation of a kernel manager. | ||
@@ -39,3 +35,3 @@ */ | ||
this._options = null; | ||
this._options = utils.copy(options); | ||
this._options = utils.copy(options || {}); | ||
} | ||
@@ -67,2 +63,10 @@ /** | ||
/** | ||
* Find a kernel by id. | ||
* | ||
* @param options - Overrides for the default options. | ||
*/ | ||
KernelManager.prototype.findById = function (id, options) { | ||
return findKernelById(id, this._getOptions(options)); | ||
}; | ||
/** | ||
* Connect to a running kernel. See also [[connectToKernel]]. | ||
@@ -94,5 +98,31 @@ * | ||
return KernelManager; | ||
})(); | ||
}()); | ||
exports.KernelManager = KernelManager; | ||
/** | ||
* Find a kernel by id. | ||
* | ||
* #### Notes | ||
* If the kernel was already started via `startNewKernel`, the existing | ||
* IKernel object is used as the fulfillment value. | ||
* | ||
* Otherwise, if `options` are given, we attempt to find to the existing | ||
* kernel. | ||
* The promise is fulfilled when the kernel is found, | ||
* otherwise the promise is rejected. | ||
*/ | ||
function findKernelById(id, options) { | ||
var kernels = Private.runningKernels; | ||
for (var kernelId in kernels) { | ||
var kernel = kernels[kernelId]; | ||
if (kernelId === id) { | ||
var result = { id: kernel.id, name: kernel.name }; | ||
return Promise.resolve(result); | ||
} | ||
} | ||
return Private.getKernelId(id, options).catch(function () { | ||
return Private.typedThrow("No running kernel with id: " + id); | ||
}); | ||
} | ||
exports.findKernelById = findKernelById; | ||
/** | ||
* Fetch the kernel specs. | ||
@@ -104,2 +134,3 @@ * | ||
function getKernelSpecs(options) { | ||
options = options || {}; | ||
var baseUrl = options.baseUrl || utils.getBaseUrl(); | ||
@@ -144,2 +175,3 @@ var url = utils.urlPathJoin(baseUrl, KERNELSPEC_SERVICE_URL); | ||
function listRunningKernels(options) { | ||
options = options || {}; | ||
var baseUrl = options.baseUrl || utils.getBaseUrl(); | ||
@@ -171,2 +203,5 @@ var url = utils.urlPathJoin(baseUrl, KERNEL_SERVICE_URL); | ||
* | ||
* If no options are given or the kernel name is not given, the | ||
* default kernel will by started by the server. | ||
* | ||
* Wraps the result in a Kernel object. The promise is fulfilled | ||
@@ -176,2 +211,3 @@ * when the kernel is started by the server, otherwise the promise is rejected. | ||
function startNewKernel(options) { | ||
options = options || {}; | ||
var baseUrl = options.baseUrl || utils.getBaseUrl(); | ||
@@ -209,15 +245,10 @@ var url = utils.urlPathJoin(baseUrl, KERNEL_SERVICE_URL); | ||
function connectToKernel(id, options) { | ||
var kernel = Private.runningKernels.get(id); | ||
var kernel = Private.runningKernels[id]; | ||
if (kernel) { | ||
return Promise.resolve(kernel); | ||
} | ||
if (options === void 0) { | ||
return Promise.reject(new Error('Please specify kernel options')); | ||
} | ||
options.baseUrl = options.baseUrl || utils.getBaseUrl(); | ||
return listRunningKernels(options).then(function (kernelIds) { | ||
if (!kernelIds.some(function (k) { return k.id === id; })) { | ||
throw new Error('No running kernel with id: ' + id); | ||
} | ||
return Private.getKernelId(id, options).then(function (kernelId) { | ||
return new Kernel(options, id); | ||
}).catch(function () { | ||
return Private.typedThrow("No running kernel with id: " + id); | ||
}); | ||
@@ -286,3 +317,3 @@ } | ||
this._createSocket(); | ||
Private.runningKernels.set(this._id, this); | ||
Private.runningKernels[this._id] = this; | ||
} | ||
@@ -411,3 +442,3 @@ Object.defineProperty(Kernel.prototype, "statusChanged", { | ||
this._status = ikernel_1.KernelStatus.Dead; | ||
if (this._ws != null) { | ||
if (this._ws !== null) { | ||
this._ws.close(); | ||
@@ -428,3 +459,3 @@ } | ||
phosphor_signaling_1.clearSignalData(this); | ||
Private.runningKernels.delete(this._id); | ||
delete Private.runningKernels[this._id]; | ||
}; | ||
@@ -830,3 +861,3 @@ /** | ||
var timeout = Math.pow(2, this._reconnectAttempt); | ||
console.error("Connection lost, reconnecting in " + timeout + " seconds."); | ||
console.error('Connection lost, reconnecting in ' + timeout + ' seconds.'); | ||
setTimeout(this._createSocket.bind(this), 1e3 * timeout); | ||
@@ -921,11 +952,10 @@ this._reconnectAttempt += 1; | ||
var content = msg.content; | ||
var targetName = content.target_name; | ||
var promise = utils.loadClass(content.target_name, content.target_module, this._targetRegistry).then(function (target) { | ||
var comm = new Comm(content.target_name, content.comm_id, _this._sendCommMessage.bind(_this), function () { _this._unregisterComm(content.comm_id); }); | ||
try { | ||
var response = target(comm, msg); | ||
target(comm, msg); | ||
} | ||
catch (e) { | ||
comm.close(); | ||
console.error("Exception opening new comm"); | ||
console.error('Exception opening new comm'); | ||
throw (e); | ||
@@ -967,3 +997,3 @@ } | ||
catch (e) { | ||
console.error("Exception closing comm: ", e, e.stack, msg); | ||
console.error('Exception closing comm: ', e, e.stack, msg); | ||
} | ||
@@ -1002,3 +1032,3 @@ }); | ||
catch (e) { | ||
console.error("Exception handling comm msg: ", e, e.stack, msg); | ||
console.error('Exception handling comm msg: ', e, e.stack, msg); | ||
} | ||
@@ -1031,3 +1061,3 @@ return comm; | ||
return Kernel; | ||
})(); | ||
}()); | ||
/** | ||
@@ -1049,3 +1079,3 @@ * A private namespace for the Kernel. | ||
*/ | ||
Private.runningKernels = new Map(); | ||
Private.runningKernels = Object.create(null); | ||
/** | ||
@@ -1110,6 +1140,27 @@ * Restart a kernel. | ||
/** | ||
* Get a full kernel id model from the server by kernel id string. | ||
*/ | ||
function getKernelId(id, options) { | ||
options = options || {}; | ||
var baseUrl = options.baseUrl || utils.getBaseUrl(); | ||
var url = utils.urlPathJoin(baseUrl, KERNEL_SERVICE_URL, id); | ||
var ajaxSettings = options.ajaxSettings || {}; | ||
ajaxSettings.method = 'GET'; | ||
ajaxSettings.dataType = 'json'; | ||
ajaxSettings.cache = false; | ||
return utils.ajaxRequest(url, ajaxSettings).then(function (success) { | ||
if (success.xhr.status !== 200) { | ||
throw Error('Invalid Status: ' + success.xhr.status); | ||
} | ||
var data = success.data; | ||
validate.validateKernelId(data); | ||
return data; | ||
}, Private.onKernelError); | ||
} | ||
Private.getKernelId = getKernelId; | ||
/** | ||
* Log the current kernel status. | ||
*/ | ||
function logKernelStatus(kernel) { | ||
if (kernel.status == ikernel_1.KernelStatus.Idle || | ||
if (kernel.status === ikernel_1.KernelStatus.Idle || | ||
kernel.status === ikernel_1.KernelStatus.Busy || | ||
@@ -1138,3 +1189,3 @@ kernel.status === ikernel_1.KernelStatus.Unknown) { | ||
function onKernelError(error) { | ||
console.error("API request failed (" + error.statusText + "): "); | ||
console.error('API request failed (' + error.statusText + '): '); | ||
throw Error(error.statusText); | ||
@@ -1171,2 +1222,9 @@ } | ||
var KernelFutureFlag = Private.KernelFutureFlag; | ||
/** | ||
* Throw a typed error. | ||
*/ | ||
function typedThrow(msg) { | ||
throw new Error(msg); | ||
} | ||
Private.typedThrow = typedThrow; | ||
})(Private || (Private = {})); | ||
@@ -1358,10 +1416,4 @@ /** | ||
}; | ||
/** | ||
* Clear the given future flag. | ||
*/ | ||
KernelFutureHandler.prototype._clearFlag = function (flag) { | ||
this._status &= ~flag; | ||
}; | ||
return KernelFutureHandler; | ||
})(phosphor_disposable_1.DisposableDelegate); | ||
}(phosphor_disposable_1.DisposableDelegate)); | ||
/** | ||
@@ -1515,3 +1567,3 @@ * Comm channel handler. | ||
metadata: metadata, | ||
buffers: buffers, | ||
buffers: buffers | ||
}; | ||
@@ -1560,2 +1612,2 @@ if (this._msgFunc === void 0) { | ||
return Comm; | ||
})(phosphor_disposable_1.DisposableDelegate); | ||
}(phosphor_disposable_1.DisposableDelegate)); |
@@ -12,3 +12,3 @@ // Copyright (c) Jupyter Development Team. | ||
var value; | ||
if (typeof data === "string") { | ||
if (typeof data === 'string') { | ||
value = JSON.parse(data); | ||
@@ -49,3 +49,3 @@ } | ||
if (nbufs < 2) { | ||
throw new Error("Invalid incoming Kernel Message"); | ||
throw new Error('Invalid incoming Kernel Message'); | ||
} | ||
@@ -107,3 +107,3 @@ for (var i = 1; i <= nbufs; i++) { | ||
function replace_buffers(key, value) { | ||
if (key === "buffers") { | ||
if (key === 'buffers') { | ||
return undefined; | ||
@@ -110,0 +110,0 @@ } |
@@ -12,3 +12,3 @@ import { IKernelSpecIds } from './ikernel'; | ||
*/ | ||
constructor(options: ISessionOptions); | ||
constructor(options?: ISessionOptions); | ||
/** | ||
@@ -34,6 +34,9 @@ * Get the available kernel specs. See also [[getKernelSpecs]]. | ||
/** | ||
* Connect to a running session. See also [[connectToSession]]. | ||
* | ||
* @param options - Overrides for the default options. | ||
* Find a session by id. | ||
*/ | ||
findById(id: string, options?: ISessionOptions): Promise<ISessionId>; | ||
/** | ||
* Find a session by notebook path. | ||
*/ | ||
findByPath(path: string, options?: ISessionOptions): Promise<ISessionId>; | ||
connectTo(id: string, options?: ISessionOptions): Promise<INotebookSession>; | ||
@@ -54,3 +57,3 @@ /** | ||
*/ | ||
export declare function listRunningSessions(options: ISessionOptions): Promise<ISessionId[]>; | ||
export declare function listRunningSessions(options?: ISessionOptions): Promise<ISessionId[]>; | ||
/** | ||
@@ -62,2 +65,6 @@ * Start a new session. | ||
* | ||
* A notebook path must be provided. If a kernel id is given, it will | ||
* connect to an existing kernel. If no kernel id or name is given, | ||
* the server will start the default kernel type. | ||
* | ||
* The promise is fulfilled on a valid response and rejected otherwise. | ||
@@ -71,2 +78,31 @@ | ||
/** | ||
* Find a session by id. | ||
* | ||
* #### Notes | ||
* If the session was already started via `startNewSession`, the existing | ||
* NotebookSession object is used as the fulfillment value. | ||
* | ||
* Otherwise, if `options` are given, we attempt to find to the existing | ||
* session. | ||
* The promise is fulfilled when the session is found, | ||
* otherwise the promise is rejected. | ||
*/ | ||
export declare function findSessionById(id: string, options?: ISessionOptions): Promise<ISessionId>; | ||
/** | ||
* Find a session by notebook path. | ||
* | ||
* #### Notes | ||
* If the session was already started via `startNewSession`, the existing | ||
* NotebookSession object is used as the fulfillment value. | ||
* | ||
* Otherwise, if `options` are given, we attempt to find to the existing | ||
* session using [listRunningSessions]. | ||
* The promise is fulfilled when the session is found, | ||
* otherwise the promise is rejected. | ||
* | ||
* If the session was not already started and no `options` are given, | ||
* the promise is rejected. | ||
*/ | ||
export declare function findSessionByPath(path: string, options?: ISessionOptions): Promise<ISessionId>; | ||
/** | ||
* Connect to a running notebook session. | ||
@@ -79,3 +115,3 @@ * | ||
* Otherwise, if `options` are given, we attempt to connect to the existing | ||
* session found by calling `listRunningSessions`. | ||
* session. | ||
* The promise is fulfilled when the session is ready on the server, | ||
@@ -82,0 +118,0 @@ * otherwise the promise is rejected. |
@@ -23,3 +23,3 @@ // Copyright (c) Jupyter Development Team. | ||
this._options = null; | ||
this._options = utils.copy(options); | ||
this._options = utils.copy(options || {}); | ||
} | ||
@@ -52,14 +52,18 @@ /** | ||
/** | ||
* Find a session by id. | ||
*/ | ||
NotebookSessionManager.prototype.findById = function (id, options) { | ||
return findSessionById(id, this._getOptions(options)); | ||
}; | ||
/** | ||
* Find a session by notebook path. | ||
*/ | ||
NotebookSessionManager.prototype.findByPath = function (path, options) { | ||
return findSessionByPath(path, this._getOptions(options)); | ||
}; | ||
/* | ||
* Connect to a running session. See also [[connectToSession]]. | ||
* | ||
* @param options - Overrides for the default options. | ||
*/ | ||
NotebookSessionManager.prototype.connectTo = function (id, options) { | ||
if (options) { | ||
options = this._getOptions(options); | ||
} | ||
else { | ||
options = utils.copy(this._options); | ||
} | ||
return connectToSession(id, options); | ||
return connectToSession(id, this._getOptions(options)); | ||
}; | ||
@@ -79,3 +83,3 @@ /** | ||
return NotebookSessionManager; | ||
})(); | ||
}()); | ||
exports.NotebookSessionManager = NotebookSessionManager; | ||
@@ -91,4 +95,5 @@ /** | ||
function listRunningSessions(options) { | ||
options = options || {}; | ||
var baseUrl = options.baseUrl || utils.getBaseUrl(); | ||
var url = utils.urlPathJoin(options.baseUrl, SESSION_SERVICE_URL); | ||
var url = utils.urlPathJoin(baseUrl, SESSION_SERVICE_URL); | ||
var ajaxSettings = utils.copy(options.ajaxSettings) || {}; | ||
@@ -118,2 +123,6 @@ ajaxSettings.method = 'GET'; | ||
* | ||
* A notebook path must be provided. If a kernel id is given, it will | ||
* connect to an existing kernel. If no kernel id or name is given, | ||
* the server will start the default kernel type. | ||
* | ||
* The promise is fulfilled on a valid response and rejected otherwise. | ||
@@ -126,2 +135,5 @@ | ||
function startNewSession(options) { | ||
if (options.notebookPath === void 0) { | ||
return Promise.reject(new Error('Must specify a notebook path')); | ||
} | ||
return Private.startSession(options).then(function (sessionId) { | ||
@@ -133,2 +145,73 @@ return Private.createSession(sessionId, options); | ||
/** | ||
* Find a session by id. | ||
* | ||
* #### Notes | ||
* If the session was already started via `startNewSession`, the existing | ||
* NotebookSession object is used as the fulfillment value. | ||
* | ||
* Otherwise, if `options` are given, we attempt to find to the existing | ||
* session. | ||
* The promise is fulfilled when the session is found, | ||
* otherwise the promise is rejected. | ||
*/ | ||
function findSessionById(id, options) { | ||
var sessions = Private.runningSessions; | ||
for (var sessionId in sessions) { | ||
var session = sessions[sessionId]; | ||
if (sessionId === id) { | ||
var sessionId_1 = { | ||
id: id, | ||
notebook: { path: session.notebookPath }, | ||
kernel: { name: session.kernel.name, id: session.kernel.id } | ||
}; | ||
return Promise.resolve(sessionId_1); | ||
} | ||
} | ||
return Private.getSessionId(id, options).catch(function () { | ||
var msg = "No running session for id: " + id; | ||
return Private.typedThrow(msg); | ||
}); | ||
} | ||
exports.findSessionById = findSessionById; | ||
/** | ||
* Find a session by notebook path. | ||
* | ||
* #### Notes | ||
* If the session was already started via `startNewSession`, the existing | ||
* NotebookSession object is used as the fulfillment value. | ||
* | ||
* Otherwise, if `options` are given, we attempt to find to the existing | ||
* session using [listRunningSessions]. | ||
* The promise is fulfilled when the session is found, | ||
* otherwise the promise is rejected. | ||
* | ||
* If the session was not already started and no `options` are given, | ||
* the promise is rejected. | ||
*/ | ||
function findSessionByPath(path, options) { | ||
var sessions = Private.runningSessions; | ||
for (var id in sessions) { | ||
var session = sessions[id]; | ||
if (session.notebookPath === path) { | ||
var sessionId = { | ||
id: id, | ||
notebook: { path: session.notebookPath }, | ||
kernel: { name: session.kernel.name, id: session.kernel.id } | ||
}; | ||
return Promise.resolve(sessionId); | ||
} | ||
} | ||
return listRunningSessions(options).then(function (sessionIds) { | ||
for (var _i = 0, sessionIds_1 = sessionIds; _i < sessionIds_1.length; _i++) { | ||
var sessionId = sessionIds_1[_i]; | ||
if (sessionId.notebook.path === path) { | ||
return sessionId; | ||
} | ||
} | ||
var msg = "No running session for path: " + path; | ||
return Private.typedThrow(msg); | ||
}); | ||
} | ||
exports.findSessionByPath = findSessionByPath; | ||
/** | ||
* Connect to a running notebook session. | ||
@@ -141,3 +224,3 @@ * | ||
* Otherwise, if `options` are given, we attempt to connect to the existing | ||
* session found by calling `listRunningSessions`. | ||
* session. | ||
* The promise is fulfilled when the session is ready on the server, | ||
@@ -150,15 +233,11 @@ * otherwise the promise is rejected. | ||
function connectToSession(id, options) { | ||
var session = Private.runningSessions.get(id); | ||
var session = Private.runningSessions[id]; | ||
if (session) { | ||
return Promise.resolve(session); | ||
} | ||
if (options === void 0) { | ||
return Promise.reject(new Error('Please specify session options')); | ||
} | ||
return listRunningSessions(options).then(function (sessionIds) { | ||
sessionIds = sessionIds.filter(function (k) { return k.id === id; }); | ||
if (!sessionIds.length) { | ||
return Private.typedThrow('No running session with id: ' + id); | ||
} | ||
return Private.createSession(sessionIds[0], options); | ||
return Private.getSessionId(id, options).then(function (sessionId) { | ||
return Private.createSession(sessionId, options); | ||
}).catch(function () { | ||
var msg = "No running session with id: " + id; | ||
return Private.typedThrow(msg); | ||
}); | ||
@@ -187,3 +266,4 @@ } | ||
this._kernel = kernel; | ||
this._url = utils.urlPathJoin(options.baseUrl, SESSION_SERVICE_URL, this._id); | ||
var baseUrl = options.baseUrl || utils.getBaseUrl(); | ||
this._url = utils.urlPathJoin(baseUrl, SESSION_SERVICE_URL, this._id); | ||
this._kernel.statusChanged.connect(this.onKernelStatus, this); | ||
@@ -324,3 +404,3 @@ this._kernel.unhandledMessage.connect(this.onUnhandledMessage, this); | ||
phosphor_signaling_1.clearSignalData(this); | ||
Private.runningSessions.delete(this._id); | ||
delete Private.runningSessions[this._id]; | ||
}; | ||
@@ -444,3 +524,3 @@ /** | ||
return NotebookSession; | ||
})(); | ||
}()); | ||
/** | ||
@@ -470,3 +550,3 @@ * A namespace for notebook session private data. | ||
*/ | ||
Private.runningSessions = new Map(); | ||
Private.runningSessions = Object.create(null); | ||
/** | ||
@@ -521,3 +601,3 @@ * Create a new session, or return an existing session if a session if | ||
var session = new NotebookSession(options, sessionId.id, kernel); | ||
Private.runningSessions.set(session.id, session); | ||
Private.runningSessions[session.id] = session; | ||
return session; | ||
@@ -530,2 +610,23 @@ }).catch(function (error) { | ||
/** | ||
* Get a full session id model from the server by session id string. | ||
*/ | ||
function getSessionId(id, options) { | ||
options = options || {}; | ||
var baseUrl = options.baseUrl || utils.getBaseUrl(); | ||
var url = utils.urlPathJoin(baseUrl, SESSION_SERVICE_URL, id); | ||
var ajaxSettings = options.ajaxSettings || {}; | ||
ajaxSettings.method = 'GET'; | ||
ajaxSettings.dataType = 'json'; | ||
ajaxSettings.cache = false; | ||
return utils.ajaxRequest(url, ajaxSettings).then(function (success) { | ||
if (success.xhr.status !== 200) { | ||
throw Error('Invalid Status: ' + success.xhr.status); | ||
} | ||
var data = success.data; | ||
validate.validateSessionId(data); | ||
return data; | ||
}, Private.onSessionError); | ||
} | ||
Private.getSessionId = getSessionId; | ||
/** | ||
* Handle an error on a session Ajax call. | ||
@@ -532,0 +633,0 @@ */ |
@@ -107,3 +107,2 @@ // Copyright (c) Jupyter Development Team. | ||
} | ||
var content = msg.content; | ||
var names = Object.keys(fields); | ||
@@ -162,3 +161,3 @@ for (var i = 0; i < names.length; i++) { | ||
function validateKernelSpec(info) { | ||
var err = new Error("Invalid KernelSpec Model"); | ||
var err = new Error('Invalid KernelSpec Model'); | ||
if (!info.hasOwnProperty('name') || typeof info.name !== 'string') { | ||
@@ -165,0 +164,0 @@ throw err; |
{ | ||
"name": "jupyter-js-services", | ||
"version": "0.6.6", | ||
"version": "0.7.1", | ||
"description": "Client APIs for the Jupyter services REST APIs", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
174781
4919