Socket
Socket
Sign inDemoInstall

@jupyterlab/services

Package Overview
Dependencies
Maintainers
3
Versions
387
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jupyterlab/services - npm Package Compare versions

Comparing version 0.26.0 to 0.27.0

lib/terminal/default.d.ts

8

lib/contents/index.d.ts

@@ -144,2 +144,6 @@ import { JSONObject } from 'phosphor/lib/algorithm/json';

/**
* The base url of the manager.
*/
readonly baseUrl: string;
/**
* A signal emitted when a file operation takes place.

@@ -283,2 +287,6 @@ */

/**
* Get the base url of the manager.
*/
readonly baseUrl: string;
/**
* Get a copy of the default ajax settings for the contents manager.

@@ -285,0 +293,0 @@ */

@@ -56,2 +56,12 @@ // Copyright (c) Jupyter Development Team.

};
Object.defineProperty(ContentsManager.prototype, "baseUrl", {
/**
* Get the base url of the manager.
*/
get: function () {
return this._baseUrl;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ContentsManager.prototype, "ajaxSettings", {

@@ -58,0 +68,0 @@ /**

50

lib/kernel/default.d.ts

@@ -15,2 +15,6 @@ import { IDisposable } from 'phosphor/lib/core/disposable';

/**
* A signal emitted when the kernel is shut down.
*/
terminated: ISignal<Kernel.IKernel, void>;
/**
* A signal emitted when the kernel status changes.

@@ -52,18 +56,6 @@ */

/**
* The cached info for the kernel.
*
* #### Notes
* If `null`, call [[kernelInfo]] to get the value,
* which will populate this value.
* The base url of the kernel.
*/
readonly info: KernelMessage.IInfoReply;
readonly baseUrl: string;
/**
* The cached specs for the kernel.
*
* #### Notes
* If `null`, call [[Kernel.getSpecs]] to get the value,
* which will populate this value.
*/
readonly spec: Kernel.ISpecModel;
/**
* Get a copy of the default ajax settings for the kernel.

@@ -80,2 +72,10 @@ */

/**
* A promise that resolves with a cached kernel info.
*/
info(): Promise<KernelMessage.IInfoReply>;
/**
* A promise that resolves with a cached kernel spec.
*/
spec(): Promise<Kernel.ISpecModel>;
/**
* Clone the current kernel with a new clientId.

@@ -168,3 +168,3 @@ */

*/
kernelInfo(): Promise<KernelMessage.IInfoReplyMsg>;
requestKernelInfo(): Promise<KernelMessage.IInfoReplyMsg>;
/**

@@ -179,3 +179,3 @@ * Send a `complete_request` message.

*/
complete(content: KernelMessage.ICompleteRequest): Promise<KernelMessage.ICompleteReplyMsg>;
requestComplete(content: KernelMessage.ICompleteRequest): Promise<KernelMessage.ICompleteReplyMsg>;
/**

@@ -190,3 +190,3 @@ * Send an `inspect_request` message.

*/
inspect(content: KernelMessage.IInspectRequest): Promise<KernelMessage.IInspectReplyMsg>;
requestInspect(content: KernelMessage.IInspectRequest): Promise<KernelMessage.IInspectReplyMsg>;
/**

@@ -201,3 +201,3 @@ * Send a `history_request` message.

*/
history(content: KernelMessage.IHistoryRequest): Promise<KernelMessage.IHistoryReplyMsg>;
requestHistory(content: KernelMessage.IHistoryRequest): Promise<KernelMessage.IHistoryReplyMsg>;
/**

@@ -218,3 +218,3 @@ * Send an `execute_request` message.

*/
execute(content: KernelMessage.IExecuteRequest, disposeOnDone?: boolean): Kernel.IFuture;
requestExecute(content: KernelMessage.IExecuteRequest, disposeOnDone?: boolean): Kernel.IFuture;
/**

@@ -229,3 +229,3 @@ * Send an `is_complete_request` message.

*/
isComplete(content: KernelMessage.IIsCompleteRequest): Promise<KernelMessage.IIsCompleteReplyMsg>;
requestIsComplete(content: KernelMessage.IIsCompleteRequest): Promise<KernelMessage.IIsCompleteReplyMsg>;
/**

@@ -238,3 +238,3 @@ * Send a `comm_info_request` message.

*/
commInfo(content: KernelMessage.ICommInfoRequest): Promise<KernelMessage.ICommInfoReplyMsg>;
requestCommInfo(content: KernelMessage.ICommInfoRequest): Promise<KernelMessage.ICommInfoReplyMsg>;
/**

@@ -290,9 +290,2 @@ * Send an `input_reply` message.

/**
* Get the kernel spec associated with the kernel.
*
* #### Notes
* This value is cached and only fetched the first time it is requested.
*/
getSpec(): Promise<Kernel.ISpecModel>;
/**
* Create the kernel websocket connection and add socket status handlers.

@@ -357,3 +350,2 @@ */

private _targetRegistry;
private _spec;
private _info;

@@ -360,0 +352,0 @@ private _pendingMessages;

@@ -47,7 +47,5 @@ // Copyright (c) Jupyter Development Team.

this._targetRegistry = Object.create(null);
this._spec = null;
this._info = null;
this._pendingMessages = [];
this._connectionPromise = null;
this.ajaxSettings = options.ajaxSettings || {};
this._name = options.name;

@@ -57,2 +55,3 @@ this._id = id;

this._wsUrl = options.wsUrl || utils.getWsUrl(this._baseUrl);
this._ajaxSettings = JSON.stringify(options.ajaxSettings || {});
this._clientId = options.clientId || utils.uuid();

@@ -126,12 +125,8 @@ this._username = options.username || '';

});
Object.defineProperty(DefaultKernel.prototype, "info", {
Object.defineProperty(DefaultKernel.prototype, "baseUrl", {
/**
* The cached info for the kernel.
*
* #### Notes
* If `null`, call [[kernelInfo]] to get the value,
* which will populate this value.
* The base url of the kernel.
*/
get: function () {
return this._info;
return this._baseUrl;
},

@@ -141,16 +136,2 @@ enumerable: true,

});
Object.defineProperty(DefaultKernel.prototype, "spec", {
/**
* The cached specs for the kernel.
*
* #### Notes
* If `null`, call [[Kernel.getSpecs]] to get the value,
* which will populate this value.
*/
get: function () {
return this._spec;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DefaultKernel.prototype, "ajaxSettings", {

@@ -183,2 +164,31 @@ /**

/**
* A promise that resolves with a cached kernel info.
*/
DefaultKernel.prototype.info = function () {
var _this = this;
if (this._info) {
return Promise.resolve(this._info);
}
return this._connectionPromise.promise.then(function () {
return _this._info;
});
};
/**
* A promise that resolves with a cached kernel spec.
*/
DefaultKernel.prototype.spec = function () {
var _this = this;
var promise = Private.specs[this._baseUrl];
if (promise) {
return promise.then(function (specs) { return specs.kernelspecs[_this._name]; });
}
var options = {
baseUrl: this._baseUrl,
ajaxSettings: this.ajaxSettings
};
return Private.getSpecs(options).then(function (value) {
return value.kernelspecs[_this._name];
});
};
/**
* Clone the current kernel with a new clientId.

@@ -203,3 +213,2 @@ */

}
signaling_1.clearSignalData(this);
this._status = 'dead';

@@ -221,2 +230,3 @@ if (this._ws !== null) {

Private.runningKernels.remove(this);
signaling_1.clearSignalData(this);
};

@@ -347,3 +357,3 @@ /**

*/
DefaultKernel.prototype.kernelInfo = function () {
DefaultKernel.prototype.requestKernelInfo = function () {
var _this = this;

@@ -371,3 +381,3 @@ var options = {

*/
DefaultKernel.prototype.complete = function (content) {
DefaultKernel.prototype.requestComplete = function (content) {
var options = {

@@ -391,3 +401,3 @@ msgType: 'complete_request',

*/
DefaultKernel.prototype.inspect = function (content) {
DefaultKernel.prototype.requestInspect = function (content) {
var options = {

@@ -411,3 +421,3 @@ msgType: 'inspect_request',

*/
DefaultKernel.prototype.history = function (content) {
DefaultKernel.prototype.requestHistory = function (content) {
var options = {

@@ -437,3 +447,3 @@ msgType: 'history_request',

*/
DefaultKernel.prototype.execute = function (content, disposeOnDone) {
DefaultKernel.prototype.requestExecute = function (content, disposeOnDone) {
if (disposeOnDone === void 0) { disposeOnDone = true; }

@@ -466,3 +476,3 @@ var options = {

*/
DefaultKernel.prototype.isComplete = function (content) {
DefaultKernel.prototype.requestIsComplete = function (content) {
var options = {

@@ -484,3 +494,3 @@ msgType: 'is_complete_request',

*/
DefaultKernel.prototype.commInfo = function (content) {
DefaultKernel.prototype.requestCommInfo = function (content) {
var options = {

@@ -593,16 +603,2 @@ msgType: 'comm_info_request',

/**
* Get the kernel spec associated with the kernel.
*
* #### Notes
* This value is cached and only fetched the first time it is requested.
*/
DefaultKernel.prototype.getSpec = function () {
var _this = this;
return Private.getSpec(this, this._baseUrl, this.ajaxSettings)
.then(function (specs) {
_this._spec = specs;
return specs;
});
};
/**
* Create the kernel websocket connection and add socket status handlers.

@@ -636,3 +632,3 @@ */

// Get the kernel info, signaling that the kernel is ready.
this.kernelInfo().then(function () {
this.requestKernelInfo().then(function () {
_this._connectionPromise.resolve(void 0);

@@ -874,2 +870,3 @@ }).catch(function (err) {

// Define the signals for the `DefaultKernel` class.
signaling_1.defineSignal(DefaultKernel.prototype, 'terminated');
signaling_1.defineSignal(DefaultKernel.prototype, 'statusChanged');

@@ -978,2 +975,6 @@ signaling_1.defineSignal(DefaultKernel.prototype, 'iopubMessage');

/**
* A module private store of kernel specs by base url.
*/
Private.specs = Object.create(null);
/**
* Find a kernel by id.

@@ -1006,3 +1007,3 @@ */

ajaxSettings.dataType = 'json';
return utils.ajaxRequest(url, ajaxSettings).then(function (success) {
var promise = utils.ajaxRequest(url, ajaxSettings).then(function (success) {
if (success.xhr.status !== 200) {

@@ -1018,2 +1019,4 @@ return utils.makeAjaxError(success);

});
Private.specs[baseUrl] = promise;
return promise;
}

@@ -1052,3 +1055,3 @@ Private.getSpecs = getSpecs;

}
return success.data;
return updateRunningKernels(success.data);
}, onKernelError);

@@ -1058,2 +1061,21 @@ }

/**
* Update the running kernels based on new data from the server.
*/
function updateRunningKernels(kernels) {
iteration_1.each(Private.runningKernels, function (kernel) {
var updated = searching_1.find(kernels, function (model) {
if (kernel.id === model.id) {
return true;
}
});
// If kernel is no longer running on disk, emit dead signal.
if (!updated && kernel.status !== 'dead') {
kernel.terminated.emit(void 0);
kernel.dispose();
}
});
return kernels;
}
Private.updateRunningKernels = updateRunningKernels;
/**
* Start a new kernel.

@@ -1181,2 +1203,3 @@ */

if (kernel.id === id) {
kernel.terminated.emit(void 0);
kernel.dispose();

@@ -1189,23 +1212,2 @@ }

/**
* Get the kernelspec for a kernel.
*/
function getSpec(kernel, baseUrl, ajaxSettings) {
var url = utils.urlPathJoin(baseUrl, KERNELSPEC_SERVICE_URL, encodeURIComponent(kernel.name));
ajaxSettings = ajaxSettings || {};
ajaxSettings.dataType = 'json';
ajaxSettings.cache = false;
return utils.ajaxRequest(url, ajaxSettings).then(function (success) {
if (success.xhr.status !== 200) {
return utils.makeAjaxError(success);
}
try {
return validate.validateSpecModel(success.data);
}
catch (err) {
return utils.makeAjaxError(success, err.message);
}
}, onKernelError);
}
Private.getSpec = getSpec;
/**
* Get a full kernel model from the server by kernel id string.

@@ -1212,0 +1214,0 @@ */

@@ -0,1 +1,2 @@

import { IIterator } from 'phosphor/lib/algorithm/iteration';
import { JSONObject, JSONValue } from 'phosphor/lib/algorithm/json';

@@ -22,2 +23,6 @@ import { IDisposable } from 'phosphor/lib/core/disposable';

/**
* A signal emitted when the kernel is shut down.
*/
terminated: ISignal<IKernel, void>;
/**
* A signal emitted when the kernel status changes.

@@ -55,2 +60,10 @@ */

/**
* The base url of the kernel.
*/
readonly baseUrl: string;
/**
* The Ajax settings used for server requests.
*/
ajaxSettings: IAjaxSettings;
/**
* The current status of the kernel.

@@ -60,20 +73,32 @@ */

/**
* The cached info for the kernel.
* Get the kernel info.
*
* @returns A promise that resolves with a cached kernel info.
*
* #### Notes
* If `null`, call [[kernelInfo]] to get the value,
* which will populate this value.
* This value is cached when a kernel connection is made.
* This can be used to wait for a kernel connection before taking
* further action on the kernel. It can also be used to get the kernel
* info without generating an extra kernel message.
*/
readonly info: KernelMessage.IInfoReply;
info(): Promise<KernelMessage.IInfoReply>;
/**
* The cached spec for the kernel.
* Get the cached kernel spec.
*
* @returns A promise that resolves with a cached kernel spec.
*
* #### Notes
* If `null`, call [[getKernelSpecs]] to get the value,
* which will populate this value.
* It will use the cached kernel spec models for this base url or
* fetch them from the server.
*/
readonly spec: Kernel.ISpecModel;
spec(): Promise<Kernel.ISpecModel>;
/**
* Send a shell message to the kernel.
*
* @param msg - The fully formed shell message to send.
*
* @param expectReply - Whether to expect a shell reply message.
*
* @param disposeOnDone - Whether to dispose of the future when done.
*
* #### Notes

@@ -100,2 +125,4 @@ * Send a message to the kernel's shell channel, yielding a future object

*
* @returns A promise that resolves when the kernel has interrupted.
*
* #### Notes

@@ -115,2 +142,4 @@ * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/kernels).

*
* @returns A promise that resolves when the kernel has restarted.
*
* #### Notes

@@ -121,4 +150,2 @@ * 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.

*
* 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.

@@ -131,5 +158,10 @@ *

/**
* Reconnect to a disconnected kernel. This is not actually a
* standard HTTP request, but useful function nonetheless for
* reconnecting to the kernel if the connection is somehow lost.
* Reconnect to a disconnected kernel.
*
* @returns A promise that resolves when the kernel has reconnected.
*
* #### Notes
* This is not actually a standard HTTP request, but useful function
* nonetheless for reconnecting to the kernel if the connection is somehow
* lost.
*/

@@ -140,7 +172,7 @@ reconnect(): Promise<void>;

*
* @returns A promise that resolves when the kernel has shut down.
*
* #### 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, closes the websocket and disposes of the kernel

@@ -151,2 +183,5 @@ * object, and fulfills the promise.

* request fails or the response is invalid.
*
* If the server call is successful, the [[terminated]] signal will be
* emitted.
*/

@@ -157,2 +192,6 @@ shutdown(): Promise<void>;

*
* @param content - The content of the request.
*
* @returns A promise that resolves with the response message.
*
* #### Notes

@@ -164,6 +203,10 @@ * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#kernel-info).

*/
kernelInfo(): Promise<KernelMessage.IInfoReplyMsg>;
requestKernelInfo(): Promise<KernelMessage.IInfoReplyMsg>;
/**
* Send a `complete_request` message.
*
* @param content - The content of the request.
*
* @returns A promise that resolves with the response message.
*
* #### Notes

@@ -175,6 +218,10 @@ * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#completion).

*/
complete(content: KernelMessage.ICompleteRequest): Promise<KernelMessage.ICompleteReplyMsg>;
requestComplete(content: KernelMessage.ICompleteRequest): Promise<KernelMessage.ICompleteReplyMsg>;
/**
* Send an `inspect_request` message.
*
* @param content - The content of the request.
*
* @returns A promise that resolves with the response message.
*
* #### Notes

@@ -186,6 +233,10 @@ * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#introspection).

*/
inspect(content: KernelMessage.IInspectRequest): Promise<KernelMessage.IInspectReplyMsg>;
requestInspect(content: KernelMessage.IInspectRequest): Promise<KernelMessage.IInspectReplyMsg>;
/**
* Send a `history_request` message.
*
* @param content - The content of the request.
*
* @returns A promise that resolves with the response message.
*
* #### Notes

@@ -197,6 +248,12 @@ * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#history).

*/
history(content: KernelMessage.IHistoryRequest): Promise<KernelMessage.IHistoryReplyMsg>;
requestHistory(content: KernelMessage.IHistoryRequest): Promise<KernelMessage.IHistoryReplyMsg>;
/**
* Send an `execute_request` message.
*
* @param content - The content of the request.
*
* @param disposeOnDone - Whether to dispose of the future when done.
*
* @returns A promise that resolves with the response message.
*
* #### Notes

@@ -210,6 +267,10 @@ * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#execute).

*/
execute(content: KernelMessage.IExecuteRequest, disposeOnDone?: boolean): Kernel.IFuture;
requestExecute(content: KernelMessage.IExecuteRequest, disposeOnDone?: boolean): Kernel.IFuture;
/**
* Send an `is_complete_request` message.
*
* @param content - The content of the request.
*
* @returns A promise that resolves with the response message.
*
* #### Notes

@@ -221,6 +282,10 @@ * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#code-completeness).

*/
isComplete(content: KernelMessage.IIsCompleteRequest): Promise<KernelMessage.IIsCompleteReplyMsg>;
requestIsComplete(content: KernelMessage.IIsCompleteRequest): Promise<KernelMessage.IIsCompleteReplyMsg>;
/**
* Send a `comm_info_request` message.
*
* @param content - The content of the request.
*
* @returns A promise that resolves with the response message.
*
* #### Notes

@@ -232,6 +297,8 @@ * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#comm_info).

*/
commInfo(content: KernelMessage.ICommInfoRequest): Promise<KernelMessage.ICommInfoReplyMsg>;
requestCommInfo(content: KernelMessage.ICommInfoRequest): Promise<KernelMessage.ICommInfoReplyMsg>;
/**
* Send an `input_reply` message.
*
* @param content - The content of the reply.
*
* #### Notes

@@ -244,2 +311,8 @@ * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#messages-on-the-stdin-router-dealer-sockets).

*
* @param targetName - The name of the comm target.
*
* @param id - The comm id.
*
* @returns A comm instance.
*
* #### Notes

@@ -284,10 +357,2 @@ * If a client-side comm already exists, it is returned.

registerMessageHook(msgId: string, hook: (msg: KernelMessage.IIOPubMessage) => boolean): IDisposable;
/**
* Get the kernel spec associated with the kernel.
*/
getSpec(): Promise<Kernel.ISpecModel>;
/**
* Optional default settings for ajax requests, if applicable.
*/
ajaxSettings?: IAjaxSettings;
}

@@ -387,3 +452,7 @@ /**

/**
* Object which manages kernel instances.
* Object which manages kernel instances for a given base url.
*
* #### Notes
* The manager is responsible for maintaining the state of running
* kernels and the initial fetch of kernel specs.
*/

@@ -400,19 +469,58 @@ interface IManager extends IDisposable {

/**
* Get the available kernel specs.
* The base url of the manager.
*/
readonly baseUrl: string;
/**
* The base ws url of the manager.
*/
readonly wsUrl: string;
/**
* The default ajax settings for the manager.
*/
ajaxSettings?: IAjaxSettings;
/**
* Get the kernel specs.
*
* #### Notes
* This will emit a [[specsChanged]] signal if the value
* has changed since the last fetch.
* This will be `null` until the specs are fetched from
* the server.
*/
getSpecs(options?: IOptions): Promise<ISpecModels>;
readonly specs: ISpecModels | null;
/**
* Get a list of running kernels.
* Create an iterator over the known running kernels.
*
* @returns A new iterator over the running kernels.
*/
running(): IIterator<IModel>;
/**
* Force an update of the available kernel specs.
*
* @returns A promise that resolves with the kernel spec models.
*
* #### Notes
* This will emit a [[runningChanged]] signal if the value
* has changed since the last fetch.
* This is only meant to be called by the user if the kernel specs
* are known to have changed on disk.
*/
listRunning(options?: IOptions): Promise<IModel[]>;
updateSpecs(): Promise<ISpecModels>;
/**
* Force a refresh of the running kernels.
*
* @returns A promise that with the list of running kernels.
*
* #### Notes
* This is not typically meant to be called by the user, since the
* manager maintains its own internal state.
*/
refreshRunning(): Promise<IModel[]>;
/**
* Start a new kernel.
*
* @param options - The kernel options to use.
*
* @returns A promise that resolves with the kernel instance.
*
* #### Notes
* If options are given, the baseUrl and wsUrl will be forced
* to the ones used by the manager. The ajaxSettings of the manager
* will be used unless overridden.
*/

@@ -422,6 +530,21 @@ startNew(options?: IOptions): Promise<IKernel>;

* Find a kernel by id.
*
* @param id - The id of the target kernel.
*
* @returns A promise that resolves with the kernel's model.
*/
findById(id: string, options?: IOptions): Promise<IModel>;
findById(id: string): Promise<IModel>;
/**
* Connect to an existing kernel.
*
* @param id - The id of the target kernel.
*
* @param options - The kernel options to use.
*
* @returns A promise that resolves with the new kernel instance.
*
* #### Notes
* If options are given, the baseUrl and wsUrl will be forced
* to the ones used by the manager. The ajaxSettings of the manager
* will be used unless overridden.
*/

@@ -431,4 +554,8 @@ connectTo(id: string, options?: IOptions): Promise<IKernel>;

* Shut down a kernel by id.
*
* @param id - The id of the target kernel.
*
* @returns A promise that resolves when the operation is complete.
*/
shutdown(id: string, options?: IOptions): Promise<void>;
shutdown(id: string): Promise<void>;
}

@@ -522,2 +649,8 @@ /**

*
* @param data - The data to send to the server on opening.
*
* @param metadata - Additional metatada for the message.
*
* @returns A future for the generated message.
*
* #### Notes

@@ -530,2 +663,12 @@ * This sends a `comm_open` message to the server.

*
* @param data - The data to send to the server on opening.
*
* @param metadata - Additional metatada for the message.
*
* @param buffers - Optional buffer data.
*
* @param disposeOnDone - Whether to dispose of the future when done.
*
* @returns A future for the generated message.
*
* #### Notes

@@ -538,2 +681,8 @@ * This is a no-op if the comm has been closed.

*
* @param data - The data to send to the server on opening.
*
* @param metadata - Additional metatada for the message.
*
* @returns A future for the generated message.
*
* #### Notes

@@ -540,0 +689,0 @@ * This will send a `comm_close` message to the kernel, and call the

@@ -0,2 +1,4 @@

import { IIterator } from 'phosphor/lib/algorithm/iteration';
import { ISignal } from 'phosphor/lib/core/signaling';
import { IAjaxSettings } from '../utils';
import { Kernel } from './kernel';

@@ -30,14 +32,47 @@ /**

/**
* Get the kernel specs. See also [[getKernelSpecs]].
* Get the base url of the manager.
*/
readonly baseUrl: string;
/**
* Get the ws url of the manager.
*/
readonly wsUrl: string;
/**
* The default ajax settings for the manager.
*/
/**
* Set the default ajax settings for the manager.
*/
ajaxSettings: IAjaxSettings;
/**
* Get the most recent specs from the server.
*/
readonly specs: Kernel.ISpecModels;
/**
* Create an iterator over the most recent running kernels.
*
* @param options - Overrides for the default options.
* @returns A new iterator over the running kernels.
*/
getSpecs(options?: Kernel.IOptions): Promise<Kernel.ISpecModels>;
running(): IIterator<Kernel.IModel>;
/**
* List the running kernels. See also [[listRunningKernels]].
* Force an update of the available kernel specs.
*
* @param options - Overrides for the default options.
* @returns A promise that resolves with the kernel spec models.
*
* #### Notes
* This is only meant to be called by the user if the kernel specs
* are known to have changed on disk.
*/
listRunning(options?: Kernel.IOptions): Promise<Kernel.IModel[]>;
updateSpecs(): Promise<Kernel.ISpecModels>;
/**
* Force a refresh of the running kernels.
*
* @returns A promise that with the list of running kernels.
*
* #### Notes
* This is not typically meant to be called by the user, since the
* manager maintains its own internal state.
*/
refreshRunning(): Promise<Kernel.IModel[]>;
/**
* Start a new kernel. See also [[startNewKernel]].

@@ -77,7 +112,15 @@ *

*/
private _getOptions(options);
private _options;
private _getOptions(options?);
/**
* Schedule an update of the running kernels.
*/
private _scheduleUpdate();
private _baseUrl;
private _wsUrl;
private _ajaxSettings;
private _running;
private _spec;
private _specs;
private _isDisposed;
private _updateTimer;
private _refreshTimer;
}
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
"use strict";
var iteration_1 = require('phosphor/lib/algorithm/iteration');
var json_1 = require('phosphor/lib/algorithm/json');

@@ -18,7 +19,15 @@ var signaling_1 = require('phosphor/lib/core/signaling');

function KernelManager(options) {
this._options = null;
if (options === void 0) { options = {}; }
this._baseUrl = '';
this._wsUrl = '';
this._ajaxSettings = '';
this._running = [];
this._spec = null;
this._specs = null;
this._isDisposed = false;
this._options = utils.copy(options || {});
this._updateTimer = -1;
this._refreshTimer = -1;
this._baseUrl = options.baseUrl || utils.getBaseUrl();
this._wsUrl = options.wsUrl || utils.getWsUrl(this._baseUrl);
this._ajaxSettings = JSON.stringify(options.ajaxSettings || {});
this._scheduleUpdate();
}

@@ -43,16 +52,76 @@ Object.defineProperty(KernelManager.prototype, "isDisposed", {

this._isDisposed = true;
clearTimeout(this._updateTimer);
clearTimeout(this._refreshTimer);
signaling_1.clearSignalData(this);
this._spec = null;
this._specs = null;
this._running = [];
};
Object.defineProperty(KernelManager.prototype, "baseUrl", {
/**
* Get the base url of the manager.
*/
get: function () {
return this._baseUrl;
},
enumerable: true,
configurable: true
});
Object.defineProperty(KernelManager.prototype, "wsUrl", {
/**
* Get the ws url of the manager.
*/
get: function () {
return this._wsUrl;
},
enumerable: true,
configurable: true
});
Object.defineProperty(KernelManager.prototype, "ajaxSettings", {
/**
* The default ajax settings for the manager.
*/
get: function () {
return JSON.parse(this._ajaxSettings);
},
/**
* Set the default ajax settings for the manager.
*/
set: function (value) {
this._ajaxSettings = JSON.stringify(value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(KernelManager.prototype, "specs", {
/**
* Get the most recent specs from the server.
*/
get: function () {
return this._specs;
},
enumerable: true,
configurable: true
});
/**
* Get the kernel specs. See also [[getKernelSpecs]].
* Create an iterator over the most recent running kernels.
*
* @param options - Overrides for the default options.
* @returns A new iterator over the running kernels.
*/
KernelManager.prototype.getSpecs = function (options) {
KernelManager.prototype.running = function () {
return iteration_1.iter(this._running);
};
/**
* Force an update of the available kernel specs.
*
* @returns A promise that resolves with the kernel spec models.
*
* #### Notes
* This is only meant to be called by the user if the kernel specs
* are known to have changed on disk.
*/
KernelManager.prototype.updateSpecs = function () {
var _this = this;
return kernel_1.Kernel.getSpecs(this._getOptions(options)).then(function (specs) {
if (!json_1.deepEqual(specs, _this._spec)) {
_this._spec = specs;
return kernel_1.Kernel.getSpecs(this._getOptions()).then(function (specs) {
if (!json_1.deepEqual(specs, _this._specs)) {
_this._specs = specs;
_this.specsChanged.emit(specs);

@@ -64,9 +133,15 @@ }

/**
* List the running kernels. See also [[listRunningKernels]].
* Force a refresh of the running kernels.
*
* @param options - Overrides for the default options.
* @returns A promise that with the list of running kernels.
*
* #### Notes
* This is not typically meant to be called by the user, since the
* manager maintains its own internal state.
*/
KernelManager.prototype.listRunning = function (options) {
KernelManager.prototype.refreshRunning = function () {
var _this = this;
return kernel_1.Kernel.listRunning(this._getOptions(options)).then(function (running) {
clearTimeout(this._updateTimer);
clearTimeout(this._refreshTimer);
return kernel_1.Kernel.listRunning(this._getOptions()).then(function (running) {
if (!json_1.deepEqual(running, _this._running)) {

@@ -76,2 +151,5 @@ _this._running = running.slice();

}
_this._refreshTimer = setTimeout(function () {
_this.refreshRunning();
}, 10000);
return running;

@@ -90,3 +168,10 @@ });

KernelManager.prototype.startNew = function (options) {
return kernel_1.Kernel.startNew(this._getOptions(options));
var _this = this;
return kernel_1.Kernel.startNew(this._getOptions(options)).then(function (kernel) {
_this._scheduleUpdate();
kernel.terminated.connect(function () {
_this._scheduleUpdate();
});
return kernel;
});
};

@@ -107,3 +192,9 @@ /**

KernelManager.prototype.connectTo = function (id, options) {
return kernel_1.Kernel.connectTo(id, this._getOptions(options));
var _this = this;
return kernel_1.Kernel.connectTo(id, this._getOptions(options)).then(function (kernel) {
kernel.terminated.connect(function () {
_this._scheduleUpdate();
});
return kernel;
});
};

@@ -120,3 +211,6 @@ /**

KernelManager.prototype.shutdown = function (id, options) {
return kernel_1.Kernel.shutdown(id, this._getOptions(options));
var _this = this;
return kernel_1.Kernel.shutdown(id, this._getOptions(options)).then(function () {
_this._scheduleUpdate();
});
};

@@ -127,10 +221,20 @@ /**

KernelManager.prototype._getOptions = function (options) {
if (options) {
options = utils.extend(utils.copy(this._options), options);
}
else {
options = this._options;
}
if (options === void 0) { options = {}; }
options.baseUrl = this._baseUrl;
options.wsUrl = this._wsUrl;
options.ajaxSettings = options.ajaxSettings || this.ajaxSettings;
return options;
};
/**
* Schedule an update of the running kernels.
*/
KernelManager.prototype._scheduleUpdate = function () {
var _this = this;
if (this._updateTimer !== -1) {
return;
}
this._updateTimer = setTimeout(function () {
_this.refreshRunning();
}, 100);
};
return KernelManager;

@@ -137,0 +241,0 @@ }());

@@ -0,9 +1,45 @@

import { JSONObject } from 'phosphor/lib/algorithm/json';
import { IDisposable } from 'phosphor/lib/core/disposable';
import { ISignal } from 'phosphor/lib/core/signaling';
import { Contents } from './contents';
import { Kernel } from './kernel';
import { Session } from './session';
import { TerminalSession } from './terminal';
import { Contents, ContentsManager } from './contents';
import { Session, SessionManager } from './session';
import { TerminalSession, TerminalManager } from './terminal';
import { IAjaxSettings } from './utils';
/**
* A Jupyter services manager.
*/
export declare class ServiceManager implements ServiceManager.IManager {
/**
* Construct a new services provider.
*/
constructor(options?: ServiceManager.IOptions);
/**
* Test whether the terminal manager is disposed.
*/
readonly isDisposed: boolean;
/**
* Get the base url of the server.
*/
readonly baseUrl: string;
/**
* Dispose of the resources used by the manager.
*/
dispose(): void;
/**
* Get the session manager instance.
*/
readonly sessions: SessionManager;
/**
* Get the contents manager instance.
*/
readonly contents: ContentsManager;
/**
* Get the terminal manager instance.
*/
readonly terminals: TerminalManager;
private _sessionManager;
private _contentsManager;
private _terminalManager;
private _isDisposed;
}
/**
* The namespace for `ServiceManager` statics.

@@ -17,14 +53,6 @@ */

/**
* A signal emitted when the specs change on the service manager.
* The base url of the manager.
*/
specsChanged: ISignal<IManager, Kernel.ISpecModels>;
readonly baseUrl: string;
/**
* The kernel specs for the manager.
*/
readonly kernelspecs: Kernel.ISpecModels;
/**
* The kernel manager for the manager.
*/
readonly kernels: Kernel.IManager;
/**
* The session manager for the manager.

@@ -43,13 +71,5 @@ */

/**
* Create a new service manager.
*
* @param options - The service manager creation options.
*
* @returns A promise that resolves with a service manager.
*/
function create(options?: IOptions): Promise<IManager>;
/**
* The options used to create a service manager.
*/
interface IOptions {
interface IOptions extends JSONObject {
/**

@@ -60,10 +80,10 @@ * The base url of the server.

/**
* The base ws url of the server.
*/
wsUrl?: string;
/**
* The ajax settings for the manager.
*/
ajaxSettings?: IAjaxSettings;
/**
* The kernelspecs for the manager.
*/
kernelspecs?: Kernel.ISpecModels;
}
}
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
"use strict";
var signaling_1 = require('phosphor/lib/core/signaling');
var contents_1 = require('./contents');
var kernel_1 = require('./kernel');
var session_1 = require('./session');

@@ -11,58 +9,22 @@ var terminal_1 = require('./terminal');

/**
* The namespace for `ServiceManager` statics.
* A Jupyter services manager.
*/
var ServiceManager;
(function (ServiceManager) {
var ServiceManager = (function () {
/**
* Create a new service manager.
*
* @param options - The service manager creation options.
*
* @returns A promise that resolves with a service manager.
*/
function create(options) {
if (options === void 0) { options = {}; }
options.baseUrl = options.baseUrl || utils_1.getBaseUrl();
options.ajaxSettings = options.ajaxSettings || {};
if (options.kernelspecs) {
return Promise.resolve(new DefaultServiceManager(options));
}
var kernelOptions = {
baseUrl: options.baseUrl,
ajaxSettings: options.ajaxSettings
};
return kernel_1.Kernel.getSpecs(kernelOptions).then(function (specs) {
options.kernelspecs = specs;
return new DefaultServiceManager(options);
});
}
ServiceManager.create = create;
})(ServiceManager = exports.ServiceManager || (exports.ServiceManager = {}));
/**
* An implementation of a services manager.
*/
var DefaultServiceManager = (function () {
/**
* Construct a new services provider.
*/
function DefaultServiceManager(options) {
this._kernelManager = null;
function ServiceManager(options) {
this._sessionManager = null;
this._contentsManager = null;
this._terminalManager = null;
this._kernelspecs = null;
this._isDisposed = false;
var subOptions = {
baseUrl: options.baseUrl,
ajaxSettings: options.ajaxSettings
};
this._kernelspecs = options.kernelspecs;
this._kernelManager = new kernel_1.KernelManager(subOptions);
this._sessionManager = new session_1.SessionManager(subOptions);
this._contentsManager = new contents_1.ContentsManager(subOptions);
this._terminalManager = new terminal_1.TerminalManager(subOptions);
this._kernelManager.specsChanged.connect(this._onSpecsChanged, this);
this._sessionManager.specsChanged.connect(this._onSpecsChanged, this);
options = options || {};
options.wsUrl = options.wsUrl || utils_1.getWsUrl();
options.baseUrl = options.baseUrl || utils_1.getBaseUrl();
options.ajaxSettings = options.ajaxSettings || {};
this._sessionManager = new session_1.SessionManager(options);
this._contentsManager = new contents_1.ContentsManager(options);
this._terminalManager = new terminal_1.TerminalManager(options);
}
Object.defineProperty(DefaultServiceManager.prototype, "isDisposed", {
Object.defineProperty(ServiceManager.prototype, "isDisposed", {
/**

@@ -77,6 +39,16 @@ * Test whether the terminal manager is disposed.

});
Object.defineProperty(ServiceManager.prototype, "baseUrl", {
/**
* Get the base url of the server.
*/
get: function () {
return this._sessionManager.baseUrl;
},
enumerable: true,
configurable: true
});
/**
* Dispose of the resources used by the manager.
*/
DefaultServiceManager.prototype.dispose = function () {
ServiceManager.prototype.dispose = function () {
if (this.isDisposed) {

@@ -86,26 +58,8 @@ return;

this._isDisposed = true;
signaling_1.clearSignalData(this);
this._sessionManager.dispose();
this._contentsManager.dispose();
this._sessionManager.dispose();
};
Object.defineProperty(DefaultServiceManager.prototype, "kernelspecs", {
Object.defineProperty(ServiceManager.prototype, "sessions", {
/**
* Get kernel specs.
*/
get: function () {
return this._kernelspecs;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DefaultServiceManager.prototype, "kernels", {
/**
* Get kernel manager instance.
*/
get: function () {
return this._kernelManager;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DefaultServiceManager.prototype, "sessions", {
/**
* Get the session manager instance.

@@ -119,3 +73,3 @@ */

});
Object.defineProperty(DefaultServiceManager.prototype, "contents", {
Object.defineProperty(ServiceManager.prototype, "contents", {
/**

@@ -130,3 +84,3 @@ * Get the contents manager instance.

});
Object.defineProperty(DefaultServiceManager.prototype, "terminals", {
Object.defineProperty(ServiceManager.prototype, "terminals", {
/**

@@ -141,12 +95,4 @@ * Get the terminal manager instance.

});
/**
* Handle a change in kernel specs.
*/
DefaultServiceManager.prototype._onSpecsChanged = function (sender, args) {
this._kernelspecs = args;
this.specsChanged.emit(args);
};
return DefaultServiceManager;
return ServiceManager;
}());
// Define the signals for the `ServiceManager` class.
signaling_1.defineSignal(DefaultServiceManager.prototype, 'specsChanged');
exports.ServiceManager = ServiceManager;

@@ -16,5 +16,5 @@ import { ISignal } from 'phosphor/lib/core/signaling';

/**
* A signal emitted when the session dies.
* A signal emitted when the session is shut down.
*/
sessionDied: ISignal<Session.ISession, void>;
terminated: ISignal<Session.ISession, void>;
/**

@@ -69,2 +69,6 @@ * A signal emitted when the kernel changes.

/**
* Get the base url of the session.
*/
readonly baseUrl: string;
/**
* Get a copy of the default ajax settings for the session.

@@ -71,0 +75,0 @@ */

@@ -33,3 +33,2 @@ // Copyright (c) Jupyter Development Team.

this._updating = false;
this.ajaxSettings = options.ajaxSettings || {};
this._id = id;

@@ -39,2 +38,3 @@ this._path = options.path;

this._uuid = utils.uuid();
this._ajaxSettings = JSON.stringify(options.ajaxSettings || {});
Private.runningSessions.pushBack(this);

@@ -108,2 +108,12 @@ this.setupKernel(kernel);

});
Object.defineProperty(DefaultSession.prototype, "baseUrl", {
/**
* Get the base url of the session.
*/
get: function () {
return this._baseUrl;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DefaultSession.prototype, "ajaxSettings", {

@@ -177,7 +187,6 @@ /**

}
this._options = null;
if (this._kernel) {
this._kernel.dispose();
}
this.sessionDied.emit(void 0);
this._options = null;
Private.runningSessions.remove(this);

@@ -296,5 +305,5 @@ this._kernel = null;

}
var data = success.data;
var value = success.data;
try {
validate.validateModel(data);
validate.validateModel(value);
}

@@ -304,3 +313,3 @@ catch (err) {

}
return Private.updateByModel(data);
return Private.updateFromServer(value);
}, function (error) {

@@ -314,4 +323,4 @@ _this._updating = false;

exports.DefaultSession = DefaultSession;
// Define the signals for the `Session` class.
signaling_1.defineSignal(DefaultSession.prototype, 'sessionDied');
// Define the signals for the `DefaultSession` class.
signaling_1.defineSignal(DefaultSession.prototype, 'terminated');
signaling_1.defineSignal(DefaultSession.prototype, 'kernelChanged');

@@ -514,3 +523,3 @@ signaling_1.defineSignal(DefaultSession.prototype, 'statusChanged');

var data = success.data;
return updateByModel(data);
return updateFromServer(data);
}, onSessionError);

@@ -571,3 +580,3 @@ }

}
return updateByModel(data);
return updateFromServer(data);
}, Private.onSessionError);

@@ -590,3 +599,3 @@ }

if (!updated && session.status !== 'dead') {
session.sessionDied.emit(void 0);
session.terminated.emit(void 0);
}

@@ -600,3 +609,3 @@ });

*/
function updateByModel(model) {
function updateFromServer(model) {
var promises = [];

@@ -610,3 +619,3 @@ iteration_1.each(Private.runningSessions, function (session) {

}
Private.updateByModel = updateByModel;
Private.updateFromServer = updateFromServer;
/**

@@ -627,2 +636,3 @@ * Shut down a session by id.

if (session.id === id) {
session.terminated.emit(void 0);
session.dispose();

@@ -629,0 +639,0 @@ }

@@ -0,3 +1,5 @@

import { IIterator } from 'phosphor/lib/algorithm/iteration';
import { ISignal } from 'phosphor/lib/core/signaling';
import { Kernel } from '../kernel';
import { IAjaxSettings } from '../utils';
import { Session } from './session';

@@ -31,14 +33,47 @@ /**

/**
* Get the available kernel specs. See also [[Kernel.getSpecs]].
* Get the most recent specs from the server.
*/
readonly specs: Kernel.ISpecModels | null;
/**
* The base url of the manager.
*/
readonly baseUrl: string;
/**
* The base ws url of the manager.
*/
readonly wsUrl: string;
/**
* The default ajax settings for the manager.
*/
/**
* Set the default ajax settings for the manager.
*/
ajaxSettings: IAjaxSettings;
/**
* Create an iterator over the most recent running sessions.
*
* @param options - Overrides for the default options.
* @returns A new iterator over the running sessions.
*/
getSpecs(options?: Session.IOptions): Promise<Kernel.ISpecModels>;
running(): IIterator<Session.IModel>;
/**
* List the running sessions. See also [[listRunningSessions]].
* Force an update of the available kernel specs.
*
* @param options - Overrides for the default options.
* @returns A promise that resolves with the kernel spec models.
*
* #### Notes
* This is only meant to be called by the user if the kernel specs
* are known to have changed on disk.
*/
listRunning(options?: Session.IOptions): Promise<Session.IModel[]>;
updateSpecs(): Promise<Kernel.ISpecModels>;
/**
* Force a refresh of the running sessions.
*
* @returns A promise that with the list of running sessions.
*
* #### Notes
* This is not typically meant to be called by the user, since the
* manager maintains its own internal state.
*/
refreshRunning(): Promise<Session.IModel[]>;
/**
* Start a new session. See also [[startNewSession]].

@@ -48,6 +83,2 @@ *

* `'path'`.
*
* #### Notes
* This will emit [[runningChanged]] if the running kernels list
* changes.
*/

@@ -66,6 +97,2 @@ startNew(options: Session.IOptions): Promise<Session.ISession>;

* Shut down a session by id.
*
* #### Notes
* This will emit [[runningChanged]] if the running kernels list
* changes.
*/

@@ -76,7 +103,15 @@ shutdown(id: string, options?: Session.IOptions): Promise<void>;

*/
private _getOptions(options);
private _options;
private _getOptions(options?);
/**
* Schedule an update of the running sessions.
*/
private _scheduleUpdate();
private _baseUrl;
private _wsUrl;
private _ajaxSettings;
private _isDisposed;
private _running;
private _specs;
private _updateTimer;
private _refreshTimer;
}
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
"use strict";
var iteration_1 = require('phosphor/lib/algorithm/iteration');
var json_1 = require('phosphor/lib/algorithm/json');

@@ -19,7 +20,15 @@ var signaling_1 = require('phosphor/lib/core/signaling');

function SessionManager(options) {
this._options = null;
if (options === void 0) { options = {}; }
this._baseUrl = '';
this._wsUrl = '';
this._ajaxSettings = '';
this._isDisposed = false;
this._running = [];
this._specs = null;
this._options = utils.copy(options || {});
this._updateTimer = -1;
this._refreshTimer = -1;
this._baseUrl = options.baseUrl || utils.getBaseUrl();
this._wsUrl = options.wsUrl || utils.getWsUrl(this._baseUrl);
this._ajaxSettings = JSON.stringify(options.ajaxSettings || {});
this._scheduleUpdate();
}

@@ -44,13 +53,77 @@ Object.defineProperty(SessionManager.prototype, "isDisposed", {

this._isDisposed = true;
clearTimeout(this._updateTimer);
clearTimeout(this._refreshTimer);
signaling_1.clearSignalData(this);
this._running = [];
};
Object.defineProperty(SessionManager.prototype, "specs", {
/**
* Get the most recent specs from the server.
*/
get: function () {
return this._specs;
},
enumerable: true,
configurable: true
});
Object.defineProperty(SessionManager.prototype, "baseUrl", {
/**
* The base url of the manager.
*/
get: function () {
return this._baseUrl;
},
enumerable: true,
configurable: true
});
Object.defineProperty(SessionManager.prototype, "wsUrl", {
/**
* The base ws url of the manager.
*/
get: function () {
return this._wsUrl;
},
enumerable: true,
configurable: true
});
Object.defineProperty(SessionManager.prototype, "ajaxSettings", {
/**
* The default ajax settings for the manager.
*/
get: function () {
return JSON.parse(this._ajaxSettings);
},
/**
* Set the default ajax settings for the manager.
*/
set: function (value) {
this._ajaxSettings = JSON.stringify(value);
},
enumerable: true,
configurable: true
});
/**
* Get the available kernel specs. See also [[Kernel.getSpecs]].
* Create an iterator over the most recent running sessions.
*
* @param options - Overrides for the default options.
* @returns A new iterator over the running sessions.
*/
SessionManager.prototype.getSpecs = function (options) {
SessionManager.prototype.running = function () {
return iteration_1.iter(this._running);
};
/**
* Force an update of the available kernel specs.
*
* @returns A promise that resolves with the kernel spec models.
*
* #### Notes
* This is only meant to be called by the user if the kernel specs
* are known to have changed on disk.
*/
SessionManager.prototype.updateSpecs = function () {
var _this = this;
return kernel_1.Kernel.getSpecs(this._getOptions(options)).then(function (specs) {
var options = {
baseUrl: this._baseUrl,
ajaxSettings: this.ajaxSettings
};
return kernel_1.Kernel.getSpecs(options).then(function (specs) {
if (!json_1.deepEqual(specs, _this._specs)) {

@@ -64,9 +137,15 @@ _this._specs = specs;

/**
* List the running sessions. See also [[listRunningSessions]].
* Force a refresh of the running sessions.
*
* @param options - Overrides for the default options.
* @returns A promise that with the list of running sessions.
*
* #### Notes
* This is not typically meant to be called by the user, since the
* manager maintains its own internal state.
*/
SessionManager.prototype.listRunning = function (options) {
SessionManager.prototype.refreshRunning = function () {
var _this = this;
return session_1.Session.listRunning(this._getOptions(options)).then(function (running) {
clearTimeout(this._updateTimer);
clearTimeout(this._refreshTimer);
return session_1.Session.listRunning(this._getOptions({})).then(function (running) {
if (!json_1.deepEqual(running, _this._running)) {

@@ -76,2 +155,9 @@ _this._running = running.slice();

}
// Throttle the next request.
if (_this._updateTimer !== -1) {
_this._scheduleUpdate();
}
_this._refreshTimer = setTimeout(function () {
_this.refreshRunning();
}, 10000);
return running;

@@ -85,9 +171,10 @@ });

* `'path'`.
*
* #### Notes
* This will emit [[runningChanged]] if the running kernels list
* changes.
*/
SessionManager.prototype.startNew = function (options) {
return session_1.Session.startNew(this._getOptions(options));
var _this = this;
return session_1.Session.startNew(this._getOptions(options)).then(function (session) {
_this._scheduleUpdate();
session.terminated.connect(function () { _this._scheduleUpdate(); });
return session;
});
};

@@ -110,13 +197,16 @@ /**

SessionManager.prototype.connectTo = function (id, options) {
return session_1.Session.connectTo(id, this._getOptions(options));
var _this = this;
return session_1.Session.connectTo(id, this._getOptions(options)).then(function (session) {
session.terminated.connect(function () { _this._scheduleUpdate(); });
return session;
});
};
/**
* Shut down a session by id.
*
* #### Notes
* This will emit [[runningChanged]] if the running kernels list
* changes.
*/
SessionManager.prototype.shutdown = function (id, options) {
return session_1.Session.shutdown(id, this._getOptions(options));
var _this = this;
return session_1.Session.shutdown(id, this._getOptions(options)).then(function () {
_this._scheduleUpdate();
});
};

@@ -127,10 +217,20 @@ /**

SessionManager.prototype._getOptions = function (options) {
if (options) {
options = utils.extend(utils.copy(this._options), options);
}
else {
options = this._options;
}
if (options === void 0) { options = {}; }
options.baseUrl = this._baseUrl;
options.wsUrl = this._wsUrl;
options.ajaxSettings = options.ajaxSettings || this.ajaxSettings;
return options;
};
/**
* Schedule an update of the running sessions.
*/
SessionManager.prototype._scheduleUpdate = function () {
var _this = this;
if (this._updateTimer !== -1) {
return;
}
this._updateTimer = setTimeout(function () {
_this.refreshRunning();
}, 100);
};
return SessionManager;

@@ -137,0 +237,0 @@ }());

@@ -0,1 +1,2 @@

import { IIterator } from 'phosphor/lib/algorithm/iteration';
import { JSONObject } from 'phosphor/lib/algorithm/json';

@@ -17,3 +18,3 @@ import { IDisposable } from 'phosphor/lib/core/disposable';

*/
sessionDied: ISignal<ISession, void>;
terminated: ISignal<ISession, void>;
/**

@@ -48,2 +49,6 @@ * A signal emitted when the kernel changes.

/**
* The base url of the session.
*/
readonly baseUrl: string;
/**
* The model associated with the session.

@@ -77,2 +82,4 @@ */

*
* @returns A promise that resolves when the session has renamed.
*
* #### Notes

@@ -88,2 +95,4 @@ * This uses the Jupyter REST API, and the response is validated.

*
* @returns A promise that resolves with the new kernel model.
*
* #### Notes

@@ -97,2 +106,4 @@ * This shuts down the existing kernel and creates a new kernel,

*
* @returns A promise that resolves when the session is shut down.
*
* #### Notes

@@ -107,2 +118,6 @@ * This uses the Jupyter REST API, and the response is validated.

*
* @param options - The options used for the request.
*
* @returns A promise that resolves with the list of session models.
*
* #### Notes

@@ -119,2 +134,6 @@ * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/sessions), and validates the response.

*
* @param options - The options used to start the session.
*
* @returns A promise that resolves with the session instance.
*
* #### Notes

@@ -137,4 +156,10 @@ * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/sessions), and validates the response.

*
* @param id - The id of the target session.
*
* @param options - The options used to fetch the session.
*
* @returns A promise that resolves with the session model.
*
* #### Notes
* If the session was already started via `startNewSession`, the existing
* If the session was already started via `startNew`, the existing
* Session object's information is used in the fulfillment value.

@@ -151,2 +176,8 @@ *

*
* @param path - The path of the target session.
*
* @param options - The options used to fetch the session.
*
* @returns A promise that resolves with the session model.
*
* #### Notes

@@ -168,4 +199,10 @@ * If the session was already started via `startNewSession`, the existing

*
* @param id - The id of the target session.
*
* @param options - The options used to fetch the session.
*
* @returns A promise that resolves with the session instance.
*
* #### Notes
* If the session was already started via `startNewSession`, the existing
* If the session was already started via `startNew`, the existing
* Session object is used as the fulfillment value.

@@ -184,2 +221,9 @@ *

* Shut down a session by id.
*
* @param id - The id of the target session.
*
* @param options - The options used to fetch the session.
*
* @returns A promise that resolves when the session is shut down.
*
*/

@@ -226,2 +270,6 @@ function shutdown(id: string, options?: Session.IOptions): Promise<void>;

* Object which manages session instances.
*
* #### Notes
* The manager is responsible for maintaining the state of running
* sessions and the initial fetch of kernel specs.
*/

@@ -238,12 +286,38 @@ interface IManager extends IDisposable {

/**
* Get the available kernel specs.
* The base url of the manager.
*/
readonly baseUrl: string;
/**
* The base ws url of the manager.
*/
readonly wsUrl: string;
/**
* The default ajax settings for the manager.
*/
ajaxSettings?: IAjaxSettings;
/**
* Get the most recent specs from the server.
*
* #### Notes
* This will emit a [[specsChange]] signal if the value
* has changed since the last fetch.
* This will be `null` until the specs are fetched from
* the server.
*/
getSpecs(options?: IOptions): Promise<Kernel.ISpecModels>;
listRunning(options?: IOptions): Promise<IModel[]>;
readonly specs: Kernel.ISpecModels | null;
/**
* Create an iterator over the known running sessions.
*
* @returns A new iterator over the running sessions.
*/
running(): IIterator<IModel>;
/**
* Start a new session.
*
* @param options - The session options to use.
*
* @returns A promise that resolves with the session instance.
*
* #### Notes
* The baseUrl and wsUrl of the options will be forced
* to the ones used by the manager. The ajaxSettings of the manager
* will be used unless overridden.
*/

@@ -253,10 +327,29 @@ startNew(options: IOptions): Promise<ISession>;

* Find a session by id.
*
* @param id - The id of the target session.
*
* @returns A promise that resolves with the session's model.
*/
findById(id: string, options?: IOptions): Promise<IModel>;
findById(id: string): Promise<IModel>;
/**
* Find a session by path.
*
* @param path - The path of the target session.
*
* @returns A promise that resolves with the session's model.
*/
findByPath(path: string, options?: IOptions): Promise<IModel>;
findByPath(path: string): Promise<IModel>;
/**
* Connect to a running session.
*
* @param id - The id of the target session.
*
* @param options - The session options to use.
*
* @returns A promise that resolves with the new session instance.
*
* #### Notes
* If options are given, the baseUrl and wsUrl will be forced
* to the ones used by the manager. The ajaxSettings of the manager
* will be used unless overridden.
*/

@@ -266,4 +359,28 @@ connectTo(id: string, options?: IOptions): Promise<ISession>;

* Shut down a session by id.
*
* @param id - The id of the target kernel.
*
* @returns A promise that resolves when the operation is complete.
*/
shutdown(id: string, options?: IOptions): Promise<void>;
shutdown(id: string): Promise<void>;
/**
* Force an update of the available kernel specs.
*
* @returns A promise that resolves with the kernel spec models.
*
* #### Notes
* This is only meant to be called by the user if the kernel specs
* are known to have changed on disk.
*/
updateSpecs(): Promise<Kernel.ISpecModels>;
/**
* Force a refresh of the running sessions.
*
* @returns A promise that with the list of running sessions.
*
* #### Notes
* This is not typically meant to be called by the user, since the
* manager maintains its own internal state.
*/
refreshRunning(): Promise<IModel[]>;
}

@@ -270,0 +387,0 @@ /**

@@ -13,2 +13,6 @@ // Copyright (c) Jupyter Development Team.

*
* @param options - The options used for the request.
*
* @returns A promise that resolves with the list of session models.
*
* #### Notes

@@ -28,2 +32,6 @@ * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/sessions), and validates the response.

*
* @param options - The options used to start the session.
*
* @returns A promise that resolves with the session instance.
*
* #### Notes

@@ -49,4 +57,10 @@ * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/sessions), and validates the response.

*
* @param id - The id of the target session.
*
* @param options - The options used to fetch the session.
*
* @returns A promise that resolves with the session model.
*
* #### Notes
* If the session was already started via `startNewSession`, the existing
* If the session was already started via `startNew`, the existing
* Session object's information is used in the fulfillment value.

@@ -66,2 +80,8 @@ *

*
* @param path - The path of the target session.
*
* @param options - The options used to fetch the session.
*
* @returns A promise that resolves with the session model.
*
* #### Notes

@@ -86,4 +106,10 @@ * If the session was already started via `startNewSession`, the existing

*
* @param id - The id of the target session.
*
* @param options - The options used to fetch the session.
*
* @returns A promise that resolves with the session instance.
*
* #### Notes
* If the session was already started via `startNewSession`, the existing
* If the session was already started via `startNew`, the existing
* Session object is used as the fulfillment value.

@@ -105,2 +131,9 @@ *

* Shut down a session by id.
*
* @param id - The id of the target session.
*
* @param options - The options used to fetch the session.
*
* @returns A promise that resolves when the session is shut down.
*
*/

@@ -107,0 +140,0 @@ function shutdown(id, options) {

@@ -1,174 +0,2 @@

import { JSONPrimitive, JSONObject } from 'phosphor/lib/algorithm/json';
import { IDisposable } from 'phosphor/lib/core/disposable';
import { ISignal } from 'phosphor/lib/core/signaling';
import * as utils from '../utils';
/**
* The namespace for TerminalSession.ISession statics.
*/
export declare namespace TerminalSession {
/**
* An interface for a terminal session.
*/
interface ISession extends IDisposable {
/**
* A signal emitted when a message is received from the server.
*/
messageReceived: ISignal<ISession, TerminalSession.IMessage>;
/**
* Get the name of the terminal session.
*/
readonly name: string;
/**
* Send a message to the terminal session.
*/
send(message: TerminalSession.IMessage): void;
/**
* Shut down the terminal session.
*/
shutdown(): Promise<void>;
}
/**
* Create a terminal session or connect to an existing session.
*
* #### Notes
* If the session is already running on the client, the existing
* instance will be returned.
*/
function open(options?: TerminalSession.IOptions): Promise<TerminalSession.ISession>;
/**
* The options for intializing a terminal session object.
*/
interface IOptions extends JSONObject {
/**
* The name of the terminal.
*/
name?: string;
/**
* The base url.
*/
baseUrl?: string;
/**
* The base websocket url.
*/
wsUrl?: string;
/**
* The Ajax settings used for server requests.
*/
ajaxSettings?: utils.IAjaxSettings;
}
/**
* The server model for a terminal session.
*/
interface IModel extends JSONObject {
/**
* The name of the terminal session.
*/
readonly name: string;
}
/**
* A message from the terminal session.
*/
interface IMessage {
/**
* The type of the message.
*/
readonly type: MessageType;
/**
* The content of the message.
*/
readonly content?: JSONPrimitive[];
}
/**
* Valid message types for the terminal.
*/
type MessageType = 'stdout' | 'disconnect' | 'set_size' | 'stdin';
/**
* The interface for a terminal manager.
*/
interface IManager extends IDisposable {
/**
* A signal emitted when the running terminals change.
*/
runningChanged: ISignal<IManager, IModel[]>;
/**
* Create a new terminal session or connect to an existing session.
*
* #### Notes
* This will emit [[runningChanged]] if the running terminals list
* changes.
*/
create(options?: TerminalSession.IOptions): Promise<TerminalSession.ISession>;
/**
* Shut down a terminal session by name.
*
* #### Notes
* This will emit [[runningChanged]] if the running terminals list
* changes.
*/
shutdown(name: string): Promise<void>;
/**
* Get the list of models for the terminals running on the server.
*/
listRunning(): Promise<IModel[]>;
}
}
/**
* A terminal session manager.
*/
export declare class TerminalManager implements TerminalSession.IManager {
/**
* Construct a new terminal manager.
*/
constructor(options?: TerminalManager.IOptions);
/**
* A signal emitted when the running terminals change.
*/
runningChanged: ISignal<this, TerminalSession.IModel[]>;
/**
* Test whether the terminal manager is disposed.
*/
readonly isDisposed: boolean;
/**
* Dispose of the resources used by the manager.
*/
dispose(): void;
/**
* Create a new terminal session or connect to an existing session.
*/
create(options?: TerminalSession.IOptions): Promise<TerminalSession.ISession>;
/**
* Shut down a terminal session by name.
*/
shutdown(name: string): Promise<void>;
/**
* Get the list of models for the terminals running on the server.
*/
listRunning(): Promise<TerminalSession.IModel[]>;
private _baseUrl;
private _wsUrl;
private _ajaxSettings;
private _running;
private _isDisposed;
}
/**
* The namespace for TerminalManager statics.
*/
export declare namespace TerminalManager {
/**
* The options used to initialize a terminal manager.
*/
interface IOptions {
/**
* The base url.
*/
baseUrl?: string;
/**
* The base websocket url.
*/
wsUrl?: string;
/**
* The Ajax settings used for server requests.
*/
ajaxSettings?: utils.IAjaxSettings;
}
}
export * from './manager';
export * from './terminal';
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
"use strict";
var json_1 = require('phosphor/lib/algorithm/json');
var signaling_1 = require('phosphor/lib/core/signaling');
var utils = require('../utils');
/**
* The url for the terminal service.
*/
var TERMINAL_SERVICE_URL = 'api/terminals';
/**
* The namespace for TerminalSession.ISession statics.
*/
var TerminalSession;
(function (TerminalSession) {
/**
* Create a terminal session or connect to an existing session.
*
* #### Notes
* If the session is already running on the client, the existing
* instance will be returned.
*/
function open(options) {
if (options === void 0) { options = {}; }
if (options.name && options.name in Private.running) {
return Private.running[options.name];
}
return new DefaultTerminalSession(options).connect();
}
TerminalSession.open = open;
})(TerminalSession = exports.TerminalSession || (exports.TerminalSession = {}));
/**
* A terminal session manager.
*/
var TerminalManager = (function () {
/**
* Construct a new terminal manager.
*/
function TerminalManager(options) {
if (options === void 0) { options = {}; }
this._baseUrl = '';
this._wsUrl = '';
this._ajaxSettings = null;
this._running = [];
this._isDisposed = false;
this._baseUrl = options.baseUrl || utils.getBaseUrl();
this._wsUrl = options.wsUrl || utils.getWsUrl(this._baseUrl);
this._ajaxSettings = utils.copy(options.ajaxSettings || {});
}
Object.defineProperty(TerminalManager.prototype, "isDisposed", {
/**
* Test whether the terminal manager is disposed.
*/
get: function () {
return this._isDisposed;
},
enumerable: true,
configurable: true
});
/**
* Dispose of the resources used by the manager.
*/
TerminalManager.prototype.dispose = function () {
if (this.isDisposed) {
return;
}
this._isDisposed = true;
signaling_1.clearSignalData(this);
this._running = [];
};
/**
* Create a new terminal session or connect to an existing session.
*/
TerminalManager.prototype.create = function (options) {
if (options === void 0) { options = {}; }
options.baseUrl = options.baseUrl || this._baseUrl;
options.wsUrl = options.wsUrl || this._wsUrl;
options.ajaxSettings = (options.ajaxSettings || utils.copy(this._ajaxSettings));
return TerminalSession.open(options);
};
/**
* Shut down a terminal session by name.
*/
TerminalManager.prototype.shutdown = function (name) {
var url = utils.urlPathJoin(this._baseUrl, TERMINAL_SERVICE_URL, name);
var ajaxSettings = utils.copy(this._ajaxSettings || {});
ajaxSettings.method = 'DELETE';
return utils.ajaxRequest(url, ajaxSettings).then(function (success) {
if (success.xhr.status !== 204) {
return utils.makeAjaxError(success);
}
});
};
/**
* Get the list of models for the terminals running on the server.
*/
TerminalManager.prototype.listRunning = function () {
var _this = this;
var url = utils.urlPathJoin(this._baseUrl, TERMINAL_SERVICE_URL);
var ajaxSettings = utils.copy(this._ajaxSettings || {});
ajaxSettings.method = 'GET';
ajaxSettings.dataType = 'json';
return utils.ajaxRequest(url, ajaxSettings).then(function (success) {
if (success.xhr.status !== 200) {
return utils.makeAjaxError(success);
}
var data = success.data;
if (!Array.isArray(data)) {
return utils.makeAjaxError(success, 'Invalid terminal data');
}
if (!json_1.deepEqual(data, _this._running)) {
_this._running = data;
_this.runningChanged.emit(data);
}
return data;
});
};
return TerminalManager;
}());
exports.TerminalManager = TerminalManager;
/**
* An implementation of a terminal interface.
*/
var DefaultTerminalSession = (function () {
/**
* Construct a new terminal session.
*/
function DefaultTerminalSession(options) {
if (options === void 0) { options = {}; }
this._ajaxSettings = null;
this._ws = null;
this._isDisposed = false;
this._promise = null;
this._baseUrl = options.baseUrl || utils.getBaseUrl();
this._ajaxSettings = options.ajaxSettings || {};
this._name = options.name;
this._wsUrl = options.wsUrl || utils.getWsUrl(this._baseUrl);
this._promise = new utils.PromiseDelegate();
}
Object.defineProperty(DefaultTerminalSession.prototype, "name", {
/**
* Get the name of the terminal session.
*/
get: function () {
return this._name;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DefaultTerminalSession.prototype, "url", {
/**
* Get the websocket url used by the terminal session.
*/
get: function () {
return this._url;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DefaultTerminalSession.prototype, "isDisposed", {
/**
* Test whether the session is disposed.
*/
get: function () {
return this._isDisposed;
},
enumerable: true,
configurable: true
});
/**
* Dispose of the resources held by the session.
*/
DefaultTerminalSession.prototype.dispose = function () {
if (this.isDisposed) {
return;
}
this._isDisposed = true;
if (this._ws) {
this._ws.close();
this._ws = null;
}
delete Private.running[this._name];
this._promise = null;
signaling_1.clearSignalData(this);
};
/**
* Send a message to the terminal session.
*/
DefaultTerminalSession.prototype.send = function (message) {
var msg = [message.type];
msg.push.apply(msg, message.content);
this._ws.send(JSON.stringify(msg));
};
/**
* Shut down the terminal session.
*/
DefaultTerminalSession.prototype.shutdown = function () {
var _this = this;
var url = utils.urlPathJoin(this._baseUrl, TERMINAL_SERVICE_URL, this._name);
var ajaxSettings = utils.copy(this._ajaxSettings);
ajaxSettings.method = 'DELETE';
return utils.ajaxRequest(url, ajaxSettings).then(function (success) {
if (success.xhr.status !== 204) {
return utils.makeAjaxError(success);
}
_this.dispose();
});
};
/**
* Connect to the terminal session.
*/
DefaultTerminalSession.prototype.connect = function () {
var _this = this;
if (this._name) {
return this._initializeSocket();
}
return this._getName().then(function (name) {
_this._name = name;
return _this._initializeSocket();
});
};
/**
* Get a name for the terminal from the server.
*/
DefaultTerminalSession.prototype._getName = function () {
var url = utils.urlPathJoin(this._baseUrl, TERMINAL_SERVICE_URL);
var ajaxSettings = utils.copy(this._ajaxSettings);
ajaxSettings.method = 'POST';
ajaxSettings.dataType = 'json';
return utils.ajaxRequest(url, ajaxSettings).then(function (success) {
if (success.xhr.status !== 200) {
return utils.makeAjaxError(success);
}
return success.data.name;
});
};
/**
* Connect to the websocket.
*/
DefaultTerminalSession.prototype._initializeSocket = function () {
var _this = this;
var name = this._name;
Private.running[name] = this._promise.promise;
this._url = this._wsUrl + "terminals/websocket/" + name;
this._ws = new WebSocket(this._url);
this._ws.onmessage = function (event) {
var data = JSON.parse(event.data);
_this.messageReceived.emit({
type: data[0],
content: data.slice(1)
});
};
this._ws.onopen = function (event) {
_this._promise.resolve(_this);
};
return this._promise.promise;
};
return DefaultTerminalSession;
}());
// Define the signals for the `TerminalManager` class.
signaling_1.defineSignal(TerminalManager.prototype, 'runningChanged');
// Define the signals for the `DefaultTerminalSession` class.
signaling_1.defineSignal(DefaultTerminalSession.prototype, 'messageReceived');
/**
* A namespace for private data.
*/
var Private;
(function (Private) {
/**
* A mapping of running terminals by name.
*/
Private.running = Object.create(null);
})(Private || (Private = {}));
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
__export(require('./manager'));
__export(require('./terminal'));
{
"name": "@jupyterlab/services",
"version": "0.26.0",
"version": "0.27.0",
"description": "Client APIs for the Jupyter services REST APIs",

@@ -44,2 +44,3 @@ "main": "lib/index.js",

"test:integration": "cd test && python integration_test.py",
"test:devtool": "devtool node_modules/mocha/bin/_mocha -qc test/build/**/**.spec.js --foo bar",
"test:debug": "mocha test/build/**/*.spec.js --foo bar --debug-brk",

@@ -46,0 +47,0 @@ "test": "mocha test/build/**/*.spec.js --foo bar"

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc