ketting
Version:
Opinionated HATEOAS / Rest client.
43 lines (42 loc) • 1.17 kB
TypeScript
import { BaseState } from './base-state.js';
import Client from '../client.js';
/**
* Turns a HTTP response into a JsonApiState
*/
export declare const factory: (client: Client, uri: string, response: Response) => Promise<BaseState<JsonApiTopLevelObject>>;
/**
* A JSON:API link can either be a string, or an object with at least a href
* property.
*/
type JsonApiLink = string | {
href: string;
};
/**
* This type is a full 'links' object, which might appear on the top level
* or on resource objects.
*/
type JsonApiLinksObject = {
self?: JsonApiLink;
profile?: JsonApiLink;
[rel: string]: JsonApiLink | JsonApiLink[] | undefined;
};
/**
* This is a single JSON:API resource. Its type contains just the properties
* we care about.
*/
type JsonApiResource = {
type: string;
id: string;
links?: JsonApiLinksObject;
};
/**
* This type represents a valid JSON:API response. We're only interested
* in the links object at the moment, so everything else is (for now)
* untyped.
*/
type JsonApiTopLevelObject = {
links?: JsonApiLinksObject;
data: JsonApiResource | JsonApiResource[] | null;
[s: string]: any;
};
export {};