Skip to main content
Version: 2.0.0-alpha

Interface: DataSource

Implement this interface and pass it to a FireCMS to connect it to your data source. A Firestore implementation of this interface can be found in useFirestoreDataSource

Methods

checkUniqueField

checkUniqueField(path, name, value, property, entityId?): Promise<boolean>

Check if the given property is unique in the given collection

Parameters

NameTypeDescription
pathstringCollection path
namestringof the property
valueany
propertyResolvedStringProperty | ResolvedNumberProperty | ResolvedBooleanProperty | ResolvedReferenceProperty | ResolvedGeopointProperty | ResolvedTimestampProperty | ResolvedMapProperty<{ [Key: string]: any; }> | ResolvedArrayProperty<CMSType[], any>
entityId?string

Returns

Promise<boolean>

true if there are no other fields besides the given entity

Defined in

lib/src/models/datasource.ts:198


deleteEntity

deleteEntity<M>(entity): Promise<void>

Delete an entity

Type parameters

Name
M

Parameters

NameType
entityDeleteEntityProps<M>

Returns

Promise<void>

was the whole deletion flow successful

Defined in

lib/src/models/datasource.ts:183


fetchCollection

fetchCollection<M>(__namedParameters): Promise<Entity<M>[]>

Fetch data from a collection

see useCollectionFetch if you need this functionality implemented as a hook

Type parameters

Name
M

Parameters

NameType
__namedParametersFetchCollectionProps<M>

Returns

Promise<Entity<M>[]>

Function to cancel subscription

Defined in

lib/src/models/datasource.ts:89


fetchEntity

fetchEntity<M>(__namedParameters): Promise<undefined | Entity<M>>

Retrieve an entity given a path and a collection

Type parameters

Name
M

Parameters

NameType
__namedParametersFetchEntityProps<M>

Returns

Promise<undefined | Entity<M>>

Defined in

lib/src/models/datasource.ts:138


generateEntityId

generateEntityId(path): string

Generate an id for a new entity

Parameters

NameType
pathstring

Returns

string

Defined in

lib/src/models/datasource.ts:209


listenCollection

Optional listenCollection<M>(__namedParameters): () => void

Listen to a entities in a given path. If you don't implement this method fetchCollection will be used instead, with no real time updates.

see useCollectionFetch if you need this functionality implemented as a hook

Type parameters

Name
M

Parameters

NameType
__namedParametersListenCollectionProps<M>

Returns

fn

Function to cancel subscription

▸ (): void

Listen to a entities in a given path. If you don't implement this method fetchCollection will be used instead, with no real time updates.

see useCollectionFetch if you need this functionality implemented as a hook

Returns

void

Function to cancel subscription

Defined in

lib/src/models/datasource.ts:117


listenEntity

Optional listenEntity<M>(__namedParameters): () => void

Get realtime updates on one entity.

Type parameters

Name
M

Parameters

NameType
__namedParametersListenEntityProps<M>

Returns

fn

Function to cancel subscription

▸ (): void

Get realtime updates on one entity.

Returns

void

Function to cancel subscription

Defined in

lib/src/models/datasource.ts:154


saveEntity

saveEntity<M>(__namedParameters): Promise<Entity<M>>

Save entity to the specified path

Type parameters

Name
M

Parameters

NameType
__namedParametersSaveEntityProps<M>

Returns

Promise<Entity<M>>

Defined in

lib/src/models/datasource.ts:169