haystack-nclient
Version:
Project Haystack Network Client
34 lines (33 loc) • 1.3 kB
TypeScript
import { HVal } from 'haystack-core';
export declare const HS_ACCEPT_HEADER_VALUE = "text/zinc,application/vnd.haystack+json";
export interface FetchMethod {
(resource: RequestInfo, options?: RequestInit | undefined): Promise<Response>;
}
/**
* Validate the HTTP response object.
*
* @param resp The response to validate.
* @param val The associated value.
* @throws Error if the response is invalid.
*/
export declare function validateResponse(resp: Response, val?: unknown): void;
/**
* Make some haystack value options.
*
* @param options The fetch options.
* @returns The updated fetch optons.
*/
export declare function makeHsOptions(options?: RequestInit): RequestInit;
/**
* Convience method to fetch a haystack value from the server.
*
* If the returned value is a grid and has an error then the returned promise
* will be rejected with a `GridError` instance.
*
* @param resource The resource to request.
* @param options Optional object containing any custom settings.
* @param fetchFunc Optional fetch function to use instead of global fetch.
* @returns A promise that resolves to a value.
* @throws A fetch or grid error.
*/
export declare function fetchVal<T extends HVal>(resource: RequestInfo, options?: RequestInit, fetchFunc?: FetchMethod): Promise<T>;