@jupyterlab/observables 2.1.1-alpha.0 → 2.1.1
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 +6 -6
- package/lib/index.js +15 -15
- package/lib/modeldb.d.ts +427 -427
- package/lib/modeldb.js +294 -294
- package/lib/observablejson.d.ts +61 -61
- package/lib/observablejson.js +54 -54
- package/lib/observablelist.d.ts +504 -504
- package/lib/observablelist.js +384 -384
- package/lib/observablemap.d.ts +226 -226
- package/lib/observablemap.js +180 -180
- package/lib/observablestring.d.ts +147 -147
- package/lib/observablestring.js +109 -109
- package/lib/undoablelist.d.ts +132 -132
- package/lib/undoablelist.js +228 -228
- package/package.json +7 -4
package/lib/modeldb.d.ts
CHANGED
|
@@ -1,427 +1,427 @@
|
|
|
1
|
-
import { IDisposable } from '@phosphor/disposable';
|
|
2
|
-
import { ISignal } from '@phosphor/signaling';
|
|
3
|
-
import { JSONValue, JSONObject } from '@phosphor/coreutils';
|
|
4
|
-
import { IObservableJSON } from './observablejson';
|
|
5
|
-
import { IObservableString } from './observablestring';
|
|
6
|
-
import { IObservableUndoableList } from './undoablelist';
|
|
7
|
-
import { IObservableMap } from './observablemap';
|
|
8
|
-
/**
|
|
9
|
-
* String type annotations for Observable objects that can be
|
|
10
|
-
* created and placed in the IModelDB interface.
|
|
11
|
-
*/
|
|
12
|
-
export declare type ObservableType = 'Map' | 'List' | 'String' | 'Value';
|
|
13
|
-
/**
|
|
14
|
-
* Base interface for Observable objects.
|
|
15
|
-
*/
|
|
16
|
-
export interface IObservable extends IDisposable {
|
|
17
|
-
/**
|
|
18
|
-
* The type of this object.
|
|
19
|
-
*/
|
|
20
|
-
readonly type: ObservableType;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Interface for an Observable object that represents
|
|
24
|
-
* an opaque JSON value.
|
|
25
|
-
*/
|
|
26
|
-
export interface IObservableValue extends IObservable {
|
|
27
|
-
/**
|
|
28
|
-
* The type of this object.
|
|
29
|
-
*/
|
|
30
|
-
readonly type: 'Value';
|
|
31
|
-
/**
|
|
32
|
-
* The changed signal.
|
|
33
|
-
*/
|
|
34
|
-
readonly changed: ISignal<IObservableValue, ObservableValue.IChangedArgs>;
|
|
35
|
-
/**
|
|
36
|
-
* Get the current value, or `undefined` if it has not been set.
|
|
37
|
-
*/
|
|
38
|
-
get(): JSONValue | undefined;
|
|
39
|
-
/**
|
|
40
|
-
* Set the value.
|
|
41
|
-
*/
|
|
42
|
-
set(value: JSONValue): void;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Interface for an object representing a single collaborator
|
|
46
|
-
* on a realtime model.
|
|
47
|
-
*/
|
|
48
|
-
export interface ICollaborator extends JSONObject {
|
|
49
|
-
/**
|
|
50
|
-
* A user id for the collaborator.
|
|
51
|
-
* This might not be unique, if the user has more than
|
|
52
|
-
* one editing session at a time.
|
|
53
|
-
*/
|
|
54
|
-
readonly userId: string;
|
|
55
|
-
/**
|
|
56
|
-
* A session id, which should be unique to a
|
|
57
|
-
* particular view on a collaborative model.
|
|
58
|
-
*/
|
|
59
|
-
readonly sessionId: string;
|
|
60
|
-
/**
|
|
61
|
-
* A human-readable display name for a collaborator.
|
|
62
|
-
*/
|
|
63
|
-
readonly displayName: string;
|
|
64
|
-
/**
|
|
65
|
-
* A color to be used to identify the collaborator in
|
|
66
|
-
* UI elements.
|
|
67
|
-
*/
|
|
68
|
-
readonly color: string;
|
|
69
|
-
/**
|
|
70
|
-
* A human-readable short name for a collaborator, for
|
|
71
|
-
* use in places where the full `displayName` would take
|
|
72
|
-
* too much space.
|
|
73
|
-
*/
|
|
74
|
-
readonly shortName: string;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Interface for an IObservableMap that tracks collaborators.
|
|
78
|
-
*/
|
|
79
|
-
export interface ICollaboratorMap extends IObservableMap<ICollaborator> {
|
|
80
|
-
/**
|
|
81
|
-
* The local collaborator on a model.
|
|
82
|
-
*/
|
|
83
|
-
readonly localCollaborator: ICollaborator;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* An interface for a path based database for
|
|
87
|
-
* creating and storing values, which is agnostic
|
|
88
|
-
* to the particular type of store in the backend.
|
|
89
|
-
*/
|
|
90
|
-
export interface IModelDB extends IDisposable {
|
|
91
|
-
/**
|
|
92
|
-
* The base path for the `IModelDB`. This is prepended
|
|
93
|
-
* to all the paths that are passed in to the member
|
|
94
|
-
* functions of the object.
|
|
95
|
-
*/
|
|
96
|
-
readonly basePath: string;
|
|
97
|
-
/**
|
|
98
|
-
* Whether the database has been disposed.
|
|
99
|
-
*/
|
|
100
|
-
readonly isDisposed: boolean;
|
|
101
|
-
/**
|
|
102
|
-
* Whether the database has been populated
|
|
103
|
-
* with model values prior to connection.
|
|
104
|
-
*/
|
|
105
|
-
readonly isPrepopulated: boolean;
|
|
106
|
-
/**
|
|
107
|
-
* Whether the database is collaborative.
|
|
108
|
-
*/
|
|
109
|
-
readonly isCollaborative: boolean;
|
|
110
|
-
/**
|
|
111
|
-
* A promise that resolves when the database
|
|
112
|
-
* has connected to its backend, if any.
|
|
113
|
-
*/
|
|
114
|
-
readonly connected: Promise<void>;
|
|
115
|
-
/**
|
|
116
|
-
* A map of the currently active collaborators
|
|
117
|
-
* for the database, including the local user.
|
|
118
|
-
*/
|
|
119
|
-
readonly collaborators?: ICollaboratorMap;
|
|
120
|
-
/**
|
|
121
|
-
* Get a value for a path.
|
|
122
|
-
*
|
|
123
|
-
* @param path: the path for the object.
|
|
124
|
-
*
|
|
125
|
-
* @returns an `IObservable`.
|
|
126
|
-
*/
|
|
127
|
-
get(path: string): IObservable | undefined;
|
|
128
|
-
/**
|
|
129
|
-
* Whether the `IModelDB` has an object at this path.
|
|
130
|
-
*
|
|
131
|
-
* @param path: the path for the object.
|
|
132
|
-
*
|
|
133
|
-
* @returns a boolean for whether an object is at `path`.
|
|
134
|
-
*/
|
|
135
|
-
has(path: string): boolean;
|
|
136
|
-
/**
|
|
137
|
-
* Create a string and insert it in the database.
|
|
138
|
-
*
|
|
139
|
-
* @param path: the path for the string.
|
|
140
|
-
*
|
|
141
|
-
* @returns the string that was created.
|
|
142
|
-
*/
|
|
143
|
-
createString(path: string): IObservableString;
|
|
144
|
-
/**
|
|
145
|
-
* Create an undoable list and insert it in the database.
|
|
146
|
-
*
|
|
147
|
-
* @param path: the path for the list.
|
|
148
|
-
*
|
|
149
|
-
* @returns the list that was created.
|
|
150
|
-
*
|
|
151
|
-
* #### Notes
|
|
152
|
-
* The list can only store objects that are simple
|
|
153
|
-
* JSON Objects and primitives.
|
|
154
|
-
*/
|
|
155
|
-
createList<T extends JSONValue>(path: string): IObservableUndoableList<T>;
|
|
156
|
-
/**
|
|
157
|
-
* Create a map and insert it in the database.
|
|
158
|
-
*
|
|
159
|
-
* @param path: the path for the map.
|
|
160
|
-
*
|
|
161
|
-
* @returns the map that was created.
|
|
162
|
-
*
|
|
163
|
-
* #### Notes
|
|
164
|
-
* The map can only store objects that are simple
|
|
165
|
-
* JSON Objects and primitives.
|
|
166
|
-
*/
|
|
167
|
-
createMap(path: string): IObservableJSON;
|
|
168
|
-
/**
|
|
169
|
-
* Create an opaque value and insert it in the database.
|
|
170
|
-
*
|
|
171
|
-
* @param path: the path for the value.
|
|
172
|
-
*
|
|
173
|
-
* @returns the value that was created.
|
|
174
|
-
*/
|
|
175
|
-
createValue(path: string): IObservableValue;
|
|
176
|
-
/**
|
|
177
|
-
* Get a value at a path, or `undefined if it has not been set
|
|
178
|
-
* That value must already have been created using `createValue`.
|
|
179
|
-
*
|
|
180
|
-
* @param path: the path for the value.
|
|
181
|
-
*/
|
|
182
|
-
getValue(path: string): JSONValue | undefined;
|
|
183
|
-
/**
|
|
184
|
-
* Set a value at a path. That value must already have
|
|
185
|
-
* been created using `createValue`.
|
|
186
|
-
*
|
|
187
|
-
* @param path: the path for the value.
|
|
188
|
-
*
|
|
189
|
-
* @param value: the new value.
|
|
190
|
-
*/
|
|
191
|
-
setValue(path: string, value: JSONValue): void;
|
|
192
|
-
/**
|
|
193
|
-
* Create a view onto a subtree of the model database.
|
|
194
|
-
*
|
|
195
|
-
* @param basePath: the path for the root of the subtree.
|
|
196
|
-
*
|
|
197
|
-
* @returns an `IModelDB` with a view onto the original
|
|
198
|
-
* `IModelDB`, with `basePath` prepended to all paths.
|
|
199
|
-
*/
|
|
200
|
-
view(basePath: string): IModelDB;
|
|
201
|
-
/**
|
|
202
|
-
* Dispose of the resources held by the database.
|
|
203
|
-
*/
|
|
204
|
-
dispose(): void;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* A concrete implementation of an `IObservableValue`.
|
|
208
|
-
*/
|
|
209
|
-
export declare class ObservableValue implements IObservableValue {
|
|
210
|
-
/**
|
|
211
|
-
* Constructor for the value.
|
|
212
|
-
*
|
|
213
|
-
* @param initialValue: the starting value for the `ObservableValue`.
|
|
214
|
-
*/
|
|
215
|
-
constructor(initialValue?: JSONValue);
|
|
216
|
-
/**
|
|
217
|
-
* The observable type.
|
|
218
|
-
*/
|
|
219
|
-
readonly type: 'Value';
|
|
220
|
-
/**
|
|
221
|
-
* Whether the value has been disposed.
|
|
222
|
-
*/
|
|
223
|
-
readonly isDisposed: boolean;
|
|
224
|
-
/**
|
|
225
|
-
* The changed signal.
|
|
226
|
-
*/
|
|
227
|
-
readonly changed: ISignal<this, ObservableValue.IChangedArgs>;
|
|
228
|
-
/**
|
|
229
|
-
* Get the current value, or `undefined` if it has not been set.
|
|
230
|
-
*/
|
|
231
|
-
get(): JSONValue;
|
|
232
|
-
/**
|
|
233
|
-
* Set the current value.
|
|
234
|
-
*/
|
|
235
|
-
set(value: JSONValue): void;
|
|
236
|
-
/**
|
|
237
|
-
* Dispose of the resources held by the value.
|
|
238
|
-
*/
|
|
239
|
-
dispose(): void;
|
|
240
|
-
private _value;
|
|
241
|
-
private _changed;
|
|
242
|
-
private _isDisposed;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* The namespace for the `ObservableValue` class statics.
|
|
246
|
-
*/
|
|
247
|
-
export declare namespace ObservableValue {
|
|
248
|
-
/**
|
|
249
|
-
* The changed args object emitted by the `IObservableValue`.
|
|
250
|
-
*/
|
|
251
|
-
class IChangedArgs {
|
|
252
|
-
/**
|
|
253
|
-
* The old value.
|
|
254
|
-
*/
|
|
255
|
-
oldValue: JSONValue | undefined;
|
|
256
|
-
/**
|
|
257
|
-
* The new value.
|
|
258
|
-
*/
|
|
259
|
-
newValue: JSONValue | undefined;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* A concrete implementation of an `IModelDB`.
|
|
264
|
-
*/
|
|
265
|
-
export declare class ModelDB implements IModelDB {
|
|
266
|
-
/**
|
|
267
|
-
* Constructor for the `ModelDB`.
|
|
268
|
-
*/
|
|
269
|
-
constructor(options?: ModelDB.ICreateOptions);
|
|
270
|
-
/**
|
|
271
|
-
* The base path for the `ModelDB`. This is prepended
|
|
272
|
-
* to all the paths that are passed in to the member
|
|
273
|
-
* functions of the object.
|
|
274
|
-
*/
|
|
275
|
-
readonly basePath: string;
|
|
276
|
-
/**
|
|
277
|
-
* Whether the database is disposed.
|
|
278
|
-
*/
|
|
279
|
-
readonly isDisposed: boolean;
|
|
280
|
-
/**
|
|
281
|
-
* Whether the model has been populated with
|
|
282
|
-
* any model values.
|
|
283
|
-
*/
|
|
284
|
-
readonly isPrepopulated: boolean;
|
|
285
|
-
/**
|
|
286
|
-
* Whether the model is collaborative.
|
|
287
|
-
*/
|
|
288
|
-
readonly isCollaborative: boolean;
|
|
289
|
-
/**
|
|
290
|
-
* A promise resolved when the model is connected
|
|
291
|
-
* to its backend. For the in-memory ModelDB it
|
|
292
|
-
* is immediately resolved.
|
|
293
|
-
*/
|
|
294
|
-
readonly connected: Promise<void>;
|
|
295
|
-
/**
|
|
296
|
-
* Get a value for a path.
|
|
297
|
-
*
|
|
298
|
-
* @param path: the path for the object.
|
|
299
|
-
*
|
|
300
|
-
* @returns an `IObservable`.
|
|
301
|
-
*/
|
|
302
|
-
get(path: string): IObservable | undefined;
|
|
303
|
-
/**
|
|
304
|
-
* Whether the `IModelDB` has an object at this path.
|
|
305
|
-
*
|
|
306
|
-
* @param path: the path for the object.
|
|
307
|
-
*
|
|
308
|
-
* @returns a boolean for whether an object is at `path`.
|
|
309
|
-
*/
|
|
310
|
-
has(path: string): boolean;
|
|
311
|
-
/**
|
|
312
|
-
* Create a string and insert it in the database.
|
|
313
|
-
*
|
|
314
|
-
* @param path: the path for the string.
|
|
315
|
-
*
|
|
316
|
-
* @returns the string that was created.
|
|
317
|
-
*/
|
|
318
|
-
createString(path: string): IObservableString;
|
|
319
|
-
/**
|
|
320
|
-
* Create an undoable list and insert it in the database.
|
|
321
|
-
*
|
|
322
|
-
* @param path: the path for the list.
|
|
323
|
-
*
|
|
324
|
-
* @returns the list that was created.
|
|
325
|
-
*
|
|
326
|
-
* #### Notes
|
|
327
|
-
* The list can only store objects that are simple
|
|
328
|
-
* JSON Objects and primitives.
|
|
329
|
-
*/
|
|
330
|
-
createList<T extends JSONValue>(path: string): IObservableUndoableList<T>;
|
|
331
|
-
/**
|
|
332
|
-
* Create a map and insert it in the database.
|
|
333
|
-
*
|
|
334
|
-
* @param path: the path for the map.
|
|
335
|
-
*
|
|
336
|
-
* @returns the map that was created.
|
|
337
|
-
*
|
|
338
|
-
* #### Notes
|
|
339
|
-
* The map can only store objects that are simple
|
|
340
|
-
* JSON Objects and primitives.
|
|
341
|
-
*/
|
|
342
|
-
createMap(path: string): IObservableJSON;
|
|
343
|
-
/**
|
|
344
|
-
* Create an opaque value and insert it in the database.
|
|
345
|
-
*
|
|
346
|
-
* @param path: the path for the value.
|
|
347
|
-
*
|
|
348
|
-
* @returns the value that was created.
|
|
349
|
-
*/
|
|
350
|
-
createValue(path: string): IObservableValue;
|
|
351
|
-
/**
|
|
352
|
-
* Get a value at a path, or `undefined if it has not been set
|
|
353
|
-
* That value must already have been created using `createValue`.
|
|
354
|
-
*
|
|
355
|
-
* @param path: the path for the value.
|
|
356
|
-
*/
|
|
357
|
-
getValue(path: string): JSONValue | undefined;
|
|
358
|
-
/**
|
|
359
|
-
* Set a value at a path. That value must already have
|
|
360
|
-
* been created using `createValue`.
|
|
361
|
-
*
|
|
362
|
-
* @param path: the path for the value.
|
|
363
|
-
*
|
|
364
|
-
* @param value: the new value.
|
|
365
|
-
*/
|
|
366
|
-
setValue(path: string, value: JSONValue): void;
|
|
367
|
-
/**
|
|
368
|
-
* Create a view onto a subtree of the model database.
|
|
369
|
-
*
|
|
370
|
-
* @param basePath: the path for the root of the subtree.
|
|
371
|
-
*
|
|
372
|
-
* @returns an `IModelDB` with a view onto the original
|
|
373
|
-
* `IModelDB`, with `basePath` prepended to all paths.
|
|
374
|
-
*/
|
|
375
|
-
view(basePath: string): ModelDB;
|
|
376
|
-
/**
|
|
377
|
-
* Set a value at a path. Not intended to
|
|
378
|
-
* be called by user code, instead use the
|
|
379
|
-
* `create*` factory methods.
|
|
380
|
-
*
|
|
381
|
-
* @param path: the path to set the value at.
|
|
382
|
-
*
|
|
383
|
-
* @param value: the value to set at the path.
|
|
384
|
-
*/
|
|
385
|
-
set(path: string, value: IObservable): void;
|
|
386
|
-
/**
|
|
387
|
-
* Dispose of the resources held by the database.
|
|
388
|
-
*/
|
|
389
|
-
dispose(): void;
|
|
390
|
-
/**
|
|
391
|
-
* Compute the fully resolved path for a path argument.
|
|
392
|
-
*/
|
|
393
|
-
private _resolvePath;
|
|
394
|
-
private _basePath;
|
|
395
|
-
private _db;
|
|
396
|
-
private _toDispose;
|
|
397
|
-
private _isDisposed;
|
|
398
|
-
private _disposables;
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* A namespace for the `ModelDB` class statics.
|
|
402
|
-
*/
|
|
403
|
-
export declare namespace ModelDB {
|
|
404
|
-
/**
|
|
405
|
-
* Options for creating a `ModelDB` object.
|
|
406
|
-
*/
|
|
407
|
-
interface ICreateOptions {
|
|
408
|
-
/**
|
|
409
|
-
* The base path to prepend to all the path arguments.
|
|
410
|
-
*/
|
|
411
|
-
basePath?: string;
|
|
412
|
-
/**
|
|
413
|
-
* A ModelDB to use as the store for this
|
|
414
|
-
* ModelDB. If none is given, it uses its own store.
|
|
415
|
-
*/
|
|
416
|
-
baseDB?: ModelDB;
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* A factory interface for creating `IModelDB` objects.
|
|
420
|
-
*/
|
|
421
|
-
interface IFactory {
|
|
422
|
-
/**
|
|
423
|
-
* Create a new `IModelDB` instance.
|
|
424
|
-
*/
|
|
425
|
-
createNew(path: string): IModelDB;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
1
|
+
import { IDisposable } from '@phosphor/disposable';
|
|
2
|
+
import { ISignal } from '@phosphor/signaling';
|
|
3
|
+
import { JSONValue, JSONObject } from '@phosphor/coreutils';
|
|
4
|
+
import { IObservableJSON } from './observablejson';
|
|
5
|
+
import { IObservableString } from './observablestring';
|
|
6
|
+
import { IObservableUndoableList } from './undoablelist';
|
|
7
|
+
import { IObservableMap } from './observablemap';
|
|
8
|
+
/**
|
|
9
|
+
* String type annotations for Observable objects that can be
|
|
10
|
+
* created and placed in the IModelDB interface.
|
|
11
|
+
*/
|
|
12
|
+
export declare type ObservableType = 'Map' | 'List' | 'String' | 'Value';
|
|
13
|
+
/**
|
|
14
|
+
* Base interface for Observable objects.
|
|
15
|
+
*/
|
|
16
|
+
export interface IObservable extends IDisposable {
|
|
17
|
+
/**
|
|
18
|
+
* The type of this object.
|
|
19
|
+
*/
|
|
20
|
+
readonly type: ObservableType;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Interface for an Observable object that represents
|
|
24
|
+
* an opaque JSON value.
|
|
25
|
+
*/
|
|
26
|
+
export interface IObservableValue extends IObservable {
|
|
27
|
+
/**
|
|
28
|
+
* The type of this object.
|
|
29
|
+
*/
|
|
30
|
+
readonly type: 'Value';
|
|
31
|
+
/**
|
|
32
|
+
* The changed signal.
|
|
33
|
+
*/
|
|
34
|
+
readonly changed: ISignal<IObservableValue, ObservableValue.IChangedArgs>;
|
|
35
|
+
/**
|
|
36
|
+
* Get the current value, or `undefined` if it has not been set.
|
|
37
|
+
*/
|
|
38
|
+
get(): JSONValue | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Set the value.
|
|
41
|
+
*/
|
|
42
|
+
set(value: JSONValue): void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Interface for an object representing a single collaborator
|
|
46
|
+
* on a realtime model.
|
|
47
|
+
*/
|
|
48
|
+
export interface ICollaborator extends JSONObject {
|
|
49
|
+
/**
|
|
50
|
+
* A user id for the collaborator.
|
|
51
|
+
* This might not be unique, if the user has more than
|
|
52
|
+
* one editing session at a time.
|
|
53
|
+
*/
|
|
54
|
+
readonly userId: string;
|
|
55
|
+
/**
|
|
56
|
+
* A session id, which should be unique to a
|
|
57
|
+
* particular view on a collaborative model.
|
|
58
|
+
*/
|
|
59
|
+
readonly sessionId: string;
|
|
60
|
+
/**
|
|
61
|
+
* A human-readable display name for a collaborator.
|
|
62
|
+
*/
|
|
63
|
+
readonly displayName: string;
|
|
64
|
+
/**
|
|
65
|
+
* A color to be used to identify the collaborator in
|
|
66
|
+
* UI elements.
|
|
67
|
+
*/
|
|
68
|
+
readonly color: string;
|
|
69
|
+
/**
|
|
70
|
+
* A human-readable short name for a collaborator, for
|
|
71
|
+
* use in places where the full `displayName` would take
|
|
72
|
+
* too much space.
|
|
73
|
+
*/
|
|
74
|
+
readonly shortName: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Interface for an IObservableMap that tracks collaborators.
|
|
78
|
+
*/
|
|
79
|
+
export interface ICollaboratorMap extends IObservableMap<ICollaborator> {
|
|
80
|
+
/**
|
|
81
|
+
* The local collaborator on a model.
|
|
82
|
+
*/
|
|
83
|
+
readonly localCollaborator: ICollaborator;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* An interface for a path based database for
|
|
87
|
+
* creating and storing values, which is agnostic
|
|
88
|
+
* to the particular type of store in the backend.
|
|
89
|
+
*/
|
|
90
|
+
export interface IModelDB extends IDisposable {
|
|
91
|
+
/**
|
|
92
|
+
* The base path for the `IModelDB`. This is prepended
|
|
93
|
+
* to all the paths that are passed in to the member
|
|
94
|
+
* functions of the object.
|
|
95
|
+
*/
|
|
96
|
+
readonly basePath: string;
|
|
97
|
+
/**
|
|
98
|
+
* Whether the database has been disposed.
|
|
99
|
+
*/
|
|
100
|
+
readonly isDisposed: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Whether the database has been populated
|
|
103
|
+
* with model values prior to connection.
|
|
104
|
+
*/
|
|
105
|
+
readonly isPrepopulated: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Whether the database is collaborative.
|
|
108
|
+
*/
|
|
109
|
+
readonly isCollaborative: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* A promise that resolves when the database
|
|
112
|
+
* has connected to its backend, if any.
|
|
113
|
+
*/
|
|
114
|
+
readonly connected: Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* A map of the currently active collaborators
|
|
117
|
+
* for the database, including the local user.
|
|
118
|
+
*/
|
|
119
|
+
readonly collaborators?: ICollaboratorMap;
|
|
120
|
+
/**
|
|
121
|
+
* Get a value for a path.
|
|
122
|
+
*
|
|
123
|
+
* @param path: the path for the object.
|
|
124
|
+
*
|
|
125
|
+
* @returns an `IObservable`.
|
|
126
|
+
*/
|
|
127
|
+
get(path: string): IObservable | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* Whether the `IModelDB` has an object at this path.
|
|
130
|
+
*
|
|
131
|
+
* @param path: the path for the object.
|
|
132
|
+
*
|
|
133
|
+
* @returns a boolean for whether an object is at `path`.
|
|
134
|
+
*/
|
|
135
|
+
has(path: string): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Create a string and insert it in the database.
|
|
138
|
+
*
|
|
139
|
+
* @param path: the path for the string.
|
|
140
|
+
*
|
|
141
|
+
* @returns the string that was created.
|
|
142
|
+
*/
|
|
143
|
+
createString(path: string): IObservableString;
|
|
144
|
+
/**
|
|
145
|
+
* Create an undoable list and insert it in the database.
|
|
146
|
+
*
|
|
147
|
+
* @param path: the path for the list.
|
|
148
|
+
*
|
|
149
|
+
* @returns the list that was created.
|
|
150
|
+
*
|
|
151
|
+
* #### Notes
|
|
152
|
+
* The list can only store objects that are simple
|
|
153
|
+
* JSON Objects and primitives.
|
|
154
|
+
*/
|
|
155
|
+
createList<T extends JSONValue>(path: string): IObservableUndoableList<T>;
|
|
156
|
+
/**
|
|
157
|
+
* Create a map and insert it in the database.
|
|
158
|
+
*
|
|
159
|
+
* @param path: the path for the map.
|
|
160
|
+
*
|
|
161
|
+
* @returns the map that was created.
|
|
162
|
+
*
|
|
163
|
+
* #### Notes
|
|
164
|
+
* The map can only store objects that are simple
|
|
165
|
+
* JSON Objects and primitives.
|
|
166
|
+
*/
|
|
167
|
+
createMap(path: string): IObservableJSON;
|
|
168
|
+
/**
|
|
169
|
+
* Create an opaque value and insert it in the database.
|
|
170
|
+
*
|
|
171
|
+
* @param path: the path for the value.
|
|
172
|
+
*
|
|
173
|
+
* @returns the value that was created.
|
|
174
|
+
*/
|
|
175
|
+
createValue(path: string): IObservableValue;
|
|
176
|
+
/**
|
|
177
|
+
* Get a value at a path, or `undefined if it has not been set
|
|
178
|
+
* That value must already have been created using `createValue`.
|
|
179
|
+
*
|
|
180
|
+
* @param path: the path for the value.
|
|
181
|
+
*/
|
|
182
|
+
getValue(path: string): JSONValue | undefined;
|
|
183
|
+
/**
|
|
184
|
+
* Set a value at a path. That value must already have
|
|
185
|
+
* been created using `createValue`.
|
|
186
|
+
*
|
|
187
|
+
* @param path: the path for the value.
|
|
188
|
+
*
|
|
189
|
+
* @param value: the new value.
|
|
190
|
+
*/
|
|
191
|
+
setValue(path: string, value: JSONValue): void;
|
|
192
|
+
/**
|
|
193
|
+
* Create a view onto a subtree of the model database.
|
|
194
|
+
*
|
|
195
|
+
* @param basePath: the path for the root of the subtree.
|
|
196
|
+
*
|
|
197
|
+
* @returns an `IModelDB` with a view onto the original
|
|
198
|
+
* `IModelDB`, with `basePath` prepended to all paths.
|
|
199
|
+
*/
|
|
200
|
+
view(basePath: string): IModelDB;
|
|
201
|
+
/**
|
|
202
|
+
* Dispose of the resources held by the database.
|
|
203
|
+
*/
|
|
204
|
+
dispose(): void;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* A concrete implementation of an `IObservableValue`.
|
|
208
|
+
*/
|
|
209
|
+
export declare class ObservableValue implements IObservableValue {
|
|
210
|
+
/**
|
|
211
|
+
* Constructor for the value.
|
|
212
|
+
*
|
|
213
|
+
* @param initialValue: the starting value for the `ObservableValue`.
|
|
214
|
+
*/
|
|
215
|
+
constructor(initialValue?: JSONValue);
|
|
216
|
+
/**
|
|
217
|
+
* The observable type.
|
|
218
|
+
*/
|
|
219
|
+
readonly type: 'Value';
|
|
220
|
+
/**
|
|
221
|
+
* Whether the value has been disposed.
|
|
222
|
+
*/
|
|
223
|
+
readonly isDisposed: boolean;
|
|
224
|
+
/**
|
|
225
|
+
* The changed signal.
|
|
226
|
+
*/
|
|
227
|
+
readonly changed: ISignal<this, ObservableValue.IChangedArgs>;
|
|
228
|
+
/**
|
|
229
|
+
* Get the current value, or `undefined` if it has not been set.
|
|
230
|
+
*/
|
|
231
|
+
get(): JSONValue;
|
|
232
|
+
/**
|
|
233
|
+
* Set the current value.
|
|
234
|
+
*/
|
|
235
|
+
set(value: JSONValue): void;
|
|
236
|
+
/**
|
|
237
|
+
* Dispose of the resources held by the value.
|
|
238
|
+
*/
|
|
239
|
+
dispose(): void;
|
|
240
|
+
private _value;
|
|
241
|
+
private _changed;
|
|
242
|
+
private _isDisposed;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* The namespace for the `ObservableValue` class statics.
|
|
246
|
+
*/
|
|
247
|
+
export declare namespace ObservableValue {
|
|
248
|
+
/**
|
|
249
|
+
* The changed args object emitted by the `IObservableValue`.
|
|
250
|
+
*/
|
|
251
|
+
class IChangedArgs {
|
|
252
|
+
/**
|
|
253
|
+
* The old value.
|
|
254
|
+
*/
|
|
255
|
+
oldValue: JSONValue | undefined;
|
|
256
|
+
/**
|
|
257
|
+
* The new value.
|
|
258
|
+
*/
|
|
259
|
+
newValue: JSONValue | undefined;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* A concrete implementation of an `IModelDB`.
|
|
264
|
+
*/
|
|
265
|
+
export declare class ModelDB implements IModelDB {
|
|
266
|
+
/**
|
|
267
|
+
* Constructor for the `ModelDB`.
|
|
268
|
+
*/
|
|
269
|
+
constructor(options?: ModelDB.ICreateOptions);
|
|
270
|
+
/**
|
|
271
|
+
* The base path for the `ModelDB`. This is prepended
|
|
272
|
+
* to all the paths that are passed in to the member
|
|
273
|
+
* functions of the object.
|
|
274
|
+
*/
|
|
275
|
+
readonly basePath: string;
|
|
276
|
+
/**
|
|
277
|
+
* Whether the database is disposed.
|
|
278
|
+
*/
|
|
279
|
+
readonly isDisposed: boolean;
|
|
280
|
+
/**
|
|
281
|
+
* Whether the model has been populated with
|
|
282
|
+
* any model values.
|
|
283
|
+
*/
|
|
284
|
+
readonly isPrepopulated: boolean;
|
|
285
|
+
/**
|
|
286
|
+
* Whether the model is collaborative.
|
|
287
|
+
*/
|
|
288
|
+
readonly isCollaborative: boolean;
|
|
289
|
+
/**
|
|
290
|
+
* A promise resolved when the model is connected
|
|
291
|
+
* to its backend. For the in-memory ModelDB it
|
|
292
|
+
* is immediately resolved.
|
|
293
|
+
*/
|
|
294
|
+
readonly connected: Promise<void>;
|
|
295
|
+
/**
|
|
296
|
+
* Get a value for a path.
|
|
297
|
+
*
|
|
298
|
+
* @param path: the path for the object.
|
|
299
|
+
*
|
|
300
|
+
* @returns an `IObservable`.
|
|
301
|
+
*/
|
|
302
|
+
get(path: string): IObservable | undefined;
|
|
303
|
+
/**
|
|
304
|
+
* Whether the `IModelDB` has an object at this path.
|
|
305
|
+
*
|
|
306
|
+
* @param path: the path for the object.
|
|
307
|
+
*
|
|
308
|
+
* @returns a boolean for whether an object is at `path`.
|
|
309
|
+
*/
|
|
310
|
+
has(path: string): boolean;
|
|
311
|
+
/**
|
|
312
|
+
* Create a string and insert it in the database.
|
|
313
|
+
*
|
|
314
|
+
* @param path: the path for the string.
|
|
315
|
+
*
|
|
316
|
+
* @returns the string that was created.
|
|
317
|
+
*/
|
|
318
|
+
createString(path: string): IObservableString;
|
|
319
|
+
/**
|
|
320
|
+
* Create an undoable list and insert it in the database.
|
|
321
|
+
*
|
|
322
|
+
* @param path: the path for the list.
|
|
323
|
+
*
|
|
324
|
+
* @returns the list that was created.
|
|
325
|
+
*
|
|
326
|
+
* #### Notes
|
|
327
|
+
* The list can only store objects that are simple
|
|
328
|
+
* JSON Objects and primitives.
|
|
329
|
+
*/
|
|
330
|
+
createList<T extends JSONValue>(path: string): IObservableUndoableList<T>;
|
|
331
|
+
/**
|
|
332
|
+
* Create a map and insert it in the database.
|
|
333
|
+
*
|
|
334
|
+
* @param path: the path for the map.
|
|
335
|
+
*
|
|
336
|
+
* @returns the map that was created.
|
|
337
|
+
*
|
|
338
|
+
* #### Notes
|
|
339
|
+
* The map can only store objects that are simple
|
|
340
|
+
* JSON Objects and primitives.
|
|
341
|
+
*/
|
|
342
|
+
createMap(path: string): IObservableJSON;
|
|
343
|
+
/**
|
|
344
|
+
* Create an opaque value and insert it in the database.
|
|
345
|
+
*
|
|
346
|
+
* @param path: the path for the value.
|
|
347
|
+
*
|
|
348
|
+
* @returns the value that was created.
|
|
349
|
+
*/
|
|
350
|
+
createValue(path: string): IObservableValue;
|
|
351
|
+
/**
|
|
352
|
+
* Get a value at a path, or `undefined if it has not been set
|
|
353
|
+
* That value must already have been created using `createValue`.
|
|
354
|
+
*
|
|
355
|
+
* @param path: the path for the value.
|
|
356
|
+
*/
|
|
357
|
+
getValue(path: string): JSONValue | undefined;
|
|
358
|
+
/**
|
|
359
|
+
* Set a value at a path. That value must already have
|
|
360
|
+
* been created using `createValue`.
|
|
361
|
+
*
|
|
362
|
+
* @param path: the path for the value.
|
|
363
|
+
*
|
|
364
|
+
* @param value: the new value.
|
|
365
|
+
*/
|
|
366
|
+
setValue(path: string, value: JSONValue): void;
|
|
367
|
+
/**
|
|
368
|
+
* Create a view onto a subtree of the model database.
|
|
369
|
+
*
|
|
370
|
+
* @param basePath: the path for the root of the subtree.
|
|
371
|
+
*
|
|
372
|
+
* @returns an `IModelDB` with a view onto the original
|
|
373
|
+
* `IModelDB`, with `basePath` prepended to all paths.
|
|
374
|
+
*/
|
|
375
|
+
view(basePath: string): ModelDB;
|
|
376
|
+
/**
|
|
377
|
+
* Set a value at a path. Not intended to
|
|
378
|
+
* be called by user code, instead use the
|
|
379
|
+
* `create*` factory methods.
|
|
380
|
+
*
|
|
381
|
+
* @param path: the path to set the value at.
|
|
382
|
+
*
|
|
383
|
+
* @param value: the value to set at the path.
|
|
384
|
+
*/
|
|
385
|
+
set(path: string, value: IObservable): void;
|
|
386
|
+
/**
|
|
387
|
+
* Dispose of the resources held by the database.
|
|
388
|
+
*/
|
|
389
|
+
dispose(): void;
|
|
390
|
+
/**
|
|
391
|
+
* Compute the fully resolved path for a path argument.
|
|
392
|
+
*/
|
|
393
|
+
private _resolvePath;
|
|
394
|
+
private _basePath;
|
|
395
|
+
private _db;
|
|
396
|
+
private _toDispose;
|
|
397
|
+
private _isDisposed;
|
|
398
|
+
private _disposables;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* A namespace for the `ModelDB` class statics.
|
|
402
|
+
*/
|
|
403
|
+
export declare namespace ModelDB {
|
|
404
|
+
/**
|
|
405
|
+
* Options for creating a `ModelDB` object.
|
|
406
|
+
*/
|
|
407
|
+
interface ICreateOptions {
|
|
408
|
+
/**
|
|
409
|
+
* The base path to prepend to all the path arguments.
|
|
410
|
+
*/
|
|
411
|
+
basePath?: string;
|
|
412
|
+
/**
|
|
413
|
+
* A ModelDB to use as the store for this
|
|
414
|
+
* ModelDB. If none is given, it uses its own store.
|
|
415
|
+
*/
|
|
416
|
+
baseDB?: ModelDB;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* A factory interface for creating `IModelDB` objects.
|
|
420
|
+
*/
|
|
421
|
+
interface IFactory {
|
|
422
|
+
/**
|
|
423
|
+
* Create a new `IModelDB` instance.
|
|
424
|
+
*/
|
|
425
|
+
createNew(path: string): IModelDB;
|
|
426
|
+
}
|
|
427
|
+
}
|