New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@jupyterlab/docregistry

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/docregistry - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

47

lib/context.d.ts

@@ -1,5 +0,6 @@

import { Contents, Kernel, ServiceManager } from '@jupyterlab/services';
import { Contents, ServiceManager } from '@jupyterlab/services';
import { IDisposable } from '@phosphor/disposable';
import { ISignal } from '@phosphor/signaling';
import { Widget } from '@phosphor/widgets';
import { ClientSession, IClientSession } from '@jupyterlab/apputils';
import { DocumentRegistry } from '.';

@@ -17,6 +18,2 @@ /**

/**
* A signal emitted when the kernel changes.
*/
readonly kernelChanged: ISignal<this, Kernel.IKernel>;
/**
* A signal emitted when the path changes.

@@ -38,5 +35,5 @@ */

/**
* The current kernel associated with the document.
* The client session object associated with the context.
*/
readonly kernel: Kernel.IKernel;
readonly session: ClientSession;
/**

@@ -69,6 +66,2 @@ * The current path associated with the document.

/**
* The kernel spec models
*/
readonly specs: Kernel.ISpecModels;
/**
* Whether the context is ready.

@@ -82,12 +75,2 @@ */

/**
* Start the default kernel for the context.
*
* @returns A promise that resolves with the new kernel.
*/
startDefaultKernel(): Promise<Kernel.IKernel>;
/**
* Change the current kernel associated with the document.
*/
changeKernel(options: Kernel.IModel): Promise<Kernel.IKernel>;
/**
* Save the document contents to disk.

@@ -137,14 +120,6 @@ */

/**
* Start a session and set up its signals.
* Handle a change to a session property.
*/
private _startSession(options);
private _onSessionChanged();
/**
* Handle a change to a session path.
*/
private _onSessionPathChanged(sender, path);
/**
* Handle a change to the kernel.
*/
private _onKernelChanged(sender);
/**
* Update our contents model, without the content.

@@ -154,6 +129,2 @@ */

/**
* Handle a change to the running sessions.
*/
private _onSessionsChanged(sender, models);
/**
* Handle an initial population.

@@ -166,3 +137,2 @@ */

private _path;
private _session;
private _factory;

@@ -174,3 +144,2 @@ private _contentsModel;

private _isReady;
private _kernelChanged;
private _pathChanged;

@@ -201,2 +170,6 @@ private _fileChanged;

/**
* The kernel preference associated with the context.
*/
kernelPreference?: IClientSession.IKernelPreference;
/**
* An optional callback for opening sibling widgets.

@@ -203,0 +176,0 @@ */

// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
"use strict";
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 algorithm_1 = require("@phosphor/algorithm");
var coreutils_1 = require("@phosphor/coreutils");

@@ -27,3 +34,2 @@ var disposable_1 = require("@phosphor/disposable");

this._path = '';
this._session = null;
this._factory = null;

@@ -34,3 +40,2 @@ this._contentsModel = null;

this._isReady = false;
this._kernelChanged = new signaling_1.Signal(this);
this._pathChanged = new signaling_1.Signal(this);

@@ -46,18 +51,14 @@ this._fileChanged = new signaling_1.Signal(this);

