Interface: Document

ReactiveDb.Document

Represents the content of a document of the ReactiveDb database.
It can represent an actual exising document, as well as a fictive non-existing document.

Members

(readonly) acked :ReactiveDb.Document.AcknowledgementStatus

Gives the acknowledgement status of the document.

Type:

(readonly, nullable) createdAt :Date

Gives the creation date of the document, if this instance represents an existing document.

Type:
  • Date

(readonly) exists :boolean

Indicates whether this instance represents an existing document.

Type:
  • boolean

(readonly) id :string

Gets the identifier of the document.

Type:
  • string

(readonly, nullable) updatedAt :Date

Gives the date of the last modification of the document, if this instance represents an existing document.

Type:
  • Date

(readonly, nullable) version :number

Gives the version of the document, if this instance represents an existing document.

Version is a positive integer number, which starts at 1 for newly created documents and is incremented at each update of the document.

Type:
  • number

Methods

getData() → {ReactiveDb.JSONObject}

Gets the user content of this document as a pure JSON object.

Returns:

A JSON object representing the content of this document or an empty object {} if this instance represents a non-existing document.

Type
ReactiveDb.JSONObject

getDataAs(type) → {T|undefined}

Gets the user content of this document and deserializes it into a given data type.

Parameters:
Name Type Description
type ReactiveDb.Deserializable

The target type, given as an object with a deserialize method of template type T.

Returns:

An instance of the target type representing the content of this document or undefined if this instance represents a non-existing document.

Type
T | undefined

getDataAt(field) → (nullable) {ReactiveDb.JSONValue}

Gets the user content of this document at a given field as a pure JSON value.

Throws an exception if the given field refers to a metadata.

Parameters:
Name Type Description
field ReactiveDb.DocumentField

The targeted field of the document.

Returns:

A JSON value representing the content of this document at the given field or undefined if this instance represents a non-existing document or a document without the targeted field.

Type
ReactiveDb.JSONValue

getDataAtAs(field, type) → {T|undefined}

Gets the user content of this document at a given field and deserializes it into a given data type.

Throws an exception if the given field refers to a metadata.

Parameters:
Name Type Description
field ReactiveDb.DocumentField

The targeted field of the document.

type ReactiveDb.Deserializable

The target type, given as an object with a deserialize method of template type T.

Returns:

An instance of the target type representing the content of this document at the given field or undefined if this instance represents a non-existing document or a document without the targeted field.

Type
T | undefined

isEqual(other) → {boolean}

Checks whether this instance represents the same document as another given one.

Parameters:
Name Type Description
other ReactiveDb.Document

The document to compare to.

Returns:
Type
boolean

Type Definitions

AcknowledgementStatus

Represents the acknowledgement status of a document:

  • 0 (SomeWritesPending) is not acknowledged at all: the writing of some parts of the document is still pending,
  • 1 (AllWritesAcked) is "partially acknowledged": all pending writes have been acknowledged, but some parts of the document come the local cache and may not be up-to-date with the actual document stored on the back end,
  • 2 (DocumentAcked) is "fully acknowledged": the whole content of the document has been acknowledged and is in a state that actually exists (or has actually existed) on the back end.
Type:
  • 0 | 1 | 2
deprecated
Authentication
ServerlessDb
ReactiveDb