Quellcode durchsuchen

update statedb/settings for TS 2.4

S. Chris Colbert vor 7 Jahren
Ursprung
Commit
90fbd0fb65

+ 6 - 5
packages/coreutils/src/interfaces.ts

@@ -28,7 +28,7 @@ interface IChangedArgs<T> {
  * The description of a general purpose data connector.
  */
 export
-interface IDataConnector<T, U> {
+interface IDataConnector<T, U = T> {
   /**
    * Retrieve a saved bundle from the data connector.
    *
@@ -37,10 +37,11 @@ interface IDataConnector<T, U> {
    * @returns A promise that bears a data payload if available.
    *
    * #### Notes
-   * The promise returned by this method may be rejected if an error occurs in
-   * retrieving the data. Non-existence of an `id` will succeed with `null`.
+   * The promise returned by this method may be rejected if an error
+   * occurs in  retrieving the data. Non-existence of an `id` will
+   * succeed with `undefined`.
    */
-  fetch(id: string): Promise<T | null>;
+  fetch(id: string): Promise<T | undefined>;
 
   /**
    * Remove a value from the data connector.
@@ -60,5 +61,5 @@ interface IDataConnector<T, U> {
    *
    * @returns A promise that is rejected if saving fails and succeeds otherwise.
    */
-  save(id: string, value: U): Promise<T | void>;
+  save(id: string, value: U): Promise<void>;
 }

+ 7 - 8
packages/coreutils/src/settingregistry.ts

@@ -20,8 +20,8 @@ import {
 } from '@phosphor/signaling';
 
 import {
-  IDataConnector, StateDB
-} from '.';
+  IDataConnector
+} from './interfaces';
 
 
 /**
@@ -399,9 +399,8 @@ class SettingRegistry {
   /**
    * Create a new setting registry.
    */
-  constructor(options: SettingRegistry.IOptions = { }) {
-    const namespace = 'jupyter.db.settings';
-    this._connector = options.connector || new StateDB({ namespace });
+  constructor(options: SettingRegistry.IOptions) {
+    this._connector = options.connector;
     this._validator = options.validator || new DefaultSchemaValidator();
     this._preload = options.preload || (() => { /* no op */ });
   }
@@ -574,7 +573,7 @@ class SettingRegistry {
    * #### Notes
    * Only the `user` data will be saved.
    */
-  upload(raw: ISettingRegistry.IPlugin): Promise<void | ISchemaValidator.IError[]> {
+  upload(raw: ISettingRegistry.IPlugin): Promise<void> {
     const plugins = this._plugins;
     const plugin = raw.id;
     let errors: ISchemaValidator.IError[] | null = null;
@@ -633,7 +632,7 @@ class SettingRegistry {
     this._plugins[plugin.id] = plugin;
   }
 
-  private _connector: IDataConnector<ISettingRegistry.IPlugin, JSONObject> | null = null;
+  private _connector: IDataConnector<ISettingRegistry.IPlugin, JSONObject>;
   private _pluginChanged = new Signal<this, string>(this);
   private _plugins: { [name: string]: ISettingRegistry.IPlugin } = Object.create(null);
   private _preload: (plugin: string, schema: ISettingRegistry.ISchema) => void;
@@ -826,7 +825,7 @@ namespace SettingRegistry {
     /**
      * The data connector used by the setting registry.
      */
-    connector?: IDataConnector<ISettingRegistry.IPlugin, ISettingRegistry.IPlugin>;
+    connector: IDataConnector<ISettingRegistry.IPlugin, JSONObject>;
 
     /**
      * A function that preloads a plugin's schema in the client-side cache.

+ 5 - 51
packages/coreutils/src/statedb.ts

@@ -20,6 +20,7 @@ const IStateDB = new Token<IStateDB>('jupyter.services.statedb');
 
 
 /**
+ * An object which holds an id/value pair.
  */
 export
 interface IStateItem {
@@ -39,7 +40,7 @@ interface IStateItem {
  * The description of a state database.
  */
 export
-interface IStateDB extends IDataConnector<JSONObject, JSONObject> {
+interface IStateDB extends IDataConnector<JSONObject> {
   /**
    * The maximum allowed length of the data after it has been serialized.
    */
@@ -49,31 +50,12 @@ interface IStateDB extends IDataConnector<JSONObject, JSONObject> {
    * The namespace prefix for all state database entries.
    *
    * #### Notes
-   * This value should be set at instantiation and will only be used internally
-   * by a state database. That means, for example, that an app could have
-   * multiple, mutually exclusive state databases.
+   * This value should be set at instantiation and will only be used
+   * internally by a state database. That means, for example, that an
+   * app could have multiple, mutually exclusive state databases.
    */
   readonly namespace: string;
 
-  /**
-   * Retrieve a saved bundle from the database.
-   *
-   * @param id - The identifier used to retrieve a data bundle.
-   *
-   * @returns A promise that bears a data payload if available.
-   *
-   * #### Notes
-   * The `id` values of stored items in the state database are formatted:
-   * `'namespace:identifier'`, which is the same convention that command
-   * identifiers in JupyterLab use as well. While this is not a technical
-   * requirement for `fetch()`, `remove()`, and `save()`, it *is* necessary for
-   * using the `fetchNamespace()` method.
-   *
-   * The promise returned by this method may be rejected if an error occurs in
-   * retrieving the data. Non-existence of an `id` will succeed, however.
-   */
-  fetch(id: string): Promise<JSONObject | null>;
-
   /**
    * Retrieve all the saved bundles for a namespace.
    *
@@ -91,37 +73,9 @@ interface IStateDB extends IDataConnector<JSONObject, JSONObject> {
    * This promise will always succeed.
    */
   fetchNamespace(namespace: string): Promise<IStateItem[]>;
-
-  /**
-   * Remove a value from the database.
-   *
-   * @param id - The identifier for the data being removed.
-   *
-   * @returns A promise that is rejected if remove fails and succeeds otherwise.
-   */
-  remove(id: string): Promise<void>;
-
-  /**
-   * Save a value in the database.
-   *
-   * @param id - The identifier for the data being saved.
-   *
-   * @param value - The data being saved.
-   *
-   * @returns A promise that is rejected if saving fails and succeeds otherwise.
-   *
-   * #### Notes
-   * The `id` values of stored items in the state database are formatted:
-   * `'namespace:identifier'`, which is the same convention that command
-   * identifiers in JupyterLab use as well. While this is not a technical
-   * requirement for `fetch()`, `remove()`, and `save()`, it *is* necessary for
-   * using the `fetchNamespace()` method.
-   */
-  save(id: string, value: JSONObject): Promise<void>;
 }
 
 
-
 /**
  * The default concrete implementation of a state database.
  */