@jupyterlab/statedb 4.0.0-alpha.2 → 4.0.0-alpha.20
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/dataconnector.js.map +1 -1
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/restorablepool.js.map +1 -1
- package/lib/statedb.js.map +1 -1
- package/lib/tokens.js +0 -1
- package/lib/tokens.js.map +1 -1
- package/package.json +12 -13
- package/src/dataconnector.ts +87 -0
- package/src/index.ts +14 -0
- package/src/interfaces.ts +269 -0
- package/src/restorablepool.ts +385 -0
- package/src/statedb.ts +344 -0
- package/src/tokens.ts +24 -0
package/lib/dataconnector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataconnector.js","sourceRoot":"","sources":["../src/dataconnector.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;;AAI3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAsB,aAAa;
|
|
1
|
+
{"version":3,"file":"dataconnector.js","sourceRoot":"","sources":["../src/dataconnector.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;;AAI3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAsB,aAAa;IAgBjC;;;;;;;;;OASG;IACH,KAAK,CAAC,IAAI,CAAC,KAAS;QAClB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,MAAM,CAAC,EAAK;QAChB,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,IAAI,CAAC,EAAK,EAAE,KAAQ;QACxB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;CACF;AA3DD,sCA2DC"}
|
package/lib/index.js
CHANGED
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
*/
|
|
10
10
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
11
|
if (k2 === undefined) k2 = k;
|
|
12
|
-
Object.
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
13
17
|
}) : (function(o, m, k, k2) {
|
|
14
18
|
if (k2 === undefined) k2 = k;
|
|
15
19
|
o[k2] = m[k];
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;+EAG+E;AAC/E;;;GAGG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;+EAG+E;AAC/E;;;GAGG;;;;;;;;;;;;;;;;AAEH,kDAAgC;AAChC,+CAA6B;AAC7B,mDAAiC;AACjC,4CAA0B;AAC1B,2CAAyB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restorablepool.js","sourceRoot":"","sources":["../src/restorablepool.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;;AAE3D,iDAAoD;AAEpD,mDAAsD;AACtD,iDAAoD;AAGpD;;;;GAIG;AACH,MAAa,cAAc;
|
|
1
|
+
{"version":3,"file":"restorablepool.js","sourceRoot":"","sources":["../src/restorablepool.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;;AAE3D,iDAAoD;AAEpD,mDAAsD;AACtD,iDAAoD;AAGpD;;;;GAIG;AACH,MAAa,cAAc;IAIzB;;;;OAIG;IACH,YAAY,OAAgC;QAsTpC,WAAM,GAAG,IAAI,kBAAM,C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","sourceRoot":"","sources":["../src/statedb.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;;AAG3D,iDAAoD;AAIpD;;GAEG;AACH,MAAa,OAAO;
|
|
1
|
+
{"version":3,"file":"statedb.js","sourceRoot":"","sources":["../src/statedb.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;;AAG3D,iDAAoD;AAIpD;;GAEG;AACH,MAAa,OAAO;IAIlB;;;;OAIG;IACH,YAAY,UAA+B,EAAE;QAuMrC,aAAQ,GAAG,IAAI,kBAAM,CAAuB,IAAI,CAAC,CAAC;QAtMxD,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;QAEzC,IAAI,CAAC,UAAU,GAAG,SAAS,IAAI,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACvD,IAAI,CAAC,SAAS,EAAE;YACd,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;SAC1C;aAAM;YACL,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;gBAC5C,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC;gBAE1C,QAAQ,IAAI,EAAE;oBACZ,KAAK,QAAQ;wBACX,OAAO;oBACT,KAAK,OAAO;wBACV,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;oBACvB,KAAK,OAAO;wBACV,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;oBACrC,KAAK,WAAW;wBACd,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;oBACzC;wBACE,OAAO;iBACV;YACH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC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OAAO,GAAG,CAAC;YACb,CAAC,EACD,EAAE,GAAG,EAAE,EAAc,EAAE,MAAM,EAAE,EAAc,EAAE,CAChD,CAAC;QACJ,CAAC;QAED;;WAEG;QACH,KAAK,CAAC,MAAM,CAAC,EAAU;YACrB,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC3B,CAAC;QAED;;WAEG;QACH,KAAK,CAAC,IAAI,CAAC,EAAU,EAAE,KAAa;YAClC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC;QAC5B,CAAC;KAGF;IA1CY,iBAAS,YA0CrB,CAAA;AACH,CAAC,EA1GgB,OAAO,GAAP,eAAO,KAAP,eAAO,QA0GvB"}
|
package/lib/tokens.js
CHANGED
package/lib/tokens.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;;AAE3D,iDAAoE;AAGpE
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;;AAE3D,iDAAoE;AAGpE;;GAEG;AACU,QAAA,QAAQ,GAAG,IAAI,iBAAK,CAAW,gCAAgC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlab/statedb",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.20",
|
|
4
4
|
"description": "Package for managing state in Jupyterlab",
|
|
5
5
|
"homepage": "https://github.com/jupyterlab/jupyterlab",
|
|
6
6
|
"bugs": {
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
|
|
23
23
|
"schema/*.json",
|
|
24
|
-
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}"
|
|
24
|
+
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}",
|
|
25
|
+
"src/**/*.{ts,tsx}"
|
|
25
26
|
],
|
|
26
27
|
"scripts": {
|
|
27
28
|
"build": "tsc -b",
|
|
@@ -35,20 +36,18 @@
|
|
|
35
36
|
"watch": "tsc -b --watch"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@lumino/commands": "^
|
|
39
|
-
"@lumino/coreutils": "^
|
|
40
|
-
"@lumino/disposable": "^
|
|
41
|
-
"@lumino/properties": "^
|
|
42
|
-
"@lumino/signaling": "^
|
|
39
|
+
"@lumino/commands": "^2.0.0-rc.0",
|
|
40
|
+
"@lumino/coreutils": "^2.0.0-rc.0",
|
|
41
|
+
"@lumino/disposable": "^2.0.0-rc.0",
|
|
42
|
+
"@lumino/properties": "^2.0.0-rc.0",
|
|
43
|
+
"@lumino/signaling": "^2.0.0-rc.0"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
|
-
"@jupyterlab/
|
|
46
|
-
"@types/jest": "^
|
|
47
|
-
"jest": "^26.4.2",
|
|
46
|
+
"@jupyterlab/testing": "^4.0.0-alpha.20",
|
|
47
|
+
"@types/jest": "^29.2.0",
|
|
48
48
|
"rimraf": "~3.0.0",
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"typescript": "~4.5.2"
|
|
49
|
+
"typedoc": "~0.23.25",
|
|
50
|
+
"typescript": "~5.0.0-beta"
|
|
52
51
|
},
|
|
53
52
|
"publishConfig": {
|
|
54
53
|
"access": "public"
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { IDataConnector } from './interfaces';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* An abstract class that adheres to the data connector interface.
|
|
8
|
+
*
|
|
9
|
+
* @typeparam T - The basic entity response type a service's connector.
|
|
10
|
+
*
|
|
11
|
+
* @typeparam U - The basic entity request type, which is conventionally the
|
|
12
|
+
* same as the response type but may be different if a service's implementation
|
|
13
|
+
* requires input data to be different from output responses. Defaults to `T`.
|
|
14
|
+
*
|
|
15
|
+
* @typeparam V - The basic token applied to a request, conventionally a string
|
|
16
|
+
* ID or filter, but may be set to a different type when an implementation
|
|
17
|
+
* requires it. Defaults to `string`.
|
|
18
|
+
*
|
|
19
|
+
* @typeparam W - The type of the optional `query` parameter of the `list`
|
|
20
|
+
* method. Defaults to `string`.
|
|
21
|
+
*
|
|
22
|
+
* #### Notes
|
|
23
|
+
* The only abstract method in this class is the `fetch` method, which must be
|
|
24
|
+
* reimplemented by all subclasses. The `remove` and `save` methods have a
|
|
25
|
+
* default implementation that returns a promise that will always reject. This
|
|
26
|
+
* class is a convenience superclass for connectors that only need to `fetch`.
|
|
27
|
+
*/
|
|
28
|
+
export abstract class DataConnector<T, U = T, V = string, W = string>
|
|
29
|
+
implements IDataConnector<T, U, V, W>
|
|
30
|
+
{
|
|
31
|
+
/**
|
|
32
|
+
* Retrieve an item from the data connector.
|
|
33
|
+
*
|
|
34
|
+
* @param id - The identifier used to retrieve an item.
|
|
35
|
+
*
|
|
36
|
+
* @returns A promise that resolves with a data payload if available.
|
|
37
|
+
*
|
|
38
|
+
* #### Notes
|
|
39
|
+
* The promise returned by this method may be rejected if an error occurs in
|
|
40
|
+
* retrieving the data. Nonexistence of an `id` will succeed with `undefined`.
|
|
41
|
+
*/
|
|
42
|
+
abstract fetch(id: V): Promise<T | undefined>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Retrieve the list of items available from the data connector.
|
|
46
|
+
*
|
|
47
|
+
* @param query - The optional query filter to apply to the connector request.
|
|
48
|
+
*
|
|
49
|
+
* @returns A promise that always rejects with an error.
|
|
50
|
+
*
|
|
51
|
+
* #### Notes
|
|
52
|
+
* Subclasses should reimplement if they support a back-end that can list.
|
|
53
|
+
*/
|
|
54
|
+
async list(query?: W): Promise<{ ids: V[]; values: T[] }> {
|
|
55
|
+
throw new Error('DataConnector#list method has not been implemented.');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Remove a value using the data connector.
|
|
60
|
+
*
|
|
61
|
+
* @param id - The identifier for the data being removed.
|
|
62
|
+
*
|
|
63
|
+
* @returns A promise that always rejects with an error.
|
|
64
|
+
*
|
|
65
|
+
* #### Notes
|
|
66
|
+
* Subclasses should reimplement if they support a back-end that can remove.
|
|
67
|
+
*/
|
|
68
|
+
async remove(id: V): Promise<any> {
|
|
69
|
+
throw new Error('DataConnector#remove method has not been implemented.');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Save a value using the data connector.
|
|
74
|
+
*
|
|
75
|
+
* @param id - The identifier for the data being saved.
|
|
76
|
+
*
|
|
77
|
+
* @param value - The data being saved.
|
|
78
|
+
*
|
|
79
|
+
* @returns A promise that always rejects with an error.
|
|
80
|
+
*
|
|
81
|
+
* #### Notes
|
|
82
|
+
* Subclasses should reimplement if they support a back-end that can save.
|
|
83
|
+
*/
|
|
84
|
+
async save(id: V, value: U): Promise<any> {
|
|
85
|
+
throw new Error('DataConnector#save method has not been implemented.');
|
|
86
|
+
}
|
|
87
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* -----------------------------------------------------------------------------
|
|
2
|
+
| Copyright (c) Jupyter Development Team.
|
|
3
|
+
| Distributed under the terms of the Modified BSD License.
|
|
4
|
+
|----------------------------------------------------------------------------*/
|
|
5
|
+
/**
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
* @module statedb
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export * from './dataconnector';
|
|
11
|
+
export * from './interfaces';
|
|
12
|
+
export * from './restorablepool';
|
|
13
|
+
export * from './statedb';
|
|
14
|
+
export * from './tokens';
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { CommandRegistry } from '@lumino/commands';
|
|
5
|
+
import {
|
|
6
|
+
ReadonlyPartialJSONObject,
|
|
7
|
+
ReadonlyPartialJSONValue
|
|
8
|
+
} from '@lumino/coreutils';
|
|
9
|
+
import { IDisposable, IObservableDisposable } from '@lumino/disposable';
|
|
10
|
+
import { ISignal } from '@lumino/signaling';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The description of a general purpose data connector.
|
|
14
|
+
*
|
|
15
|
+
* @typeparam T - The basic entity response type a service's connector.
|
|
16
|
+
*
|
|
17
|
+
* @typeparam U - The basic entity request type, which is conventionally the
|
|
18
|
+
* same as the response type but may be different if a service's implementation
|
|
19
|
+
* requires input data to be different from output responses. Defaults to `T`.
|
|
20
|
+
*
|
|
21
|
+
* @typeparam V - The basic token applied to a request, conventionally a string
|
|
22
|
+
* ID or filter, but may be set to a different type when an implementation
|
|
23
|
+
* requires it. Defaults to `string`.
|
|
24
|
+
*
|
|
25
|
+
* @typeparam W - The type of the optional `query` parameter of the `list`
|
|
26
|
+
* method. Defaults to `string`;
|
|
27
|
+
*/
|
|
28
|
+
export interface IDataConnector<T, U = T, V = string, W = string> {
|
|
29
|
+
/**
|
|
30
|
+
* Retrieve an item from the data connector.
|
|
31
|
+
*
|
|
32
|
+
* @param id - The identifier used to retrieve an item.
|
|
33
|
+
*
|
|
34
|
+
* @returns A promise that bears a data payload if available.
|
|
35
|
+
*
|
|
36
|
+
* #### Notes
|
|
37
|
+
* The promise returned by this method may be rejected if an error occurs in
|
|
38
|
+
* retrieving the data. Nonexistence of an `id` resolves with `undefined`.
|
|
39
|
+
*/
|
|
40
|
+
fetch(id: V): Promise<T | undefined>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Retrieve the list of items available from the data connector.
|
|
44
|
+
*
|
|
45
|
+
* @param query - The optional query filter to apply to the connector request.
|
|
46
|
+
*
|
|
47
|
+
* @returns A promise that bears a list of `values` and an associated list of
|
|
48
|
+
* fetch `ids`.
|
|
49
|
+
*
|
|
50
|
+
* #### Notes
|
|
51
|
+
* The promise returned by this method may be rejected if an error occurs in
|
|
52
|
+
* retrieving the data. The two lists will always be the same size. If there
|
|
53
|
+
* is no data, this method will succeed with empty `ids` and `values`.
|
|
54
|
+
*/
|
|
55
|
+
list(query?: W): Promise<{ ids: V[]; values: T[] }>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Remove a value using the data connector.
|
|
59
|
+
*
|
|
60
|
+
* @param id - The identifier for the data being removed.
|
|
61
|
+
*
|
|
62
|
+
* @returns A promise that is rejected if remove fails and succeeds otherwise.
|
|
63
|
+
*
|
|
64
|
+
* #### Notes
|
|
65
|
+
* This promise may resolve with a back-end response or `undefined`.
|
|
66
|
+
* Existence of resolved content in the promise is not prescribed and must be
|
|
67
|
+
* tested for. For example, some back-ends may return a copy of the item of
|
|
68
|
+
* type `T` being removed while others may return no content.
|
|
69
|
+
*/
|
|
70
|
+
remove(id: V): Promise<any>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Save a value using the data connector.
|
|
74
|
+
*
|
|
75
|
+
* @param id - The identifier for the data being saved.
|
|
76
|
+
*
|
|
77
|
+
* @param value - The data being saved.
|
|
78
|
+
*
|
|
79
|
+
* @returns A promise that is rejected if saving fails and succeeds otherwise.
|
|
80
|
+
*
|
|
81
|
+
* #### Notes
|
|
82
|
+
* This promise may resolve with a back-end response or `undefined`.
|
|
83
|
+
* Existence of resolved content in the promise is not prescribed and must be
|
|
84
|
+
* tested for. For example, some back-ends may return a copy of the item of
|
|
85
|
+
* type `T` being saved while others may return no content.
|
|
86
|
+
*/
|
|
87
|
+
save(id: V, value: U): Promise<any>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* A pool of objects whose disposable lifecycle is tracked.
|
|
92
|
+
*
|
|
93
|
+
* @typeparam T - The type of object held in the pool.
|
|
94
|
+
*/
|
|
95
|
+
export interface IObjectPool<T extends IObservableDisposable>
|
|
96
|
+
extends IDisposable {
|
|
97
|
+
/**
|
|
98
|
+
* A signal emitted when an object is added.
|
|
99
|
+
*
|
|
100
|
+
* ####
|
|
101
|
+
* This signal does not emit if an object is added using `inject()`.
|
|
102
|
+
*/
|
|
103
|
+
readonly added: ISignal<this, T>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The current object.
|
|
107
|
+
*/
|
|
108
|
+
readonly current: T | null;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* A signal emitted when the current object changes.
|
|
112
|
+
*
|
|
113
|
+
* #### Notes
|
|
114
|
+
* If the last object being tracked is disposed, `null` will be emitted.
|
|
115
|
+
*/
|
|
116
|
+
readonly currentChanged: ISignal<this, T | null>;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The number of objects held by the pool.
|
|
120
|
+
*/
|
|
121
|
+
readonly size: number;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A signal emitted when an object is updated.
|
|
125
|
+
*/
|
|
126
|
+
readonly updated: ISignal<this, T>;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Find the first object in the pool that satisfies a filter function.
|
|
130
|
+
*
|
|
131
|
+
* @param - fn The filter function to call on each object.
|
|
132
|
+
*
|
|
133
|
+
* #### Notes
|
|
134
|
+
* If nothing is found, the value returned is `undefined`.
|
|
135
|
+
*/
|
|
136
|
+
find(fn: (obj: T) => boolean): T | undefined;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Iterate through each object in the pool.
|
|
140
|
+
*
|
|
141
|
+
* @param fn - The function to call on each object.
|
|
142
|
+
*/
|
|
143
|
+
forEach(fn: (obj: T) => void): void;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Filter the objects in the pool based on a predicate.
|
|
147
|
+
*
|
|
148
|
+
* @param fn - The function by which to filter.
|
|
149
|
+
*/
|
|
150
|
+
filter(fn: (obj: T) => boolean): T[];
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Check if this pool has the specified object.
|
|
154
|
+
*
|
|
155
|
+
* @param obj - The object whose existence is being checked.
|
|
156
|
+
*/
|
|
157
|
+
has(obj: T): boolean;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* An interface for a state restorer.
|
|
162
|
+
*
|
|
163
|
+
* @typeparam T - The restorable collection's type.
|
|
164
|
+
*
|
|
165
|
+
* @typeparam U - The type of object held by the restorable collection.
|
|
166
|
+
*
|
|
167
|
+
* @typeparam V - The `restored` promise resolution type. Defaults to `any`.
|
|
168
|
+
*/
|
|
169
|
+
export interface IRestorer<
|
|
170
|
+
T extends IRestorable<U> = IRestorable<IObservableDisposable>,
|
|
171
|
+
U extends IObservableDisposable = IObservableDisposable,
|
|
172
|
+
V = any
|
|
173
|
+
> {
|
|
174
|
+
/**
|
|
175
|
+
* Restore the objects in a given restorable collection.
|
|
176
|
+
*
|
|
177
|
+
* @param restorable - The restorable collection being restored.
|
|
178
|
+
*
|
|
179
|
+
* @param options - The configuration options that describe restoration.
|
|
180
|
+
*
|
|
181
|
+
* @returns A promise that settles when restored with `any` results.
|
|
182
|
+
*
|
|
183
|
+
*/
|
|
184
|
+
restore(restorable: T, options: IRestorable.IOptions<U>): Promise<V>;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* A promise that settles when the collection has been restored.
|
|
188
|
+
*/
|
|
189
|
+
readonly restored: Promise<V>;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* A namespace for `IRestorer` interface definitions.
|
|
194
|
+
*/
|
|
195
|
+
export namespace IRestorer {
|
|
196
|
+
/**
|
|
197
|
+
* The state restoration configuration options.
|
|
198
|
+
*
|
|
199
|
+
* @typeparam T - The type of object held by the restorable collection.
|
|
200
|
+
*/
|
|
201
|
+
export interface IOptions<T extends IObservableDisposable> {
|
|
202
|
+
/**
|
|
203
|
+
* The command to execute when restoring instances.
|
|
204
|
+
*/
|
|
205
|
+
command: string;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* A function that returns the args needed to restore an instance.
|
|
209
|
+
*/
|
|
210
|
+
args?: (obj: T) => ReadonlyPartialJSONObject;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* A function that returns a unique persistent name for this instance.
|
|
214
|
+
*/
|
|
215
|
+
name: (obj: T) => string;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* The point after which it is safe to restore state.
|
|
219
|
+
*/
|
|
220
|
+
when?: Promise<any> | Array<Promise<any>>;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* An interface for objects that can be restored.
|
|
226
|
+
*
|
|
227
|
+
* @typeparam T - The type of object held by the restorable collection.
|
|
228
|
+
*
|
|
229
|
+
* @typeparam U - The `restored` promise resolution type. Defaults to `any`.
|
|
230
|
+
*/
|
|
231
|
+
export interface IRestorable<T extends IObservableDisposable, U = any> {
|
|
232
|
+
/**
|
|
233
|
+
* Restore the objects in this restorable collection.
|
|
234
|
+
*
|
|
235
|
+
* @param options - The configuration options that describe restoration.
|
|
236
|
+
*
|
|
237
|
+
* @returns A promise that settles when restored with `any` results.
|
|
238
|
+
*
|
|
239
|
+
*/
|
|
240
|
+
restore(options: IRestorable.IOptions<T>): Promise<U>;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* A promise that settles when the collection has been restored.
|
|
244
|
+
*/
|
|
245
|
+
readonly restored: Promise<U>;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* A namespace for `IRestorable` interface definitions.
|
|
250
|
+
*/
|
|
251
|
+
export namespace IRestorable {
|
|
252
|
+
/**
|
|
253
|
+
* The state restoration configuration options.
|
|
254
|
+
*
|
|
255
|
+
* @typeparam T - The type of object held by the restorable collection.
|
|
256
|
+
*/
|
|
257
|
+
export interface IOptions<T extends IObservableDisposable>
|
|
258
|
+
extends IRestorer.IOptions<T> {
|
|
259
|
+
/**
|
|
260
|
+
* The data connector to fetch restore data.
|
|
261
|
+
*/
|
|
262
|
+
connector: IDataConnector<ReadonlyPartialJSONValue>;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The command registry which holds the restore command.
|
|
266
|
+
*/
|
|
267
|
+
registry: CommandRegistry;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { PromiseDelegate } from '@lumino/coreutils';
|
|
5
|
+
import { IObservableDisposable } from '@lumino/disposable';
|
|
6
|
+
import { AttachedProperty } from '@lumino/properties';
|
|
7
|
+
import { ISignal, Signal } from '@lumino/signaling';
|
|
8
|
+
import { IObjectPool, IRestorable } from './interfaces';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* An object pool that supports restoration.
|
|
12
|
+
*
|
|
13
|
+
* @typeparam T - The type of object being tracked.
|
|
14
|
+
*/
|
|
15
|
+
export class RestorablePool<
|
|
16
|
+
T extends IObservableDisposable = IObservableDisposable
|
|
17
|
+
> implements IObjectPool<T>, IRestorable<T>
|
|
18
|
+
{
|
|
19
|
+
/**
|
|
20
|
+
* Create a new restorable pool.
|
|
21
|
+
*
|
|
22
|
+
* @param options - The instantiation options for a restorable pool.
|
|
23
|
+
*/
|
|
24
|
+
constructor(options: RestorablePool.IOptions) {
|
|
25
|
+
this.namespace = options.namespace;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A namespace for all tracked objects.
|
|
30
|
+
*/
|
|
31
|
+
readonly namespace: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A signal emitted when an object object is added.
|
|
35
|
+
*
|
|
36
|
+
* #### Notes
|
|
37
|
+
* This signal will only fire when an object is added to the pool.
|
|
38
|
+
* It will not fire if an object injected into the pool.
|
|
39
|
+
*/
|
|
40
|
+
get added(): ISignal<this, T> {
|
|
41
|
+
return this._added;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The current object.
|
|
46
|
+
*
|
|
47
|
+
* #### Notes
|
|
48
|
+
* The restorable pool does not set `current`. It is intended for client use.
|
|
49
|
+
*
|
|
50
|
+
* If `current` is set to an object that does not exist in the pool, it is a
|
|
51
|
+
* no-op.
|
|
52
|
+
*/
|
|
53
|
+
get current(): T | null {
|
|
54
|
+
return this._current;
|
|
55
|
+
}
|
|
56
|
+
set current(obj: T | null) {
|
|
57
|
+
if (this._current === obj) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (obj !== null && this._objects.has(obj)) {
|
|
61
|
+
this._current = obj;
|
|
62
|
+
this._currentChanged.emit(this._current);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A signal emitted when the current widget changes.
|
|
68
|
+
*/
|
|
69
|
+
get currentChanged(): ISignal<this, T | null> {
|
|
70
|
+
return this._currentChanged;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Test whether the pool is disposed.
|
|
75
|
+
*/
|
|
76
|
+
get isDisposed(): boolean {
|
|
77
|
+
return this._isDisposed;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* A promise resolved when the restorable pool has been restored.
|
|
82
|
+
*/
|
|
83
|
+
get restored(): Promise<void> {
|
|
84
|
+
return this._restored.promise;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The number of objects held by the pool.
|
|
89
|
+
*/
|
|
90
|
+
get size(): number {
|
|
91
|
+
return this._objects.size;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* A signal emitted when an object is updated.
|
|
96
|
+
*/
|
|
97
|
+
get updated(): ISignal<this, T> {
|
|
98
|
+
return this._updated;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Add a new object to the pool.
|
|
103
|
+
*
|
|
104
|
+
* @param obj - The object object being added.
|
|
105
|
+
*
|
|
106
|
+
* #### Notes
|
|
107
|
+
* The object passed into the pool is added synchronously; its existence in
|
|
108
|
+
* the pool can be checked with the `has()` method. The promise this method
|
|
109
|
+
* returns resolves after the object has been added and saved to an underlying
|
|
110
|
+
* restoration connector, if one is available.
|
|
111
|
+
*/
|
|
112
|
+
async add(obj: T): Promise<void> {
|
|
113
|
+
if (obj.isDisposed) {
|
|
114
|
+
const warning = 'A disposed object cannot be added.';
|
|
115
|
+
console.warn(warning, obj);
|
|
116
|
+
throw new Error(warning);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (this._objects.has(obj)) {
|
|
120
|
+
const warning = 'This object already exists in the pool.';
|
|
121
|
+
console.warn(warning, obj);
|
|
122
|
+
throw new Error(warning);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
this._objects.add(obj);
|
|
126
|
+
obj.disposed.connect(this._onInstanceDisposed, this);
|
|
127
|
+
|
|
128
|
+
if (Private.injectedProperty.get(obj)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (this._restore) {
|
|
133
|
+
const { connector } = this._restore;
|
|
134
|
+
const objName = this._restore.name(obj);
|
|
135
|
+
|
|
136
|
+
if (objName) {
|
|
137
|
+
const name = `${this.namespace}:${objName}`;
|
|
138
|
+
const data = this._restore.args?.(obj);
|
|
139
|
+
|
|
140
|
+
Private.nameProperty.set(obj, name);
|
|
141
|
+
await connector.save(name, { data });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Emit the added signal.
|
|
146
|
+
this._added.emit(obj);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Dispose of the resources held by the pool.
|
|
151
|
+
*
|
|
152
|
+
* #### Notes
|
|
153
|
+
* Disposing a pool does not affect the underlying data in the data connector,
|
|
154
|
+
* it simply disposes the client-side pool without making any connector calls.
|
|
155
|
+
*/
|
|
156
|
+
dispose(): void {
|
|
157
|
+
if (this.isDisposed) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
this._current = null;
|
|
161
|
+
this._isDisposed = true;
|
|
162
|
+
this._objects.clear();
|
|
163
|
+
Signal.clearData(this);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Find the first object in the pool that satisfies a filter function.
|
|
168
|
+
*
|
|
169
|
+
* @param - fn The filter function to call on each object.
|
|
170
|
+
*/
|
|
171
|
+
find(fn: (obj: T) => boolean): T | undefined {
|
|
172
|
+
const values = this._objects.values();
|
|
173
|
+
for (const value of values) {
|
|
174
|
+
if (fn(value)) {
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Iterate through each object in the pool.
|
|
183
|
+
*
|
|
184
|
+
* @param fn - The function to call on each object.
|
|
185
|
+
*/
|
|
186
|
+
forEach(fn: (obj: T) => void): void {
|
|
187
|
+
this._objects.forEach(fn);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Filter the objects in the pool based on a predicate.
|
|
192
|
+
*
|
|
193
|
+
* @param fn - The function by which to filter.
|
|
194
|
+
*/
|
|
195
|
+
filter(fn: (obj: T) => boolean): T[] {
|
|
196
|
+
const filtered: T[] = [];
|
|
197
|
+
this.forEach(obj => {
|
|
198
|
+
if (fn(obj)) {
|
|
199
|
+
filtered.push(obj);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
return filtered;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Inject an object into the restorable pool without the pool handling its
|
|
207
|
+
* restoration lifecycle.
|
|
208
|
+
*
|
|
209
|
+
* @param obj - The object to inject into the pool.
|
|
210
|
+
*/
|
|
211
|
+
inject(obj: T): Promise<void> {
|
|
212
|
+
Private.injectedProperty.set(obj, true);
|
|
213
|
+
return this.add(obj);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Check if this pool has the specified object.
|
|
218
|
+
*
|
|
219
|
+
* @param obj - The object whose existence is being checked.
|
|
220
|
+
*/
|
|
221
|
+
has(obj: T): boolean {
|
|
222
|
+
return this._objects.has(obj);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Restore the objects in this pool's namespace.
|
|
227
|
+
*
|
|
228
|
+
* @param options - The configuration options that describe restoration.
|
|
229
|
+
*
|
|
230
|
+
* @returns A promise that resolves when restoration has completed.
|
|
231
|
+
*
|
|
232
|
+
* #### Notes
|
|
233
|
+
* This function should almost never be invoked by client code. Its primary
|
|
234
|
+
* use case is to be invoked by a layout restorer plugin that handles
|
|
235
|
+
* multiple restorable pools and, when ready, asks them each to restore their
|
|
236
|
+
* respective objects.
|
|
237
|
+
*/
|
|
238
|
+
async restore(options: IRestorable.IOptions<T>): Promise<any> {
|
|
239
|
+
if (this._hasRestored) {
|
|
240
|
+
throw new Error('This pool has already been restored.');
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
this._hasRestored = true;
|
|
244
|
+
|
|
245
|
+
const { command, connector, registry, when } = options;
|
|
246
|
+
const namespace = this.namespace;
|
|
247
|
+
const promises = when
|
|
248
|
+
? [connector.list(namespace)].concat(when)
|
|
249
|
+
: [connector.list(namespace)];
|
|
250
|
+
|
|
251
|
+
this._restore = options;
|
|
252
|
+
|
|
253
|
+
const [saved] = await Promise.all(promises);
|
|
254
|
+
const values = await Promise.all(
|
|
255
|
+
saved.ids.map(async (id, index) => {
|
|
256
|
+
const value = saved.values[index];
|
|
257
|
+
const args = value && (value as any).data;
|
|
258
|
+
|
|
259
|
+
if (args === undefined) {
|
|
260
|
+
return connector.remove(id);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Execute the command and if it fails, delete the state restore data.
|
|
264
|
+
return registry
|
|
265
|
+
.execute(command, args)
|
|
266
|
+
.catch(() => connector.remove(id));
|
|
267
|
+
})
|
|
268
|
+
);
|
|
269
|
+
this._restored.resolve();
|
|
270
|
+
return values;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Save the restore data for a given object.
|
|
275
|
+
*
|
|
276
|
+
* @param obj - The object being saved.
|
|
277
|
+
*/
|
|
278
|
+
async save(obj: T): Promise<void> {
|
|
279
|
+
const injected = Private.injectedProperty.get(obj);
|
|
280
|
+
|
|
281
|
+
if (!this._restore || !this.has(obj) || injected) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const { connector } = this._restore;
|
|
286
|
+
const objName = this._restore.name(obj);
|
|
287
|
+
const oldName = Private.nameProperty.get(obj);
|
|
288
|
+
const newName = objName ? `${this.namespace}:${objName}` : '';
|
|
289
|
+
|
|
290
|
+
if (oldName && oldName !== newName) {
|
|
291
|
+
await connector.remove(oldName);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Set the name property irrespective of whether the new name is null.
|
|
295
|
+
Private.nameProperty.set(obj, newName);
|
|
296
|
+
|
|
297
|
+
if (newName) {
|
|
298
|
+
const data = this._restore.args?.(obj);
|
|
299
|
+
await connector.save(newName, { data });
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (oldName !== newName) {
|
|
303
|
+
this._updated.emit(obj);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Clean up after disposed objects.
|
|
309
|
+
*/
|
|
310
|
+
private _onInstanceDisposed(obj: T): void {
|
|
311
|
+
this._objects.delete(obj);
|
|
312
|
+
|
|
313
|
+
if (obj === this._current) {
|
|
314
|
+
this._current = null;
|
|
315
|
+
this._currentChanged.emit(this._current);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (Private.injectedProperty.get(obj)) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (!this._restore) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const { connector } = this._restore;
|
|
327
|
+
const name = Private.nameProperty.get(obj);
|
|
328
|
+
|
|
329
|
+
if (name) {
|
|
330
|
+
void connector.remove(name);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
private _added = new Signal<this, T>(this);
|
|
335
|
+
private _current: T | null = null;
|
|
336
|
+
private _currentChanged = new Signal<this, T | null>(this);
|
|
337
|
+
private _hasRestored = false;
|
|
338
|
+
private _isDisposed = false;
|
|
339
|
+
private _objects = new Set<T>();
|
|
340
|
+
private _restore: IRestorable.IOptions<T> | null = null;
|
|
341
|
+
private _restored = new PromiseDelegate<void>();
|
|
342
|
+
private _updated = new Signal<this, T>(this);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* A namespace for `RestorablePool` statics.
|
|
347
|
+
*/
|
|
348
|
+
export namespace RestorablePool {
|
|
349
|
+
/**
|
|
350
|
+
* The instantiation options for the restorable pool.
|
|
351
|
+
*/
|
|
352
|
+
export interface IOptions {
|
|
353
|
+
/**
|
|
354
|
+
* A namespace designating objects from this pool.
|
|
355
|
+
*/
|
|
356
|
+
namespace: string;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/*
|
|
361
|
+
* A namespace for private data.
|
|
362
|
+
*/
|
|
363
|
+
namespace Private {
|
|
364
|
+
/**
|
|
365
|
+
* An attached property to indicate whether an object has been injected.
|
|
366
|
+
*/
|
|
367
|
+
export const injectedProperty = new AttachedProperty<
|
|
368
|
+
IObservableDisposable,
|
|
369
|
+
boolean
|
|
370
|
+
>({
|
|
371
|
+
name: 'injected',
|
|
372
|
+
create: () => false
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* An attached property for an object's ID.
|
|
377
|
+
*/
|
|
378
|
+
export const nameProperty = new AttachedProperty<
|
|
379
|
+
IObservableDisposable,
|
|
380
|
+
string
|
|
381
|
+
>({
|
|
382
|
+
name: 'name',
|
|
383
|
+
create: () => ''
|
|
384
|
+
});
|
|
385
|
+
}
|
package/src/statedb.ts
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { ReadonlyPartialJSONValue } from '@lumino/coreutils';
|
|
5
|
+
import { ISignal, Signal } from '@lumino/signaling';
|
|
6
|
+
import { IDataConnector } from './interfaces';
|
|
7
|
+
import { IStateDB } from './tokens';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The default concrete implementation of a state database.
|
|
11
|
+
*/
|
|
12
|
+
export class StateDB<
|
|
13
|
+
T extends ReadonlyPartialJSONValue = ReadonlyPartialJSONValue
|
|
14
|
+
> implements IStateDB<T>
|
|
15
|
+
{
|
|
16
|
+
/**
|
|
17
|
+
* Create a new state database.
|
|
18
|
+
*
|
|
19
|
+
* @param options - The instantiation options for a state database.
|
|
20
|
+
*/
|
|
21
|
+
constructor(options: StateDB.IOptions<T> = {}) {
|
|
22
|
+
const { connector, transform } = options;
|
|
23
|
+
|
|
24
|
+
this._connector = connector || new StateDB.Connector();
|
|
25
|
+
if (!transform) {
|
|
26
|
+
this._ready = Promise.resolve(undefined);
|
|
27
|
+
} else {
|
|
28
|
+
this._ready = transform.then(transformation => {
|
|
29
|
+
const { contents, type } = transformation;
|
|
30
|
+
|
|
31
|
+
switch (type) {
|
|
32
|
+
case 'cancel':
|
|
33
|
+
return;
|
|
34
|
+
case 'clear':
|
|
35
|
+
return this._clear();
|
|
36
|
+
case 'merge':
|
|
37
|
+
return this._merge(contents || {});
|
|
38
|
+
case 'overwrite':
|
|
39
|
+
return this._overwrite(contents || {});
|
|
40
|
+
default:
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A signal that emits the change type any time a value changes.
|
|
49
|
+
*/
|
|
50
|
+
get changed(): ISignal<this, StateDB.Change> {
|
|
51
|
+
return this._changed;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Clear the entire database.
|
|
56
|
+
*/
|
|
57
|
+
async clear(): Promise<void> {
|
|
58
|
+
await this._ready;
|
|
59
|
+
await this._clear();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Retrieve a saved bundle from the database.
|
|
64
|
+
*
|
|
65
|
+
* @param id - The identifier used to retrieve a data bundle.
|
|
66
|
+
*
|
|
67
|
+
* @returns A promise that bears a data payload if available.
|
|
68
|
+
*
|
|
69
|
+
* #### Notes
|
|
70
|
+
* The `id` values of stored items in the state database are formatted:
|
|
71
|
+
* `'namespace:identifier'`, which is the same convention that command
|
|
72
|
+
* identifiers in JupyterLab use as well. While this is not a technical
|
|
73
|
+
* requirement for `fetch()`, `remove()`, and `save()`, it *is* necessary for
|
|
74
|
+
* using the `list(namespace: string)` method.
|
|
75
|
+
*
|
|
76
|
+
* The promise returned by this method may be rejected if an error occurs in
|
|
77
|
+
* retrieving the data. Non-existence of an `id` will succeed with the `value`
|
|
78
|
+
* `undefined`.
|
|
79
|
+
*/
|
|
80
|
+
async fetch(id: string): Promise<T | undefined> {
|
|
81
|
+
await this._ready;
|
|
82
|
+
return this._fetch(id);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Retrieve all the saved bundles for a namespace.
|
|
87
|
+
*
|
|
88
|
+
* @param filter - The namespace prefix to retrieve.
|
|
89
|
+
*
|
|
90
|
+
* @returns A promise that bears a collection of payloads for a namespace.
|
|
91
|
+
*
|
|
92
|
+
* #### Notes
|
|
93
|
+
* Namespaces are entirely conventional entities. The `id` values of stored
|
|
94
|
+
* items in the state database are formatted: `'namespace:identifier'`, which
|
|
95
|
+
* is the same convention that command identifiers in JupyterLab use as well.
|
|
96
|
+
*
|
|
97
|
+
* If there are any errors in retrieving the data, they will be logged to the
|
|
98
|
+
* console in order to optimistically return any extant data without failing.
|
|
99
|
+
* This promise will always succeed.
|
|
100
|
+
*/
|
|
101
|
+
async list(namespace: string): Promise<{ ids: string[]; values: T[] }> {
|
|
102
|
+
await this._ready;
|
|
103
|
+
return this._list(namespace);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Remove a value from the database.
|
|
108
|
+
*
|
|
109
|
+
* @param id - The identifier for the data being removed.
|
|
110
|
+
*
|
|
111
|
+
* @returns A promise that is rejected if remove fails and succeeds otherwise.
|
|
112
|
+
*/
|
|
113
|
+
async remove(id: string): Promise<void> {
|
|
114
|
+
await this._ready;
|
|
115
|
+
await this._remove(id);
|
|
116
|
+
this._changed.emit({ id, type: 'remove' });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Save a value in the database.
|
|
121
|
+
*
|
|
122
|
+
* @param id - The identifier for the data being saved.
|
|
123
|
+
*
|
|
124
|
+
* @param value - The data being saved.
|
|
125
|
+
*
|
|
126
|
+
* @returns A promise that is rejected if saving fails and succeeds otherwise.
|
|
127
|
+
*
|
|
128
|
+
* #### Notes
|
|
129
|
+
* The `id` values of stored items in the state database are formatted:
|
|
130
|
+
* `'namespace:identifier'`, which is the same convention that command
|
|
131
|
+
* identifiers in JupyterLab use as well. While this is not a technical
|
|
132
|
+
* requirement for `fetch()`, `remove()`, and `save()`, it *is* necessary for
|
|
133
|
+
* using the `list(namespace: string)` method.
|
|
134
|
+
*/
|
|
135
|
+
async save(id: string, value: T): Promise<void> {
|
|
136
|
+
await this._ready;
|
|
137
|
+
await this._save(id, value);
|
|
138
|
+
this._changed.emit({ id, type: 'save' });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Return a serialized copy of the state database's entire contents.
|
|
143
|
+
*
|
|
144
|
+
* @returns A promise that resolves with the database contents as JSON.
|
|
145
|
+
*/
|
|
146
|
+
async toJSON(): Promise<{ readonly [id: string]: T }> {
|
|
147
|
+
await this._ready;
|
|
148
|
+
|
|
149
|
+
const { ids, values } = await this._list();
|
|
150
|
+
|
|
151
|
+
return values.reduce((acc, val, idx) => {
|
|
152
|
+
acc[ids[idx]] = val;
|
|
153
|
+
return acc;
|
|
154
|
+
}, {} as { [id: string]: T });
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Clear the entire database.
|
|
159
|
+
*/
|
|
160
|
+
private async _clear(): Promise<void> {
|
|
161
|
+
await Promise.all((await this._list()).ids.map(id => this._remove(id)));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Fetch a value from the database.
|
|
166
|
+
*/
|
|
167
|
+
private async _fetch(id: string): Promise<T | undefined> {
|
|
168
|
+
const value = await this._connector.fetch(id);
|
|
169
|
+
|
|
170
|
+
if (value) {
|
|
171
|
+
return (JSON.parse(value) as Private.Envelope).v as T;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Fetch a list from the database.
|
|
177
|
+
*/
|
|
178
|
+
private async _list(namespace = ''): Promise<{ ids: string[]; values: T[] }> {
|
|
179
|
+
const { ids, values } = await this._connector.list(namespace);
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
ids,
|
|
183
|
+
values: values.map(val => (JSON.parse(val) as Private.Envelope).v as T)
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Merge data into the state database.
|
|
189
|
+
*/
|
|
190
|
+
private async _merge(contents: StateDB.Content<T>): Promise<void> {
|
|
191
|
+
await Promise.all(
|
|
192
|
+
Object.keys(contents).map(
|
|
193
|
+
key => contents[key] && this._save(key, contents[key]!)
|
|
194
|
+
)
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Overwrite the entire database with new contents.
|
|
200
|
+
*/
|
|
201
|
+
private async _overwrite(contents: StateDB.Content<T>): Promise<void> {
|
|
202
|
+
await this._clear();
|
|
203
|
+
await this._merge(contents);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Remove a key in the database.
|
|
208
|
+
*/
|
|
209
|
+
private async _remove(id: string): Promise<void> {
|
|
210
|
+
return this._connector.remove(id);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Save a key and its value in the database.
|
|
215
|
+
*/
|
|
216
|
+
private async _save(id: string, value: T): Promise<void> {
|
|
217
|
+
return this._connector.save(id, JSON.stringify({ v: value }));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private _changed = new Signal<this, StateDB.Change>(this);
|
|
221
|
+
private _connector: IDataConnector<string>;
|
|
222
|
+
private _ready: Promise<void>;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* A namespace for StateDB statics.
|
|
227
|
+
*/
|
|
228
|
+
export namespace StateDB {
|
|
229
|
+
/**
|
|
230
|
+
* A state database change.
|
|
231
|
+
*/
|
|
232
|
+
export type Change = {
|
|
233
|
+
/**
|
|
234
|
+
* The key of the database item that was changed.
|
|
235
|
+
*
|
|
236
|
+
* #### Notes
|
|
237
|
+
* This field is set to `null` for global changes (i.e. `clear`).
|
|
238
|
+
*/
|
|
239
|
+
id: string | null;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* The type of change.
|
|
243
|
+
*/
|
|
244
|
+
type: 'clear' | 'remove' | 'save';
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* A data transformation that can be applied to a state database.
|
|
249
|
+
*/
|
|
250
|
+
export type DataTransform<
|
|
251
|
+
T extends ReadonlyPartialJSONValue = ReadonlyPartialJSONValue
|
|
252
|
+
> = {
|
|
253
|
+
/*
|
|
254
|
+
* The change operation being applied.
|
|
255
|
+
*/
|
|
256
|
+
type: 'cancel' | 'clear' | 'merge' | 'overwrite';
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* The contents of the change operation.
|
|
260
|
+
*/
|
|
261
|
+
contents: Content<T> | null;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Database content map
|
|
266
|
+
*/
|
|
267
|
+
export type Content<T> = { [id: string]: T | undefined };
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* The instantiation options for a state database.
|
|
271
|
+
*/
|
|
272
|
+
export interface IOptions<
|
|
273
|
+
T extends ReadonlyPartialJSONValue = ReadonlyPartialJSONValue
|
|
274
|
+
> {
|
|
275
|
+
/**
|
|
276
|
+
* Optional string key/value connector. Defaults to in-memory connector.
|
|
277
|
+
*/
|
|
278
|
+
connector?: IDataConnector<string>;
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* An optional promise that resolves with a data transformation that is
|
|
282
|
+
* applied to the database contents before the database begins resolving
|
|
283
|
+
* client requests.
|
|
284
|
+
*/
|
|
285
|
+
transform?: Promise<DataTransform<T>>;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* An in-memory string key/value data connector.
|
|
290
|
+
*/
|
|
291
|
+
export class Connector implements IDataConnector<string> {
|
|
292
|
+
/**
|
|
293
|
+
* Retrieve an item from the data connector.
|
|
294
|
+
*/
|
|
295
|
+
async fetch(id: string): Promise<string> {
|
|
296
|
+
return this._storage[id];
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Retrieve the list of items available from the data connector.
|
|
301
|
+
*
|
|
302
|
+
* @param namespace - If not empty, only keys whose first token before `:`
|
|
303
|
+
* exactly match `namespace` will be returned, e.g. `foo` in `foo:bar`.
|
|
304
|
+
*/
|
|
305
|
+
async list(namespace = ''): Promise<{ ids: string[]; values: string[] }> {
|
|
306
|
+
return Object.keys(this._storage).reduce(
|
|
307
|
+
(acc, val) => {
|
|
308
|
+
if (namespace === '' ? true : namespace === val.split(':')[0]) {
|
|
309
|
+
acc.ids.push(val);
|
|
310
|
+
acc.values.push(this._storage[val]);
|
|
311
|
+
}
|
|
312
|
+
return acc;
|
|
313
|
+
},
|
|
314
|
+
{ ids: [] as string[], values: [] as string[] }
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Remove a value using the data connector.
|
|
320
|
+
*/
|
|
321
|
+
async remove(id: string): Promise<void> {
|
|
322
|
+
delete this._storage[id];
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Save a value using the data connector.
|
|
327
|
+
*/
|
|
328
|
+
async save(id: string, value: string): Promise<void> {
|
|
329
|
+
this._storage[id] = value;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
private _storage: { [key: string]: string } = {};
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/*
|
|
337
|
+
* A namespace for private module data.
|
|
338
|
+
*/
|
|
339
|
+
namespace Private {
|
|
340
|
+
/**
|
|
341
|
+
* An envelope around a JSON value stored in the state database.
|
|
342
|
+
*/
|
|
343
|
+
export type Envelope = { readonly v: ReadonlyPartialJSONValue };
|
|
344
|
+
}
|
package/src/tokens.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { ReadonlyPartialJSONValue, Token } from '@lumino/coreutils';
|
|
5
|
+
import { IDataConnector } from './interfaces';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The default state database token.
|
|
9
|
+
*/
|
|
10
|
+
export const IStateDB = new Token<IStateDB>('@jupyterlab/coreutils:IStateDB');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The description of a state database.
|
|
14
|
+
*/
|
|
15
|
+
export interface IStateDB<
|
|
16
|
+
T extends ReadonlyPartialJSONValue = ReadonlyPartialJSONValue
|
|
17
|
+
> extends IDataConnector<T> {
|
|
18
|
+
/**
|
|
19
|
+
* Return a serialized copy of the state database's entire contents.
|
|
20
|
+
*
|
|
21
|
+
* @returns A promise that bears the database contents as JSON.
|
|
22
|
+
*/
|
|
23
|
+
toJSON(): Promise<{ [id: string]: T }>;
|
|
24
|
+
}
|