Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jupyterlab/services

Package Overview
Dependencies
Maintainers
3
Versions
392
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.29.0 to 0.30.0

20

lib/kernel/default.d.ts

@@ -70,10 +70,20 @@ import { IDisposable } from 'phosphor/lib/core/disposable';

/**
* A promise that resolves with a cached kernel info.
* The cached kernel info.
*
* #### Notes
* This value will be null until the kernel is ready.
*/
info(): Promise<KernelMessage.IInfoReply>;
readonly info: KernelMessage.IInfoReply | null;
/**
* A promise that resolves with a cached kernel spec.
* The cached kernel spec.
*
* #### Notes
* This value will be null until the kernel is ready.
*/
spec(): Promise<Kernel.ISpecModel>;
readonly spec: Kernel.ISpecModel | null;
/**
* A promise that is fulfilled when the kernel is ready.
*/
ready(): Promise<void>;
/**
* Clone the current kernel with a new clientId.

@@ -343,2 +353,4 @@ */

private _connectionPromise;
private _readyPromise;
private _spec;
}

@@ -345,0 +357,0 @@ /**

71

lib/kernel/default.js

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

function DefaultKernel(options, id) {
var _this = this;
this._id = '';

@@ -61,2 +62,6 @@ this._name = '';

this._comms = new Map();
this._readyPromise = Private.findSpecs(options).then(function (specs) {
_this._spec = specs.kernelspecs[_this._name];
return _this._connectionPromise.promise;
});
this._createSocket();

@@ -161,32 +166,35 @@ Private.runningKernels.pushBack(this);

});
Object.defineProperty(DefaultKernel.prototype, "info", {
/**
* The cached kernel info.
*
* #### Notes
* This value will be null until the kernel is ready.
*/
get: function () {
return this._info;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DefaultKernel.prototype, "spec", {
/**
* The cached kernel spec.
*
* #### Notes
* This value will be null until the kernel is ready.
*/
get: function () {
return this._spec;
},
enumerable: true,
configurable: true
});
/**
* A promise that resolves with a cached kernel info.
* A promise that is fulfilled when the kernel is ready.
*/
DefaultKernel.prototype.info = function () {
var _this = this;
if (this._info) {
return Promise.resolve(this._info);
}
return this._connectionPromise.promise.then(function () {
return _this._info;
});
DefaultKernel.prototype.ready = function () {
return this._readyPromise;
};
/**
* 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.

@@ -980,2 +988,13 @@ */

/**
* Get the cached kernel specs or fetch them.
*/
function findSpecs(options) {
var promise = Private.specs[options.baseUrl];
if (promise) {
return promise;
}
return getSpecs(options);
}
Private.findSpecs = findSpecs;
/**
* Fetch all of the kernel specs.

@@ -982,0 +1001,0 @@ *

@@ -71,24 +71,20 @@ import { IIterator } from 'phosphor/lib/algorithm/iteration';

/**
* Get the kernel info.
* The cached kernel info.
*
* @returns A promise that resolves with a cached kernel info.
*
* #### Notes
* 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.
* This value will be null until the kernel is ready.
*/
info(): Promise<KernelMessage.IInfoReply>;
readonly info: KernelMessage.IInfoReply | null;
/**
* Get the cached kernel spec.
* The cached kernel spec.
*
* @returns A promise that resolves with a cached kernel spec.
*
* #### Notes
* It will use the cached kernel spec models for this base url or
* fetch them from the server.
* This value will be null until the kernel is ready.
*/
spec(): Promise<Kernel.ISpecModel>;
readonly spec: Kernel.ISpecModel | null;
/**
* A promise that is fulfilled when the kernel is initially ready.
*/
ready(): Promise<void>;
/**
* Send a shell message to the kernel.

@@ -442,3 +438,3 @@ *

/**
* A signal emitted when the specs change.
* A signal emitted when the kernel specs change.
*/

@@ -463,6 +459,13 @@ specsChanged: ISignal<IManager, ISpecModels>;

/**
* Get the most recently fetched kernel specs.
* The kernel spec models.
*
* #### Notes
* The value will be null until the manager is ready.
*/
readonly specs: Kernel.ISpecModels | null;
/**
* A promise that fulfills when the manager is initially ready.
*/
ready(): Promise<void>;
/**
* Create an iterator over the known running kernels.

@@ -474,17 +477,21 @@ *

/**
* Fetch the specs from the server.
* Force a refresh of the specs from the server.
*
* @returns A promise that resolves with the kernel spec models.
* @returns A promise that resolves when the specs are fetched.
*
* #### Notes
* This is intended to be called only in response to a user action,
* since the manager maintains its internal state.
*/
fetchSpecs(): Promise<ISpecModels>;
refreshSpecs(): Promise<void>;
/**
* Force a refresh of the running kernels.
*
* @returns A promise that with the list of running kernels.
* @returns A promise that resolves when the models are refreshed.
*
* #### Notes
* This is not typically meant to be called by the user, since the
* manager maintains its own internal state.
* This is intended to be called only in response to a user action,
* since the manager maintains its internal state.
*/
refreshRunning(): Promise<IModel[]>;
refreshRunning(): Promise<void>;
/**

@@ -491,0 +498,0 @@ * Start a new kernel.

@@ -51,2 +51,6 @@ import { IIterator } from 'phosphor/lib/algorithm/iteration';

/**
* A promise that fulfills when the manager is ready.
*/
ready(): Promise<void>;
/**
* Create an iterator over the most recent running kernels.

@@ -58,11 +62,15 @@ *

/**
* Fetch the specs from the server.
* Force a refresh of the specs from the server.
*
* @returns A promise that resolves with the kernel spec models.
* @returns A promise that resolves when the specs are fetched.
*
* #### Notes
* This is intended to be called only in response to a user action,
* since the manager maintains its internal state.
*/
fetchSpecs(): Promise<Kernel.ISpecModels>;
refreshSpecs(): Promise<void>;
/**
* Force a refresh of the running kernels.
*
* @returns A promise that with the list of running kernels.
* @returns A promise that with the list of running sessions.
*

@@ -73,3 +81,3 @@ * #### Notes

*/
refreshRunning(): Promise<Kernel.IModel[]>;
refreshRunning(): Promise<void>;
/**

@@ -79,6 +87,2 @@ * Start a new kernel. See also [[startNewKernel]].

* @param options - Overrides for the default options.
*
* #### Notes
* This will emit [[runningChanged]] if the running kernels list
* changes.
*/

@@ -109,9 +113,13 @@ startNew(options?: Kernel.IOptions): Promise<Kernel.IKernel>;

/**
* Refresh the specs.
*/
private _refreshSpecs();
/**
* Refresh the running sessions.
*/
private _refreshRunning();
/**
* Get optionally overidden options.
*/
private _getOptions(options?);
/**
* Schedule an update of the running kernels.
*/
private _scheduleUpdate();
private _baseUrl;

@@ -123,6 +131,5 @@ private _wsUrl;

private _isDisposed;
private _updateTimer;
private _refreshTimer;
private _specPromise;
private _runningPromise;
private _runningTimer;
private _specsTimer;
private _readyPromise;
}

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

