FrostDelegate
@frost-orm/frost-web-client / Exports / FrostDelegate
Class: FrostDelegate<T>
Type parameters
Name | Type |
---|---|
T | extends ModelTypes = ModelTypes |
Table of contents
Constructors
Methods
- add
- delete
- findMany
- findMultiple
- findOne
- getAddMap
- getAllConnectedKeys
- getConnectedKeys
- getDeleteMap
- getRelated
- getRelatedObservable
- getUpdateMap
- observeMany
- observeManyOld
- observeMultiple
- observeOne
- update
Constructors
constructor
• new FrostDelegate<T
>(firebaseDB
)
Type parameters
Name | Type |
---|---|
T | extends ModelTypes = ModelTypes |
Parameters
Name | Type |
---|---|
firebaseDB | Database |
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
Warning: Changes to nested instances won't be applied
See
Parameters
Name | Type | Description |
---|---|---|
object | T ["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
Name | Type | Description |
---|---|---|
object | FrostObject | either 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
Name | Type |
---|---|
I | extends Partial <Record <string , boolean >> |
Parameters
Name | Type | Description |
---|---|---|
options | Object | options for the query |
options.include? | I | see IncludeOptions. |
...queryConstraints | QueryConstraint [] | 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
Name | Type |
---|---|
I | extends Partial <Record <string , boolean >> |
K | extends string [] |
Parameters
Name | Type | Description |
---|---|---|
keys | K | an array of the instances' IDs that you want to observe |
options? | Object | options for the query |
options.include? | I | see 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
Name | Type |
---|---|
I | extends Partial <Record <string , boolean >> |
Parameters
Name | Type | Description |
---|---|---|
id | string | 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
>>
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.
Warning: Changes to nested instances won't be applied
See
Parameters
Name | Type | Description |
---|---|---|
object | T ["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
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
Name | Type | Description |
---|---|---|
object | T ["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
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
Name | Type | Description |
---|---|---|
propertyName | T ["RelationsFieldsKeys" ] | the name of the property with the relation which keys' you require. |
object | T ["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
Parameters
Name | Type | Description |
---|---|---|
object | FrostObject | either 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
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
Name | Type |
---|---|
I | extends Partial <Record <string , boolean >> |
Parameters
Name | Type | Description |
---|---|---|
object | T ["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
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
Name | Type |
---|---|
I | extends Partial <Record <string , boolean >> |
Parameters
Name | Type | Description |
---|---|---|
object | T ["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? | ListenToNestedChanges | see 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
Warning: Changes to nested instances won't be applied
See
Parameters
Name | Type | Description |
---|---|---|
object | Partial <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
Name | Type |
---|---|
I | extends Partial <Record <string , boolean >> |
Parameters
Name | Type | Description |
---|---|---|
options? | Object | options for the observable |
options.debounceDuration? | number | in Milliseconds. incase multiple changes happen to the query in short time, this will prevent the observable to emit too many times |
options.include? | I | see IncludeOptions. |
options.listenToNestedChanges? | ListenToNestedChanges | see ListenToNestedChanges. |
...queryConstraints | QueryConstraint [] | 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
Name | Type |
---|---|
I | extends Partial <Record <string , boolean >> |
Parameters
Name | Type | Description |
---|---|---|
options? | Object | options for the observable |
options.debounceDuration? | number | in 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? | ListenToNestedChanges | see ListenToNestedChanges. |
...queryConstraints | QueryConstraint [] | 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
Name | Type |
---|---|
I | extends Partial <Record <string , boolean >> |
K | extends string [] |
Parameters
Name | Type | Description |
---|---|---|
keys | K | an array of the instances' IDs that you want to observe |
options? | Object | options for the query |
options.include? | I | see IncludeOptions. |
options.listenToNestedChanges | ListenToNestedChanges | see 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
Name | Type |
---|---|
I | extends Partial <Record <string , boolean >> |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
id | string | undefined | 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? | I | undefined | see IncludeOptions. |
listenToNestedChanges | ListenToNestedChanges | false | see 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
Warning: Changes to nested instances won't be applied
See
Parameters
Name | Type | Description |
---|---|---|
object | Partial <T ["Model" ]> & Required <FrostObject > | The object instance containing the new changes |
connect? | T ["ConnectOptions" ] | see ConnectOptions. |
disconnect? | T ["DisconnectOptions" ] | see DisconnectOptions. |
Returns
Promise
<void
>