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

@jupyterlab/coreutils

Package Overview
Dependencies
Maintainers
5
Versions
355
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jupyterlab/coreutils - npm Package Compare versions

Comparing version 0.7.1 to 0.8.0

10

lib/interfaces.d.ts

@@ -19,7 +19,7 @@ /**

/**
* The description of a general purpose datastore.
* The description of a general purpose data connector.
*/
export interface IDatastore<T, U> {
export interface IDataConnector<T, U> {
/**
* Retrieve a saved bundle from the datastore.
* Retrieve a saved bundle from the data connector.
*

@@ -36,3 +36,3 @@ * @param id - The identifier used to retrieve a data bundle.

/**
* Remove a value from the datastore.
* Remove a value from the data connector.
*

@@ -45,3 +45,3 @@ * @param id - The identifier for the data being removed.

/**
* Save a value in the datastore.
* Save a value in the data connector.
*

@@ -48,0 +48,0 @@ * @param id - The identifier for the data being saved.

import { JSONObject, JSONValue, Token } from '@phosphor/coreutils';
import { IDisposable } from '@phosphor/disposable';
import { ISignal } from '@phosphor/signaling';
import { IDatastore } from '.';
import { IDataConnector } from '.';
/**
* The setting registry token.
* The key in the schema for setting editor icon class hints.
*/
export declare const ISettingRegistry: Token<ISettingRegistry>;
export declare const ICON_CLASS_KEY = "jupyter.lab.setting-icon-class";
/**
* A namespace for setting registry interfaces.
* The key in the schema for setting editor icon label hints.
*/
export declare namespace ISettingRegistry {
export declare const ICON_LABEL_KEY = "jupyter.lab.setting-icon-label";
/**
* An implementation of a schema validator.
*/
export interface ISchemaValidator {
/**
* The setting level: user or system.
* Add a schema to the validator.
*
* @param plugin - The plugin ID.
*
* @param schema - The schema being added.
*
* @return A list of errors if the schema fails to validate or `null` if there
* are no errors.
*
* #### Notes
* It is safe to call this function multiple times with the same plugin name.
*/
type Level = 'system' | 'user';
addSchema(plugin: string, schema: ISettingRegistry.ISchema): ISchemaValidator.IError[] | null;
/**
* An annotation for a specific setting or a plugin.
* Validate a plugin's schema and user data; populate the `composite` data.
*
* @param plugin - The plugin being validated. Its `composite` data will be
* populated by reference.
*
* @return A list of errors if either the schema or data fail to validate or
* `null` if there are no errors.
*/
interface IAnnotation extends JSONObject {
validateData(plugin: ISettingRegistry.IPlugin): ISchemaValidator.IError[] | null;
}
/**
* A namespace for schema validator interfaces.
*/
export declare namespace ISchemaValidator {
/**
* A schema validation error definition.
*/
interface IError {
/**
* The caption for the setting.
* The keyword whose validation failed.
*/
caption?: string;
keyword: string;
/**
* The extra class name for the setting.
* The error message.
*/
className?: string;
message: string;
/**
* The icon class for the setting.
* The path in the schema where the error occurred.
*/
iconClass?: string;
/**
* The icon label for the setting.
*/
iconLabel?: string;
/**
* The label for the setting.
*/
label?: string;
schemaPath: string;
}
}
/**
* The setting registry token.
*/
export declare const ISettingRegistry: Token<ISettingRegistry>;
/**
* A namespace for setting registry interfaces.
*/
export declare namespace ISettingRegistry {
/**

@@ -53,23 +83,74 @@ * The settings for a specific plugin.

*/
data: ISettingBundle | null;
data: ISettingBundle;
/**
* The JSON schema for the plugin.
*/
schema: ISchema;
}
/**
* The annotations for a plugin.
* A schema type that is a minimal subset of the formal JSON Schema along with
* optional JupyterLab rendering hints.
*/
interface IPluginAnnotations extends JSONObject {
annotation: IAnnotation;
keys?: {
[key: string]: IAnnotation;
interface ISchema extends JSONObject {
/**
* The JupyterLab icon class hint for a plugin can be overridden by user
* settings. It can also be root level and therefore "private".
*/
'jupyter.lab.setting-icon-class'?: string;
/**
* The JupyterLab icon label hint for a plugin can be overridden by user
* settings. It can also be root level and therefore "private".
*/
'jupyter.lab.setting-icon-label'?: string;
/**
* The default value, if any.
*/
default?: any;
/**
* The schema description.
*/
description?: string;
/**
* The schema's child properties.
*/
properties?: {
/**
* The JupyterLab icon class hint for a plugin can be overridden by user
* settings. It can also be root level and therefore "private".
*/
'jupyter.lab.setting-icon-class'?: ISchema;
/**
* The JupyterLab icon label hint for a plugin can be overridden by user
* settings. It can also be root level and therefore "private".
*/
'jupyter.lab.setting-icon-label'?: ISchema;
/**
* Arbitrary setting keys can be added.
*/
[key: string]: ISchema;
};
/**
* The title of the schema.
*/
title?: string;
/**
* The type or types of the data.
*/
type?: string | string[];
}
/**
* The collection of user and system preferences for a plugin.
* The setting values for a plugin.
*/
interface ISettingBundle extends JSONObject {
system?: {
[key: string]: JSONValue;
};
user?: {
[key: string]: JSONValue;
};
/**
* A composite of the user setting values and the plugin schema defaults.
*
* #### Notes
* The `composite` values will always be a superset of the `user` values.
*/
composite: JSONObject;
/**
* The user setting values.
*/
user: JSONObject;
}

@@ -81,15 +162,19 @@ /**

/**
* The annotation hints for a plugin.
* A signal that emits when the plugin's settings have changed.
*/
readonly annotations: IPluginAnnotations | null;
readonly changed: ISignal<this, void>;
/**
* A signal that emits when the plugin's settings have changed.
* Get the composite of user settings and extension defaults.
*/
readonly changed: ISignal<this, void>;
readonly composite: JSONObject;
readonly plugin: string;
/**
* Get the raw plugin settings.
* Get the plugin settings schema.
*/
readonly raw: IPlugin;
readonly schema: ISettingRegistry.ISchema;
/**
* Get the user settings.
*/
readonly user: JSONObject;
/**
* Remove a single setting.

@@ -110,15 +195,12 @@ *

*
* @param level - The setting level. Defaults to `user`.
*
* @returns The setting value.
*
* #### Notes
* This method returns synchronously because it uses a cached copy of the
* plugin settings that is synchronized with the registry.
*/
get(key: string, level?: Level): JSONValue;
get(key: string): {
composite: JSONValue;
user: JSONValue;
};
/**
* Save all of the plugin's settings at once.
* Save all of the plugin's user settings at once.
*/
save(raw: IPlugin): Promise<void>;
save(user: JSONObject): Promise<void>;
/**

@@ -145,2 +227,37 @@ * Set a single setting.

/**
* The default implementation of a schema validator.
*/
export declare class DefaultSchemaValidator implements ISchemaValidator {
/**
* Instantiate a schema validator.
*/
constructor();
/**
* Add a schema to the validator.
*
* @param plugin - The plugin ID.
*
* @param schema - The schema being added.
*
* @return A list of errors if the schema fails to validate or `null` if there
* are no errors.
*
* #### Notes
* It is safe to call this function multiple times with the same plugin name.
*/
addSchema(plugin: string, schema: ISettingRegistry.ISchema): ISchemaValidator.IError[] | null;
/**
* Validate a plugin's schema and user data; populate the `composite` data.
*
* @param plugin - The plugin being validated. Its `composite` data will be
* populated by reference.
*
* @return A list of errors if either the schema or data fail to validate or
* `null` if there are no errors.
*/
validateData(plugin: ISettingRegistry.IPlugin): ISchemaValidator.IError[] | null;
private _composer;
private _validator;
}
/**
* The default concrete implementation of a setting registry.

@@ -154,7 +271,5 @@ */

/**
* Returns a map of annotation hints for plugins in the registry.
* The schema of the setting registry.
*/
readonly annotations: {
[plugin: string]: ISettingRegistry.IPluginAnnotations;
};
readonly schema: ISettingRegistry.ISchema;
/**

@@ -169,13 +284,2 @@ * A signal that emits the name of a plugin when its settings change.

/**
* Annotate a plugin or a setting item for places where it might be displayed.
*
* @param plugin - The name of the plugin whose setting is being annotated.
*
* @param key - The name of the key being annotated. If `null` or empty, the
* annotation will be applied at the plugin level.
*
* @param annotation - The annotation describing a plugin or a setting.
*/
annotate(plugin: string, key: string, annotation: ISettingRegistry.IAnnotation): void;
/**
* Get an individual setting.

@@ -187,7 +291,8 @@ *

*
* @param level - The setting level. Defaults to `user`.
*
* @returns A promise that resolves when the setting is retrieved.
*/
get(plugin: string, key: string, level?: ISettingRegistry.Level): Promise<JSONValue>;
get(plugin: string, key: string): Promise<{
composite: JSONValue;
user: JSONValue;
}>;
/**

@@ -198,6 +303,19 @@ * Load a plugin's settings into the setting registry.

*
* @returns A promise that resolves with a plugin settings object.
* @returns A promise that resolves with a plugin settings object or rejects
* if the plugin is not found.
*/
load(plugin: string): Promise<ISettingRegistry.ISettings>;
/**
* Preload the schema for a plugin.
*
* @param plugin - The plugin ID.
*
* @param schema - The schema being added.
*
* #### Notes
* This method is deprecated and is only intented for use until there is a
* server-side API for storing setting data.
*/
preload(plugin: string, schema: ISettingRegistry.ISchema): void;
/**
* Reload a plugin's settings into the registry even if they already exist.

@@ -207,3 +325,4 @@ *

*
* @returns A promise that resolves with a plugin settings object.
* @returns A promise that resolves with a plugin settings object or rejects
* with a list of `ISchemaValidator.IError` objects if it fails.
*/

@@ -242,5 +361,5 @@ reload(plugin: string): Promise<ISettingRegistry.ISettings>;

* #### Notes
* Only the `user` level data will be saved.
* Only the `user` data will be saved.
*/
upload(raw: ISettingRegistry.IPlugin): Promise<void>;
upload(raw: ISettingRegistry.IPlugin): Promise<void | ISchemaValidator.IError[]>;
/**

@@ -250,8 +369,103 @@ * Save a plugin in the registry.

private _save(plugin);
private _annotations;
private _datastore;
/**
* Validate a plugin's data and schema, compose the `composite` data.
*/
private _validate(plugin);
private _connector;
private _pluginChanged;
private _plugins;
private _preload;
private _validator;
}
/**
* A manager for a specific plugin's settings.
*/
export declare class Settings implements ISettingRegistry.ISettings {
/**
* Instantiate a new plugin settings manager.
*/
constructor(options: Settings.IOptions);
/**
* A signal that emits when the plugin's settings have changed.
*/
readonly changed: ISignal<this, void>;
/**
* Get the composite of user settings and extension defaults.
*/
readonly composite: JSONObject;
/**
* Test whether the plugin settings manager disposed.
*/
readonly isDisposed: boolean;
/**
* Get the plugin settings schema.
*/
readonly schema: ISettingRegistry.ISchema;
/**
* Get the user settings.
*/
readonly user: JSONObject;
readonly plugin: string;
/**
* The system registry instance used by the settings manager.
*/
readonly registry: SettingRegistry;
/**
* Dispose of the plugin settings resources.
*/
dispose(): void;
/**
* Get an individual setting.
*
* @param key - The name of the setting being retrieved.
*
* @returns The setting value.
*
* #### Notes
* This method returns synchronously because it uses a cached copy of the
* plugin settings that is synchronized with the registry.
*/
get(key: string): {
composite: JSONValue;
user: JSONValue;
};
/**
* Remove a single setting.
*
* @param key - The name of the setting being removed.
*
* @returns A promise that resolves when the setting is removed.
*
* #### Notes
* This function is asynchronous because it writes to the setting registry.
*/
remove(key: string): Promise<void>;
/**
* Save all of the plugin's user settings at once.
*/
save(user: JSONObject): Promise<void>;
/**
* Set a single setting.
*
* @param key - The name of the setting being set.
*
* @param value - The value of the setting.
*
* @returns A promise that resolves when the setting has been saved.
*
* #### Notes
* This function is asynchronous because it writes to the setting registry.
*/
set(key: string, value: JSONValue): Promise<void>;
/**
* Handle plugin changes in the setting registry.
*/
private _onPluginChanged(sender, plugin);
private _changed;
private _composite;
private _isDisposed;
private _schema;
private _user;
}
/**
* A namespace for `SettingRegistry` statics.

@@ -265,6 +479,45 @@ */

/**
* The datastore used by the setting registry.
* The data connector used by the setting registry.
*/
datastore: IDatastore<ISettingRegistry.IPlugin, ISettingRegistry.IPlugin>;
connector?: IDataConnector<ISettingRegistry.IPlugin, ISettingRegistry.IPlugin>;
/**
* A function that preloads a plugin's schema in the client-side cache.
*
* #### Notes
* This param is deprecated and is only intented for use until there is a
* server-side API for storing setting data.
*/
preload?: (plugin: string, schema: ISettingRegistry.ISchema) => void;
/**
* The validator used to enforce the settings JSON schema.
*/
validator?: ISchemaValidator;
}
}
/**
* A namespace for `Settings` statics.
*/
export declare namespace Settings {
/**
* The instantiation options for a `Settings` object.
*/
interface IOptions {
/**
* The setting values for a plugin.
*/
plugin: ISettingRegistry.IPlugin;
/**
* The system registry instance used by the settings manager.
*/
registry: SettingRegistry;
}
}
/**
* A namespace for private module data.
*/
export declare namespace Private {
/**
* The schema for settings.
*/
const SCHEMA: ISettingRegistry.ISchema;
}

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

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

@@ -11,6 +12,10 @@ var coreutils_1 = require("@phosphor/coreutils");

/**
* The default level that is used when level is unspecified in a request.
* The key in the schema for setting editor icon class hints.
*/
var LEVEL = 'user';
exports.ICON_CLASS_KEY = 'jupyter.lab.setting-icon-class';
/**
* The key in the schema for setting editor icon label hints.
*/
exports.ICON_LABEL_KEY = 'jupyter.lab.setting-icon-label';
/**
* An alias for the JSON deep copy function.

@@ -25,2 +30,79 @@ */

/**
* The default implementation of a schema validator.
*/
var DefaultSchemaValidator = (function () {
/**
* Instantiate a schema validator.
*/
function DefaultSchemaValidator() {
this._composer = new Ajv({ useDefaults: true });
this._validator = new Ajv();
this._composer.addSchema(Private.SCHEMA, 'main');
this._validator.addSchema(Private.SCHEMA, 'main');
}
/**
* Add a schema to the validator.
*
* @param plugin - The plugin ID.
*
* @param schema - The schema being added.
*
* @return A list of errors if the schema fails to validate or `null` if there
* are no errors.
*
* #### Notes
* It is safe to call this function multiple times with the same plugin name.
*/
DefaultSchemaValidator.prototype.addSchema = function (plugin, schema) {
var composer = this._composer;
var validator = this._validator;
var validate = validator.getSchema('main');
// Validate against the main schema.
if (!validate(schema)) {
return validate.errors;
}
// Validate against the JSON schema meta-schema.
if (!validator.validateSchema(schema)) {
return validator.errors;
}
// Remove if schema already exists.
composer.removeSchema(plugin);
validator.removeSchema(plugin);
// Add schema to the validator and composer.
composer.addSchema(schema, plugin);
validator.addSchema(schema, plugin);
return null;
};
/**
* Validate a plugin's schema and user data; populate the `composite` data.
*
* @param plugin - The plugin being validated. Its `composite` data will be
* populated by reference.
*
* @return A list of errors if either the schema or data fail to validate or
* `null` if there are no errors.
*/
DefaultSchemaValidator.prototype.validateData = function (plugin) {
var validate = this._validator.getSchema(plugin.id);
var compose = this._composer.getSchema(plugin.id);
if (!validate || !compose) {
var errors = this.addSchema(plugin.id, plugin.schema);
if (errors) {
return errors;
}
}
if (!validate(plugin.data.user)) {
return validate.errors;
}
// Copy the user data before validating (and merging defaults).
plugin.data.composite = copy(plugin.data.user);
if (!compose(plugin.data.composite)) {
return compose.errors;
}
return null;
};
return DefaultSchemaValidator;
}());
exports.DefaultSchemaValidator = DefaultSchemaValidator;
/**
* The default concrete implementation of a setting registry.

@@ -33,21 +115,16 @@ */

function SettingRegistry(options) {
if (options === void 0) { options = { datastore: null }; }
this._annotations = Object.create(null);
this._datastore = null;
if (options === void 0) { options = {}; }
/**
* The schema of the setting registry.
*/
this.schema = Private.SCHEMA;
this._connector = null;
this._pluginChanged = new signaling_1.Signal(this);
this._plugins = Object.create(null);
this._validator = null;
var namespace = 'jupyter.db.settings';
this._datastore = options.datastore || new _1.StateDB({ namespace: namespace });
this._connector = options.connector || new _1.StateDB({ namespace: namespace });
this._validator = options.validator || new DefaultSchemaValidator();
this._preload = options.preload || (function () { });
}
Object.defineProperty(SettingRegistry.prototype, "annotations", {
/**
* Returns a map of annotation hints for plugins in the registry.
*/
get: function () {
var annotations = this._annotations;
return copy(annotations);
},
enumerable: true,
configurable: true
});
Object.defineProperty(SettingRegistry.prototype, "pluginChanged", {

@@ -76,24 +153,2 @@ /**

/**
* Annotate a plugin or a setting item for places where it might be displayed.
*
* @param plugin - The name of the plugin whose setting is being annotated.
*
* @param key - The name of the key being annotated. If `null` or empty, the
* annotation will be applied at the plugin level.
*
* @param annotation - The annotation describing a plugin or a setting.
*/
SettingRegistry.prototype.annotate = function (plugin, key, annotation) {
if (!this._annotations[plugin]) {
this._annotations[plugin] = { annotation: null, keys: {} };
}
if (key) {
this._annotations[plugin].keys[key] = annotation;
}
else {
this._annotations[plugin].annotation = annotation;
}
this._pluginChanged.emit(plugin);
};
/**
* Get an individual setting.

@@ -105,16 +160,16 @@ *

*
* @param level - The setting level. Defaults to `user`.
*
* @returns A promise that resolves when the setting is retrieved.
*/
SettingRegistry.prototype.get = function (plugin, key, level) {
SettingRegistry.prototype.get = function (plugin, key) {
var _this = this;
if (level === void 0) { level = LEVEL; }
var plugins = this._plugins;
if (plugin in plugins) {
var bundle = plugins[plugin] && plugins[plugin].data;
var value = bundle && bundle[level] && bundle[level][key] || null;
return Promise.resolve(copy(value));
var _a = plugins[plugin].data, composite = _a.composite, user = _a.user;
var result = {
composite: key in composite ? copy(composite[key]) : void 0,
user: key in user ? copy(user[key]) : void 0
};
return Promise.resolve(result);
}
return this.load(plugin).then(function () { return _this.get(plugin, key, level); });
return this.load(plugin).then(function () { return _this.get(plugin, key); });
};

@@ -126,3 +181,4 @@ /**

*
* @returns A promise that resolves with a plugin settings object.
* @returns A promise that resolves with a plugin settings object or rejects
* if the plugin is not found.
*/

@@ -134,11 +190,23 @@ SettingRegistry.prototype.load = function (plugin) {

if (plugin in plugins) {
var annotations = this._annotations[plugin] || null;
var content = plugins[plugin];
var settings = new Settings({ annotations: annotations, content: content, plugin: plugin, registry: registry });
var settings = new Settings({ plugin: plugins[plugin], registry: registry });
return Promise.resolve(settings);
}
// If the plugin needs to be loaded from the datastore, fetch.
// If the plugin needs to be loaded from the data connector, fetch.
return this.reload(plugin);
};
/**
* Preload the schema for a plugin.
*
* @param plugin - The plugin ID.
*
* @param schema - The schema being added.
*
* #### Notes
* This method is deprecated and is only intented for use until there is a
* server-side API for storing setting data.
*/
SettingRegistry.prototype.preload = function (plugin, schema) {
this._preload(plugin, schema);
};
/**
* Reload a plugin's settings into the registry even if they already exist.

@@ -148,18 +216,18 @@ *

*
* @returns A promise that resolves with a plugin settings object.
* @returns A promise that resolves with a plugin settings object or rejects
* with a list of `ISchemaValidator.IError` objects if it fails.
*/
SettingRegistry.prototype.reload = function (plugin) {
var _this = this;
var datastore = this._datastore;
var connector = this._connector;
var plugins = this._plugins;
// If the plugin needs to be loaded from the datastore, fetch.
return datastore.fetch(plugin).then(function (result) {
// Set the local copy.
plugins[plugin] = result || { id: plugin, data: {} };
// Copy over any annotations that may be available.
var annotations = copy(_this._annotations[plugin]);
// If the plugin needs to be loaded from the connector, fetch.
return connector.fetch(plugin).then(function (data) {
if (!data) {
var message = "Setting data for " + plugin + " does not exist.";
throw [{ keyword: '', message: message, schemaPath: '' }];
}
_this._validate(data);
return new Settings({
annotations: annotations,
content: copy(plugins[plugin]),
plugin: plugin,
plugin: copy(plugins[plugin]),
registry: _this

@@ -183,8 +251,3 @@ });

}
var bundle = plugins[plugin].data;
var level = 'user';
if (!bundle[level]) {
return Promise.resolve(void 0);
}
delete bundle[level][key];
delete plugins[plugin].data.user[key];
return this._save(plugin);

@@ -210,8 +273,3 @@ };

}
var bundle = plugins[plugin].data;
var level = 'user';
if (!bundle[level]) {
bundle[level] = Object.create(null);
}
bundle[level][key] = value;
plugins[plugin].data.user[key] = value;
return this._save(plugin);

@@ -227,7 +285,18 @@ };

* #### Notes
* Only the `user` level data will be saved.
* Only the `user` data will be saved.
*/
SettingRegistry.prototype.upload = function (raw) {
this._plugins[raw.id] = copy(raw);
return this._save(raw.id);
var plugins = this._plugins;
var plugin = raw.id;
var errors = null;
// Validate the user data and create the composite data.
raw.data.user = raw.data.user || {};
delete raw.data.composite;
errors = this._validator.validateData(raw);
if (errors) {
return Promise.reject(errors);
}
// Set the local copy.
plugins[plugin] = raw;
return this._save(plugin);
};

@@ -243,5 +312,26 @@ /**

}
return this._datastore.save(plugin, plugins[plugin])
this._validate(plugins[plugin]);
return this._connector.save(plugin, plugins[plugin].data.user)
.then(function () { _this._pluginChanged.emit(plugin); });
};
/**
* Validate a plugin's data and schema, compose the `composite` data.
*/
SettingRegistry.prototype._validate = function (plugin) {
var errors = null;
// Add the schema to the registry.
errors = this._validator.addSchema(plugin.id, plugin.schema);
if (errors) {
throw errors;
}
// Validate the user data and create the composite data.
plugin.data.user = plugin.data.user || {};
delete plugin.data.composite;
errors = this._validator.validateData(plugin);
if (errors) {
throw errors;
}
// Set the local copy.
this._plugins[plugin.id] = plugin;
};
return SettingRegistry;

@@ -258,18 +348,21 @@ }());

function Settings(options) {
this._annotations = null;
this._changed = new signaling_1.Signal(this);
this._content = null;
this._composite = Object.create(null);
this._isDisposed = false;
this._annotations = options.annotations;
this._content = options.content;
this.plugin = options.plugin;
this._schema = Object.create(null);
this._user = Object.create(null);
var plugin = options.plugin;
this.plugin = plugin.id;
this.registry = options.registry;
this._composite = plugin.data.composite || {};
this._schema = plugin.schema || { type: 'object' };
this._user = plugin.data.user || {};
this.registry.pluginChanged.connect(this._onPluginChanged, this);
}
Object.defineProperty(Settings.prototype, "annotations", {
Object.defineProperty(Settings.prototype, "changed", {
/**
* The annotation hints for the plugin.
* A signal that emits when the plugin's settings have changed.
*/
get: function () {
return this._annotations;
return this._changed;
},

@@ -279,8 +372,8 @@ enumerable: true,

});
Object.defineProperty(Settings.prototype, "changed", {
Object.defineProperty(Settings.prototype, "composite", {
/**
* A signal that emits when the plugin's settings have changed.
* Get the composite of user settings and extension defaults.
*/
get: function () {
return this._changed;
return this._composite;
},

@@ -300,8 +393,8 @@ enumerable: true,

});
Object.defineProperty(Settings.prototype, "raw", {
Object.defineProperty(Settings.prototype, "schema", {
/**
* Get the raw plugin settings.
* Get the plugin settings schema.
*/
get: function () {
return copy(this._content);
return this._schema;
},

@@ -311,14 +404,13 @@ enumerable: true,

});
Object.defineProperty(Settings.prototype, "user", {
/**
* Get the user settings.
*/
get: function () {
return this._user;
},
enumerable: true,
configurable: true
});
/**
* Annotate a plugin or a setting item for places where it might be displayed.
*
* @param key - The name of the key being annotated. If `null` or empty, the
* annotation will be applied at the plugin level.
*
* @param annotation - The annotation describing a plugin or a setting.
*/
Settings.prototype.annotate = function (key, annotation) {
this.registry.annotate(this.plugin, key, annotation);
};
/**
* Dispose of the plugin settings resources.

@@ -331,3 +423,5 @@ */

this._isDisposed = true;
this._content = null;
this._composite = null;
this._schema = null;
this._user = null;
signaling_1.Signal.clearData(this);

@@ -340,4 +434,2 @@ };

*
* @param level - The setting level. Defaults to `user`.
*
* @returns The setting value.

@@ -349,6 +441,8 @@ *

*/
Settings.prototype.get = function (key, level) {
if (level === void 0) { level = LEVEL; }
var data = this._content.data;
return data[level] && data[level][key];
Settings.prototype.get = function (key) {
var _a = this, composite = _a.composite, user = _a.user;
return {
composite: key in composite ? copy(composite[key]) : void 0,
user: key in user ? copy(user[key]) : void 0
};
};

@@ -369,6 +463,10 @@ /**

/**
* Save all of the plugin's settings at once.
* Save all of the plugin's user settings at once.
*/
Settings.prototype.save = function (raw) {
return this.registry.upload(raw);
Settings.prototype.save = function (user) {
return this.registry.upload({
id: this.plugin,
data: { composite: this._composite, user: user },
schema: this._schema
});
};

@@ -395,3 +493,11 @@ /**

if (plugin === this.plugin) {
this._content = algorithm_1.find(this.registry.plugins, function (p) { return p.id === plugin; });
var found = algorithm_1.find(this.registry.plugins, function (p) { return p.id === plugin; });
if (!found) {
return;
}
var _a = found.data, composite = _a.composite, user = _a.user;
var schema = found.schema;
this._composite = composite || {};
this._schema = schema || { type: 'object' };
this._user = user || {};
this._changed.emit(void 0);

@@ -402,1 +508,25 @@ }

}());
exports.Settings = Settings;
/**
* A namespace for private module data.
*/
var Private;
(function (Private) {
/* tslint:disable */
/**
* The schema for settings.
*/
Private.SCHEMA = {
"$schema": "http://json-schema.org/draft-06/schema",
"title": "Jupyter Settings/Preferences Schema",
"description": "Jupyter settings/preferences schema v0.1.0",
"type": "object",
"additionalProperties": true,
"properties": (_a = {},
_a[exports.ICON_CLASS_KEY] = { "type": "string", "default": "jp-FileIcon" },
_a[exports.ICON_LABEL_KEY] = { "type": "string", "default": "Plugin" },
_a)
};
var _a;
/* tslint:enable */
})(Private = exports.Private || (exports.Private = {}));
import { JSONObject, Token } from '@phosphor/coreutils';
import { IDatastore } from '.';
import { IDataConnector } from '.';
/**

@@ -22,3 +22,3 @@ * The default state database token.

*/
export interface IStateDB extends IDatastore<JSONObject, JSONObject> {
export interface IStateDB extends IDataConnector<JSONObject, JSONObject> {
/**

@@ -25,0 +25,0 @@ * The maximum allowed length of the data after it has been serialized.

{
"name": "@jupyterlab/coreutils",
"version": "0.7.1",
"version": "0.8.0",
"description": "JupyterLab - Core Utilities",

@@ -16,6 +16,7 @@ "main": "lib/index.js",

"@phosphor/algorithm": "^1.1.1",
"@phosphor/coreutils": "^1.1.1",
"@phosphor/coreutils": "^1.2.0",
"@phosphor/disposable": "^1.1.1",
"@phosphor/messaging": "^1.2.1",
"@phosphor/signaling": "^1.2.1",
"ajv": "^5.1.5",
"minimist": "^1.2.0",

@@ -27,5 +28,6 @@ "moment": "^2.17.1",

"devDependencies": {
"@types/ajv": "^1.0.0",
"@types/minimist": "^1.2.0",
"rimraf": "^2.5.2",
"typescript": "^2.2.1"
"typescript": "~2.3.1"
},

@@ -32,0 +34,0 @@ "scripts": {

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