Data Storage Provider

The data storage provider is responsible for loading resource data pack into DataBus from various storage systems, as well as writing data changes into these systems.


The interface, IDataStorageProvider, defines methods for loading data from the storage system and writing data changes into it.


IDataStorageProvider is the combination of two interfaces, IDataLoader and IDataSaver.


IDataLoader

The IDataLoader interface is responsible for loading resource packs from some storage system.

Methods

loadDatasheetPack

loadDatasheetPack(datasheetId: string, options: ILoadDatasheetPackOptions): Promise<IServerDatasheetPack | null>

Load a datasheet pack from some storage system given the datasheet ID. If the datasheet does not exist, null should be returned.

The implementor is free to extend the ILoadDatasheetPackOptions and add custom options fields required for the data loading.

loadDashboardPack

loadDashboardPack(dashboardId: string, options: ILoadDashboardPackOptions): Promise<IServerDashboardPack | null>

Load a dashboard pack from some storage system given the dashboard ID. If the dashboard does not exist, null should be returned.

The implementor is free to extend the ILoadDashboardPackOptions and add custom options fields required for the data loading.


IDataSaver

The IDataSaver interface is responsible for writing resource data changes resulted from either user interaction or API invocation into some storage system.

Methods

saveOps

saveOps(ops: IResourceOpsCollect[], options: ISaveOpsOptions): Promise<any> | any

Save the operations (ops) representing resource data changes into some storage system. To understand operations, see Changesets & Operations & Actions.

Example

An example implementation of the data storage provider for front-end:

export interface IDataLoader {
  /**
   * Loads a datasheet pack for a datasheet from the data source.
   *
   * The implementor can derive `ILoadDatasheetPackOptions` and add custom fields.
   * 
   * @returns If the datasheet is not found, null is returned.
   */
  loadDatasheetPack(datasheetId: string, options: ILoadDatasheetPackOptions): Promise<IServerDatasheetPack | null>;

  /**
   * Loads a dashboard pack for a dashboard from the data source.
   *
   * The implementor can derive `ILoadDataboardPackOptions` and add custom fields.
   * 
   * @returns If the dashboard is not found, null is returned.
   */
  loadDashboardPack(dashboardId: string, options: ILoadDashboardPackOptions): Promise<IServerDashboardPack | null>
}

interface IClientLoadDatasheetPackOptions extends databus.ILoadDatasheetPackOptions {
    requestToken: string
}

interface IClientLoadDashboardPackOptions extends databus.ILoadDashboardPackOptions {
    requestToken: string
}

class ClientDataStoreProvider implements databus.IDataLoader {
    async loadDatasheetPack(datasheetId, options: IClientLoadDatasheetPackOptions): Promise<IServerDatasheetPack | null> {
        const dataPack = await requestDatasheetPackFromServer(datasheetId, options.requestToken)
        return dataPack
    }
    
    async loadDashboardPack(dashboardId, options: IClientLoadDashboardPackOptions): Promise<IServerDashboardPack | null> {
        // similar to above
    }
}