Socket
Socket
Sign inDemoInstall

@jupyterlab/services

Package Overview
Dependencies
Maintainers
4
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.42.1 to 0.43.0

18

lib/config/index.js
"use strict";
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var coreutils_1 = require("@jupyterlab/coreutils");
var coreutils_2 = require("@phosphor/coreutils");
var utils = require("../utils");

@@ -41,3 +51,3 @@ /**

this.ajaxSettings = utils.ajaxSettingsWithToken(options.ajaxSettings, options.token);
this._url = utils.urlPathJoin(baseUrl, SERVICE_CONFIG_URL, encodeURIComponent(options.name));
this._url = coreutils_1.URLExt.join(baseUrl, SERVICE_CONFIG_URL, encodeURIComponent(options.name));
}

@@ -49,3 +59,3 @@ Object.defineProperty(DefaultConfigSection.prototype, "ajaxSettings", {

get: function () {
return utils.copy(this._ajaxSettings);
return coreutils_2.JSONExt.deepCopy(this._ajaxSettings);
},

@@ -56,3 +66,3 @@ /**

set: function (value) {
this._ajaxSettings = utils.copy(value);
this._ajaxSettings = coreutils_2.JSONExt.deepCopy(value);
},

@@ -107,3 +117,3 @@ enumerable: true,

var _this = this;
this._data = utils.extend(this._data, newdata);
this._data = __assign({}, this._data, newdata);
var ajaxSettings = this.ajaxSettings;

@@ -110,0 +120,0 @@ ajaxSettings.method = 'PATCH';

@@ -5,2 +5,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var coreutils_1 = require("@jupyterlab/coreutils");
var coreutils_2 = require("@phosphor/coreutils");
var signaling_1 = require("@phosphor/signaling");

@@ -82,3 +84,3 @@ var utils = require("../utils");

get: function () {
return utils.copy(this._ajaxSettings);
return coreutils_2.JSONExt.deepCopy(this._ajaxSettings);
},

@@ -89,3 +91,3 @@ /**

set: function (value) {
this._ajaxSettings = utils.copy(value);
this._ajaxSettings = coreutils_2.JSONExt.deepCopy(value);
},

@@ -117,5 +119,5 @@ enumerable: true,

}
var params = utils.copy(options);
var params = coreutils_2.JSONExt.deepCopy(options);
params.content = options.content ? '1' : '0';
url += utils.jsonToQueryString(params);
url += coreutils_1.URLExt.objectToQueryString(params);
}

@@ -144,3 +146,3 @@ return utils.ajaxRequest(url, ajaxSettings).then(function (success) {

ContentsManager.prototype.getDownloadUrl = function (path) {
return Promise.resolve(utils.urlPathJoin(this._baseUrl, FILES_URL, utils.urlEncodeParts(path)));
return Promise.resolve(coreutils_1.URLExt.join(this._baseUrl, FILES_URL, coreutils_1.URLExt.encodeParts(path)));
};

@@ -474,4 +476,4 @@ /**

}
var parts = args.map(function (path) { return utils.urlEncodeParts(path); });
return utils.urlPathJoin.apply(utils, [this._baseUrl, SERVICE_CONTENTS_URL].concat(parts));
var parts = args.map(function (path) { return coreutils_1.URLExt.encodeParts(path); });
return coreutils_1.URLExt.join.apply(coreutils_1.URLExt, [this._baseUrl, SERVICE_CONTENTS_URL].concat(parts));
};

@@ -478,0 +480,0 @@ return ContentsManager;

"use strict";
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var coreutils_1 = require("@jupyterlab/coreutils");
var algorithm_1 = require("@phosphor/algorithm");
var coreutils_1 = require("@phosphor/coreutils");
var coreutils_2 = require("@phosphor/coreutils");
var disposable_1 = require("@phosphor/disposable");

@@ -61,3 +70,3 @@ var signaling_1 = require("@phosphor/signaling");

this._token = options.token || utils.getConfigOption('token');
this._clientId = options.clientId || utils.uuid();
this._clientId = options.clientId || coreutils_1.uuid();
this._username = options.username || '';

@@ -516,3 +525,3 @@ this._futures = new Map();

};
content = utils.extend(defaults, content);
content = __assign({}, defaults, content);
var msg = messages_1.KernelMessage.createShellMessage(options, content);

@@ -645,3 +654,3 @@ return this.sendShellMessage(msg, true, disposeOnDone);

if (commId === void 0) {
commId = utils.uuid();
commId = coreutils_1.uuid();
}

@@ -660,7 +669,7 @@ var comm = this._comms.get(commId);

var _this = this;
var partialUrl = utils.urlPathJoin(this._wsUrl, KERNEL_SERVICE_URL, encodeURIComponent(this._id));
var partialUrl = coreutils_1.URLExt.join(this._wsUrl, KERNEL_SERVICE_URL, encodeURIComponent(this._id));
// Strip any authentication from the display string.
var parsed = utils.urlParse(partialUrl);
console.log('Starting websocket', parsed.hostname);
var url = utils.urlPathJoin(partialUrl, 'channels?session_id=' + encodeURIComponent(this._clientId));
var parsed = coreutils_1.URLExt.parse(partialUrl);
console.log('Starting websocket', parsed.host);
var url = coreutils_1.URLExt.join(partialUrl, 'channels?session_id=' + encodeURIComponent(this._clientId));
// if token authentication is in use

@@ -670,3 +679,3 @@ if (this._token !== '') {

}
this._connectionPromise = new coreutils_1.PromiseDelegate();
this._connectionPromise = new coreutils_2.PromiseDelegate();
this._ws = new WebSocket(url);

@@ -1065,3 +1074,3 @@ // Ensure incoming binary messages are not Blobs

var baseUrl = options.baseUrl || utils.getBaseUrl();
var url = utils.urlPathJoin(baseUrl, KERNELSPEC_SERVICE_URL);
var url = coreutils_1.URLExt.join(baseUrl, KERNELSPEC_SERVICE_URL);
var ajaxSettings = utils.ajaxSettingsWithToken(options.ajaxSettings, options.token);

@@ -1096,3 +1105,3 @@ ajaxSettings.method = 'GET';

var baseUrl = options.baseUrl || utils.getBaseUrl();
var url = utils.urlPathJoin(baseUrl, KERNEL_SERVICE_URL);
var url = coreutils_1.URLExt.join(baseUrl, KERNEL_SERVICE_URL);
var ajaxSettings = utils.ajaxSettingsWithToken(options.ajaxSettings, options.token);

@@ -1146,3 +1155,3 @@ ajaxSettings.method = 'GET';

var baseUrl = options.baseUrl || utils.getBaseUrl();
var url = utils.urlPathJoin(baseUrl, KERNEL_SERVICE_URL);
var url = coreutils_1.URLExt.join(baseUrl, KERNEL_SERVICE_URL);
var ajaxSettings = utils.ajaxSettingsWithToken(options.ajaxSettings, options.token);

@@ -1159,3 +1168,3 @@ ajaxSettings.method = 'POST';

validate.validateModel(success.data);
options = utils.copy(options);
options = coreutils_2.JSONExt.deepCopy(options);
options.name = success.data.name;

@@ -1189,3 +1198,3 @@ return new DefaultKernel(options, success.data.id);

return getKernelModel(id, options).then(function (model) {
options = utils.copy(options);
options = coreutils_2.JSONExt.deepCopy(options);
options.name = model.name;

@@ -1215,3 +1224,3 @@ return new DefaultKernel(options, id);

}
var url = utils.urlPathJoin(baseUrl, KERNEL_SERVICE_URL, encodeURIComponent(kernel.id), 'restart');
var url = coreutils_1.URLExt.join(baseUrl, KERNEL_SERVICE_URL, encodeURIComponent(kernel.id), 'restart');
ajaxSettings = ajaxSettings || {};

@@ -1241,3 +1250,3 @@ ajaxSettings.method = 'POST';

}
var url = utils.urlPathJoin(baseUrl, KERNEL_SERVICE_URL, encodeURIComponent(kernel.id), 'interrupt');
var url = coreutils_1.URLExt.join(baseUrl, KERNEL_SERVICE_URL, encodeURIComponent(kernel.id), 'interrupt');
ajaxSettings = ajaxSettings || {};

@@ -1258,3 +1267,3 @@ ajaxSettings.method = 'POST';

function shutdownKernel(id, baseUrl, ajaxSettings) {
var url = utils.urlPathJoin(baseUrl, KERNEL_SERVICE_URL, encodeURIComponent(id));
var url = coreutils_1.URLExt.join(baseUrl, KERNEL_SERVICE_URL, encodeURIComponent(id));
ajaxSettings = ajaxSettings || {};

@@ -1298,3 +1307,3 @@ ajaxSettings.method = 'DELETE';

var baseUrl = options.baseUrl || utils.getBaseUrl();
var url = utils.urlPathJoin(baseUrl, KERNEL_SERVICE_URL, encodeURIComponent(id));
var url = coreutils_1.URLExt.join(baseUrl, KERNEL_SERVICE_URL, encodeURIComponent(id));
var ajaxSettings = utils.ajaxSettingsWithToken(options.ajaxSettings, options.token);

@@ -1301,0 +1310,0 @@ ajaxSettings.method = 'GET';

@@ -299,5 +299,5 @@ "use strict";

if (options === void 0) { options = {}; }
options.baseUrl = this._baseUrl;
options.wsUrl = this._wsUrl;
options.token = this._token;
options.baseUrl = this._baseUrl || '';
options.wsUrl = this._wsUrl || '';
options.token = this._token || '';
options.ajaxSettings = options.ajaxSettings || this.ajaxSettings;

@@ -304,0 +304,0 @@ return options;

@@ -41,3 +41,3 @@ import { nbformat } from '@jupyterlab/coreutils';

channel: Channel;
buffers: (ArrayBuffer | ArrayBufferView)[];
buffers?: (ArrayBuffer | ArrayBufferView)[];
}

@@ -44,0 +44,0 @@ /**

@@ -5,3 +5,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var utils = require("../utils");
var coreutils_1 = require("@jupyterlab/coreutils");
/**

@@ -24,3 +24,3 @@ * A namespace for kernel messages.

session: options.session,
msg_id: options.msgId || utils.uuid(),
msg_id: options.msgId || coreutils_1.uuid(),
msg_type: options.msgType

@@ -27,0 +27,0 @@ },

@@ -74,8 +74,13 @@ "use strict";

var encoder = new TextEncoder('utf8');
var jsonUtf8 = encoder.encode(JSON.stringify(msg, replaceBuffers));
var origBuffers = [];
if (msg.buffers !== undefined) {
origBuffers = msg.buffers;
delete msg['buffers'];
}
var jsonUtf8 = encoder.encode(JSON.stringify(msg));
buffers.push(jsonUtf8.buffer);
for (var i = 0; i < msg.buffers.length; i++) {
for (var i = 0; i < origBuffers.length; i++) {
// msg.buffers elements could be either views or ArrayBuffers
// buffers elements are ArrayBuffers
var b = msg.buffers[i];
var b = origBuffers[i];
buffers.push(b instanceof ArrayBuffer ? b : b.buffer);

@@ -103,10 +108,1 @@ }

}
/**
* Filter `"buffers"` key for `JSON.stringify`.
*/
function replaceBuffers(key, value) {
if (key === 'buffers') {
return undefined;
}
return value;
}

