import { BotonicEvent , User } from '@botonic/core' ; import { DynamoDBDataProvider } from './dynamodb-data-provider' ; import { LocalDevDataProvider } from './local-data-provider' ; export const dataProviderProtocols = { DYNAMO_DB : 'dynamodb' , FILE : 'file' , } ; export interface DataProvider { getUsers ( limit ? , offset ? ) : User [ ] | Promise < User [ ] > ; getUser ( id ) : User | Promise < User | undefined > | undefined ; getUserByWebsocketId ( websocketId ) : User | Promise < User | undefined > | undefined ; getUserByField ( field , value ) : User | Promise < User | undefined > | undefined ; saveUser ( user ) : User | Promise < User > ; updateUser ( user ) : User | Promise < User > ; deleteUser ( id ) : User | Promise < User | undefined > | undefined ; getEvents ( limit ? , offset ? ) : BotonicEvent [ ] | Promise < BotonicEvent [ ] > ; getEvent ( id ) : BotonicEvent | Promise < BotonicEvent | undefined > | undefined ; saveEvent ( event ) : BotonicEvent | Promise < BotonicEvent > ; updateEvent ( event ) : BotonicEvent | Promise < BotonicEvent > ; deleteEvent ( id ) : BotonicEvent | Promise < BotonicEvent | undefined > | undefined ; } /** URL examples:
 * dynamodb://my-table.my-region.aws.com
 * postgresql://my-database.my-db-provider.com
 * file://path/to/local/db.json
 */ export function dataProviderFactory ( url ? ) { if ( ! url ) { return new LocalDevDataProvider ( ) ; } const protocol = url . split ( '://' ) [ 0 ] ; switch ( protocol ) { case dataProviderProtocols . DYNAMO_DB : return new DynamoDBDataProvider ( url ) ; case dataProviderProtocols . FILE : return new LocalDevDataProvider ( url ) ; default : console . error ( `Protocol ${ protocol } not implemented, using local DB instead.` ) ; return new LocalDevDataProvider ( ) ; } }