- Since:
- 3.8
Extends
- WebcomService
Classes
- CollectionReference
- DocumentAcknowledgement
- DocumentAddition
- DocumentChange
- DocumentField
- DocumentMove
- DocumentReference
- DocumentRemoval
- DocumentUpdate
- Filter
- UpdateOperator
Interfaces
- Deserializable
- Document
- DocumentCopy
- DocumentSeries
- Filterable
- Limitable
- Projectable
- QueryNotification
- Queryable
- Serializable
- Sortable
- Unwatcher
- Watcher
Members
(readonly) connectionState :ReactiveDb.ConnectionState
Gives the current state of the web-socket between the client and the ReactiveDb service of the Webcom back end.
Type:
(readonly) serverTime :Date
Gives the current time of the Webcom back end. If a web-socket is established with the ReactiveDb service, the given time takes into account the possible time offset between the client and the server.
Type:
- Date
Methods
col(collectionId) → {ReactiveDb.CollectionReference}
Gets a reference to a collection.
Parameters:
Name | Type | Description |
---|---|---|
collectionId |
string | The identifier of the targeted collection. |
Returns:
A reference to the requested collection.
connect() → {Promise.<void>}
Opens a web-socket to the ReactiveDb service of the Webcom back end. If already opened, this method just returns an already completed Promise.
Returns:
The returned Promise completes as soon as the web-socket to the ReactiveDb service is successfully established.
- Type
- Promise.<void>
countRemotely(query) → {Promise.<number>}
Returns the count of documents that are matched by a given query. This request requires connectivity to the
Webcom back end (it never counts the documents within the local cache) and is aimed at evaluating the
actual bandwidth required to download a series of documents from the back end before performing such a download
(e.g. using the ReactiveDb#findMany
method).
Parameters:
Name | Type | Description |
---|---|---|
query |
ReactiveDb.Queryable | The query that matches the targeted documents. |
Returns:
The count of matched documents is returned asynchronously through a Promise.
- Type
- Promise.<number>
createUniqueKey() → {string}
Generates a unique identifier across all possible clients. Such a unique key is intended to be used as a Document
identifier.
Returns:
- Type
- string
deleteMany(query) → {Promise.<number>}
Deletes a series of documents that are matched by a given query.
Parameters:
Name | Type | Description |
---|---|---|
query |
ReactiveDb.Queryable | The query that matches the documents to delete. |
- See:
Returns:
The returned Promise will be resolved with the number of actually deleted documents (which may be zero if the query matches no document) as soon as the request completion is acknowledged by the Webcom back end. As a consequence, it remains pending as long as no connection to the back end is opened.
- Type
- Promise.<number>
deleteOne(docRef) → {Promise.<void>}
Deletes an existing document from a collection.
If the document to delete doesn't exist, then the method fails.
Parameters:
Name | Type | Description |
---|---|---|
docRef |
ReactiveDb.DocumentReference | The document to delete. |
Returns:
The returned Promise will be resolved as soon as the request completion is acknowledged by the Webcom back end. As a consequence, it remains pending as long as no connection to the back end is opened.
- Type
- Promise.<void>
disconnect()
Closes the web-socket to the ReactiveDb service of the Webcom back end. If already closed, this method does nothing.
findMany(query) → {Promise.<ReactiveDb.DocumentSeries>}
Retrieves a series of documents that are matched by a given query, either from the local cache if no connectivity to the Webcom back end is available, or from the Webcom back end otherwise.
Parameters:
Name | Type | Description |
---|---|---|
query |
ReactiveDb.Queryable | The query that matches the targeted documents. |
Returns:
The retrieved document series is returned asynchronously through a Promise.
- Type
- Promise.<ReactiveDb.DocumentSeries>
findManyLocally(query) → {ReactiveDb.DocumentSeries}
Retrieves a series of documents from the local cache, without requesting the Webcom back end.
Parameters:
Name | Type | Description |
---|---|---|
query |
ReactiveDb.Queryable | The query that matches the targeted documents. |
Returns:
The retrieved document series.
findManyRemotely(query) → {Promise.<ReactiveDb.DocumentSeries>}
Retrieves a series of documents that are matched by a given query from the Webcom back end. If no connectivity is available, the returned Promise is rejected.
Parameters:
Name | Type | Description |
---|---|---|
query |
ReactiveDb.Queryable | The query that matches the targeted documents. |
Returns:
The retrieved document series is returned asynchronously through a Promise.
- Type
- Promise.<ReactiveDb.DocumentSeries>
findOne(docRef) → {Promise.<ReactiveDb.DocumentCopy>}
Retrieves a given document, either from the local cache if no connectivity to the Webcom back end is available, or from the Webcom back end otherwise.
Parameters:
Name | Type | Description |
---|---|---|
docRef |
ReactiveDb.DocumentReference | The document to retrieve. |
Returns:
The retrieved document is returned asynchronously through a Promise.
- Type
- Promise.<ReactiveDb.DocumentCopy>
findOneLocally(docRef) → {ReactiveDb.DocumentCopy}
Retrieves a given document from the local cache, without requesting the Webcom back end.
Parameters:
Name | Type | Description |
---|---|---|
docRef |
ReactiveDb.DocumentReference | The document to retrieve. |
Returns:
The retrieved document.
findOneRemotely(docRef) → {Promise.<ReactiveDb.DocumentCopy>}
Retrieves a given document from the Webcom back end. If no connectivity is available, the returned Promise is rejected.
Parameters:
Name | Type | Description |
---|---|---|
docRef |
ReactiveDb.DocumentReference | The document to retrieve. |
Returns:
The retrieved document is returned asynchronously through a Promise.
- Type
- Promise.<ReactiveDb.DocumentCopy>
insertOne(docRef, docContent) → {Promise.<void>}
Inserts a new document in a collection. If no connectivity to the Webcom back end is available, the request is cached and will be actually sent to the back end as soon as a connection is established.
If the document to insert already exists, then the request fails.
Parameters:
Name | Type | Description |
---|---|---|
docRef |
ReactiveDb.DocumentReference | The document to insert. |
docContent |
ReactiveDb.DocumentData | Data content of the document to insert. |
Returns:
The returned Promise will be resolved as soon as the request completion is acknowledged by the Webcom back end. As a consequence, it remains pending as long as no connection to the back end is opened.
- Type
- Promise.<void>
insertOneInto(colRef, docContent) → {Promise.<string>}
Inserts a new document in a given collection. The difference with the insertOne
method
is that the document identifier is automatically generated and is unique across all clients.
If no connectivity to the Webcom back end is available, the request is cached and will be actually sent to the back end as soon as a connection is established.
Parameters:
Name | Type | Description |
---|---|---|
colRef |
ReactiveDb.CollectionReference | The collection where to insert the new document. |
docContent |
ReactiveDb.DocumentData | Data content of the document to insert. |
Returns:
The returned Promise will be resolved with the identifier of the inserted document as soon as the request completion is acknowledged by the Webcom back end. As a consequence, it remains pending as long as no connection to the back end is opened.
- Type
- Promise.<string>
replaceOne(docRef, docContent) → {Promise.<void>}
Overwrites an existing document in a collection. If no connectivity to the Webcom back end is available, the request is cached and will be actually sent to the back end as soon as a connection is established.
If the document to overwrite doesn't already exist, then the request fails.
Parameters:
Name | Type | Description |
---|---|---|
docRef |
ReactiveDb.DocumentReference | The document to overwrite. |
docContent |
ReactiveDb.DocumentData | Data content of the document to overwrite. |
Returns:
The returned Promise will be resolved as soon as the request completion is acknowledged by the Webcom back end. As a consequence, it remains pending as long as no connection to the back end is opened.
- Type
- Promise.<void>
setOne(docRef, docContent) → {Promise.<boolean>}
Overwrites a given document, and insert it if it doesn't exist yet in the database. If no connectivity to the Webcom back end is available, the request is cached and will be actually sent to the back end as soon as a connection is established.
Parameters:
Name | Type | Description |
---|---|---|
docRef |
ReactiveDb.DocumentReference | The document to (over)write. |
docContent |
ReactiveDb.DocumentData | Data content of the document to (over)write. |
Returns:
The returned Promise will be resolved with true
if the document has been inserted
(meaning it didn't exist before the setOne
performance) or false
if the document did already exist and has
been replaced. It will be resolved as soon as the request completion is acknowledged by the Webcom back
end. As a consequence, it remains pending as long as no connection to the back end is opened.
- Type
- Promise.<boolean>
updateMany(query, diff) → {Promise.<number>}
Updates a series of documents that are matched by a given query with a given diff.
Parameters:
Name | Type | Description |
---|---|---|
query |
ReactiveDb.Queryable | The query that matches the documents to update. |
diff |
ReactiveDb.Update | JSON object describing the updates to apply. |
- See:
Returns:
The returned Promise will be resolved with the number of actually updated documents (which may be zero if the query matches no document) as soon as the request completion is acknowledged by the Webcom back end. As a consequence, it remains pending as long as no connection to the back end is opened.
- Type
- Promise.<number>
updateOne(docRef, diff) → {Promise.<void>}
Updates an existing document with a given diff.
If the document to update doesn't exist, this method fails.
Parameters:
Name | Type | Description |
---|---|---|
docRef |
ReactiveDb.DocumentReference | The document to update. |
diff |
ReactiveDb.Update | JSON object describing the updates to apply. |
Returns:
The returned Promise will be resolved as soon as the request completion is acknowledged by the Webcom back end. As a consequence, it remains pending as long as no connection to the back end is opened.
- Type
- Promise.<void>
watchMany(query, optionsopt) → {ReactiveDb.Watcher}
Watches a set of documents that satisfy a given query. All changes to this set will be notified realtime to the
returned Watcher
.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
query |
ReactiveDb.Queryable | The query that matches the documents to watch. |
||
options |
ReactiveDb.WatchOptions |
<optional> |
{} | Options to filter notifications related to acknowledgement events. |
Returns:
An object that will receive notifications for each change in the set of watched documents:
- Notifications must be caught using the
ReactiveDb.Watcher#forEach
method, - Stopping watching the documents may be performed by calling the
ReactiveDb.Watcher#unwatch
method, ReactiveDb.Watcher
also implements thePromise
interface: its instances will be rejected as soon as the associated subscription is revoked by the Webcom server, and resolved as soon as it is cancelled by the client (using theReactiveDb.Watcher#unwatch
method).
- Type
- ReactiveDb.Watcher
watchOne(docRef, optionsopt) → {ReactiveDb.Watcher}
Watches a given document in a collection. All changes to this document (including its creation, its modification or
its removal) will be notified realtime to the returned ReactiveDb.Watcher
.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
docRef |
ReactiveDb.DocumentReference | The document to watch. |
||
options |
ReactiveDb.WatchOptions |
<optional> |
{} | Options to filter notifications related to acknowledgement events. |
Returns:
An object that will receive notifications for each change in the watched document:
- Notifications must be caught using the
ReactiveDb.Watcher#forEach
method, - Stopping watching the document may be performed by calling the
ReactiveDb.Watcher#unwatch
method, ReactiveDb.Watcher
also implements thePromise
interface: its instances will be rejected as soon as the associated subscription is revoked by the Webcom server, and resolved as soon as it is cancelled by the client (using theReactiveDb.Watcher#unwatch
method).
- Type
- ReactiveDb.Watcher
Type Definitions
API
Constants and static methods associated to the ReactiveDb
service.
Such an object is available through the Webcom.ReactiveDb
property.
Properties:
Name | Type | Description |
---|---|---|
DocumentField |
ReactiveDb.DocumentField | Convenient link to access the static members of the
|
Filter |
ReactiveDb.Filter | Convenient link to access the static members of the
|
UpdateOperator |
ReactiveDb.UpdateOperator | Convenient link to access the static members of the
|
- Since:
- 3.8
Configuration
Properties:
Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
baseUrl |
URL | string |
<optional> |
Base URL for the |
|||||||||||||||||||||||||||||||||||
connection |
Object |
<optional> |
Configuration of the realtime connection to the Properties
|
ConnectionState
Represents the connection state of the web-socket between the client and the ReactiveDb service of the Webcom
back end. It is mainly returned by the ReactiveDb#connectionState
property.
Properties:
Name | Type | Description |
---|---|---|
online |
boolean |
|
connecting |
boolean |
|
connected |
boolean |
|
DocumentData
Represents the content (or "user data") of a document to write (typically passed to the ReactiveDb#insertOne
method).
It can be either:
- any object implementing the
ReactiveDb.Serializable
interface, in this case the content is the value returned by theserialize
method, - any JSON value (including objects, arrays, primitives and
null
), - an enhanced JSON value, that is an array whose elements are recursively
ReactiveDb.DocumentData
values or a JSON object whose mapped values are recursivelyReactiveDb.DocumentData
values.
Example: Serializable object
{
serialize() {
return {key: "value"};
}
}
Example: Basic JSON value
{
key:"value"
}
Example: Enhanced JSON
{
key: { serialize() { return "value"; } }
}
Type:
- ReactiveDb.SimpleDocumentData | Object.<(string|number), ReactiveDb.DocumentData>
JSONPrimitive
Type:
- null | number | boolean | string
JSONValue
Formal definition of a JSON value.
It is mainly used as return type of functions that read some content from a document (for example
ReactiveDb.Document#getDataAt
).
Type:
SimpleDocumentData
Type:
Update
Represents an update descriptor (passed to the ReactiveDb#updateOne
and ReactiveDb#updateMany
methods).
It basically consists in a JSON object, in which:
- each key represents a segment of a document field to update (it may use the dotted notation to give a path, that is a series of segments),
- each key describes the update to apply on the segment. It can be either:
- recursively an
Update
descriptor (typically to reach deeper document fields), - an
ReactiveDb.UpdateOperator
that specifies the update operation to apply on the segment, - a simple JSON value (basically a number, a string, a boolean or an array), in this case it is equivalent to
the
ReactiveDb.UpdateOperator.set
operator with this value.
- recursively an
Type:
- Object.<string, (ReactiveDb.Update|ReactiveDb.UpdateOperator|ReactiveDb.SimpleDocumentData)>
Example
{
segment1: {
segment1a: "foo",
segment1b: UpdateOperator.increment(3)
},
"segment2.segment2a": UpdateOperator.decrement()
}