Matteo Scandolo | 5461a7c | 2017-08-08 13:05:24 -0700 | [diff] [blame^] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | fc4b37b | 2017-02-02 12:18:47 -0800 | [diff] [blame] | 19 | // Generated by typings |
| 20 | // Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/19854af46f2bcd37cf416341ce74ef03ab1717b9/angularjs/angular-resource.d.ts |
| 21 | declare module 'angular-resource' { |
| 22 | var _: string; |
| 23 | export = _; |
| 24 | } |
| 25 | |
| 26 | /////////////////////////////////////////////////////////////////////////////// |
| 27 | // ngResource module (angular-resource.js) |
| 28 | /////////////////////////////////////////////////////////////////////////////// |
| 29 | declare namespace angular.resource { |
| 30 | |
| 31 | /** |
| 32 | * Currently supported options for the $resource factory options argument. |
| 33 | */ |
| 34 | interface IResourceOptions { |
| 35 | /** |
| 36 | * If true then the trailing slashes from any calculated URL will be stripped (defaults to true) |
| 37 | */ |
| 38 | stripTrailingSlashes?: boolean; |
| 39 | /** |
| 40 | * If true, the request made by a "non-instance" call will be cancelled (if not already completed) by calling |
| 41 | * $cancelRequest() on the call's return value. This can be overwritten per action. (Defaults to false.) |
| 42 | */ |
| 43 | cancellable?: boolean; |
| 44 | } |
| 45 | |
| 46 | |
| 47 | /////////////////////////////////////////////////////////////////////////// |
| 48 | // ResourceService |
| 49 | // see http://docs.angularjs.org/api/ngResource.$resource |
| 50 | // Most part of the following definitions were achieved by analyzing the |
| 51 | // actual implementation, since the documentation doesn't seem to cover |
| 52 | // that deeply. |
| 53 | /////////////////////////////////////////////////////////////////////////// |
| 54 | interface IResourceService { |
| 55 | (url: string, paramDefaults?: any, |
| 56 | /** example: {update: { method: 'PUT' }, delete: deleteDescriptor } |
| 57 | where deleteDescriptor : IActionDescriptor */ |
| 58 | actions?: IActionHash, options?: IResourceOptions): IResourceClass<IResource<any>>; |
| 59 | <T, U>(url: string, paramDefaults?: any, |
| 60 | /** example: {update: { method: 'PUT' }, delete: deleteDescriptor } |
| 61 | where deleteDescriptor : IActionDescriptor */ |
| 62 | actions?: IActionHash, options?: IResourceOptions): U; |
| 63 | <T>(url: string, paramDefaults?: any, |
| 64 | /** example: {update: { method: 'PUT' }, delete: deleteDescriptor } |
| 65 | where deleteDescriptor : IActionDescriptor */ |
| 66 | actions?: IActionHash, options?: IResourceOptions): IResourceClass<T>; |
| 67 | } |
| 68 | |
| 69 | // Hash of action descriptors allows custom action names |
| 70 | interface IActionHash { |
| 71 | [action: string]: IActionDescriptor |
| 72 | } |
| 73 | |
| 74 | // Just a reference to facilitate describing new actions |
| 75 | interface IActionDescriptor { |
| 76 | method: string; |
| 77 | params?: any; |
| 78 | url?: string; |
| 79 | isArray?: boolean; |
| 80 | transformRequest?: angular.IHttpRequestTransformer | angular.IHttpRequestTransformer[]; |
| 81 | transformResponse?: angular.IHttpResponseTransformer | angular.IHttpResponseTransformer[]; |
| 82 | headers?: any; |
| 83 | cache?: boolean | angular.ICacheObject; |
| 84 | /** |
| 85 | * Note: In contrast to $http.config, promises are not supported in $resource, because the same value |
| 86 | * would be used for multiple requests. If you are looking for a way to cancel requests, you should |
| 87 | * use the cancellable option. |
| 88 | */ |
| 89 | timeout?: number |
| 90 | cancellable?: boolean; |
| 91 | withCredentials?: boolean; |
| 92 | responseType?: string; |
| 93 | interceptor?: IHttpInterceptor; |
| 94 | } |
| 95 | |
| 96 | // Allow specify more resource methods |
| 97 | // No need to add duplicates for all four overloads. |
| 98 | interface IResourceMethod<T> { |
| 99 | (): T; |
| 100 | (params: Object): T; |
| 101 | (success: Function, error?: Function): T; |
| 102 | (params: Object, success: Function, error?: Function): T; |
| 103 | (params: Object, data: Object, success?: Function, error?: Function): T; |
| 104 | } |
| 105 | |
| 106 | // Allow specify resource moethod which returns the array |
| 107 | // No need to add duplicates for all four overloads. |
| 108 | interface IResourceArrayMethod<T> { |
| 109 | (): IResourceArray<T>; |
| 110 | (params: Object): IResourceArray<T>; |
| 111 | (success: Function, error?: Function): IResourceArray<T>; |
| 112 | (params: Object, success: Function, error?: Function): IResourceArray<T>; |
| 113 | (params: Object, data: Object, success?: Function, error?: Function): IResourceArray<T>; |
| 114 | } |
| 115 | |
| 116 | // Baseclass for every resource with default actions. |
| 117 | // If you define your new actions for the resource, you will need |
| 118 | // to extend this interface and typecast the ResourceClass to it. |
| 119 | // |
| 120 | // In case of passing the first argument as anything but a function, |
| 121 | // it's gonna be considered data if the action method is POST, PUT or |
| 122 | // PATCH (in other words, methods with body). Otherwise, it's going |
| 123 | // to be considered as parameters to the request. |
| 124 | // https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L461-L465 |
| 125 | // |
| 126 | // Only those methods with an HTTP body do have 'data' as first parameter: |
| 127 | // https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L463 |
| 128 | // More specifically, those methods are POST, PUT and PATCH: |
| 129 | // https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L432 |
| 130 | // |
| 131 | // Also, static calls always return the IResource (or IResourceArray) retrieved |
| 132 | // https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L538-L549 |
| 133 | interface IResourceClass<T> { |
| 134 | new(dataOrParams? : any) : T & IResource<T>; |
| 135 | get: IResourceMethod<T>; |
| 136 | |
| 137 | query: IResourceArrayMethod<T>; |
| 138 | |
| 139 | save: IResourceMethod<T>; |
| 140 | |
| 141 | remove: IResourceMethod<T>; |
| 142 | |
| 143 | delete: IResourceMethod<T>; |
| 144 | } |
| 145 | |
| 146 | // Instance calls always return the the promise of the request which retrieved the object |
| 147 | // https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L538-L546 |
| 148 | interface IResource<T> { |
| 149 | $get(): angular.IPromise<T>; |
| 150 | $get(params?: Object, success?: Function, error?: Function): angular.IPromise<T>; |
| 151 | $get(success: Function, error?: Function): angular.IPromise<T>; |
| 152 | |
| 153 | $query(): angular.IPromise<IResourceArray<T>>; |
| 154 | $query(params?: Object, success?: Function, error?: Function): angular.IPromise<IResourceArray<T>>; |
| 155 | $query(success: Function, error?: Function): angular.IPromise<IResourceArray<T>>; |
| 156 | |
| 157 | $save(): angular.IPromise<T>; |
| 158 | $save(params?: Object, success?: Function, error?: Function): angular.IPromise<T>; |
| 159 | $save(success: Function, error?: Function): angular.IPromise<T>; |
| 160 | |
| 161 | $remove(): angular.IPromise<T>; |
| 162 | $remove(params?: Object, success?: Function, error?: Function): angular.IPromise<T>; |
| 163 | $remove(success: Function, error?: Function): angular.IPromise<T>; |
| 164 | |
| 165 | $delete(): angular.IPromise<T>; |
| 166 | $delete(params?: Object, success?: Function, error?: Function): angular.IPromise<T>; |
| 167 | $delete(success: Function, error?: Function): angular.IPromise<T>; |
| 168 | |
| 169 | $cancelRequest(): void; |
| 170 | |
| 171 | /** the promise of the original server interaction that created this instance. **/ |
| 172 | $promise : angular.IPromise<T>; |
| 173 | $resolved : boolean; |
| 174 | toJSON(): T; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Really just a regular Array object with $promise and $resolve attached to it |
| 179 | */ |
| 180 | interface IResourceArray<T> extends Array<T & IResource<T>> { |
| 181 | $cancelRequest(): void; |
| 182 | |
| 183 | /** the promise of the original server interaction that created this collection. **/ |
| 184 | $promise : angular.IPromise<IResourceArray<T>>; |
| 185 | $resolved : boolean; |
| 186 | } |
| 187 | |
| 188 | /** when creating a resource factory via IModule.factory */ |
| 189 | interface IResourceServiceFactoryFunction<T> { |
| 190 | ($resource: angular.resource.IResourceService): IResourceClass<T>; |
| 191 | <U extends IResourceClass<T>>($resource: angular.resource.IResourceService): U; |
| 192 | } |
| 193 | |
| 194 | // IResourceServiceProvider used to configure global settings |
| 195 | interface IResourceServiceProvider extends angular.IServiceProvider { |
| 196 | |
| 197 | defaults: IResourceOptions; |
| 198 | } |
| 199 | |
| 200 | } |
| 201 | |
| 202 | /** extensions to base ng based on using angular-resource */ |
| 203 | declare namespace angular { |
| 204 | |
| 205 | interface IModule { |
| 206 | /** creating a resource service factory */ |
| 207 | factory(name: string, resourceServiceFactoryFunction: angular.resource.IResourceServiceFactoryFunction<any>): IModule; |
| 208 | } |
| 209 | |
| 210 | namespace auto { |
| 211 | interface IInjectorService { |
| 212 | get(name: '$resource'): ng.resource.IResourceService; |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | interface Array<T> |
| 218 | { |
| 219 | /** the promise of the original server interaction that created this collection. **/ |
| 220 | $promise : angular.IPromise<Array<T>>; |
| 221 | $resolved : boolean; |
| 222 | } |