Skip to main content
Version: Codegen-V1.0.0

FrostDelegate

@frost-orm/frost-web-client / Exports / FrostDelegate

Class: FrostDelegate<T>

Type parameters​

NameType
Textends ModelTypes = ModelTypes

Table of contents​

Constructors​

Methods​

Constructors​

constructor​

• new FrostDelegate<T>(firebaseDB)

Type parameters​

NameType
Textends ModelTypes = ModelTypes

Parameters​

NameType
firebaseDBDatabase

Methods​

add​

▸ add(object, connect?): Promise<{ id: string }>

inserts the new object with the new key from the push function or the key that was passed down with the object instance. also connects the instance depending on the connect parameter

caution

Warning: Changes to nested instances won't be applied

See

ConnectOptions.

Parameters​

NameTypeDescription
objectT["Model"]The object instance containing the new changes
connect?T["ConnectOptions"]see ConnectOptions.

Returns​

Promise<{ id: string }>

an object containing the update map and the new node id


delete​

▸ delete(object, disconnect?): Promise<void>

Removes the Object from the database and disconnects related objects depending on the disconnect parameter

See

Parameters​

NameTypeDescription
objectFrostObjecteither the whole model or just a map with the id (ie; {id: "..."})
disconnect?T["DisconnectOptions"]see DisconnectOptions.

Returns​

Promise<void>


findMany​

▸ findMany<I>(options, ...queryConstraints): Promise<FetchReturnType<T, I>[]>

Just like the query function in the firebaseDB, but the first parameter is options for relations then is spread parameter like query

Just like observeMany but with promises instead of observables.

See

Type parameters​

NameType
Iextends Partial<Record<string, boolean>>

Parameters​

NameTypeDescription
optionsObjectoptions for the query
options.include?Isee IncludeOptions.
...queryConstraintsQueryConstraint[]see QueryConstraint.

Returns​

Promise<FetchReturnType<T, I>[]>

the query results with related objects that were given in the include parameter


findMultiple​

▸ findMultiple<I, K>(keys, options?): Promise<Record<ArrayValuesType<K>, FetchReturnType<T, I>>>

Fetch Multiple Nodes in the Database.

Just like findOne but with an array of ids instead of one Just like observeMultiple but asynchronous(promise) instead of reactive.

See

Type parameters​

NameType
Iextends Partial<Record<string, boolean>>
Kextends string[]

Parameters​

NameTypeDescription
keysKan array of the instances' IDs that you want to observe
options?Objectoptions for the query
options.include?Isee IncludeOptions.

Returns​

Promise<Record<ArrayValuesType<K>, FetchReturnType<T, I>>>

a Map of the requested nodes instances


findOne​

▸ findOne<I>(id, include?): Promise<FetchReturnType<T, I>>

Returns the object with the given id and containing the related instances with it (depending on the include parameter)

Just like observeOne but with promises instead of observables

See

Type parameters​

NameType
Iextends Partial<Record<string, boolean>>

Parameters​

