Skip to content

Documentation / @ember-data/store / index / Document

Defined in: packages/store/src/-private/document.ts:32

A Document is a class that wraps the response content from a request to the API returned by Cache.put or Cache.peek, converting resource-identifiers into record instances.

It is not directly instantiated by the user, and its properties should not be directly modified. Whether individual properties are mutable or not is determined by the record instance itself.

ReactiveDocument

Type Parameters

T

T

Constructors

Constructor

ts
new Document<T>(
   store, 
   identifier, 
localCache): ReactiveDocument<T>;

Defined in: packages/store/src/-private/document.ts:94

Parameters

store

default

identifier

null | StableDocumentIdentifier

localCache

null | { document: ResourceDocument; request: ImmutableRequestInfo; }

Returns

ReactiveDocument<T>

Properties

_localCache

ts
protected readonly _localCache: 
  | null
  | {
  document: ResourceDocument;
  request: ImmutableRequestInfo;
};

Defined in: packages/store/src/-private/document.ts:92


_store

ts
protected readonly _store: default;

Defined in: packages/store/src/-private/document.ts:91


data?

ts
readonly optional data: T;

Defined in: packages/store/src/-private/document.ts:62

The primary data for this document, if any.

If this document has no primary data (e.g. because it is an error document) this property will be undefined.

For collections this will be an array of record instances, for single resource requests it will be a single record instance or null.


errors?

ts
readonly optional errors: object[];

Defined in: packages/store/src/-private/document.ts:71

The errors returned by the API for this request, if any


identifier

ts
readonly identifier: 
  | null
  | StableDocumentIdentifier;

Defined in: packages/store/src/-private/document.ts:89

The identifier associated with this document, if any


ts
readonly optional links: PaginationLinks;

Defined in: packages/store/src/-private/document.ts:48

The links object for this document, if any

e.g.

{
  self: '/articles?page[number]=3',
}

meta?

ts
readonly optional meta: ObjectValue;

Defined in: packages/store/src/-private/document.ts:80

The meta object for this document, if any

Methods

fetch()

ts
fetch(options): Promise<ReactiveDocument<T>>;

Defined in: packages/store/src/-private/document.ts:155

Fetches the related link for this document, returning a promise that resolves with the document when the request completes. If no related link is present, will fallback to the self link if present

Parameters

options

RequestInfo<ReactiveDocument<T>, T> = ...

Returns

Promise<ReactiveDocument<T>>


first()

ts
first(options): Promise<null | ReactiveDocument<T>>;

Defined in: packages/store/src/-private/document.ts:199

Fetches the first link for this document, returning a promise that resolves with the new document when the request completes, or null if there is no first link.

Parameters

options

RequestInfo<ReactiveDocument<T>, T>

Returns

Promise<null | ReactiveDocument<T>>


last()

ts
last(options): Promise<null | ReactiveDocument<T>>;

Defined in: packages/store/src/-private/document.ts:212

Fetches the last link for this document, returning a promise that resolves with the new document when the request completes, or null if there is no last link.

Parameters

options

RequestInfo<ReactiveDocument<T>, T>

Returns

Promise<null | ReactiveDocument<T>>


next()

ts
next(options?): Promise<null | ReactiveDocument<T>>;

Defined in: packages/store/src/-private/document.ts:173

Fetches the next link for this document, returning a promise that resolves with the new document when the request completes, or null if there is no next link.

Parameters

options?

RequestInfo<ReactiveDocument<T>, T>

Returns

Promise<null | ReactiveDocument<T>>


prev()

ts
prev(options): Promise<null | ReactiveDocument<T>>;

Defined in: packages/store/src/-private/document.ts:186

Fetches the prev link for this document, returning a promise that resolves with the new document when the request completes, or null if there is no prev link.

Parameters

options

RequestInfo<ReactiveDocument<T>, T>

Returns

Promise<null | ReactiveDocument<T>>


toJSON()

ts
toJSON(): object;

Defined in: packages/store/src/-private/document.ts:228

Implemented for JSON.stringify support.

Returns the JSON representation of the document wrapper.

This is a shallow serialization, it does not deeply serialize the document's contents, leaving that to the individual record instances to determine how to do, if at all.

Returns

object

Released under the MIT License.