@magicbell/core
Version:
Official MagicBell API wrapper
36 lines (35 loc) • 1.21 kB
TypeScript
import IReader from './IReader.js';
import IWriter from './IWriter.js';
/**
* Class to represent a client that interacts with the MagicBell API.
*
* @example
* class NotificationRepo extends RemoteRepository<Notification> {}
*/
export default abstract class RemoteRepository<RemoteType, CreationType = RemoteType> implements IReader<RemoteType>, IWriter<CreationType> {
remotePathOrUrl: string;
constructor(remotePathOrUrl: string);
/**
* Get an element from the API server by ID.
*
* @example
* const notification = await repo.get('3df592eb-5f09dd6b');
*/
get(id: string | number): Promise<RemoteType>;
/**
* Get elements that match params from the API server.
*
* @example
* const notifications = await repo.findBy({ unread: true });
*/
findBy(queryParams: any): Promise<RemoteType[]>;
create(item: CreationType): Promise<CreationType>;
update(id: string | number, item: CreationType): Promise<CreationType>;
/**
* Delete an element by ID from the API server.
*
* @example
* const deleted = await repo.delete('3df592eb-5f09dd6b');
*/
delete(id: string | number): Promise<boolean>;
}