rest-client-sdk
Version:
Rest Client SDK for API
78 lines (77 loc) • 4.51 kB
TypeScript
import URI from 'urijs';
import type ClassMetadata from '../Mapping/ClassMetadata';
import type RestClientSdk from '../RestClientSdk';
import type { MetadataDefinition, SdkMetadata } from '../RestClientSdk';
import type SerializerInterface from '../serializer/SerializerInterface';
declare class AbstractClient<D extends MetadataDefinition> {
#private;
sdk: RestClientSdk<SdkMetadata>;
serializer: SerializerInterface;
metadata: ClassMetadata;
constructor(sdk: RestClientSdk<SdkMetadata>, metadata: ClassMetadata, isUnitOfWorkEnabled?: boolean);
withUnitOfWork(enabled: boolean): AbstractClient<D>;
getDefaultParameters(): Record<string, unknown>;
getPathBase(pathParameters: Record<string, unknown>): string;
getEntityURI(entity: D['entity']): string;
/**
* get an entity by its id
*
* @param {string|number} id the entity identifier
* @param {Record<string, unknown>} queryParam query parameters that will be added to the request
* @param {Record<string, unknown>} pathParameters path parameters, will be pass to the `getPathBase` method
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call
*/
find(id: string | number, queryParam?: Record<string, unknown>, pathParameters?: Record<string, unknown>, requestParams?: Record<string, unknown>): Promise<D['entity']>;
/**
* get a list of entities by some parameters
*
* @param {Record<string, unknown>} queryParam query parameters that will be added to the request
* @param {Record<string, unknown>} pathParameters path parameters, will be pass to the `getPathBase` method
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call
*/
findBy(queryParam: Record<string, unknown>, pathParameters?: Record<string, unknown>, requestParams?: Record<string, unknown>): Promise<D['list']>;
/**
* get a list of all entities
*
* @param {Record<string, unknown>} queryParam query parameters that will be added to the request
* @param {Record<string, unknown>} pathParameters path parameters, will be pass to the `getPathBase` method
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call
*/
findAll(queryParam?: Record<string, unknown>, pathParameters?: Record<string, unknown>, requestParams?: Record<string, unknown>): Promise<D['list']>;
/**
* create an entity
*
* @param {Record<string, unknown>} entity the entity to persist
* @param {Record<string, unknown>} queryParam query parameters that will be added to the request
* @param {Record<string, unknown>} pathParameters path parameters, will be pass to the `getPathBase` method
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call
*/
create(entity: D['entity'], queryParam?: Record<string, unknown>, pathParameters?: Record<string, unknown>, requestParams?: Record<string, unknown>): Promise<D['entity']>;
/**
* update an entity
*
* @param {Record<string, unknown>} entity the entity to update
* @param {Record<string, unknown>} queryParam query parameters that will be added to the request
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call
*/
update(entity: D['entity'], queryParam?: Record<string, unknown>, requestParams?: Record<string, unknown>): Promise<D['entity']>;
/**
* delete an entity
*
* @param {Record<string, unknown>} the entity to delete
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call
*/
delete(entity: D['entity'], requestParams?: {}): Promise<Response>;
deserializeResponse(requestPromise: Promise<Response>, listOrItem: 'list'): Promise<D['list']>;
deserializeResponse(requestPromise: Promise<Response>, listOrItem: 'item'): Promise<D['entity']>;
makeUri(input: string | URI): URI;
authorizedFetch(input: string | URI, requestParams?: {}): Promise<Response>;
private _generateUrlFromParams;
private _fetchWithToken;
private _refreshTokenAndRefetch;
private _manageUnauthorized;
private _doFetch;
private _getEntityIdentifier;
private _handleRefreshTokenFailure;
}
export default AbstractClient;