function KernelManager(options) {
var _this = this;
if (options === void 0) { options = {}; }

@@ -27,10 +28,18 @@ this._baseUrl = '';

this._isDisposed = false;
this._updateTimer = -1;
this._refreshTimer = -1;
this._specPromise = null;
this._runningPromise = null;
this._runningTimer = -1;
this._specsTimer = -1;
this._baseUrl = options.baseUrl || utils.getBaseUrl();
this._wsUrl = options.wsUrl || utils.getWsUrl(this._baseUrl);
this._ajaxSettings = JSON.stringify(options.ajaxSettings || {});
this._scheduleUpdate();
// Initialize internal data.
this._readyPromise = this._refreshSpecs().then(function () {
return _this._refreshRunning();
});
// Set up polling.
this._runningTimer = setInterval(function () {
_this._refreshRunning();
}, 10000);
this._specsTimer = setInterval(function () {
_this._refreshSpecs();
}, 61000);
}

@@ -55,4 +64,4 @@ Object.defineProperty(KernelManager.prototype, "isDisposed", {

this._isDisposed = true;
clearTimeout(this._updateTimer);
clearTimeout(this._refreshTimer);
clearInterval(this._runningTimer);
clearInterval(this._specsTimer);
signaling_1.clearSignalData(this);

@@ -109,2 +118,8 @@ this._specs = null;

/**
* A promise that fulfills when the manager is ready.
*/
KernelManager.prototype.ready = function () {
return this._readyPromise;
};
/**
* Create an iterator over the most recent running kernels.

@@ -118,24 +133,12 @@ *

/**
* Fetch the specs from the server.
* Force a refresh of the specs from the server.
*
* @returns A promise that resolves with the kernel spec models.
* @returns A promise that resolves when the specs are fetched.
*
* #### Notes
* This is intended to be called only in response to a user action,
* since the manager maintains its internal state.
*/
KernelManager.prototype.fetchSpecs = function () {
var _this = this;
if (this._specPromise) {
return this._specPromise;
}
var options = {
baseUrl: this._baseUrl,
ajaxSettings: this.ajaxSettings
};
this._specPromise = kernel_1.Kernel.getSpecs(options).then(function (specs) {
if (!json_1.deepEqual(specs, _this._specs)) {
_this._specs = specs;
_this._specPromise = null;
_this.specsChanged.emit(specs);
}
return specs;
});
return this._specPromise;
KernelManager.prototype.refreshSpecs = function () {
return this._refreshSpecs();
};

@@ -145,3 +148,3 @@ /**

*
* @returns A promise that with the list of running kernels.
* @returns A promise that with the list of running sessions.
*

@@ -153,21 +156,3 @@ * #### Notes

KernelManager.prototype.refreshRunning = function () {
var _this = this;
clearTimeout(this._updateTimer);
clearTimeout(this._refreshTimer);
if (this._runningPromise) {
return this._runningPromise;
}
var promise = kernel_1.Kernel.listRunning(this._getOptions()).then(function (running) {
if (!json_1.deepEqual(running, _this._running)) {
_this._running = running.slice();
_this._runningPromise = null;
_this.runningChanged.emit(running);
}
_this._refreshTimer = setTimeout(function () {
_this.refreshRunning();
}, 10000);
return running;
});
this._runningPromise = promise;
return promise;
return this._refreshRunning();
};

@@ -178,16 +163,5 @@ /**

* @param options - Overrides for the default options.
*
* #### Notes
* This will emit [[runningChanged]] if the running kernels list
* changes.
*/
KernelManager.prototype.startNew = function (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;
});
return kernel_1.Kernel.startNew(this._getOptions(options));
};

@@ -208,9 +182,3 @@ /**

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

@@ -227,8 +195,33 @@ /**

KernelManager.prototype.shutdown = function (id, options) {
return kernel_1.Kernel.shutdown(id, this._getOptions(options));
};
/**
* Refresh the specs.
*/
KernelManager.prototype._refreshSpecs = function () {
var _this = this;
return kernel_1.Kernel.shutdown(id, this._getOptions(options)).then(function () {
_this._scheduleUpdate();
var options = {
baseUrl: this._baseUrl,
ajaxSettings: this.ajaxSettings
};
return kernel_1.Kernel.getSpecs(options).then(function (specs) {
if (!json_1.deepEqual(specs, _this._specs)) {
_this._specs = specs;
_this.specsChanged.emit(specs);
}
});
};
/**
* Refresh the running sessions.
*/
KernelManager.prototype._refreshRunning = function () {
var _this = this;
return kernel_1.Kernel.listRunning(this._getOptions({})).then(function (running) {
if (!json_1.deepEqual(running, _this._running)) {
_this._running = running.slice();
_this.runningChanged.emit(running);
}
});
};
/**
* Get optionally overidden options.

@@ -243,14 +236,2 @@ */

};
/**
* 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;

@@ -257,0 +238,0 @@ }());

import { JSONObject } from 'phosphor/lib/algorithm/json';
import { IDisposable } from 'phosphor/lib/core/disposable';
import { ISignal } from 'phosphor/lib/core/signaling';
import { Contents, ContentsManager } from './contents';
import { Kernel } from './kernel';
import { Session, SessionManager } from './session';

@@ -16,2 +18,6 @@ import { TerminalSession, TerminalManager } from './terminal';

/**
* A signal emitted when the kernel specs change.
*/
specsChanged: ISignal<this, Kernel.ISpecModels>;
/**
* Test whether the terminal manager is disposed.

@@ -21,2 +27,10 @@ */

/**
* Dispose of the resources used by the manager.
*/
dispose(): void;
/**
* The kernel spec models.
*/
readonly specs: Kernel.ISpecModels | null;
/**
* Get the base url of the server.

@@ -26,6 +40,2 @@ */

/**
* Dispose of the resources used by the manager.
*/
dispose(): void;
/**
* Get the session manager instance.

@@ -42,2 +52,6 @@ */

readonly terminals: TerminalManager;
/**
* A promise that fulfills when the manager is ready.
*/
ready(): Promise<void>;
private _sessionManager;

@@ -47,2 +61,3 @@ private _contentsManager;

private _isDisposed;
private _readyPromise;
}

@@ -58,2 +73,10 @@ /**

/**
* A signal emitted when the kernel specs change.
*/
specsChanged: ISignal<IManager, Kernel.ISpecModels>;
/**
* The kernel spec models.
*/
readonly specs: Kernel.ISpecModels | null;
/**
* The base url of the manager.

@@ -74,2 +97,6 @@ */

readonly terminals: TerminalSession.IManager;
/**
* A promise that fulfills when the manager is initially ready.
*/
ready(): Promise<void>;
}

