PalmyraAbstractStore#
@palmyralabs/palmyra-wire · PalmyraAbstractStore (exported as AbstractStore)
Overview#
HTTP base class every Palmyra store extends. Holds the shared AxiosInstance, the baseUrl, the IEndPoint (string or per-verb MultiEndPoint), and helpers for URL formatting and query-param conversion. Installs a response interceptor that hands errors to the factory-level error handler.
Not a store on its own — you subclass it or, in practice, let the factory hand you a concrete store that already extends it.
Constructor#
new PalmyraAbstractStore(
baseUrl: string,
endPoint: IEndPoint,
options: StoreOptions,
handlerFactory?: APIErrorHandlerFactory,
)Methods#
| Method | Signature |
|---|---|
getClient |
getClient(): AxiosInstance |
getEndPoint |
getEndPoint(): IEndPoint |
getOptions |
getOptions(): Record<string, string | number> |
getTarget |
getTarget(): string — resolved base target after merging options |
queryUrl |
queryUrl(): string | undefined |
getUrl |
getUrl(): string | undefined |
postUrl |
postUrl(): string | undefined |
putUrl |
putUrl(): string | undefined |
deleteUrl |
deleteUrl(): string | undefined |
formatUrl |
formatUrl(urlFormat: string, request?: AbstractRequest): string |
isUrlValid |
isUrlValid(url: string): boolean |
handleError |
handleError(error: any, request?: AbstractRequest): Promise<never> |
convertQueryParams |
convertQueryParams(queryParams: QueryParams, limit = 15): any — maps filter/sort/page into the _offset / _limit / _orderBy / _total wire format |
Example#
Subclass only when you need verbs or headers the supplied stores don’t cover — e.g. a custom PATCH or a server action:
import { PalmyraAbstractStore } from '@palmyralabs/palmyra-wire';
class UserActionStore extends PalmyraAbstractStore {
async resetPassword(id: number): Promise<void> {
const url = this.formatUrl('/user/{id}/reset-password', { id });
await this.getClient().post(url, {});
}
}
const store = new UserActionStore('/api/palmyra', '/user/{id}', {}, errorHandlerFactory);
await store.resetPassword(42);