-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhyperjs.d.ts
84 lines (77 loc) · 2.62 KB
/
hyperjs.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
declare module 'hyperjs/errors/HttpError' {
export default class HttpError extends Error {
url: string;
status: number;
statusText: string;
data: any;
constructor(url: string, status: number, statusText: string, data: any);
}
}
declare module 'hyperjs/HttpClient' {
export interface RequestOptions {
method: string;
url: string;
data?: any;
headers?: any;
contentType?: string;
}
export function request(options: RequestOptions): Promise<any>;
}
declare module 'hyperjs/errors/LinkNotFoundError' {
export default class LinkNotFoundError extends Error {
rel: string;
constructor(rel: string);
}
}
declare module 'hyperjs/errors/UrlMustBeSetError' {
export default class UrlMustBeSetError extends Error {
constructor();
}
}
declare module 'hyperjs/errors/ResourceNotLoadedError' {
export default class ResourceNotLoadedError extends Error {
constructor(resourceUrl: string);
}
}
declare module 'hyperjs/TemplateParameters' {
export function setParameters(url: string, templateParameters: any, queryParameters?: any): string;
}
declare module 'hyperjs/HyperJS' {
import { RequestOptions } from 'hyperjs/HttpClient';
export interface ResourceLink {
rel: string;
href: string;
method?: string;
}
export interface Resource<TData = any> {
fetch(parameters?: any): Promise<Resource<TData>>;
data: TData;
action(rel: string, method: string, body?: any, parameters?: any): Promise<any>;
patch(body?: any, parameters?: any): Promise<any>;
post(body?: any, parameters?: any): Promise<any>;
put(body?: any, parameters?: any): Promise<any>;
delete(body?: any, parameters?: any): Promise<any>;
getLink(rel: string): ResourceLink;
hasLink(rel: string): boolean;
followLink<RType = any>(rel: string, templateParameters?: any, queryParameters?: any): Resource<RType>;
}
export interface CustomRequestOptions {
method?: string;
url?: string;
data?: string | object;
headers?: object;
contentType?: string;
}
export interface ResourceBuilder {
withSelfCallback: (callback: (data: any) => string) => ResourceBuilder;
withLinkCallback: (callback: (rel: string, data: any) => string) => ResourceBuilder;
withRequestOptions: (callback: (resource: Resource, options: RequestOptions) => CustomRequestOptions) => ResourceBuilder;
getResource<TData = any>(resourceUrl: string): Resource<TData>;
wrapResource<TData = any>(resource: TData): Resource<TData>;
}
export function builder(): ResourceBuilder;
}
declare module 'hyperjs' {
import main = require('hyperjs/HyperJS');
export = main;
}