@@ -76,0 +103,0 @@ /**

// 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');

@@ -16,2 +17,3 @@ var session_1 = require('./session');

function ServiceManager(options) {
var _this = this;
this._sessionManager = null;

@@ -28,2 +30,8 @@ this._contentsManager = null;

this._terminalManager = new terminal_1.TerminalManager(options);
this._sessionManager.specsChanged.connect(function (sender, specs) {
_this.specsChanged.emit(specs);
});
this._readyPromise = this._sessionManager.ready().then(function () {
return _this._terminalManager.ready;
});
}

@@ -40,12 +48,2 @@ Object.defineProperty(ServiceManager.prototype, "isDisposed", {

});
Object.defineProperty(ServiceManager.prototype, "baseUrl", {
/**
* Get the base url of the server.
*/
get: function () {
return this._sessionManager.baseUrl;
},
enumerable: true,
configurable: true
});
/**

@@ -59,2 +57,3 @@ * Dispose of the resources used by the manager.

this._isDisposed = true;
signaling_1.clearSignalData(this);
this._sessionManager.dispose();

@@ -64,2 +63,22 @@ this._contentsManager.dispose();

};
Object.defineProperty(ServiceManager.prototype, "specs", {
/**
* The kernel spec models.
*/
get: function () {
return this._sessionManager.specs;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ServiceManager.prototype, "baseUrl", {
/**
* Get the base url of the server.
*/
get: function () {
return this._sessionManager.baseUrl;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ServiceManager.prototype, "sessions", {

@@ -95,4 +114,12 @@ /**

});
/**
* A promise that fulfills when the manager is ready.
*/
ServiceManager.prototype.ready = function () {
return this._readyPromise;
};
return ServiceManager;
}());
exports.ServiceManager = ServiceManager;
// Define the signals for the `ServiceManager` class.
signaling_1.defineSignal(ServiceManager.prototype, 'specsChanged');

@@ -52,2 +52,6 @@ import { IIterator } from 'phosphor/lib/algorithm/iteration';

/**
* A promise that fulfills when the manager is ready.
*/
ready(): Promise<void>;
/**
* Create an iterator over the most recent running sessions.

@@ -59,7 +63,11 @@ *

/**
* Fetch the specs from the server.
* Force a refresh of the specs from the server.
*
* @returns A promise that resolves with the kernel spec models.
* @returns A promise that resolves when the specs are fetched.
*
* #### Notes
* This is intended to be called only in response to a user action,
* since the manager maintains its internal state.
*/
fetchSpecs(): Promise<Kernel.ISpecModels>;
refreshSpecs(): Promise<void>;
/**

@@ -74,3 +82,3 @@ * Force a refresh of the running sessions.

*/
refreshRunning(): Promise<Session.IModel[]>;
refreshRunning(): Promise<void>;
/**

@@ -101,5 +109,9 @@ * Start a new session. See also [[startNewSession]].

/**
* Schedule an update of the running sessions.
* Refresh the specs.
*/
private _scheduleUpdate();
private _refreshSpecs();
/**
* Refresh the running sessions.
*/
private _refreshRunning();
private _baseUrl;

@@ -111,6 +123,5 @@ private _wsUrl;

private _specs;
private _updateTimer;
private _refreshTimer;
private _specPromise;
private _runningPromise;
private _runningTimer;
private _specsTimer;
private _readyPromise;
}

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

function SessionManager(options) {
var _this = this;
if (options === void 0) { options = {}; }

@@ -28,10 +29,18 @@ this._baseUrl = '';

this._specs = null;
this._updateTimer = -1;
this._refreshTimer = -1;
this._specPromise = null;
this._runningPromise = null;
this._runningTimer = -1;
this._specsTimer = -1;
this._baseUrl = options.baseUrl || utils.getBaseUrl();
this._wsUrl = options.wsUrl || utils.getWsUrl(this._baseUrl);
this._ajaxSettings = JSON.stringify(options.ajaxSettings || {});
this._scheduleUpdate();
// Initialize internal data.
this._readyPromise = this._refreshSpecs().then(function () {
return _this._refreshRunning();
});
// Set up polling.
this._runningTimer = setInterval(function () {
_this._refreshRunning();
}, 10000);
this._specsTimer = setInterval(function () {
_this._refreshSpecs();
}, 61000);
}

@@ -56,4 +65,4 @@ Object.defineProperty(SessionManager.prototype, "isDisposed", {

this._isDisposed = true;
clearTimeout(this._updateTimer);
clearTimeout(this._refreshTimer);
clearInterval(this._runningTimer);
clearInterval(this._specsTimer);
signaling_1.clearSignalData(this);

@@ -109,2 +118,8 @@ this._running = [];

/**
* A promise that fulfills when the manager is ready.
*/
SessionManager.prototype.ready = function () {
return this._readyPromise;
};
/**
* Create an iterator over the most recent running sessions.

@@ -118,24 +133,12 @@ *

/**
* Fetch the specs from the server.
* Force a refresh of the specs from the server.
*
* @returns A promise that resolves with the kernel spec models.
* @returns A promise that resolves when the specs are fetched.
*
* #### Notes
* This is intended to be called only in response to a user action,
* since the manager maintains its internal state.
*/
SessionManager.prototype.fetchSpecs = function () {
var _this = this;
if (this._specPromise) {
return this._specPromise;
}
var options = {
baseUrl: this._baseUrl,
ajaxSettings: this.ajaxSettings
};
this._specPromise = kernel_1.Kernel.getSpecs(options).then(function (specs) {
if (!json_1.deepEqual(specs, _this._specs)) {
_this._specs = specs;
_this._specPromise = null;
_this.specsChanged.emit(specs);
}
return specs;
});
return this._specPromise;
SessionManager.prototype.refreshSpecs = function () {
return this._refreshSpecs();
};

@@ -152,25 +155,3 @@ /**

SessionManager.prototype.refreshRunning = function () {
var _this = this;
clearTimeout(this._updateTimer);
clearTimeout(this._refreshTimer);
if (this._runningPromise) {
return this._runningPromise;
}
var promise = session_1.Session.listRunning(this._getOptions({})).then(function (running) {
if (!json_1.deepEqual(running, _this._running)) {
_this._running = running.slice();
_this._runningPromise = null;
_this.runningChanged.emit(running);
}
// Throttle the next request.
if (_this._updateTimer !== -1) {
_this._scheduleUpdate();
}
_this._refreshTimer = setTimeout(function () {
_this.refreshRunning();
}, 10000);
return running;
});
this._runningPromise = promise;
return promise;
return this._refreshRunning();
};

@@ -184,8 +165,3 @@ /**

SessionManager.prototype.startNew = function (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;
});
return session_1.Session.startNew(this._getOptions(options));
};

@@ -208,7 +184,3 @@ /**

SessionManager.prototype.connectTo = function (id, options) {
var _this = this;
return session_1.Session.connectTo(id, this._getOptions(options)).then(function (session) {
session.terminated.connect(function () { _this._scheduleUpdate(); });
return session;
});
return session_1.Session.connectTo(id, this._getOptions(options));
};

@@ -219,6 +191,3 @@ /**

SessionManager.prototype.shutdown = function (id, options) {
var _this = this;
return session_1.Session.shutdown(id, this._getOptions(options)).then(function () {
_this._scheduleUpdate();
});
return session_1.Session.shutdown(id, this._getOptions(options));
};

@@ -236,13 +205,29 @@ /**

/**
* Schedule an update of the running sessions.
* Refresh the specs.
*/
SessionManager.prototype._scheduleUpdate = function () {
SessionManager.prototype._refreshSpecs = function () {
var _this = this;
if (this._updateTimer !== -1) {
return;
}
this._updateTimer = setTimeout(function () {
_this.refreshRunning();
}, 100);
var options = {
baseUrl: this._baseUrl,
ajaxSettings: this.ajaxSettings
};
return kernel_1.Kernel.getSpecs(options).then(function (specs) {
if (!json_1.deepEqual(specs, _this._specs)) {
_this._specs = specs;
_this.specsChanged.emit(specs);
}
});
};
/**
* Refresh the running sessions.
*/
SessionManager.prototype._refreshRunning = function () {
var _this = this;
return session_1.Session.listRunning(this._getOptions({})).then(function (running) {
if (!json_1.deepEqual(running, _this._running)) {
_this._running = running.slice();
_this.runningChanged.emit(running);
}
});
};
return SessionManager;

@@ -249,0 +234,0 @@ }());

@@ -286,6 +286,13 @@ import { IIterator } from 'phosphor/lib/algorithm/iteration';

/**
* Get the most recently fetched kernel specs.
* The cached kernel specs.
*
* #### Notes
* This value will be null until the manager is ready.
*/
readonly specs: Kernel.ISpecModels | null;
/**
* A promise that is fulfilled when the manager is ready.
*/
ready(): Promise<void>;
/**
* Create an iterator over the known running sessions.

@@ -349,17 +356,21 @@ *

/**
* Fetch the specs from the server.
* Force a refresh of the specs from the server.
*
* @returns A promise that resolves with the kernel spec models.
* @returns A promise that resolves when the specs are fetched.
*
* #### Notes
* This is intended to be called only in response to a user action,
* since the manager maintains its internal state.
*/
fetchSpecs(): Promise<Kernel.ISpecModels>;
refreshSpecs(): Promise<void>;
/**
* Force a refresh of the running sessions.
*
* @returns A promise that with the list of running sessions.
* @returns A promise that resolves when the models are refreshed.
*
* #### Notes
* This is not typically meant to be called by the user, since the
* manager maintains its own internal state.
* This is intended to be called only in response to a user action,
* since the manager maintains its internal state.
*/
refreshRunning(): Promise<IModel[]>;
refreshRunning(): Promise<void>;
}

@@ -366,0 +377,0 @@ /**

@@ -48,2 +48,6 @@ import { ISignal } from 'phosphor/lib/core/signaling';

/**
* A promise that fulfills when the manager is ready.
*/
ready(): Promise<void>;
/**
* Send a message to the terminal session.

@@ -57,10 +61,2 @@ */

/**
* Connect to the terminal session.
*/
connect(): Promise<TerminalSession.ISession>;
/**
* Get a name for the terminal from the server.
*/
private _getName();
/**
* Connect to the websocket.

@@ -76,4 +72,7 @@ */

private _isDisposed;
private _promise;
private _readyPromise;
}
/**
* The static namespace for `DefaultTerminalSession`.
*/
export declare namespace DefaultTerminalSession {

@@ -80,0 +79,0 @@ /**

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

this._isDisposed = false;
this._name = name;
this._baseUrl = options.baseUrl || utils.getBaseUrl();
this._ajaxSettings = JSON.stringify(options.ajaxSettings || {});
this._wsUrl = options.wsUrl || utils.getWsUrl(this._baseUrl);
this._readyPromise = this._initializeSocket();
}

@@ -97,6 +99,12 @@ Object.defineProperty(DefaultTerminalSession.prototype, "name", {

delete Private.running[this._url];
this._promise = null;
this._readyPromise = null;
signaling_1.clearSignalData(this);
};
/**
* A promise that fulfills when the manager is ready.
*/
DefaultTerminalSession.prototype.ready = function () {
return this._readyPromise;
};
/**
* Send a message to the terminal session.

@@ -125,35 +133,2 @@ */

/**
* Connect to the terminal session.
*/
DefaultTerminalSession.prototype.connect = function () {
var _this = this;
if (this._promise) {
return this._promise;
}
if (this._name) {
this._promise = this._initializeSocket();
return this._promise;
}
this._promise = this._getName().then(function (value) {
_this._name = value;
return _this._initializeSocket();
});
return this._promise;
};
/**
* Get a name for the terminal from the server.
*/
DefaultTerminalSession.prototype._getName = function () {
var url = Private.getBaseUrl(this._baseUrl);
var ajaxSettings = 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.

@@ -177,6 +152,6 @@ */

_this._ws.onopen = function (event) {
resolve(_this);
resolve(void 0);
};
_this._ws.onerror = function (event) {
reject(_this);
reject(event);
};

@@ -188,2 +163,5 @@ });

exports.DefaultTerminalSession = DefaultTerminalSession;
/**
* The static namespace for `DefaultTerminalSession`.
*/
var DefaultTerminalSession;

@@ -200,3 +178,14 @@ (function (DefaultTerminalSession) {

if (options === void 0) { options = {}; }
return new DefaultTerminalSession('', options).connect();
var baseUrl = options.baseUrl || utils.getBaseUrl();
var url = Private.getBaseUrl(baseUrl);
var ajaxSettings = utils.copy(options.ajaxSettings || {});
ajaxSettings.method = 'POST';
ajaxSettings.dataType = 'json';
return utils.ajaxRequest(url, ajaxSettings).then(function (success) {
if (success.xhr.status !== 200) {
return utils.makeAjaxError(success);
}
var name = success.data.name;
return new DefaultTerminalSession(name, options);
});
}

@@ -227,8 +216,9 @@ DefaultTerminalSession.startNew = startNew;

if (options === void 0) { options = {}; }
options.baseUrl = options.baseUrl || utils.getBaseUrl();
var url = Private.getTermUrl(options.baseUrl, name);
var baseUrl = options.baseUrl || utils.getBaseUrl();
var url = Private.getTermUrl(baseUrl, name);
if (url in Private.running) {
return Private.running[url].connect();
return Promise.resolve(Private.running[url]);
}
return new DefaultTerminalSession(name, options).connect();
var session = new DefaultTerminalSession(name, options);
return Promise.resolve(session);
}

@@ -235,0 +225,0 @@ DefaultTerminalSession.connectTo = connectTo;

@@ -42,2 +42,6 @@ import { IIterator } from 'phosphor/lib/algorithm/iteration';

/**
* A promise that fulfills when the manager is ready.
*/
ready(): Promise<void>;
/**
* Create an iterator over the most recent running terminals.

@@ -68,13 +72,19 @@ *

/**
* Force a refresh of the running terminals.
* 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<TerminalSession.IModel[]>;
refreshRunning(): Promise<void>;
/**
* Refresh the running sessions.
*/
private _refreshRunning();
/**
* Get a set of options to pass.
*/
private _getOptions(options?);
/**
* Schedule an update of the running sessions.
*/
private _scheduleUpdate();
private _baseUrl;

@@ -85,4 +95,4 @@ private _wsUrl;

private _isDisposed;
private _updateTimer;
private _refreshTimer;
private _readyPromise;
}

