@jupyterlab/workspaces 4.2.0-alpha.2

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 ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @module workspaces
4
+ */
5
+ export * from './model';
6
+ export * from './tokens';
package/lib/index.js ADDED
@@ -0,0 +1,9 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ /**
4
+ * @packageDocumentation
5
+ * @module workspaces
6
+ */
7
+ export * from './model';
8
+ export * from './tokens';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAC3D;;;GAGG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
package/lib/model.d.ts ADDED
@@ -0,0 +1,87 @@
1
+ import { Poll } from '@lumino/polling';
2
+ import { ISignal } from '@lumino/signaling';
3
+ import { Workspace } from '@jupyterlab/services';
4
+ import { IWorkspacesModel } from './tokens';
5
+ /**
6
+ * An implementation of a workspaces model.
7
+ */
8
+ export declare class WorkspacesModel implements IWorkspacesModel {
9
+ constructor(options: WorkspacesModel.IOptions);
10
+ /**
11
+ * The list of available workspaces.
12
+ */
13
+ get workspaces(): Workspace.IWorkspace[];
14
+ /**
15
+ * The list of workspace identifiers.
16
+ */
17
+ get identifiers(): string[];
18
+ /**
19
+ * Create an empty workspace.
20
+ */
21
+ create(workspaceId: string): Promise<void>;
22
+ /**
23
+ * A signal emitted when the workspaces list is refreshed.
24
+ */
25
+ get refreshed(): ISignal<WorkspacesModel, void>;
26
+ /**
27
+ * Force a refresh of the workspaces list.
28
+ */
29
+ refresh(): Promise<void>;
30
+ /**
31
+ * Rename a workspace.
32
+ */
33
+ rename(workspaceId: string, newName: string): Promise<void>;
34
+ /**
35
+ * Reset a workspace.
36
+ */
37
+ reset(workspaceId: string): Promise<void>;
38
+ /**
39
+ * Remove a workspace.
40
+ */
41
+ remove(workspaceId: string): Promise<void>;
42
+ /**
43
+ * Save workspace under a different name.
44
+ */
45
+ saveAs(workspaceId: string, newName: string): Promise<void>;
46
+ /**
47
+ * Get whether the model is disposed.
48
+ */
49
+ get isDisposed(): boolean;
50
+ /**
51
+ * Dispose of the resources held by the model.
52
+ */
53
+ dispose(): void;
54
+ private _fetchList;
55
+ private _refreshed;
56
+ private _isDisposed;
57
+ private _poll;
58
+ private _manager;
59
+ private _workspaceData;
60
+ }
61
+ /**
62
+ * The namespace for the `WorkspacesModel` class statics.
63
+ */
64
+ export declare namespace WorkspacesModel {
65
+ /**
66
+ * An options object for initializing a the workspaces model.
67
+ */
68
+ interface IOptions {
69
+ /**
70
+ * The workspaces manager.
71
+ */
72
+ manager: Workspace.IManager;
73
+ /**
74
+ * Whether a to automatically loads initial list of workspaces.
75
+ * The default is `true`.
76
+ */
77
+ auto?: boolean;
78
+ /**
79
+ * The time interval for browser refreshing, in ms.
80
+ */
81
+ refreshInterval?: number;
82
+ /**
83
+ * When the model stops polling the API. Defaults to `when-hidden`.
84
+ */
85
+ refreshStandby?: Poll.Standby | (() => boolean | Poll.Standby);
86
+ }
87
+ }
package/lib/model.js ADDED
@@ -0,0 +1,129 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ import { Poll } from '@lumino/polling';
6
+ import { Signal } from '@lumino/signaling';
7
+ /**
8
+ * The default duration of the auto-refresh in ms
9
+ */
10
+ const DEFAULT_REFRESH_INTERVAL = 10000;
11
+ /**
12
+ * An implementation of a workspaces model.
13
+ */
14
+ export class WorkspacesModel {
15
+ constructor(options) {
16
+ var _a;
17
+ this._refreshed = new Signal(this);
18
+ this._isDisposed = false;
19
+ this._workspaceData = {
20
+ ids: [],
21
+ values: []
22
+ };
23
+ this._manager = options.manager;
24
+ const refreshInterval = options.refreshInterval || DEFAULT_REFRESH_INTERVAL;
25
+ this._poll = new Poll({
26
+ auto: (_a = options.auto) !== null && _a !== void 0 ? _a : true,
27
+ name: '@jupyterlab/workspaces:Model',
28
+ factory: () => this._fetchList(),
29
+ frequency: {
30
+ interval: refreshInterval,
31
+ backoff: true,
32
+ max: 300 * 1000
33
+ },
34
+ standby: options.refreshStandby || 'when-hidden'
35
+ });
36
+ }
37
+ /**
38
+ * The list of available workspaces.
39
+ */
40
+ get workspaces() {
41
+ return this._workspaceData.values;
42
+ }
43
+ /**
44
+ * The list of workspace identifiers.
45
+ */
46
+ get identifiers() {
47
+ return this._workspaceData.ids;
48
+ }
49
+ /**
50
+ * Create an empty workspace.
51
+ */
52
+ async create(workspaceId) {
53
+ await this._manager.save(workspaceId, {
54
+ metadata: { id: workspaceId },
55
+ data: {}
56
+ });
57
+ await this.refresh();
58
+ }
59
+ /**
60
+ * A signal emitted when the workspaces list is refreshed.
61
+ */
62
+ get refreshed() {
63
+ return this._refreshed;
64
+ }
65
+ /**
66
+ * Force a refresh of the workspaces list.
67
+ */
68
+ async refresh() {
69
+ await this._poll.refresh();
70
+ await this._poll.tick;
71
+ }
72
+ /**
73
+ * Rename a workspace.
74
+ */
75
+ async rename(workspaceId, newName) {
76
+ const workspace = await this._manager.fetch(workspaceId);
77
+ workspace.metadata.id = newName;
78
+ await this._manager.save(newName, workspace);
79
+ await this._manager.remove(workspaceId);
80
+ await this.refresh();
81
+ }
82
+ /**
83
+ * Reset a workspace.
84
+ */
85
+ async reset(workspaceId) {
86
+ const workspace = await this._manager.fetch(workspaceId);
87
+ workspace.data = {};
88
+ await this._manager.save(workspaceId, workspace);
89
+ await this.refresh();
90
+ }
91
+ /**
92
+ * Remove a workspace.
93
+ */
94
+ async remove(workspaceId) {
95
+ await this._manager.remove(workspaceId);
96
+ await this.refresh();
97
+ }
98
+ /**
99
+ * Save workspace under a different name.
100
+ */
101
+ async saveAs(workspaceId, newName) {
102
+ const data = await this._manager.fetch(workspaceId);
103
+ data.metadata.id = newName;
104
+ await this._manager.save(newName, data);
105
+ await this.refresh();
106
+ }
107
+ /**
108
+ * Get whether the model is disposed.
109
+ */
110
+ get isDisposed() {
111
+ return this._isDisposed;
112
+ }
113
+ /**
114
+ * Dispose of the resources held by the model.
115
+ */
116
+ dispose() {
117
+ if (this.isDisposed) {
118
+ return;
119
+ }
120
+ this._isDisposed = true;
121
+ this._poll.dispose();
122
+ Signal.clearData(this);
123
+ }
124
+ async _fetchList() {
125
+ this._workspaceData = await this._manager.list();
126
+ this._refreshed.emit(void 0);
127
+ }
128
+ }
129
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAW,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAIpD;;GAEG;AACH,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAEvC;;GAEG;AACH,MAAM,OAAO,eAAe;IAC1B,YAAY,OAAiC;;QAwHrC,eAAU,GAAG,IAAI,MAAM,CAAwB,IAAI,CAAC,CAAC;QACrD,gBAAW,GAAG,KAAK,CAAC;QAGpB,mBAAc,GAAsD;YAC1E,GAAG,EAAE,EAAE;YACP,MAAM,EAAE,EAAE;SACX,CAAC;QA9HA,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;QAChC,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,wBAAwB,CAAC;QAC5E,IAAI,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC;YACpB,IAAI,EAAE,MAAA,OAAO,CAAC,IAAI,mCAAI,IAAI;YAC1B,IAAI,EAAE,8BAA8B;YACpC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE;YAChC,SAAS,EAAE;gBACT,QAAQ,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,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/B,CAAC;CAUF"}
@@ -0,0 +1,66 @@
1
+ import { Token } from '@lumino/coreutils';
2
+ import { IDisposable } from '@lumino/disposable';
3
+ import { ISignal } from '@lumino/signaling';
4
+ import type { Workspace } from '@jupyterlab/services';
5
+ /**
6
+ * The token that provides the identifiers of workspace commands for reuse.
7
+ */
8
+ export declare const IWorkspaceCommands: Token<IWorkspaceCommands>;
9
+ /**
10
+ * The identifiers of loaded commands exposed for reuse.
11
+ */
12
+ export interface IWorkspaceCommands {
13
+ /**
14
+ * Command for opening a workspace by identifier.
15
+ */
16
+ open: string;
17
+ /**
18
+ * Command for deleting a workspace.
19
+ */
20
+ deleteWorkspace: string;
21
+ }
22
+ /**
23
+ * The token that provides the identifiers of workspace commands for reuse.
24
+ */
25
+ export declare const IWorkspacesModel: Token<IWorkspacesModel>;
26
+ /**
27
+ * The model for listing available workspaces.
28
+ */
29
+ export interface IWorkspacesModel extends IDisposable {
30
+ /**
31
+ * The list of available workspaces.
32
+ */
33
+ readonly workspaces: Workspace.IWorkspace[];
34
+ /**
35
+ * The list of workspace identifiers.
36
+ */
37
+ readonly identifiers: string[];
38
+ /**
39
+ * Create an empty workspace.
40
+ */
41
+ create(workspaceId: string): Promise<void>;
42
+ /**
43
+ * Rename a workspace.
44
+ */
45
+ rename(workspaceId: string, newName: string): Promise<void>;
46
+ /**
47
+ * Refresh the listing of workspaces.
48
+ */
49
+ refresh(): Promise<void>;
50
+ /**
51
+ * Signal emitted when the listing is refreshed.
52
+ */
53
+ refreshed: ISignal<IWorkspacesModel, void>;
54
+ /**
55
+ * Reset a workspace.
56
+ */
57
+ reset(workspaceId: string): Promise<void>;
58
+ /**
59
+ * Remove a workspace.
60
+ */
61
+ remove(workspaceId: string): Promise<void>;
62
+ /**
63
+ * Save workspace under a different name.
64
+ */
65
+ saveAs(workspaceId: string, newName: string): Promise<void>;
66
+ }
package/lib/tokens.js ADDED
@@ -0,0 +1,12 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ import { Token } from '@lumino/coreutils';
4
+ /**
5
+ * The token that provides the identifiers of workspace commands for reuse.
6
+ */
7
+ export const IWorkspaceCommands = new Token('@jupyterlab/workspaces:IWorkspaceCommands', 'Provides identifiers of workspace commands.');
8
+ /**
9
+ * The token that provides the identifiers of workspace commands for reuse.
10
+ */
11
+ export const IWorkspacesModel = new Token('@jupyterlab/workspaces:IWorkspacesModel', 'Provides a model for available workspaces.');
12
+ //# sourceMappingURL=tokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAK1C;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,KAAK,CACzC,2CAA2C,EAC3C,6CAA6C,CAC9C,CAAC;AAgBF;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,KAAK,CACvC,yCAAyC,EACzC,4CAA4C,CAC7C,CAAC"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@jupyterlab/workspaces",
3
+ "version": "4.2.0-alpha.2",
4
+ "description": "JupyterLab workspaces management",
5
+ "homepage": "https://github.com/jupyterlab/jupyterlab",
6
+ "bugs": {
7
+ "url": "https://github.com/jupyterlab/jupyterlab/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/jupyterlab/jupyterlab.git"
12
+ },
13
+ "license": "BSD-3-Clause",
14
+ "author": "Project Jupyter",
15
+ "sideEffects": [
16
+ "style/**/*"
17
+ ],
18
+ "main": "lib/index.js",
19
+ "types": "lib/index.d.ts",
20
+ "directories": {
21
+ "lib": "lib/"
22
+ },
23
+ "files": [
24
+ "lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
25
+ "schema/*.json",
26
+ "style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}",
27
+ "src/**/*.{ts,tsx}",
28
+ "style/index.js"
29
+ ],
30
+ "scripts": {
31
+ "build": "tsc -b",
32
+ "build:test": "tsc --build tsconfig.test.json",
33
+ "clean": "rimraf lib tsconfig.tsbuildinfo",
34
+ "docs": "typedoc src",
35
+ "test": "jest",
36
+ "test:cov": "jest --collect-coverage",
37
+ "test:debug": "node --inspect-brk ../../node_modules/.bin/jest --runInBand",
38
+ "test:debug:watch": "node --inspect-brk ../../node_modules/.bin/jest --runInBand --watch",
39
+ "watch": "tsc -b --watch"
40
+ },
41
+ "dependencies": {
42
+ "@jupyterlab/services": "^7.2.0-alpha.2",
43
+ "@lumino/coreutils": "^2.1.2",
44
+ "@lumino/disposable": "^2.1.2",
45
+ "@lumino/polling": "^2.1.2",
46
+ "@lumino/signaling": "^2.1.2"
47
+ },
48
+ "devDependencies": {
49
+ "@jupyterlab/testing": "^4.2.0-alpha.2",
50
+ "@types/jest": "^29.2.0",
51
+ "jest": "^29.2.0",
52
+ "rimraf": "~5.0.5",
53
+ "typedoc": "~0.24.7",
54
+ "typescript": "~5.1.6"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ }
59
+ }
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ /**
4
+ * @packageDocumentation
5
+ * @module workspaces
6
+ */
7
+
8
+ export * from './model';
9
+ export * from './tokens';
package/src/model.ts ADDED
@@ -0,0 +1,179 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+
6
+ import { Poll } from '@lumino/polling';
7
+ import { ISignal, Signal } from '@lumino/signaling';
8
+ import { Workspace } from '@jupyterlab/services';
9
+ import { IWorkspacesModel } from './tokens';
10
+
11
+ /**
12
+ * The default duration of the auto-refresh in ms
13
+ */
14
+ const DEFAULT_REFRESH_INTERVAL = 10000;
15
+
16
+ /**
17
+ * An implementation of a workspaces model.
18
+ */
19
+ export class WorkspacesModel implements IWorkspacesModel {
20
+ constructor(options: WorkspacesModel.IOptions) {
21
+ this._manager = options.manager;
22
+ const refreshInterval = options.refreshInterval || DEFAULT_REFRESH_INTERVAL;
23
+ this._poll = new Poll({
24
+ auto: options.auto ?? true,
25
+ name: '@jupyterlab/workspaces:Model',
26
+ factory: () => this._fetchList(),
27
+ frequency: {
28
+ interval: refreshInterval,
29
+ backoff: true,
30
+ max: 300 * 1000
31
+ },
32
+ standby: options.refreshStandby || 'when-hidden'
33
+ });
34
+ }
35
+
36
+ /**
37
+ * The list of available workspaces.
38
+ */
39
+ get workspaces(): Workspace.IWorkspace[] {
40
+ return this._workspaceData.values;
41
+ }
42
+
43
+ /**
44
+ * The list of workspace identifiers.
45
+ */
46
+ get identifiers(): string[] {
47
+ return this._workspaceData.ids;
48
+ }
49
+
50
+ /**
51
+ * Create an empty workspace.
52
+ */
53
+ async create(workspaceId: string): Promise<void> {
54
+ await this._manager.save(workspaceId, {
55
+ metadata: { id: workspaceId },
56
+ data: {}
57
+ });
58
+ await this.refresh();
59
+ }
60
+
61
+ /**
62
+ * A signal emitted when the workspaces list is refreshed.
63
+ */
64
+ get refreshed(): ISignal<WorkspacesModel, void> {
65
+ return this._refreshed;
66
+ }
67
+
68
+ /**
69
+ * Force a refresh of the workspaces list.
70
+ */
71
+ async refresh(): Promise<void> {
72
+ await this._poll.refresh();
73
+ await this._poll.tick;
74
+ }
75
+
76
+ /**
77
+ * Rename a workspace.
78
+ */
79
+ async rename(workspaceId: string, newName: string): Promise<void> {
80
+ const workspace = await this._manager.fetch(workspaceId);
81
+ workspace.metadata.id = newName;
82
+
83
+ await this._manager.save(newName, workspace);
84
+ await this._manager.remove(workspaceId);
85
+ await this.refresh();
86
+ }
87
+
88
+ /**
89
+ * Reset a workspace.
90
+ */
91
+ async reset(workspaceId: string): Promise<void> {
92
+ const workspace = await this._manager.fetch(workspaceId);
93
+ workspace.data = {};
94
+ await this._manager.save(workspaceId, workspace);
95
+ await this.refresh();
96
+ }
97
+
98
+ /**
99
+ * Remove a workspace.
100
+ */
101
+ async remove(workspaceId: string): Promise<void> {
102
+ await this._manager.remove(workspaceId);
103
+ await this.refresh();
104
+ }
105
+
106
+ /**
107
+ * Save workspace under a different name.
108
+ */
109
+ async saveAs(workspaceId: string, newName: string): Promise<void> {
110
+ const data = await this._manager.fetch(workspaceId);
111
+ data.metadata.id = newName;
112
+ await this._manager.save(newName, data);
113
+ await this.refresh();
114
+ }
115
+
116
+ /**
117
+ * Get whether the model is disposed.
118
+ */
119
+ get isDisposed(): boolean {
120
+ return this._isDisposed;
121
+ }
122
+
123
+ /**
124
+ * Dispose of the resources held by the model.
125
+ */
126
+ dispose(): void {
127
+ if (this.isDisposed) {
128
+ return;
129
+ }
130
+ this._isDisposed = true;
131
+ this._poll.dispose();
132
+ Signal.clearData(this);
133
+ }
134
+
135
+ private async _fetchList() {
136
+ this._workspaceData = await this._manager.list();
137
+ this._refreshed.emit(void 0);
138
+ }
139
+
140
+ private _refreshed = new Signal<WorkspacesModel, void>(this);
141
+ private _isDisposed = false;
142
+ private _poll: Poll;
143
+ private _manager: Workspace.IManager;
144
+ private _workspaceData: { ids: string[]; values: Workspace.IWorkspace[] } = {
145
+ ids: [],
146
+ values: []
147
+ };
148
+ }
149
+
150
+ /**
151
+ * The namespace for the `WorkspacesModel` class statics.
152
+ */
153
+ export namespace WorkspacesModel {
154
+ /**
155
+ * An options object for initializing a the workspaces model.
156
+ */
157
+ export interface IOptions {
158
+ /**
159
+ * The workspaces manager.
160
+ */
161
+ manager: Workspace.IManager;
162
+
163
+ /**
164
+ * Whether a to automatically loads initial list of workspaces.
165
+ * The default is `true`.
166
+ */
167
+ auto?: boolean;
168
+
169
+ /**
170
+ * The time interval for browser refreshing, in ms.
171
+ */
172
+ refreshInterval?: number;
173
+
174
+ /**
175
+ * When the model stops polling the API. Defaults to `when-hidden`.
176
+ */
177
+ refreshStandby?: Poll.Standby | (() => boolean | Poll.Standby);
178
+ }
179
+ }
package/src/tokens.ts ADDED
@@ -0,0 +1,86 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ import { Token } from '@lumino/coreutils';
4
+ import { IDisposable } from '@lumino/disposable';
5
+ import { ISignal } from '@lumino/signaling';
6
+ import type { Workspace } from '@jupyterlab/services';
7
+
8
+ /**
9
+ * The token that provides the identifiers of workspace commands for reuse.
10
+ */
11
+ export const IWorkspaceCommands = new Token<IWorkspaceCommands>(
12
+ '@jupyterlab/workspaces:IWorkspaceCommands',
13
+ 'Provides identifiers of workspace commands.'
14
+ );
15
+
16
+ /**
17
+ * The identifiers of loaded commands exposed for reuse.
18
+ */
19
+ export interface IWorkspaceCommands {
20
+ /**
21
+ * Command for opening a workspace by identifier.
22
+ */
23
+ open: string;
24
+ /**
25
+ * Command for deleting a workspace.
26
+ */
27
+ deleteWorkspace: string;
28
+ }
29
+
30
+ /**
31
+ * The token that provides the identifiers of workspace commands for reuse.
32
+ */
33
+ export const IWorkspacesModel = new Token<IWorkspacesModel>(
34
+ '@jupyterlab/workspaces:IWorkspacesModel',
35
+ 'Provides a model for available workspaces.'
36
+ );
37
+
38
+ /**
39
+ * The model for listing available workspaces.
40
+ */
41
+ export interface IWorkspacesModel extends IDisposable {
42
+ /**
43
+ * The list of available workspaces.
44
+ */
45
+ readonly workspaces: Workspace.IWorkspace[];
46
+
47
+ /**
48
+ * The list of workspace identifiers.
49
+ */
50
+ readonly identifiers: string[];
51
+
52
+ /**
53
+ * Create an empty workspace.
54
+ */
55
+ create(workspaceId: string): Promise<void>;
56
+
57
+ /**
58
+ * Rename a workspace.
59
+ */
60
+ rename(workspaceId: string, newName: string): Promise<void>;
61
+
62
+ /**
63
+ * Refresh the listing of workspaces.
64
+ */
65
+ refresh(): Promise<void>;
66
+
67
+ /**
68
+ * Signal emitted when the listing is refreshed.
69
+ */
70
+ refreshed: ISignal<IWorkspacesModel, void>;
71
+
72
+ /**
73
+ * Reset a workspace.
74
+ */
75
+ reset(workspaceId: string): Promise<void>;
76
+
77
+ /**
78
+ * Remove a workspace.
79
+ */
80
+ remove(workspaceId: string): Promise<void>;
81
+
82
+ /**
83
+ * Save workspace under a different name.
84
+ */
85
+ saveAs(workspaceId: string, newName: string): Promise<void>;
86
+ }