@jupyterlite/settings 0.6.0-alpha.1 → 0.6.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -1,2 +1 @@
1
1
  export * from './settings';
2
- export * from './tokens';
package/lib/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
3
  export * from './settings';
4
- export * from './tokens';
5
4
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,cAAc,YAAY,CAAC"}
package/lib/settings.d.ts CHANGED
@@ -1,9 +1,17 @@
1
+ import { ServerConnection, Setting, SettingManager } from '@jupyterlab/services';
2
+ import { ISettingRegistry } from '@jupyterlab/settingregistry';
1
3
  import type localforage from 'localforage';
2
- import { IPlugin, ISettings } from './tokens';
3
4
  /**
4
- * A class to handle requests to /api/settings
5
+ * The settings file to request
5
6
  */
6
- export declare class Settings implements ISettings {
7
+ export type SettingsFile = 'all.json' | 'all_federated.json';
8
+ /**
9
+ * A class to manage settings in the browser.
10
+ */
11
+ export declare class Settings extends SettingManager implements Setting.IManager {
12
+ /**
13
+ * Create a new settings service.
14
+ */
7
15
  constructor(options: Settings.IOptions);
8
16
  /**
9
17
  * A promise that resolves when the settings storage is fully initialized
@@ -35,12 +43,13 @@ export declare class Settings implements ISettings {
35
43
  * @param pluginId the id of the plugin
36
44
  *
37
45
  */
38
- get(pluginId: string): Promise<IPlugin | undefined>;
46
+ fetch(pluginId: string): Promise<ISettingRegistry.IPlugin>;
39
47
  /**
40
48
  * Get all the settings
41
49
  */
42
- getAll(): Promise<{
43
- settings: IPlugin[];
50
+ list(query?: 'ids'): Promise<{
51
+ ids: string[];
52
+ values: ISettingRegistry.IPlugin[];
44
53
  }>;
45
54
  /**
46
55
  * Save settings for a given plugin id
@@ -49,7 +58,7 @@ export declare class Settings implements ISettings {
49
58
  * @param raw The raw settings
50
59
  *
51
60
  */
52
- save(pluginId: string, raw: string): Promise<void>;
61
+ save(id: string, raw: string): Promise<void>;
53
62
  /**
54
63
  * Get all the settings for core or federated plugins
55
64
  */
@@ -71,5 +80,6 @@ export declare namespace Settings {
71
80
  localforage: typeof localforage;
72
81
  storageName?: string | null;
73
82
  storageDrivers?: string[] | null;
83
+ serverSettings?: ServerConnection.ISettings;
74
84
  }
75
85
  }
package/lib/settings.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { PageConfig, URLExt } from '@jupyterlab/coreutils';
2
+ import { SettingManager } from '@jupyterlab/services';
2
3
  import { PromiseDelegate } from '@lumino/coreutils';
3
4
  import * as json5 from 'json5';
4
5
  /**
@@ -6,16 +7,23 @@ import * as json5 from 'json5';
6
7
  */
7
8
  const DEFAULT_STORAGE_NAME = 'JupyterLite Storage';
8
9
  /**
9
- * A class to handle requests to /api/settings
10
+ * A class to manage settings in the browser.
10
11
  */
11
- export class Settings {
12
+ export class Settings extends SettingManager {
13
+ /**
14
+ * Create a new settings service.
15
+ */
12
16
  constructor(options) {
17
+ super({
18
+ serverSettings: options.serverSettings,
19
+ });
13
20
  this._storageName = DEFAULT_STORAGE_NAME;
14
21
  this._storageDrivers = null;
15
22
  this._localforage = options.localforage;
16
23
  this._storageName = options.storageName || DEFAULT_STORAGE_NAME;
17
24
  this._storageDrivers = options.storageDrivers || null;
18
25
  this._ready = new PromiseDelegate();
26
+ void this.initialize().catch(console.warn);
19
27
  }
20
28
  /**
21
29
  * A promise that resolves when the settings storage is fully initialized
@@ -70,18 +78,22 @@ export class Settings {
70
78
  * @param pluginId the id of the plugin
71
79
  *
72
80
  */
73
- async get(pluginId) {
74
- const all = await this.getAll();
75
- const settings = all.settings;
81
+ async fetch(pluginId) {
82
+ const all = await this.list();
83
+ const settings = all.values;
76
84
  const setting = settings.find((setting) => {
77
85
  return setting.id === pluginId;
78
86
  });
87
+ if (!setting) {
88
+ throw new Error(`Setting ${pluginId} not found`);
89
+ }
79
90
  return setting;
80
91
  }
81
92
  /**
82
93
  * Get all the settings
83
94
  */
84
- async getAll() {
95
+ async list(query) {
96
+ var _a, _b;
85
97
  const allCore = await this._getAll('all.json');
86
98
  let allFederated = [];
87
99
  try {
@@ -105,7 +117,17 @@ export class Settings {
105
117
  settings: json5.parse(raw),
106
118
  };
107
119
  }));
108
- return { settings };
120
+ // format the settings
121
+ const ids = (_a = settings.map((plugin) => plugin.id)) !== null && _a !== void 0 ? _a : [];
122
+ let values = [];
123
+ if (!query) {
124
+ values =
125
+ (_b = settings.map((plugin) => {
126
+ plugin.data = { composite: {}, user: {} };
127
+ return plugin;
128
+ })) !== null && _b !== void 0 ? _b : [];
129
+ }
130
+ return { ids, values };
109
131
  }
110
132
  /**
111
133
  * Save settings for a given plugin id
@@ -114,8 +136,8 @@ export class Settings {
114
136
  * @param raw The raw settings
115
137
  *
116
138
  */
117
- async save(pluginId, raw) {
118
- await (await this.storage).setItem(pluginId, raw);
139
+ async save(id, raw) {
140
+ await (await this.storage).setItem(id, raw);
119
141
  }
120
142
  /**
121
143
  * Get all the settings for core or federated plugins
@@ -1 +1 @@
1
- {"version":3,"file":"settings.js","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B;;GAEG;AACH,MAAM,oBAAoB,GAAG,qBAAqB,CAAC;AAEnD;;GAEG;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,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE;gBAC7E,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,OAAO,GAAG,WAAW,CAAC;aACtD;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAXe,gBAAQ,WAWvB,CAAA;AACH,CAAC,EArBS,OAAO,KAAP,OAAO,QAqBhB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyterlite/settings",
3
- "version": "0.6.0-alpha.1",
3
+ "version": "0.6.0-alpha.3",
4
4
  "description": "JupyterLite - Settings",
5
5
  "homepage": "https://github.com/jupyterlite/jupyterlite",
6
6
  "bugs": {
@@ -43,9 +43,9 @@
43
43
  "watch": "tsc -b --watch"
44
44
  },
45
45
  "dependencies": {
46
- "@jupyterlab/coreutils": "~6.4.0-alpha.3",
47
- "@jupyterlab/settingregistry": "~4.4.0-alpha.3",
48
- "@jupyterlite/localforage": "^0.6.0-alpha.1",
46
+ "@jupyterlab/coreutils": "~6.4.0-beta.1",
47
+ "@jupyterlab/settingregistry": "~4.4.0-beta.1",
48
+ "@jupyterlite/localforage": "^0.6.0-alpha.3",
49
49
  "@lumino/coreutils": "^2.2.0",
50
50
  "json5": "^2.2.0",
51
51
  "localforage": "^1.9.0"
@@ -53,12 +53,12 @@
53
53
  "devDependencies": {
54
54
  "@babel/core": "^7.11.6",
55
55
  "@babel/preset-env": "^7.12.1",
56
- "@jupyterlab/testutils": "~4.4.0-alpha.3",
56
+ "@jupyterlab/testutils": "~4.4.0-beta.1",
57
57
  "@types/jest": "^29.5.3",
58
58
  "jest": "^29.6.2",
59
59
  "rimraf": "~5.0.1",
60
60
  "ts-jest": "^29.1.1",
61
- "typescript": "~5.1.6"
61
+ "typescript": "~5.5.4"
62
62
  },
63
63
  "publishConfig": {
64
64
  "access": "public"
package/src/index.ts CHANGED
@@ -2,4 +2,3 @@
2
2
  // Distributed under the terms of the Modified BSD License.
3
3
 
4
4
  export * from './settings';
5
- export * from './tokens';
package/src/settings.ts CHANGED
@@ -1,12 +1,19 @@
1
1
  import { PageConfig, URLExt } from '@jupyterlab/coreutils';
2
2
 
3
+ import { ServerConnection, Setting, SettingManager } from '@jupyterlab/services';
4
+
5
+ import { ISettingRegistry } from '@jupyterlab/settingregistry';
6
+
3
7
  import { PromiseDelegate } from '@lumino/coreutils';
4
8
 
5
9
  import * as json5 from 'json5';
6
10
 
7
11
  import type localforage from 'localforage';
8
12
 
9
- import { IPlugin, ISettings, SettingsFile } from './tokens';
13
+ /**
14
+ * The settings file to request
15
+ */
16
+ export type SettingsFile = 'all.json' | 'all_federated.json';
10
17
 
11
18
  /**
12
19
  * The name of the local storage.
@@ -14,15 +21,22 @@ import { IPlugin, ISettings, SettingsFile } from './tokens';
14
21
  const DEFAULT_STORAGE_NAME = 'JupyterLite Storage';
15
22
 
16
23
  /**
17
- * A class to handle requests to /api/settings
24
+ * A class to manage settings in the browser.
18
25
  */
19
- export class Settings implements ISettings {
26
+ export class Settings extends SettingManager implements Setting.IManager {
27
+ /**
28
+ * Create a new settings service.
29
+ */
20
30
  constructor(options: Settings.IOptions) {
31
+ super({
32
+ serverSettings: options.serverSettings,
33
+ });
21
34
  this._localforage = options.localforage;
22
35
  this._storageName = options.storageName || DEFAULT_STORAGE_NAME;
23
36
  this._storageDrivers = options.storageDrivers || null;
24
37
 
25
38
  this._ready = new PromiseDelegate();
39
+ void this.initialize().catch(console.warn);
26
40
  }
27
41
 
28
42
  /**
@@ -83,21 +97,26 @@ export class Settings implements ISettings {
83
97
  * @param pluginId the id of the plugin
84
98
  *
85
99
  */
86
- async get(pluginId: string): Promise<IPlugin | undefined> {
87
- const all = await this.getAll();
88
- const settings = all.settings as IPlugin[];
89
- const setting = settings.find((setting: IPlugin) => {
100
+ async fetch(pluginId: string): Promise<ISettingRegistry.IPlugin> {
101
+ const all = await this.list();
102
+ const settings = all.values as ISettingRegistry.IPlugin[];
103
+ const setting = settings.find((setting: ISettingRegistry.IPlugin) => {
90
104
  return setting.id === pluginId;
91
105
  });
106
+ if (!setting) {
107
+ throw new Error(`Setting ${pluginId} not found`);
108
+ }
92
109
  return setting;
93
110
  }
94
111
 
95
112
  /**
96
113
  * Get all the settings
97
114
  */
98
- async getAll(): Promise<{ settings: IPlugin[] }> {
115
+ async list(
116
+ query?: 'ids',
117
+ ): Promise<{ ids: string[]; values: ISettingRegistry.IPlugin[] }> {
99
118
  const allCore = await this._getAll('all.json');
100
- let allFederated: IPlugin[] = [];
119
+ let allFederated: ISettingRegistry.IPlugin[] = [];
101
120
  try {
102
121
  allFederated = await this._getAll('all_federated.json');
103
122
  } catch {
@@ -121,7 +140,20 @@ export class Settings implements ISettings {
121
140
  };
122
141
  }),
123
142
  );
124
- return { settings };
143
+
144
+ // format the settings
145
+ const ids = settings.map((plugin: ISettingRegistry.IPlugin) => plugin.id) ?? [];
146
+
147
+ let values: ISettingRegistry.IPlugin[] = [];
148
+ if (!query) {
149
+ values =
150
+ settings.map((plugin: ISettingRegistry.IPlugin) => {
151
+ plugin.data = { composite: {}, user: {} };
152
+ return plugin;
153
+ }) ?? [];
154
+ }
155
+
156
+ return { ids, values };
125
157
  }
126
158
 
127
159
  /**
@@ -131,18 +163,18 @@ export class Settings implements ISettings {
131
163
  * @param raw The raw settings
132
164
  *
133
165
  */
134
- async save(pluginId: string, raw: string): Promise<void> {
135
- await (await this.storage).setItem(pluginId, raw);
166
+ async save(id: string, raw: string): Promise<void> {
167
+ await (await this.storage).setItem(id, raw);
136
168
  }
137
169
 
138
170
  /**
139
171
  * Get all the settings for core or federated plugins
140
172
  */
141
- private async _getAll(file: SettingsFile): Promise<IPlugin[]> {
173
+ private async _getAll(file: SettingsFile): Promise<ISettingRegistry.IPlugin[]> {
142
174
  const settingsUrl = PageConfig.getOption('settingsUrl') ?? '/';
143
175
  const all = (await (
144
176
  await fetch(URLExt.join(settingsUrl, file))
145
- ).json()) as IPlugin[];
177
+ ).json()) as ISettingRegistry.IPlugin[];
146
178
  return all;
147
179
  }
148
180
 
@@ -164,6 +196,7 @@ export namespace Settings {
164
196
  localforage: typeof localforage;
165
197
  storageName?: string | null;
166
198
  storageDrivers?: string[] | null;
199
+ serverSettings?: ServerConnection.ISettings;
167
200
  }
168
201
  }
169
202
 
@@ -171,16 +204,15 @@ export namespace Settings {
171
204
  * A namespace for private data
172
205
  */
173
206
  namespace Private {
174
- const _overrides: Record<string, IPlugin['schema']['default']> = JSON.parse(
175
- PageConfig.getOption('settingsOverrides') || '{}',
176
- );
207
+ const _overrides: Record<string, ISettingRegistry.IPlugin['schema']['default']> =
208
+ JSON.parse(PageConfig.getOption('settingsOverrides') || '{}');
177
209
 
178
210
  /**
179
211
  * Override the defaults of the schema with ones from PageConfig
180
212
  *
181
213
  * @see https://github.com/jupyterlab/jupyterlab_server/blob/v2.5.2/jupyterlab_server/settings_handler.py#L216-L227
182
214
  */
183
- export function override(plugin: IPlugin): IPlugin {
215
+ export function override(plugin: ISettingRegistry.IPlugin): ISettingRegistry.IPlugin {
184
216
  if (_overrides[plugin.id]) {
185
217
  if (!plugin.schema.properties) {
186
218
  // probably malformed, or only provides keyboard shortcuts, etc.
package/lib/tokens.d.ts DELETED
@@ -1,65 +0,0 @@
1
- import { ISettingRegistry } from '@jupyterlab/settingregistry';
2
- import { JSONObject, PartialJSONObject, Token } from '@lumino/coreutils';
3
- /**
4
- * The token for the settings service.
5
- */
6
- export declare const ISettings: Token<ISettings>;
7
- /**
8
- * The settings file to request
9
- */
10
- export type SettingsFile = 'all.json' | 'all_federated.json';
11
- /**
12
- * An interface for the plugin settings.
13
- */
14
- export interface IPlugin extends PartialJSONObject {
15
- /**
16
- * The name of the plugin.
17
- */
18
- id: string;
19
- /**
20
- * The settings for the plugin.
21
- */
22
- settings: JSONObject;
23
- /**
24
- * The raw user settings data as a string containing JSON with comments.
25
- */
26
- raw: string;
27
- /**
28
- * The JSON schema for the plugin.
29
- */
30
- schema: ISettingRegistry.ISchema;
31
- /**
32
- * The published version of the NPM package containing the plugin.
33
- */
34
- version: string;
35
- }
36
- /**
37
- * The interface for the Settings service.
38
- */
39
- export interface ISettings {
40
- /**
41
- * A promise that resolves after the settings have been full initialized
42
- */
43
- ready: Promise<void>;
44
- /**
45
- * Get settings by plugin id
46
- *
47
- * @param pluginId the id of the plugin
48
- *
49
- */
50
- get(pluginId: string): Promise<IPlugin | undefined>;
51
- /**
52
- * Get all the settings
53
- */
54
- getAll(): Promise<{
55
- settings: IPlugin[];
56
- }>;
57
- /**
58
- * Save settings for a given plugin id
59
- *
60
- * @param pluginId The id of the plugin
61
- * @param raw The raw settings
62
- *
63
- */
64
- save(pluginId: string, raw: string): Promise<void>;
65
- }
package/lib/tokens.js DELETED
@@ -1,6 +0,0 @@
1
- import { Token } from '@lumino/coreutils';
2
- /**
3
- * The token for the settings service.
4
- */
5
- export const ISettings = new Token('@jupyterlite/settings:ISettings');
6
- //# sourceMappingURL=tokens.js.map
package/lib/tokens.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiC,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEzE;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,KAAK,CAAY,iCAAiC,CAAC,CAAC"}
package/src/tokens.ts DELETED
@@ -1,75 +0,0 @@
1
- import { ISettingRegistry } from '@jupyterlab/settingregistry';
2
-
3
- import { JSONObject, PartialJSONObject, Token } from '@lumino/coreutils';
4
-
5
- /**
6
- * The token for the settings service.
7
- */
8
- export const ISettings = new Token<ISettings>('@jupyterlite/settings:ISettings');
9
-
10
- /**
11
- * The settings file to request
12
- */
13
- export type SettingsFile = 'all.json' | 'all_federated.json';
14
-
15
- /**
16
- * An interface for the plugin settings.
17
- */
18
- export interface IPlugin extends PartialJSONObject {
19
- /**
20
- * The name of the plugin.
21
- */
22
- id: string;
23
-
24
- /**
25
- * The settings for the plugin.
26
- */
27
- settings: JSONObject;
28
-
29
- /**
30
- * The raw user settings data as a string containing JSON with comments.
31
- */
32
- raw: string;
33
-
34
- /**
35
- * The JSON schema for the plugin.
36
- */
37
- schema: ISettingRegistry.ISchema;
38
-
39
- /**
40
- * The published version of the NPM package containing the plugin.
41
- */
42
- version: string;
43
- }
44
-
45
- /**
46
- * The interface for the Settings service.
47
- */
48
- export interface ISettings {
49
- /**
50
- * A promise that resolves after the settings have been full initialized
51
- */
52
- ready: Promise<void>;
53
-
54
- /**
55
- * Get settings by plugin id
56
- *
57
- * @param pluginId the id of the plugin
58
- *
59
- */
60
- get(pluginId: string): Promise<IPlugin | undefined>;
61
-
62
- /**
63
- * Get all the settings
64
- */
65
- getAll(): Promise<{ settings: IPlugin[] }>;
66
-
67
- /**
68
- * Save settings for a given plugin id
69
- *
70
- * @param pluginId The id of the plugin
71
- * @param raw The raw settings
72
- *
73
- */
74
- save(pluginId: string, raw: string): Promise<void>;
75
- }