@@ -89,0 +99,0 @@ /**

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

function TerminalManager(options) {
var _this = this;
if (options === void 0) { options = {}; }

@@ -24,3 +25,2 @@ this._baseUrl = '';

this._isDisposed = false;
this._updateTimer = -1;
this._refreshTimer = -1;

@@ -30,3 +30,8 @@ this._baseUrl = options.baseUrl || utils.getBaseUrl();

this._ajaxSettings = JSON.stringify(options.ajaxSettings || {});
this._scheduleUpdate();
// Initialize internal data.
this._readyPromise = this._refreshRunning();
// Set up polling.
this._refreshTimer = setInterval(function () {
_this._refreshRunning();
}, 10000);
}

@@ -87,4 +92,3 @@ Object.defineProperty(TerminalManager.prototype, "isDisposed", {

this._isDisposed = true;
clearTimeout(this._updateTimer);
clearTimeout(this._refreshTimer);
clearInterval(this._refreshTimer);
signaling_1.clearSignalData(this);

@@ -94,2 +98,8 @@ this._running = [];

/**
* A promise that fulfills when the manager is ready.
*/
TerminalManager.prototype.ready = function () {
return this._readyPromise;
};
/**
* Create an iterator over the most recent running terminals.

@@ -134,11 +144,3 @@ *

TerminalManager.prototype.connectTo = function (name, options) {
var _this = this;
options = this._getOptions(options);
return terminal_1.TerminalSession.connectTo(name, options).then(function (session) {
_this._scheduleUpdate();
session.terminated.connect(function () {
_this._scheduleUpdate();
});
return session;
});
return terminal_1.TerminalSession.connectTo(name, this._getOptions(options));
};

@@ -149,27 +151,26 @@ /**

TerminalManager.prototype.shutdown = function (name) {
var _this = this;
return terminal_1.TerminalSession.shutdown(name, this._getOptions()).then(function () {
_this._scheduleUpdate();
});
return terminal_1.TerminalSession.shutdown(name, this._getOptions());
};
/**
* Force a refresh of the running terminals.
* 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.
*/
TerminalManager.prototype.refreshRunning = function () {
return this._refreshRunning();
};
/**
* Refresh the running sessions.
*/
TerminalManager.prototype._refreshRunning = function () {
var _this = this;
clearTimeout(this._updateTimer);
clearTimeout(this._refreshTimer);
return terminal_1.TerminalSession.listRunning(this._getOptions()).then(function (data) {
if (!json_1.deepEqual(data, _this._running)) {
_this._running = data;
_this.runningChanged.emit(data);
return terminal_1.TerminalSession.listRunning(this._getOptions({})).then(function (running) {
if (!json_1.deepEqual(running, _this._running)) {
_this._running = running.slice();
_this.runningChanged.emit(running);
}
// Throttle the next request.
if (_this._updateTimer !== -1) {
_this._scheduleUpdate();
}
_this._refreshTimer = setTimeout(function () {
_this.refreshRunning();
}, 10000);
return data;
});

@@ -187,14 +188,2 @@ };

};
/**
* Schedule an update of the running sessions.
*/
TerminalManager.prototype._scheduleUpdate = function () {
var _this = this;
if (this._updateTimer !== -1) {
return;
}
this._updateTimer = setTimeout(function () {
_this.refreshRunning();
}, 100);
};
return TerminalManager;

@@ -201,0 +190,0 @@ }());

@@ -40,2 +40,6 @@ import { IIterator } from 'phosphor/lib/algorithm/iteration';

/**
* A promise that fulfills when the session is initially ready.
*/
ready(): Promise<void>;
/**
* Send a message to the terminal session.

@@ -144,2 +148,6 @@ */

/**
* A promise that fulfills when the manager is ready.
*/
ready(): Promise<void>;
/**
* Create an iterator over the known running terminals.

@@ -175,3 +183,3 @@ *

*
* @returns A promise that resolves with the list of running sessions.
* @returns A promise that with the list of running sessions.
*

@@ -182,4 +190,4 @@ * #### Notes

*/
refreshRunning(): Promise<IModel[]>;
refreshRunning(): Promise<void>;
}
}
{
"name": "@jupyterlab/services",
"version": "0.29.0",
"version": "0.30.0",
"description": "Client APIs for the Jupyter services REST APIs",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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