// Type definitions for Angular JS 1.2 (ngResource module) // Project: http://angularjs.org // Definitions by: Diego Vilar , Michael Jess // Definitions: https://github.com/daptiv/DefinitelyTyped /////////////////////////////////////////////////////////////////////////////// // ngResource module (angular-resource.js) /////////////////////////////////////////////////////////////////////////////// declare namespace ng.resource { /////////////////////////////////////////////////////////////////////////// // ResourceService // see https://code.angularjs.org/1.2.26/docs/api/ngResource/service/$resource // Most of the following definitions were achieved by analyzing the // actual implementation, since the documentation doesn't seem to cover // that deeply. /////////////////////////////////////////////////////////////////////////// interface IResourceService { (url: string, paramDefaults?: any, /** example: {update: { method: 'PUT' }, delete: deleteDescriptor } where deleteDescriptor : IActionDescriptor */ actionDescriptors?: any): IResourceClass>; (url: string, paramDefaults?: any, /** example: {update: { method: 'PUT' }, delete: deleteDescriptor } where deleteDescriptor : IActionDescriptor */ actionDescriptors?: any): U; (url: string, paramDefaults?: any, /** example: {update: { method: 'PUT' }, delete: deleteDescriptor } where deleteDescriptor : IActionDescriptor */ actionDescriptors?: any): IResourceClass; } // Just a reference to facilitate describing new actions interface IActionDescriptor { method: string; isArray?: boolean; params?: any; headers?: any; } // Baseclass for everyresource with default actions. // If you define your new actions for the resource, you will need // to extend this interface and typecast the ResourceClass to it. // // In case of passing the first argument as anything but a function, // it's gonna be considered data if the action method is POST, PUT or // PATCH (in other words, methods with body). Otherwise, it's going // to be considered as parameters to the request. // https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L461-L465 // // Only those methods with an HTTP body do have 'data' as first parameter: // https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L463 // More specifically, those methods are POST, PUT and PATCH: // https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L432 // // Also, static calls always return the IResource (or IResourceArray) retrieved // https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L538-L549 interface IResourceClass { new(dataOrParams? : any) : T; get(): T; get(params: Object): T; get(success: Function, error?: Function): T; get(params: Object, success: Function, error?: Function): T; get(params: Object, data: Object, success?: Function, error?: Function): T; query(): IResourceArray; query(params: Object): IResourceArray; query(success: Function, error?: Function): IResourceArray; query(params: Object, success: Function, error?: Function): IResourceArray; query(params: Object, data: Object, success?: Function, error?: Function): IResourceArray; save(): T; save(data: Object): T; save(success: Function, error?: Function): T; save(data: Object, success: Function, error?: Function): T; save(params: Object, data: Object, success?: Function, error?: Function): T; remove(): T; remove(params: Object): T; remove(success: Function, error?: Function): T; remove(params: Object, success: Function, error?: Function): T; remove(params: Object, data: Object, success?: Function, error?: Function): T; delete(): T; delete(params: Object): T; delete(success: Function, error?: Function): T; delete(params: Object, success: Function, error?: Function): T; delete(params: Object, data: Object, success?: Function, error?: Function): T; } // Instance calls always return the the promise of the request which retrieved the object // https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L538-L546 interface IResource { $get(): ng.IPromise; $get(params?: Object, success?: Function, error?: Function): ng.IPromise; $get(success: Function, error?: Function): ng.IPromise; $query(): ng.IPromise>; $query(params?: Object, success?: Function, error?: Function): ng.IPromise>; $query(success: Function, error?: Function): ng.IPromise>; $save(): ng.IPromise; $save(params?: Object, success?: Function, error?: Function): ng.IPromise; $save(success: Function, error?: Function): ng.IPromise; $remove(): ng.IPromise; $remove(params?: Object, success?: Function, error?: Function): ng.IPromise; $remove(success: Function, error?: Function): ng.IPromise; $delete(): ng.IPromise; $delete(params?: Object, success?: Function, error?: Function): ng.IPromise; $delete(success: Function, error?: Function): ng.IPromise; /** the promise of the original server interaction that created this instance. **/ $promise : ng.IPromise; $resolved : boolean; } /** * Really just a regular Array object with $promise and $resolve attached to it */ interface IResourceArray extends Array { /** the promise of the original server interaction that created this collection. **/ $promise : ng.IPromise>; $resolved : boolean; } /** when creating a resource factory via IModule.factory */ interface IResourceServiceFactoryFunction { ($resource: ng.resource.IResourceService): IResourceClass; >($resource: ng.resource.IResourceService): U; } } /** extensions to base ng based on using angular-resource */ declare namespace ng { interface IModule { /** creating a resource service factory */ factory(name: string, resourceServiceFactoryFunction: ng.resource.IResourceServiceFactoryFunction): IModule; } } interface Array { /** the promise of the original server interaction that created this collection. **/ $promise : ng.IPromise>; $resolved : boolean; }