|
@@ -33,6 +33,10 @@ import {
|
|
IObservableUndoableVector, ObservableUndoableVector
|
|
IObservableUndoableVector, ObservableUndoableVector
|
|
} from './undoablevector';
|
|
} from './undoablevector';
|
|
|
|
|
|
|
|
+import {
|
|
|
|
+ IObservableMap
|
|
|
|
+} from './observablemap';
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* String type annotations for Observable objects that can be
|
|
* String type annotations for Observable objects that can be
|
|
@@ -41,6 +45,7 @@ import {
|
|
export
|
|
export
|
|
type ObservableType = 'Map' | 'Vector' | 'String' | 'Value';
|
|
type ObservableType = 'Map' | 'Vector' | 'String' | 'Value';
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Base interface for Observable objects.
|
|
* Base interface for Observable objects.
|
|
*/
|
|
*/
|
|
@@ -52,6 +57,7 @@ interface IObservable extends IDisposable {
|
|
readonly type: ObservableType;
|
|
readonly type: ObservableType;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Interface for an Observable object that represents
|
|
* Interface for an Observable object that represents
|
|
* an opaque JSON value.
|
|
* an opaque JSON value.
|
|
@@ -79,6 +85,51 @@ interface IObservableValue extends IObservable {
|
|
set(value: JSONValue): void;
|
|
set(value: JSONValue): void;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Interface for an object representing a single collaborator
|
|
|
|
+ * on a realtime model.
|
|
|
|
+ */
|
|
|
|
+export
|
|
|
|
+interface ICollaborator {
|
|
|
|
+ /**
|
|
|
|
+ * A user id for the collaborator.
|
|
|
|
+ * This might not be unique, if the user has more than
|
|
|
|
+ * one editing session at a time.
|
|
|
|
+ */
|
|
|
|
+ readonly userId: string;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * A session id, which should be unique to a
|
|
|
|
+ * particular view on a collaborative model.
|
|
|
|
+ */
|
|
|
|
+ readonly sessionId: string;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * A human-readable display name for a collaborator.
|
|
|
|
+ */
|
|
|
|
+ readonly displayName: string;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * A color to be used to identify the collaborator in
|
|
|
|
+ * UI elements.
|
|
|
|
+ */
|
|
|
|
+ readonly color: string;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Interface for an IObservableMap that tracks collaborators.
|
|
|
|
+ */
|
|
|
|
+export
|
|
|
|
+interface ICollaboratorMap extends IObservableMap<ICollaborator> {
|
|
|
|
+ /**
|
|
|
|
+ * The local collaborator on a model.
|
|
|
|
+ */
|
|
|
|
+ readonly localCollaborator: ICollaborator;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* An interface for a path based database for
|
|
* An interface for a path based database for
|
|
* creating and storing values, which is agnostic
|
|
* creating and storing values, which is agnostic
|
|
@@ -104,12 +155,23 @@ interface IModelDB extends IDisposable {
|
|
*/
|
|
*/
|
|
readonly isPrepopulated: boolean;
|
|
readonly isPrepopulated: boolean;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Whether the database is collaborative.
|
|
|
|
+ */
|
|
|
|
+ readonly isCollaborative: boolean;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* A promise that resolves when the database
|
|
* A promise that resolves when the database
|
|
* has connected to its backend, if any.
|
|
* has connected to its backend, if any.
|
|
*/
|
|
*/
|
|
readonly connected: Promise<void>;
|
|
readonly connected: Promise<void>;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * A map of the currently active collaborators
|
|
|
|
+ * for the handler, including the local user.
|
|
|
|
+ */
|
|
|
|
+ readonly collaborators?: ICollaboratorMap;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Get a value for a path.
|
|
* Get a value for a path.
|
|
*
|
|
*
|
|
@@ -206,6 +268,26 @@ interface IModelDB extends IDisposable {
|
|
dispose(): void;
|
|
dispose(): void;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+export
|
|
|
|
+interface IModelDBFactory {
|
|
|
|
+ /**
|
|
|
|
+ * The IModelDB backend may require some setup before
|
|
|
|
+ * it can be used (e.g., loading external APIs, authorization).
|
|
|
|
+ * This promise is resolved when the services are ready to
|
|
|
|
+ * be used.
|
|
|
|
+ */
|
|
|
|
+ ready: Promise<void>;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Create an IModelDB for use with a document or other
|
|
|
|
+ * model.
|
|
|
|
+ *
|
|
|
|
+ * @param path: a path that identifies the location of the realtime
|
|
|
|
+ * store in the backend.
|
|
|
|
+ */
|
|
|
|
+ createModelDB(path: string): IModelDB;
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* A concrete implementation of an `IObservableValue`.
|
|
* A concrete implementation of an `IObservableValue`.
|
|
*/
|
|
*/
|
|
@@ -338,18 +420,19 @@ class ModelDB implements IModelDB {
|
|
* Whether the model has been populated with
|
|
* Whether the model has been populated with
|
|
* any model values.
|
|
* any model values.
|
|
*/
|
|
*/
|
|
- get isPrepopulated(): boolean {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
|
|
+ readonly isPrepopulated: boolean = false;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Whether the model is collaborative.
|
|
|
|
+ */
|
|
|
|
+ readonly isCollaborative: boolean = false;
|
|
|
|
|
|
/**
|
|
/**
|
|
* A promise resolved when the model is connected
|
|
* A promise resolved when the model is connected
|
|
* to its backend. For the in-memory ModelDB it
|
|
* to its backend. For the in-memory ModelDB it
|
|
* is immediately resolved.
|
|
* is immediately resolved.
|
|
*/
|
|
*/
|
|
- get connected(): Promise<void> {
|
|
|
|
- return Promise.resolve(void 0);
|
|
|
|
- }
|
|
|
|
|
|
+ readonly connected: Promise<void> = Promise.resolve(void 0);
|
|
|
|
|
|
/**
|
|
/**
|
|
* Get a value for a path.
|
|
* Get a value for a path.
|