@symanticreative/vendure-admin-client
Version:
A TypeScript GraphQL client for Vendure Admin API to create custom dashboards
121 lines (120 loc) • 4.38 kB
TypeScript
import { GraphQLClientService } from '../core/graphql/graphql-client.service';
import { IRepository, IPaginatedRepository, PaginationOptions, PaginatedResult } from '../core/interfaces/repository.interface';
/**
* Base repository implementation for GraphQL operations
* Implements common repository methods
*/
export declare abstract class BaseRepository<T, ID> implements IRepository<T, ID> {
protected graphqlClient: GraphQLClientService;
constructor(graphqlClient: GraphQLClientService);
/**
* Abstract method to be implemented by concrete repositories
* Gets the GraphQL query for finding by ID
*/
protected abstract getFindByIdQuery(): string;
/**
* Abstract method to be implemented by concrete repositories
* Gets the GraphQL query for finding all
*/
protected abstract getFindAllQuery(): string;
/**
* Abstract method to be implemented by concrete repositories
* Gets the GraphQL mutation for creating
*/
protected abstract getCreateMutation(): string;
/**
* Abstract method to be implemented by concrete repositories
* Gets the GraphQL mutation for updating
*/
protected abstract getUpdateMutation(): string;
/**
* Abstract method to be implemented by concrete repositories
* Gets the GraphQL mutation for deleting
*/
protected abstract getDeleteMutation(): string;
/**
* Abstract method to be implemented by concrete repositories
* Gets the result path for finding by ID
*/
protected abstract getFindByIdResultPath(): string;
/**
* Abstract method to be implemented by concrete repositories
* Gets the result path for finding all
*/
protected abstract getFindAllResultPath(): string;
/**
* Abstract method to be implemented by concrete repositories
* Gets the result path for creating
*/
protected abstract getCreateResultPath(): string;
/**
* Abstract method to be implemented by concrete repositories
* Gets the result path for updating
*/
protected abstract getUpdateResultPath(): string;
/**
* Abstract method to be implemented by concrete repositories
* Gets the result path for deleting
*/
protected abstract getDeleteResultPath(): string;
/**
* Find entity by ID
* @param id - Entity identifier
* @returns Promise resolving to the entity
*/
findById(id: ID): Promise<T>;
/**
* Find all entities with optional filtering
* @param filter - Optional filter criteria
* @returns Promise resolving to array of entities
*/
findAll(filter?: Record<string, any>): Promise<T[]>;
/**
* Create a new entity
* @param entity - Entity data
* @returns Promise resolving to created entity
*/
create(entity: Partial<T>): Promise<T>;
/**
* Update an existing entity
* @param id - Entity identifier
* @param entity - Updated entity data
* @returns Promise resolving to updated entity
*/
update(id: ID, entity: Partial<T>): Promise<T>;
/**
* Delete an entity
* @param id - Entity identifier
* @returns Promise resolving to boolean indicating success
*/
delete(id: ID): Promise<boolean>;
/**
* Helper method to get result by path
* @param result - GraphQL result
* @param path - Path to result in the object
* @returns Extracted result
*/
protected getResultByPath(result: any, path: string): any;
}
/**
* Base paginated repository implementation
* Extends base repository with pagination capabilities
*/
export declare abstract class BasePaginatedRepository<T, ID> extends BaseRepository<T, ID> implements IPaginatedRepository<T, ID> {
/**
* Abstract method to be implemented by concrete repositories
* Gets the GraphQL query for paginated results
*/
protected abstract getFindWithPaginationQuery(): string;
/**
* Abstract method to be implemented by concrete repositories
* Gets the result path for paginated results
*/
protected abstract getFindWithPaginationResultPath(): string;
/**
* Find entities with pagination
* @param options - Pagination options
* @returns Promise resolving to paginated result
*/
findWithPagination(options: PaginationOptions): Promise<PaginatedResult<T>>;
}