@@ -5,3 +5,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var coreutils_1 = require("@jupyterlab/coreutils");
var algorithm_1 = require("@phosphor/algorithm");
var coreutils_2 = require("@phosphor/coreutils");
var signaling_1 = require("@phosphor/signaling");

@@ -42,3 +44,3 @@ var kernel_1 = require("../kernel");

this._baseUrl = options.baseUrl || utils.getBaseUrl();
this._uuid = utils.uuid();
this._uuid = coreutils_1.uuid();
this._ajaxSettings = JSON.stringify(utils.ajaxSettingsWithToken(options.ajaxSettings || {}, options.token));

@@ -48,3 +50,3 @@ this._token = options.token || utils.getConfigOption('token');

this.setupKernel(kernel);
this._options = utils.copy(options);
this._options = coreutils_2.JSONExt.deepCopy(options);
this.terminated = new signaling_1.Signal(this);

@@ -209,3 +211,3 @@ }

return kernel_1.Kernel.connectTo(this.kernel.id, options).then(function (kernel) {
options = utils.copy(_this._options);
options = coreutils_2.JSONExt.deepCopy(_this._options);
options.ajaxSettings = _this.ajaxSettings;

@@ -351,4 +353,4 @@ return new DefaultSession(options, _this._id, kernel);

return {
baseUrl: this._options.baseUrl,
wsUrl: this._options.wsUrl,
baseUrl: this._options.baseUrl || '',
wsUrl: this._options.wsUrl || '',
username: this.kernel.username,

@@ -451,44 +453,49 @@ ajaxSettings: this.ajaxSettings

/**
* List the running sessions.
* Connect to a running session.
*/
function listRunning(options) {
function connectTo(id, options) {
if (options === void 0) { options = {}; }
var baseUrl = options.baseUrl || utils.getBaseUrl();
var url = utils.urlPathJoin(baseUrl, SESSION_SERVICE_URL);
var ajaxSettings = utils.ajaxSettingsWithToken(options.ajaxSettings, options.token);
ajaxSettings.method = 'GET';
ajaxSettings.dataType = 'json';
ajaxSettings.cache = false;
return utils.ajaxRequest(url, ajaxSettings).then(function (success) {
if (success.xhr.status !== 200) {
throw utils.makeAjaxError(success);
}
var data = success.data;
if (!Array.isArray(success.data)) {
throw utils.makeAjaxError(success, 'Invalid Session list');
}
for (var i = 0; i < data.length; i++) {
try {
validate.validateModel(data[i]);
}
catch (err) {
throw utils.makeAjaxError(success, err.message);
}
}
return updateRunningSessions(data);
}, Private.onSessionError);
var session = algorithm_1.find(Private.runningSessions, function (value) { return value.id === id; });
if (session) {
return Promise.resolve(session.clone());
}
return getSessionModel(id, options).then(function (model) {
return createSession(model, options);
}).catch(function () {
var msg = "No running session with id: " + id;
return typedThrow(msg);
});
}
Private.listRunning = listRunning;
Private.connectTo = connectTo;
/**
* Start a new session.
* Create a Promise for a kernel object given a session model and options.
*/
function startNew(options) {
if (options.path === void 0) {
return Promise.reject(new Error('Must specify a path'));
}
return startSession(options).then(function (model) {
return createSession(model, options);
function createKernel(options) {
var kernelOptions = {
name: options.kernelName || '',
baseUrl: options.baseUrl || utils.getBaseUrl(),
wsUrl: options.wsUrl || '',
username: options.username || '',
clientId: options.clientId || '',
token: options.token || '',
ajaxSettings: options.ajaxSettings || {}
};
return kernel_1.Kernel.connectTo(options.kernelId, kernelOptions);
}
/**
* Create a Session object.
*
* @returns - A promise that resolves with a started session.
*/
function createSession(model, options) {
options.kernelName = model.kernel.name;
options.kernelId = model.kernel.id;
options.path = model.notebook.path;
return createKernel(options).then(function (kernel) {
return new DefaultSession(options, model.id, kernel);
}).catch(function (error) {
return typedThrow('Session failed to start: ' + error.message);
});
}
Private.startNew = startNew;
Private.createSession = createSession;
/**

@@ -531,51 +538,19 @@ * Find a session by id.

/**
* Connect to a running session.
* Get a full session model from the server by session id string.
*/
function connectTo(id, options) {
if (options === void 0) { options = {}; }
var session = algorithm_1.find(Private.runningSessions, function (value) { return value.id === id; });
if (session) {
return Promise.resolve(session.clone());
}
return getSessionModel(id, options).then(function (model) {
return createSession(model, options);
}).catch(function () {
var msg = "No running session with id: " + id;
return typedThrow(msg);
});
}
Private.connectTo = connectTo;
/**
* Shut down a session by id.
*/
function shutdown(id, options) {
if (options === void 0) { options = {}; }
function getSessionModel(id, options) {
options = options || {};
var baseUrl = options.baseUrl || utils.getBaseUrl();
var url = getSessionUrl(baseUrl, id);
var ajaxSettings = utils.ajaxSettingsWithToken(options.ajaxSettings, options.token);
return shutdownSession(id, baseUrl, ajaxSettings);
}
Private.shutdown = shutdown;
/**
* Create a new session, or return an existing session if a session if
* the session path already exists
*/
function startSession(options) {
var baseUrl = options.baseUrl || utils.getBaseUrl();
var url = utils.urlPathJoin(baseUrl, SESSION_SERVICE_URL);
var model = {
kernel: { name: options.kernelName, id: options.kernelId },
notebook: { path: options.path }
};
var ajaxSettings = utils.ajaxSettingsWithToken(options.ajaxSettings, options.token);
ajaxSettings.method = 'POST';
ajaxSettings.method = 'GET';
ajaxSettings.dataType = 'json';
ajaxSettings.data = JSON.stringify(model);
ajaxSettings.contentType = 'application/json';
ajaxSettings.cache = false;
return utils.ajaxRequest(url, ajaxSettings).then(function (success) {
if (success.xhr.status !== 201) {
if (success.xhr.status !== 200) {
throw utils.makeAjaxError(success);
}
var data = success.data;
try {
validate.validateModel(success.data);
validate.validateModel(data);
}

@@ -585,45 +560,31 @@ catch (err) {

}
var data = success.data;
return updateFromServer(data);
}, onSessionError);
}, Private.onSessionError);
}
Private.startSession = startSession;
Private.getSessionModel = getSessionModel;
/**
* Create a Promise for a kernel object given a session model and options.
* Get a session url.
*/
function createKernel(options) {
var kernelOptions = {
name: options.kernelName,
baseUrl: options.baseUrl || utils.getBaseUrl(),
wsUrl: options.wsUrl,
username: options.username,
clientId: options.clientId,
token: options.token,
ajaxSettings: options.ajaxSettings
};
return kernel_1.Kernel.connectTo(options.kernelId, kernelOptions);
function getSessionUrl(baseUrl, id) {
return coreutils_1.URLExt.join(baseUrl, SESSION_SERVICE_URL, id);
}
Private.getSessionUrl = getSessionUrl;
/**
* Create a Session object.
*
* @returns - A promise that resolves with a started session.
* Kill the sessions by id.
*/
function createSession(model, options) {
options.kernelName = model.kernel.name;
options.kernelId = model.kernel.id;
options.path = model.notebook.path;
return createKernel(options).then(function (kernel) {
return new DefaultSession(options, model.id, kernel);
}).catch(function (error) {
return typedThrow('Session failed to start: ' + error.message);
function killSessions(id) {
algorithm_1.each(algorithm_1.toArray(Private.runningSessions), function (session) {
if (session.id === id) {
session.terminated.emit(void 0);
session.dispose();
}
});
}
Private.createSession = createSession;
/**
* Get a full session model from the server by session id string.
* List the running sessions.
*/
function getSessionModel(id, options) {
options = options || {};
function listRunning(options) {
if (options === void 0) { options = {}; }
var baseUrl = options.baseUrl || utils.getBaseUrl();
var url = getSessionUrl(baseUrl, id);
var url = coreutils_1.URLExt.join(baseUrl, SESSION_SERVICE_URL);
var ajaxSettings = utils.ajaxSettingsWithToken(options.ajaxSettings, options.token);

@@ -638,45 +599,39 @@ ajaxSettings.method = 'GET';

var data = success.data;
try {
validate.validateModel(data);
if (!Array.isArray(success.data)) {
throw utils.makeAjaxError(success, 'Invalid Session list');
}
catch (err) {
throw utils.makeAjaxError(success, err.message);
for (var i = 0; i < data.length; i++) {
try {
validate.validateModel(data[i]);
}
catch (err) {
throw utils.makeAjaxError(success, err.message);
}
}
return updateFromServer(data);
return updateRunningSessions(data);
}, Private.onSessionError);
}
Private.getSessionModel = getSessionModel;
Private.listRunning = listRunning;
/**
* Update the running sessions based on new data from the server.
* Handle an error on a session Ajax call.
*/
function updateRunningSessions(sessions) {
var promises = [];
algorithm_1.each(Private.runningSessions, function (session) {
var updated = algorithm_1.find(sessions, function (sId) {
if (session.id === sId.id) {
promises.push(session.update(sId));
return true;
}
});
// If session is no longer running on disk, emit dead signal.
if (!updated && session.status !== 'dead') {
session.terminated.emit(void 0);
}
});
return Promise.all(promises).then(function () { return sessions; });
function onSessionError(error) {
var text = (error.throwError ||
error.xhr.statusText ||
error.xhr.responseText);
var msg = "API request failed: " + text;
console.error(msg);
return Promise.reject(error);
}
Private.updateRunningSessions = updateRunningSessions;
Private.onSessionError = onSessionError;
/**
* Update the running sessions given an updated session Id.
* Shut down a session by id.
*/
function updateFromServer(model) {
var promises = [];
algorithm_1.each(Private.runningSessions, function (session) {
if (session.id === model.id) {
promises.push(session.update(model));
}
});
return Promise.all(promises).then(function () { return model; });
function shutdown(id, options) {
if (options === void 0) { options = {}; }
var baseUrl = options.baseUrl || utils.getBaseUrl();
var ajaxSettings = utils.ajaxSettingsWithToken(options.ajaxSettings, options.token);
return shutdownSession(id, baseUrl, ajaxSettings);
}
Private.updateFromServer = updateFromServer;
Private.shutdown = shutdown;
/**

@@ -711,32 +666,46 @@ * Shut down a session by id.

/**
* Kill the sessions by id.
* Start a new session.
*/
function killSessions(id) {
algorithm_1.each(algorithm_1.toArray(Private.runningSessions), function (session) {
if (session.id === id) {
session.terminated.emit(void 0);
session.dispose();
}
function startNew(options) {
if (options.path === void 0) {
return Promise.reject(new Error('Must specify a path'));
}
return startSession(options).then(function (model) {
return createSession(model, options);
});
}
Private.startNew = startNew;
/**
* Get a session url.
* Create a new session, or return an existing session if a session if
* the session path already exists
*/
function getSessionUrl(baseUrl, id) {
return utils.urlPathJoin(baseUrl, SESSION_SERVICE_URL, id);
function startSession(options) {
var baseUrl = options.baseUrl || utils.getBaseUrl();
var url = coreutils_1.URLExt.join(baseUrl, SESSION_SERVICE_URL);
var model = {
kernel: { name: options.kernelName, id: options.kernelId },
notebook: { path: options.path }
};
var ajaxSettings = utils.ajaxSettingsWithToken(options.ajaxSettings, options.token);
ajaxSettings.method = 'POST';
ajaxSettings.dataType = 'json';
ajaxSettings.data = JSON.stringify(model);
ajaxSettings.contentType = 'application/json';
ajaxSettings.cache = false;
return utils.ajaxRequest(url, ajaxSettings).then(function (success) {
if (success.xhr.status !== 201) {
throw utils.makeAjaxError(success);
}
try {
validate.validateModel(success.data);
}
catch (err) {
throw utils.makeAjaxError(success, err.message);
}
var data = success.data;
return updateFromServer(data);
}, onSessionError);
}
Private.getSessionUrl = getSessionUrl;
Private.startSession = startSession;
/**
* Handle an error on a session Ajax call.
*/
function onSessionError(error) {
var text = (error.throwError ||
error.xhr.statusText ||
error.xhr.responseText);
var msg = "API request failed: " + text;
console.error(msg);
return Promise.reject(error);
}
Private.onSessionError = onSessionError;
/**
* Throw a typed error.

@@ -748,2 +717,35 @@ */

Private.typedThrow = typedThrow;
/**
* Update the running sessions given an updated session Id.
*/
function updateFromServer(model) {
var promises = [];
algorithm_1.each(Private.runningSessions, function (session) {
if (session.id === model.id) {
promises.push(session.update(model));
}
});
return Promise.all(promises).then(function () { return model; });
}
Private.updateFromServer = updateFromServer;
/**
* Update the running sessions based on new data from the server.
*/
function updateRunningSessions(sessions) {
var promises = [];
algorithm_1.each(Private.runningSessions, function (session) {
var updated = algorithm_1.find(sessions, function (sId) {
if (session.id === sId.id) {
promises.push(session.update(sId));
return true;
}
});
// If session is no longer running on disk, emit dead signal.
if (!updated && session.status !== 'dead') {
session.terminated.emit(void 0);
}
});
return Promise.all(promises).then(function () { return sessions; });
}
Private.updateRunningSessions = updateRunningSessions;
})(Private || (Private = {}));

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

/**
* Dispose of the resources used by the manager.
*/
dispose(): void;
/**
* The base url of the manager.

@@ -44,5 +40,2 @@ */

*/
/**
* Set the default ajax settings for the manager.
*/
ajaxSettings: IAjaxSettings;

@@ -62,2 +55,6 @@ /**

/**
* Dispose of the resources used by the manager.
*/
dispose(): void;
/**
* Create an iterator over the most recent running sessions.

@@ -96,2 +93,11 @@ *

/**
* Find a session associated with a path and stop it is the only session using
* that kernel.
*
* @param path - The path in question.
*
* @returns A promise that resolves when the relevant sessions are stopped.
*/
stopIfNeeded(path: string): Promise<void>;
/**
* Find a session by id.

@@ -98,0 +104,0 @@ */

@@ -78,15 +78,2 @@ "use strict";

});
/**
* Dispose of the resources used by the manager.
*/
SessionManager.prototype.dispose = function () {
if (this.isDisposed) {
return;
}
this._isDisposed = true;
clearInterval(this._runningTimer);
clearInterval(this._specsTimer);
signaling_1.Signal.clearData(this);
this._running = [];
};
Object.defineProperty(SessionManager.prototype, "baseUrl", {

@@ -119,5 +106,2 @@ /**

},
/**
* Set the default ajax settings for the manager.
*/
set: function (value) {

@@ -160,2 +144,15 @@ this._ajaxSettings = JSON.stringify(value);

/**
* Dispose of the resources used by the manager.
*/
SessionManager.prototype.dispose = function () {
if (this.isDisposed) {
return;
}
this._isDisposed = true;
clearInterval(this._runningTimer);
clearInterval(this._specsTimer);
signaling_1.Signal.clearData(this);
this._running.length = 0;
};
/**
* Create an iterator over the most recent running sessions.

@@ -206,2 +203,20 @@ *

/**
* Find a session associated with a path and stop it is the only session using
* that kernel.
*
* @param path - The path in question.
*
* @returns A promise that resolves when the relevant sessions are stopped.
*/
SessionManager.prototype.stopIfNeeded = function (path) {
var _this = this;
return session_1.Session.listRunning().then(function (sessions) {
var matches = sessions.filter(function (value) { return value.notebook.path === path; });
if (matches.length === 1) {
var id = matches[0].id;
return _this.shutdown(id).catch(function () { });
}
}).catch(function () { return Promise.resolve(void 0); }); // Always succeed.
};
/**
* Find a session by id.

@@ -208,0 +223,0 @@ */

@@ -380,2 +380,11 @@ import { IIterator } from '@phosphor/algorithm';

refreshRunning(): Promise<void>;
/**
* Find a session associated with a path and stop it is the only session
* using that kernel.
*
* @param path - The path in question.
*
* @returns A promise that resolves when the relevant sessions are stopped.
*/
stopIfNeeded(path: string): Promise<void>;
}

@@ -382,0 +391,0 @@ /**

@@ -5,2 +5,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var coreutils_1 = require("@jupyterlab/coreutils");
var algorithm_1 = require("@phosphor/algorithm");

@@ -189,3 +190,3 @@ var signaling_1 = require("@phosphor/signaling");

Private.running[this._url] = this;
var wsUrl = utils.urlPathJoin(this._wsUrl, "terminals/websocket/" + name);
var wsUrl = coreutils_1.URLExt.join(this._wsUrl, "terminals/websocket/" + name);
if (this._token) {

@@ -328,3 +329,3 @@ wsUrl = wsUrl + ("?token=" + this._token);

var urls = algorithm_1.toArray(algorithm_1.map(data, function (item) {
return utils.urlPathJoin(url, item.name);
return coreutils_1.URLExt.join(url, item.name);
}));

@@ -394,3 +395,3 @@ algorithm_1.each(Object.keys(Private.running), function (runningUrl) {

function getTermUrl(baseUrl, name) {
return utils.urlPathJoin(baseUrl, TERMINAL_SERVICE_URL, name);
return coreutils_1.URLExt.join(baseUrl, TERMINAL_SERVICE_URL, name);
}

@@ -402,3 +403,3 @@ Private.getTermUrl = getTermUrl;

function getBaseUrl(baseUrl) {
return utils.urlPathJoin(baseUrl, TERMINAL_SERVICE_URL);
return coreutils_1.URLExt.join(baseUrl, TERMINAL_SERVICE_URL);
}

@@ -405,0 +406,0 @@ Private.getBaseUrl = getBaseUrl;

import { JSONObject } from '@phosphor/coreutils';
export { PromiseDelegate } from '@phosphor/coreutils';
/**
* Copy the contents of one object to another, recursively.
*
* From [stackoverflow](http://stackoverflow.com/a/12317051).
*/
export declare function extend(target: any, source: any): any;
/**
* Get a deep copy of a JSON object.
*/
export declare function copy(object: JSONObject): JSONObject;
/**
* Get a random 32 character hex string (not a formal UUID)
*/
export declare function uuid(): string;
/**
* A URL object.
*
* This interface is from the npm package URL object interface. We
* include it here so that downstream libraries do not have to include
* the `url` typing files, since the npm `url` package is not in the
* @types system.
*/
export interface IUrl {
href?: string;
protocol?: string;
hostname?: string;
port?: string;
host?: string;
pathname?: string;
hash?: string;
search?: string;
}
/**
* Parse a url into a URL object.
*
* @param url - The URL string to parse.
*
* @returns A URL object.
*/
export declare function urlParse(url: string): IUrl;
/**
* Join a sequence of url components with `'/'`.
*/
export declare function urlPathJoin(...parts: string[]): string;
/**
* Encode the components of a multi-segment url.
*
* #### Notes
* Preserves the `'/'` separators.
* Should not include the base url, since all parts are escaped.
*/
export declare function urlEncodeParts(uri: string): string;
/**
* Return a serialized object string suitable for a query.
*
* From [stackoverflow](http://stackoverflow.com/a/30707423).
*/
export declare function jsonToQueryString(json: JSONObject): string;
/**
* Input settings for an AJAX request.

@@ -63,0 +4,0 @@ */

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

Object.defineProperty(exports, "__esModule", { value: true });
var coreutils_1 = require("@phosphor/coreutils");
var minimist = require("minimist");
var path = require("path-posix");
var urlparse = require("url-parse");
// Export the Promise Delegate for now to preserve API.
var coreutils_1 = require("@phosphor/coreutils");
exports.PromiseDelegate = coreutils_1.PromiseDelegate;
/**
* Copy the contents of one object to another, recursively.
*
* From [stackoverflow](http://stackoverflow.com/a/12317051).
*/
function extend(target, source) {
target = target || {};
for (var prop in source) {
if (typeof source[prop] === 'object') {
target[prop] = extend(target[prop], source[prop]);
}
else {
target[prop] = source[prop];
}
}
return target;
}
exports.extend = extend;
/**
* Get a deep copy of a JSON object.
*/
function copy(object) {
return JSON.parse(JSON.stringify(object));
}
exports.copy = copy;
/**
* Get a random 32 character hex string (not a formal UUID)
*/
function uuid() {
var s = [];
var hexDigits = '0123456789abcdef';
var nChars = hexDigits.length;
for (var i = 0; i < 32; i++) {
s[i] = hexDigits.charAt(Math.floor(Math.random() * nChars));
}
return s.join('');
}
exports.uuid = uuid;
/**
* Parse a url into a URL object.
*
* @param url - The URL string to parse.
*
* @returns A URL object.
*/
function urlParse(url) {
if (typeof document !== 'undefined') {
var a = document.createElement('a');
a.href = url;
return a;
}
return urlparse(url);
}
exports.urlParse = urlParse;
/**
* Join a sequence of url components with `'/'`.
*/
function urlPathJoin() {
var parts = [];
for (var _i = 0; _i < arguments.length; _i++) {
parts[_i] = arguments[_i];
}
// Adapted from url-join.
// Copyright (c) 2016 José F. Romaniello, MIT License.
// https://github.com/jfromaniello/url-join/blob/v1.1.0/lib/url-join.js
var str = [].slice.call(parts, 0).join('/');
// make sure protocol is followed by two slashes
str = str.replace(/:\//g, '://');
// remove consecutive slashes
str = str.replace(/([^:\s])\/+/g, '$1/');
// remove trailing slash before parameters or hash
str = str.replace(/\/(\?|&|#[^!])/g, '$1');
// replace ? in parameters with &
str = str.replace(/(\?.+)\?/g, '$1&');
return str;
}
exports.urlPathJoin = urlPathJoin;
/**
* Encode the components of a multi-segment url.
*
* #### Notes
* Preserves the `'/'` separators.
* Should not include the base url, since all parts are escaped.
*/
function urlEncodeParts(uri) {
return urlPathJoin.apply(void 0, uri.split('/').map(encodeURIComponent));
}
exports.urlEncodeParts = urlEncodeParts;
/**
* Return a serialized object string suitable for a query.
*
* From [stackoverflow](http://stackoverflow.com/a/30707423).
*/
function jsonToQueryString(json) {
return '?' + Object.keys(json).map(function (key) {
return encodeURIComponent(key) + '=' + encodeURIComponent(String(json[key]));
}).join('&');
}
exports.jsonToQueryString = jsonToQueryString;
function _getCookie(name) {

@@ -338,3 +236,3 @@ // from tornado docs: http://www.tornadoweb.org/en/stable/guide/security.html

else {
ajaxSettings = copy(ajaxSettings);
ajaxSettings = coreutils_1.JSONExt.deepCopy(ajaxSettings);
}

@@ -341,0 +239,0 @@ if (!token) {

{
"name": "@jupyterlab/services",
"version": "0.42.1",
"version": "0.43.0",
"description": "Client APIs for the Jupyter services REST APIs",

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

"dependencies": {
"@jupyterlab/coreutils": "^0.3.1",
"@jupyterlab/coreutils": "^0.4.0",
"@phosphor/algorithm": "^1.0.0",

@@ -27,2 +27,3 @@ "@phosphor/coreutils": "^1.0.0",

"mocha": "^3.2.0",
"requirejs": "^2.3.3",
"rimraf": "^2.5.2",

@@ -44,8 +45,7 @@ "text-encoding": "^0.5.2",

"build:examples": "npm run example:browser && npm run example:node",
"docs": "typedoc --options typedoc.json src",
"test:coverage": "istanbul cover --dir test/coverage _mocha -- --retries 3 test/build/**/*.spec.js --foo bar --terminalsAvailable True",
"test:coverage": "istanbul cover --dir test/coverage _mocha -- --retries 3 test/build/**/*.spec.js test/build*.spec.js --foo bar --terminalsAvailable True",
"test:integration": "cd test && python integration_test.py",
"test:devtool": "devtool node_modules/mocha/bin/_mocha -qc test/build/**/**.spec.js --foo bar --terminalsAvailable True",
"test:debug": "mocha test/build/**/*.spec.js --foo bar --terminalsAvailable True --debug-brk",
"test": "mocha --retries 3 test/build/**/*.spec.js --foo bar --terminalsAvailable True"
"test:devtool": "devtool node_modules/.bin/_mocha -qc test/build/*.spec.js test/build/**/*.spec.js --foo bar --terminalsAvailable True",
"test:debug": "mocha test/build/**/*.spec.js test/build*.spec.js --foo bar --terminalsAvailable True --debug-brk",
"test": "mocha --retries 3 test/build/**.spec.js test/build/**/*.spec.js --foo bar --terminalsAvailable True"
},

@@ -52,0 +52,0 @@ "repository": {

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