this._model = this._factory.createNew(lang);
manager.sessions.runningChanged.connect(this._onSessionsChanged, this);
manager.contents.fileChanged.connect(this._onFileChanged, this);
this._readyPromise = manager.ready.then(function () {
return _this._populatedPromise.promise;
});
this.session = new apputils_1.ClientSession({
manager: manager.sessions,
path: this._path,
name: this._path.split('/').pop(),
kernelPreference: options.kernelPreference || { shouldStart: false }
});
this.session.propertyChanged.connect(this._onSessionChanged, this);
manager.contents.fileChanged.connect(this._onFileChanged, this);
}
Object.defineProperty(Context.prototype, "kernelChanged", {
/**
* A signal emitted when the kernel changes.
*/
get: function () {
return this._kernelChanged;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Context.prototype, "pathChanged", {

@@ -103,12 +104,2 @@ /**

});
Object.defineProperty(Context.prototype, "kernel", {
/**
* The current kernel associated with the document.
*/
get: function () {
return this._session ? this._session.kernel : null;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Context.prototype, "path", {

@@ -168,24 +159,10 @@ /**

var model = this._model;
var session = this._session;
this.session.dispose();
this._model = null;
this._session = null;
this._manager = null;
this._factory = null;
model.dispose();
if (session) {
session.dispose();
}
this._disposed.emit(void 0);
signaling_1.Signal.clearData(this);
};
Object.defineProperty(Context.prototype, "specs", {
/**
* The kernel spec models
*/
get: function () {
return this._manager.specs;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Context.prototype, "isReady", {

@@ -212,55 +189,2 @@ /**

/**
* Start the default kernel for the context.
*
* @returns A promise that resolves with the new kernel.
*/
Context.prototype.startDefaultKernel = function () {
var _this = this;
return this.ready.then(function () {
if (_this.isDisposed) {
return;
}
var model = _this.model;
var name = _1.findKernel(model.defaultKernelName, model.defaultKernelLanguage, _this._manager.specs);
return _this.changeKernel({ name: name });
});
};
/**
* Change the current kernel associated with the document.
*/
Context.prototype.changeKernel = function (options) {
var _this = this;
var session = this._session;
if (options) {
if (session) {
return session.changeKernel(options);
}
else {
var path = this._path;
var sOptions = {
path: path,
kernelName: options.name,
kernelId: options.id
};
return this._startSession(sOptions);
}
}
else {
if (session) {
this._session = null;
return session.shutdown().then(function () {
session.dispose();
if (_this.isDisposed) {
return;
}
_this._kernelChanged.emit(null);
return void 0;
});
}
else {
return Promise.resolve(void 0);
}
}
};
/**
* Save the document contents to disk.

@@ -287,4 +211,5 @@ */

};
var promise = this._manager.contents.save(path, options);
return promise.then(function (value) {
return this._manager.ready.then(function () {
return _this._manager.contents.save(path, options);
}).then(function (value) {
if (_this.isDisposed) {

@@ -316,17 +241,4 @@ return;

_this._path = newPath;
var session = _this._session;
if (session) {
var options = {
path: newPath,
kernelId: session.kernel.id,
kernelName: session.kernel.name
};
return _this._startSession(options).then(function () {
if (_this.isDisposed) {
return;
}
return _this.save();
});
}
return _this.save();
_this.session.setName(newPath.split('/').pop());
return _this.session.setPath(newPath).then(function () { return _this.save(); });
});

@@ -346,3 +258,5 @@ };

var model = this._model;
return this._manager.contents.get(path, opts).then(function (contents) {
return this._manager.ready.then(function () {
return _this._manager.contents.get(path, opts);
}).then(function (contents) {
if (_this.isDisposed) {

@@ -374,3 +288,7 @@ return;

Context.prototype.createCheckpoint = function () {
return this._manager.contents.createCheckpoint(this._path);
var _this = this;
var contents = this._manager.contents;
return this._manager.ready.then(function () {
return contents.createCheckpoint(_this._path);
});
};

@@ -381,3 +299,7 @@ /**

Context.prototype.deleteCheckpoint = function (checkpointId) {
return this._manager.contents.deleteCheckpoint(this._path, checkpointId);
var _this = this;
var contents = this._manager.contents;
return this._manager.ready.then(function () {
return contents.deleteCheckpoint(_this._path, checkpointId);
});
};

@@ -391,11 +313,13 @@ /**

var path = this._path;
if (checkpointId) {
return contents.restoreCheckpoint(path, checkpointId);
}
return this.listCheckpoints().then(function (checkpoints) {
if (_this.isDisposed || !checkpoints.length) {
return;
return this._manager.ready.then(function () {
if (checkpointId) {
return contents.restoreCheckpoint(path, checkpointId);
}
checkpointId = checkpoints[checkpoints.length - 1].id;
return contents.restoreCheckpoint(path, checkpointId);
return _this.listCheckpoints().then(function (checkpoints) {
if (_this.isDisposed || !checkpoints.length) {
return;
}
checkpointId = checkpoints[checkpoints.length - 1].id;
return contents.restoreCheckpoint(path, checkpointId);
});
});

@@ -407,3 +331,7 @@ };

Context.prototype.listCheckpoints = function () {
return this._manager.contents.listCheckpoints(this._path);
var _this = this;
var contents = this._manager.contents;
return this._manager.ready.then(function () {
return contents.listCheckpoints(_this._path);
});
};

@@ -415,4 +343,3 @@ /**

if (coreutils_2.URLExt.isLocal(url)) {
var path = this._session ? this._session.path : '';
var cwd = coreutils_2.PathExt.dirname(path);
var cwd = coreutils_2.PathExt.dirname(this._path);
url = coreutils_2.PathExt.resolve(cwd, url);

@@ -426,4 +353,5 @@ }

Context.prototype.getDownloadUrl = function (path) {
var contents = this._manager.contents;
if (coreutils_2.URLExt.isLocal(path)) {
return this._manager.contents.getDownloadUrl(path);
return this._manager.ready.then(function () { return contents.getDownloadUrl(path); });
}

@@ -453,8 +381,5 @@ return Promise.resolve(path);

var newPath = change.newValue.path;
if (this._session) {
this._session.rename(newPath);
}
else {
this._path = newPath;
}
this.session.setPath(newPath);
this.session.setName(newPath.split('/').pop());
this._path = newPath;
this._updateContentsModel(change.newValue);

@@ -465,34 +390,6 @@ this._pathChanged.emit(this._path);

/**
* Start a session and set up its signals.
* Handle a change to a session property.
*/
Context.prototype._startSession = function (options) {
var _this = this;
return this._manager.sessions.startNew(options).then(function (session) {
if (_this.isDisposed) {
return;
}
if (_this._session) {
_this._session.dispose();
}
_this._session = session;
_this._kernelChanged.emit(session.kernel);
session.pathChanged.connect(_this._onSessionPathChanged, _this);
session.kernelChanged.connect(_this._onKernelChanged, _this);
return session.kernel;
}).catch(function (err) {
var response = JSON.parse(err.xhr.response);
var body = document.createElement('pre');
body.textContent = response['traceback'];
apputils_1.showDialog({
title: 'Error Starting Kernel',
body: body,
buttons: [apputils_1.Dialog.okButton()]
});
return Promise.reject(err);
});
};
/**
* Handle a change to a session path.
*/
Context.prototype._onSessionPathChanged = function (sender, path) {
Context.prototype._onSessionChanged = function () {
var path = this.session.path;
if (path !== this._path) {

@@ -504,8 +401,2 @@ this._path = path;

/**
* Handle a change to the kernel.
*/
Context.prototype._onKernelChanged = function (sender) {
this._kernelChanged.emit(sender.kernel);
};
/**
* Update our contents model, without the content.

@@ -531,17 +422,2 @@ */

/**
* Handle a change to the running sessions.
*/
Context.prototype._onSessionsChanged = function (sender, models) {
var session = this._session;
if (!session) {
return;
}
var index = algorithm_1.ArrayExt.findFirstIndex(models, function (model) { return model.id === session.id; });
if (index === -1) {
session.dispose();
this._session = null;
this._kernelChanged.emit(null);
}
};
/**
* Handle an initial population.

@@ -561,2 +437,7 @@ */

}
// Update the kernel preference.
var name = (_this._model.defaultKernelName || _this.session.kernelPreference.name);
_this.session.kernelPreference = __assign({}, _this.session.kernelPreference, { name: name, language: _this._model.defaultKernelLanguage });
return _this.session.initialize();
}).then(function () {
_this._isReady = true;

@@ -563,0 +444,0 @@ _this._populatedPromise.resolve(void 0);

export * from './context';
export * from './default';
export * from './kernelselector';
export * from './registry';

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

__export(require("./default"));
__export(require("./kernelselector"));
__export(require("./registry"));

@@ -7,2 +7,3 @@ import { Contents, Kernel } from '@jupyterlab/services';

import { Widget } from '@phosphor/widgets';
import { IClientSession } from '@jupyterlab/apputils';
import { CodeEditor } from '@jupyterlab/codeeditor';

@@ -189,5 +190,7 @@ import { IChangedArgs as IChangedArgsGeneric } from '@jupyterlab/coreutils';

*
* @param kernel - An optional existing kernel model.
*
* @returns A kernel preference.
*/
getKernelPreference(ext: string, widgetName: string): DocumentRegistry.IKernelPreference;
getKernelPreference(ext: string, widgetName: string, kernel?: Kernel.IModel): IClientSession.IKernelPreference;
private _modelFactories;

@@ -272,6 +275,2 @@ private _widgetFactories;

/**
* A signal emitted when the kernel changes.
*/
kernelChanged: ISignal<this, Kernel.IKernel>;
/**
* A signal emitted when the path changes.

@@ -293,5 +292,5 @@ */

/**
* The current kernel associated with the document.
* The client session object associated with the context.
*/
readonly kernel: Kernel.IKernel;
readonly session: IClientSession;
/**

@@ -318,15 +317,2 @@ * The current path associated with the document.

/**
* Start the default kernel for the context.
*
* @returns A promise that resolves with the new kernel.
*/
startDefaultKernel(): Promise<Kernel.IKernel>;
/**
* Change the current kernel associated with the document.
*
* #### Notes
* If no options are given, the session is shut down.
*/
changeKernel(options?: Kernel.IModel): Promise<Kernel.IKernel>;
/**
* Save the document contents to disk.

@@ -516,19 +502,2 @@ */

/**
* A kernel preference for a given file path and widget.
*/
interface IKernelPreference {
/**
* The preferred kernel language.
*/
readonly language: string;
/**
* Whether to prefer having a kernel started when opening.
*/
readonly preferKernel: boolean;
/**
* Whether a kernel when can be started when opening.
*/
readonly canStartKernel: boolean;
}
/**
* An interface for a file type.

@@ -535,0 +504,0 @@ */

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

*
* @param kernel - An optional existing kernel model.
*
* @returns A kernel preference.
*/
DocumentRegistry.prototype.getKernelPreference = function (ext, widgetName) {
DocumentRegistry.prototype.getKernelPreference = function (ext, widgetName, kernel) {
ext = Private.normalizeExtension(ext);

@@ -479,6 +481,10 @@ widgetName = widgetName.toLowerCase();

var language = modelFactory.preferredLanguage(ext);
var name = kernel && kernel.name;
var id = kernel && kernel.id;
return {
id: id,
name: name,
language: language,
preferKernel: widgetFactory.preferKernel,
canStartKernel: widgetFactory.canStartKernel
shouldStart: widgetFactory.preferKernel,
canStart: widgetFactory.canStartKernel
};

@@ -485,0 +491,0 @@ };

{
"name": "@jupyterlab/docregistry",
"version": "0.1.4",
"version": "0.2.0",
"description": "JupyterLab - Document Registry",

@@ -15,12 +15,12 @@ "main": "lib/index.js",

"dependencies": {
"@jupyterlab/apputils": "^0.1.1",
"@jupyterlab/codeeditor": "^0.1.4",
"@jupyterlab/codemirror": "^0.1.4",
"@jupyterlab/coreutils": "^0.1.1",
"@jupyterlab/services": "^0.40.1",
"@phosphor/algorithm": "^0.1.1",
"@phosphor/coreutils": "^0.1.5",
"@phosphor/disposable": "^0.1.1",
"@phosphor/signaling": "^0.1.2",
"@phosphor/widgets": "^0.3.0",
"@jupyterlab/apputils": "^0.2.0",
"@jupyterlab/codeeditor": "^0.2.0",
"@jupyterlab/codemirror": "^0.2.0",
"@jupyterlab/coreutils": "^0.2.0",
"@jupyterlab/services": "^0.41.0",
"@phosphor/algorithm": "^1.0.0",
"@phosphor/coreutils": "^1.0.0",
"@phosphor/disposable": "^1.0.0",
"@phosphor/signaling": "^1.0.0",
"@phosphor/widgets": "^1.0.0",
"codemirror": "^5.24.2"

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

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