import { Entity, EntitySchema, EntitySchemaResolver, EntityStatus, EntityValues } from "./entities"; import { FilterValues } from "./collections"; import { Property } from "./properties"; /** * @category Datasource */ export interface FetchEntityProps { path: string; entityId: string; schema: EntitySchema | EntitySchemaResolver; } /** * @category Datasource */ export declare type ListenEntityProps = FetchEntityProps & { onUpdate: (entity: Entity) => void; onError?: (error: Error) => void; }; /** * @category Datasource */ export interface FetchCollectionProps { path: string; schema: EntitySchema | EntitySchemaResolver; filter?: FilterValues; limit?: number; startAfter?: any[]; orderBy?: string; searchString?: string; order?: "desc" | "asc"; } /** * @category Datasource */ export declare type ListenCollectionProps = FetchCollectionProps & { onUpdate: (entities: Entity[]) => void; onError?: (error: Error) => void; }; /** * @category Datasource */ export interface SaveEntityProps { path: string; values: Partial>; entityId?: string; previousValues?: Partial>; schema: EntitySchema | EntitySchemaResolver; status: EntityStatus; } /** * @category Datasource */ export interface DeleteEntityProps { entity: Entity; } /** * Implement this interface and pass it to a {@link FireCMS} * to connect it to your data source. * A Firestore implementation of this interface can be found in {@link useFirestoreDataSource} * @category Datasource */ export interface DataSource { /** * Fetch data from a collection * @param path * @param schema * @param filter * @param limit * @param startAfter * @param orderBy * @param order * @param searchString * @return Function to cancel subscription * @see useCollectionFetch if you need this functionality implemented as a hook */ fetchCollection({ path, schema, filter, limit, startAfter, orderBy, order, searchString }: FetchCollectionProps): Promise[]>; /** * 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. * @param path * @param schema * @param onUpdate * @param onError * @param filter * @param limit * @param startAfter * @param orderBy * @param order * @param searchString * @return Function to cancel subscription * @see useCollectionFetch if you need this functionality implemented as a hook */ listenCollection?({ path, schema, filter, limit, startAfter, searchString, orderBy, order, onUpdate, onError }: ListenCollectionProps): () => void; /** * Retrieve an entity given a path and a schema * @param path * @param entityId * @param schema */ fetchEntity({ path, entityId, schema }: FetchEntityProps): Promise>; /** * Get realtime updates on one entity. * @param path * @param entityId * @param schema * @param onUpdate * @param onError * @return Function to cancel subscription */ listenEntity?({ path, entityId, schema, onUpdate, onError }: ListenEntityProps): () => void; /** * Save entity to the specified path * @param path * @param id * @param schema * @param status */ saveEntity({ path, entityId, values, schema, status }: SaveEntityProps): Promise>; /** * Delete an entity * @param entity * @param schemaResolver * @return was the whole deletion flow successful */ deleteEntity({ entity }: DeleteEntityProps): Promise; /** * Check if the given property is unique in the given collection * @param path Collection path * @param name of the property * @param value * @param property * @param entityId * @return `true` if there are no other fields besides the given entity */ checkUniqueField(path: string, name: string, value: any, property: Property, entityId?: string): Promise; }