forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restangular.d.ts
141 lines (127 loc) · 7.25 KB
/
restangular.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Type definitions for Restangular v1.5.0
// Project: https://github.com/mgonto/restangular
// Definitions by: Boris Yankov <https://github.com/borisyankov/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../angularjs/angular.d.ts" />
// Support AMD require (copying angular.d.ts approach)
// allows for import {IRequestConfig} from 'restangular' ES6 approach
declare module 'restangular' {
export = restangular;
}
declare namespace restangular {
interface IPromise<T> extends angular.IPromise<T> {
call(methodName: string, params?: any): IPromise<T>;
get(fieldName: string): IPromise<T>;
$object: T;
}
interface ICollectionPromise<T> extends angular.IPromise<T[]> {
push(object: any): ICollectionPromise<T>;
call(methodName: string, params?: any): ICollectionPromise<T>;
get(fieldName: string): ICollectionPromise<T>;
$object: T[];
}
interface IResponse {
status: number;
data: any;
headers(name: string): string;
config: {
method: string;
url: string;
params: any;
}
}
interface IProvider {
setBaseUrl(baseUrl: string): void;
setExtraFields(fields: string[]): void;
setParentless(parentless: boolean, routes: string[]): void;
setDefaultHttpFields(httpFields: any): void;
addElementTransformer(route: string, transformer: Function): void;
addElementTransformer(route: string, isCollection: boolean, transformer: Function): void;
setTransformOnlyServerElements(active: boolean): void;
setOnElemRestangularized(callback: (elem: any, isCollection: boolean, what: string, restangular: IService) => any): void;
setResponseInterceptor(responseInterceptor: (data: any, operation: string, what: string, url: string, response: IResponse, deferred: angular.IDeferred<any>) => any): void;
setResponseExtractor(responseInterceptor: (data: any, operation: string, what: string, url: string, response: IResponse, deferred: angular.IDeferred<any>) => any): void;
addResponseInterceptor(responseInterceptor: (data: any, operation: string, what: string, url: string, response: IResponse, deferred: angular.IDeferred<any>) => any): void;
setRequestInterceptor(requestInterceptor: (element: any, operation: string, what: string, url: string) => any): void;
addRequestInterceptor(requestInterceptor: (element: any, operation: string, what: string, url: string) => any): void;
setFullRequestInterceptor(fullRequestInterceptor: (element: any, operation: string, what: string, url: string, headers: any, params: any, httpConfig: angular.IRequestShortcutConfig) => {element: any; headers: any; params: any}): void;
addFullRequestInterceptor(requestInterceptor: (element: any, operation: string, what: string, url: string, headers: any, params: any, httpConfig: angular.IRequestShortcutConfig) => {headers: any; params: any; element: any; httpConfig: angular.IRequestShortcutConfig}): void;
setErrorInterceptor(errorInterceptor: (response: IResponse, deferred: angular.IDeferred<any>, responseHandler: (response: restangular.IResponse) => any) => any): void;
setRestangularFields(fields: {[fieldName: string]: string}): void;
setMethodOverriders(overriders: string[]): void;
setJsonp(jsonp: boolean): void;
setDefaultRequestParams(params: any): void;
setDefaultRequestParams(method: string, params: any): void;
setDefaultRequestParams(methods: string[], params: any): void;
setFullResponse(fullResponse: boolean): void;
setDefaultHeaders(headers: any): void;
setRequestSuffix(suffix: string): void;
setUseCannonicalId(useCannonicalId: boolean): void;
setEncodeIds(encode: boolean): void;
}
interface ICustom {
customGET(path: string, params?: any, headers?: any): IPromise<any>;
customGETLIST(path: string, params?: any, headers?: any): ICollectionPromise<any>;
customDELETE(path: string, params?: any, headers?: any): IPromise<any>;
customPOST(elem?: any, path?: string, params?: any, headers?: any): IPromise<any>;
customPUT(elem?: any, path?: string, params?: any, headers?: any): IPromise<any>;
customOperation(operation: string, path: string, params?: any, headers?: any, elem?: any): IPromise<any>;
addRestangularMethod(name: string, operation: string, path?: string, params?: any, headers?: any, elem?: any): IPromise<any>;
}
interface IService extends ICustom, IProvider {
one(route: string, id?: number): IElement;
one(route: string, id?: string): IElement;
oneUrl(route: string, url: string): IElement;
all(route: string): IElement;
allUrl(route: string, url: string): IElement;
copy(fromElement: any): IElement;
withConfig(configurer: (RestangularProvider: IProvider) => any): IService;
restangularizeElement(parent: any, element: any, route: string, collection?: any, reqParams?: any): IElement;
restangularizeCollection(parent: any, element: any, route: string): ICollection;
service(route: string, parent?: any): IService;
stripRestangular(element: any): any;
extendModel(route: string, extender: (model: IElement) => any): void;
extendCollection(route: string, extender: (collection: ICollection) => any): void;
}
interface IElement extends IService {
get(queryParams?: any, headers?: any): IPromise<any>;
get<T>(queryParams?: any, headers?: any): IPromise<T>;
getList(subElement?: any, queryParams?: any, headers?: any): ICollectionPromise<any>;
getList<T>(subElement?: any, queryParams?: any, headers?: any): ICollectionPromise<T>;
put(queryParams?: any, headers?: any): IPromise<any>;
post(subElement: any, elementToPost: any, queryParams?: any, headers?: any): IPromise<any>;
post<T>(subElement: any, elementToPost: T, queryParams?: any, headers?: any): IPromise<T>;
post(elementToPost: any, queryParams?: any, headers?: any): IPromise<any>;
post<T>(elementToPost: T, queryParams?: any, headers?: any): IPromise<T>;
remove(queryParams?: any, headers?: any): IPromise<any>;
head(queryParams?: any, headers?: any): IPromise<any>;
trace(queryParams?: any, headers?: any): IPromise<any>;
options(queryParams?: any, headers?: any): IPromise<any>;
patch(queryParams?: any, headers?: any): IPromise<any>;
clone(): IElement;
plain(): any;
plain<T>(): T;
withHttpConfig(httpConfig: angular.IRequestShortcutConfig): IElement;
save(queryParams?: any, headers?: any): IPromise<any>;
getRestangularUrl(): string;
route?: string;
id?: string;
reqParams?: any;
}
interface ICollection extends IService, Array<any> {
getList(queryParams?: any, headers?: any): ICollectionPromise<any>;
getList<T>(queryParams?: any, headers?: any): ICollectionPromise<T>;
post(elementToPost: any, queryParams?: any, headers?: any): IPromise<any>;
post<T>(elementToPost: T, queryParams?: any, headers?: any): IPromise<T>;
head(queryParams?: any, headers?: any): IPromise<any>;
trace(queryParams?: any, headers?: any): IPromise<any>;
options(queryParams?: any, headers?: any): IPromise<any>;
patch(queryParams?: any, headers?: any): IPromise<any>;
putElement(idx: any, params: any, headers: any): IPromise<any>;
withHttpConfig(httpConfig: angular.IRequestShortcutConfig): ICollection;
clone(): ICollection;
plain(): any;
plain<T>(): T[];
getRestangularUrl(): string;
}
}