NameTypeDescription
idstringThe object that you want to get the related objects from. (doesn't have to be an instantiated object could be the data map that was fetched manually )
include?T["IncludeOptions"]see IncludeOptions.

Returns​

Promise<FetchReturnType<T, I>>

the object instance of the given id with related objects that were given in the include parameter


getAddMap​

▸ getAddMap(object, connect?): Promise<{ id: string ; map: any }>

Returns a map containing the updates to the database that could be passed to firebaseDB update function. Also the map contains the new object with the new key from the push function or the key that was passed down with the object instance. also connects the instance depending on the connect parameter.

caution

Warning: Changes to nested instances won't be applied

See

ConnectOptions.

Parameters​

NameTypeDescription
objectT["Model"]The object instance containing the new changes
connect?T["ConnectOptions"]see ConnectOptions.

Returns​

Promise<{ id: string ; map: any }>

an object containing the update map and the new node id


getAllConnectedKeys​

▸ getAllConnectedKeys(object): Record<string, string[]>

It fetches the connected instances keys of all relations

caution
This function will return the keys depending on the metadata inside the `object` param. if the metadata is not updated to the latest version then it won't return the updated keys

if you want to the latest connected instances then you should refetch the data

Parameters​

NameTypeDescription
objectT["FullModel"]the object instance that you want to get the keys from

Returns​

Record<string, string[]>

a map of property keys and corresponding array containing the ids of the instances that are connected. if there are no connected keys or the property name is incorrect then there'll be no key-value pair for the specific property


getConnectedKeys​

▸ getConnectedKeys(propertyName, object): string[]

It fetches the connected instances keys by property name

caution
This function will return the keys depending on the metadata inside the `object` param. if the metadata is not updated to the latest version then it won't return the updated keys

if you want to the latest connected instances then you should refetch the data

Parameters​

NameTypeDescription
propertyNameT["RelationsFieldsKeys"]the name of the property with the relation which keys' you require.
objectT["FullModel"]the object instance that you want to get the keys from

Returns​

string[]

an array containing the ids of the instances that are connected. if there are no connected keys or the property name is incorrect then there'll be no key-value pair for the specific property


getDeleteMap​

▸ getDeleteMap(object, disconnect?): Promise<{ map: any }>

Returns a map of the updates that could be passed to the updated function from firebaseDB if the map is applied it removes the Object from the database and disconnects related objects depending on the disconnect parameter

See

DisconnectOptions

Parameters​

NameTypeDescription
objectFrostObjecteither the whole model or just a map with the id (ie; {id: "..."})
disconnect?T["DisconnectOptions"]see DisconnectOptions

Returns​

Promise<{ map: any }>

an object containing the update map


getRelated​

▸ getRelated<I>(object, include?): Promise<FetchReturnType<T, I>>

Returns the object with the related instances with it (depending on the include parameter) Use this if you have an object instance without the related instances you want.

Same as getRelatedObservable but with promises instead of observables

caution
This function will fetch the connected instances depending on the metadata inside the `object` param. if the metadata is not updated to the latest version then it won't (not)fetch any new (dis)connected instances

if you want to the latest connected instances then you should refetch the data

See

Type parameters​

NameType
Iextends Partial<Record<string, boolean>>

Parameters​

NameTypeDescription
objectT["ModelWithMetadata"]The object that you want to get the related objects from. (doesn't have to be an instantiated object could be the data map that was fetched manually )
include?T["IncludeOptions"]see IncludeOptions.

Returns​

Promise<FetchReturnType<T, I>>

an object instance with related objects that were given in the include parameter


getRelatedObservable​

▸ getRelatedObservable<I>(object, include?, listenToNestedChanges?): Observable<FetchReturnType<T, I>>

Returns an observable of the object with the related instances with it (depending on the include parameter) Use this if you have an object instance without the related instances you want.

See

caution
This function will fetch the connected instances depending on the metadata inside the `object` param. if the metadata is not updated to the latest version then it won't (not)fetch any new (dis)connected instances

if you want to the latest connected instances then you should refetch the data

Type parameters​

NameType
Iextends Partial<Record<string, boolean>>

Parameters​

NameTypeDescription
objectT["ModelWithMetadata"]The object that you want to get the related objects from. (doesn't have to be an instantiated object could be the data map that was fetched manually )
include?T["IncludeOptions"]see IncludeOptions.
listenToNestedChanges?ListenToNestedChangessee ListenToNestedChanges.

Returns​

Observable<FetchReturnType<T, I>>

an Observable of the object instance with related objects that were given in the include parameter


getUpdateMap​

▸ getUpdateMap(object, connect?, disconnect?): Promise<{ map: any }>

Returns a map containing the updates that could be passed to firebaseDB update function

caution

Warning: Changes to nested instances won't be applied

See

Parameters​

NameTypeDescription
objectPartial<T["Model"]>The object instance containing the new changes
connect?T["ConnectOptions"]see ConnectOptions.
disconnect?T["DisconnectOptions"]see DisconnectOptions.

Returns​

Promise<{ map: any }>

an object containing the update map


observeMany​

▸ observeMany<I>(options?, ...queryConstraints): Observable<Record<string, FetchReturnType<T, I>>>

Just like the query function in the firebaseDB, but with observables, also the first parameter is options for the observable then is spread parameter like query

See

Default Value

options.debounceDuration 500

Default Value

options.listenToNestedChanges false

Type parameters​

NameType
Iextends Partial<Record<string, boolean>>

Parameters​

NameTypeDescription
options?Objectoptions for the observable
options.debounceDuration?numberin Milliseconds. incase multiple changes happen to the query in short time, this will prevent the observable to emit too many times
options.include?Isee IncludeOptions.
options.listenToNestedChanges?ListenToNestedChangessee ListenToNestedChanges.
...queryConstraintsQueryConstraint[]see QueryConstraint.

Returns​

Observable<Record<string, FetchReturnType<T, I>>>

an Observable of the query results with related objects that were given in the include parameter


observeManyOld​

▸ observeManyOld<I>(options?, ...queryConstraints): Observable<FetchReturnType<T, I>[]>

Just like the query function in the firebaseDB, but with observables, also the first parameter is options for the observable then is spread parameter like query

See

Default Value

options.debounceDuration 500

Default Value

options.listenToNestedChanges false

Type parameters​

NameType
Iextends Partial<Record<string, boolean>>

Parameters​

NameTypeDescription
options?Objectoptions for the observable
options.debounceDuration?numberin Milliseconds. incase multiple changes happen to the query in short time, this will prevent the observable to emit too many times
options.include?T["IncludeOptions"]see IncludeOptions.
options.listenToNestedChanges?ListenToNestedChangessee ListenToNestedChanges.
...queryConstraintsQueryConstraint[]see QueryConstraint.

Returns​

Observable<FetchReturnType<T, I>[]>

an Observable of the query results with related objects that were given in the include parameter


observeMultiple​

▸ observeMultiple<I, K>(keys, options?): Observable<Record<ArrayValuesType<K>, FetchReturnType<T, I>>>

Observe Multiple Nodes in the Database.

Just like observeOne but with an array of ids instead of one Just like findMultiple but reactive.

See

Default Value

listenToNestedChanges false

Type parameters​

NameType
Iextends Partial<Record<string, boolean>>
Kextends string[]

Parameters​

NameTypeDescription
keysKan array of the instances' IDs that you want to observe
options?Objectoptions for the query
options.include?Isee IncludeOptions.
options.listenToNestedChangesListenToNestedChangessee ListenToNestedChanges.

Returns​

Observable<Record<ArrayValuesType<K>, FetchReturnType<T, I>>>

a Map of the requested nodes instances


observeOne​

▸ observeOne<I>(id, include?, listenToNestedChanges?): Observable<FetchReturnType<T, I>>

Returns an observable of the object with the given id and containing the related instances with it (depending on the include parameter)

See

Default Value

listenToNestedChanges false

Type parameters​

NameType
Iextends Partial<Record<string, boolean>>

Parameters​

NameTypeDefault valueDescription
idstringundefinedThe object that you want to get the related objects from. (doesn't have to be an instantiated object could be the data map that was fetched manually )
include?Iundefinedsee IncludeOptions.
listenToNestedChangesListenToNestedChangesfalsesee ListenToNestedChanges.

Returns​

Observable<FetchReturnType<T, I>>

an Observable of the object instance of the given id with related objects that were given in the include parameter


update​

▸ update(object, connect?, disconnect?): Promise<void>

preforms the updates on the object instance and dis/connects relations depending on the options

caution

Warning: Changes to nested instances won't be applied

See

Parameters​

NameTypeDescription
objectPartial<T["Model"]> & Required<FrostObject>The object instance containing the new changes
connect?T["ConnectOptions"]see ConnectOptions.
disconnect?T["DisconnectOptions"]see DisconnectOptions.

Returns​

Promise<void>