Skip to main content
Version: 0.8.x

Class: DocumentLoader

loader.DocumentLoader

The DocumentLoader class provides APIs to batch load and cache ModelInstanceDocument streams.

It is exported by the loader module.

import { DocumentLoader } from '@composedb/loader'

Hierarchy​

  • DataLoader<LoadKey, ModelInstanceDocument, string>

    ↳ DocumentLoader

Constructors​

constructor​

• new DocumentLoader(params): DocumentLoader

Parameters​

NameType
paramsDocumentLoaderParams

Returns​

DocumentLoader

Overrides​

DataLoader&lt;LoadKey, ModelInstanceDocument, string&gt;.constructor

Methods​

_getDeterministicKey​

▸ _getDeterministicKey(meta): Promise<LoadKey>

Get or create the LoadKey for a deterministic stream.

Parameters​

NameType
metaGenesisMetadata

Returns​

Promise<LoadKey>


_loadDeterministic​

▸ _loadDeterministic<T>(meta, options?): Promise<null | ModelInstanceDocument<T>>

Load a deterministic stream and add it to the cache.

Type parameters​

NameType
Textends Record<string, unknown> = Record<string, unknown>

Parameters​

NameType
metaGenesisMetadata
optionsDeterministicLoadOptions

Returns​

Promise<null | ModelInstanceDocument<T>>


cache​

▸ cache(stream): boolean

Add a ModelInstanceDocument to the local cache, if enabled.

Parameters​

NameType
streamModelInstanceDocument<Record<string, any>>

Returns​

boolean


create​

▸ create<T>(model, content, «destructured»?): Promise<ModelInstanceDocument<T>>

Create a new ModelInstanceDocument and add it to the cache, if enabled.

Type parameters​

NameType
Textends Record<string, unknown> = Record<string, unknown>

Parameters​

NameType
modelstring | StreamID
contentT
«destructured»CreateOptions

Returns​

Promise<ModelInstanceDocument<T>>


load​

▸ load<T>(key): Promise<ModelInstanceDocument<T>>

Load a ModelInstanceDocument from the cache (if enabled) or remotely.

Type parameters​

NameType
Textends Record<string, unknown> = Record<string, unknown>

Parameters​

NameType
keyLoadKey

Returns​

Promise<ModelInstanceDocument<T>>

Overrides​

DataLoader.load


loadSet​

▸ loadSet<T>(controller, model, unique, options?): Promise<null | ModelInstanceDocument<T>>

Create or load a deterministic ModelInstanceDocument using the SET account relation and cache it.

Type parameters​

NameType
Textends Record<string, unknown> = Record<string, unknown>

Parameters​

NameType
controllerstring
modelstring | StreamID
uniquestring[]
options?DeterministicLoadOptions

Returns​

Promise<null | ModelInstanceDocument<T>>


loadSingle​

▸ loadSingle<T>(controller, model, options?): Promise<null | ModelInstanceDocument<T>>

Create or load a deterministic ModelInstanceDocument and cache it.

Type parameters​

NameType
Textends Record<string, unknown> = Record<string, unknown>

Parameters​

NameType
controllerstring
modelstring | StreamID
options?DeterministicLoadOptions

Returns​

Promise<null | ModelInstanceDocument<T>>


queryConnection​

▸ queryConnection(query): Promise<Connection<null | ModelInstanceDocument<Record<string, any>>>>

Query the index for multiple ModelInstanceDocument streams and cache the results.

Parameters​

NameType
queryConnectionQuery

Returns​

Promise<Connection<null | ModelInstanceDocument<Record<string, any>>>>


queryOne​

▸ queryOne(query): Promise<null | ModelInstanceDocument<Record<string, any>>>

Query the index for a single ModelInstanceDocument stream and cache it.

Parameters​

NameType
queryBaseQuery

Returns​

Promise<null | ModelInstanceDocument<Record<string, any>>>


update​

▸ update<T>(streamID, content, «destructured»?): Promise<ModelInstanceDocument<T>>

Update a ModelInstanceDocument after loading the stream remotely, bypassing the cache.

Type parameters​

NameType
Textends Record<string, unknown> = Record<string, unknown>

Parameters​

NameType
streamIDstring | StreamID
contentT
«destructured»UpdateOptions

Returns​

Promise<ModelInstanceDocument<T>>