import { DataProvider } from 'react-admin' ; import fakeServerFactory from '../fakeServer' ; export default ( type ) => { let dataProviderPromise = getDataProvider ( type ) ; const dataProviderWithGeneratedData = new Proxy ( defaultDataProvider , { get ( _ , name ) { return ( resource , params ) => { return dataProviderPromise . then ( dataProvider => { return dataProvider [ name . toString ( ) ] ( resource , params ) ; } ) ; } ; } , } ) ; return dataProviderWithGeneratedData ; } ; const getDataProvider = async ( type ) : Promise < DataProvider > => { await fakeServerFactory ( process . env . REACT_APP_DATA_PROVIDER || '' ) ; /**
     * This demo can work with either a fake REST server, or a fake GraphQL server.
     *
     * To avoid bundling both libraries, the dataProvider and fake server factories
     * use the import() function, so they are asynchronous.
     */ if ( type === 'graphql' ) { return import ( './graphql' ) . then ( factory => factory . default ( ) ) ; } return import ( './rest' ) . then ( provider => provider . default ) ; } ; const defaultDataProvider = { create : ( ) => Promise . resolve ( { data : { id : 0 } } ) , delete : ( ) => Promise . resolve ( { data : { } } ) , deleteMany : ( ) => Promise . resolve ( { } ) , getList : ( ) => Promise . resolve ( { data : [ ] , total : 0 } ) , getMany : ( ) => Promise . resolve ( { data : [ ] } ) , getManyReference : ( ) => Promise . resolve ( { data : [ ] , total : 0 } ) , getOne : ( ) => Promise . resolve ( { data : { } } ) , update : ( ) => Promise . resolve ( { data : { } } ) , updateMany : ( ) => Promise . resolve ( { } ) , } ;