Move all packages to a types directory

This commit is contained in:
Andy Hanson
2017-03-24 14:27:52 -07:00
parent f9869dc191
commit 354cec620d
13846 changed files with 0 additions and 0 deletions
+155
View File
@@ -0,0 +1,155 @@
// 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 types="angular" />
// Support AMD require (copying angular.d.ts approach)
// allows for import {IRequestConfig} from 'restangular' ES6 approach
import * as angular from 'angular';
export = restangular;
export as namespace 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): ICollection;
allUrl(route: string, url: string): ICollection;
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): IScopedService;
stripRestangular(element: any): any;
extendModel(route: string, extender: (model: IElement) => any): void;
extendCollection(route: string, extender: (collection: ICollection) => any): void;
}
interface IScopedService extends IService {
one(id: number): IElement;
one(id: string): IElement;
post(elementToPost: any, queryParams?: any, headers?: any): IPromise<any>;
post<T>(elementToPost: T, queryParams?: any, headers?: any): IPromise<T>;
getList(queryParams?: any, headers?: any): ICollectionPromise<any>;
getList<T>(queryParams?: any, headers?: any): ICollectionPromise<T>;
}
interface IScopedService extends IService {
one(id: number): IElement;
one(id: string): IElement;
post(elementToPost: any, queryParams?: any, headers?: any): IPromise<any>;
post<T>(elementToPost: T, queryParams?: any, headers?: any): IPromise<T>;
getList(queryParams?: any, headers?: any): ICollectionPromise<any>;
getList<T>(queryParams?: any, headers?: any): ICollectionPromise<T>;
}
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>;
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;
}
}
+211
View File
@@ -0,0 +1,211 @@
import restangular = require("restangular");
import * as angular from 'angular';
var myApp = angular.module('testModule');
myApp.config((RestangularProvider: restangular.IProvider) => {
RestangularProvider.setBaseUrl('/api/v1');
RestangularProvider.setExtraFields(['name']);
RestangularProvider.setResponseExtractor(function (response, operation) {
return response.data;
});
RestangularProvider.setDefaultHttpFields({ cache: true });
RestangularProvider.setMethodOverriders(["put", "patch"]);
RestangularProvider.setErrorInterceptor(function (response) {
console.error('' + response.status + ' ' + response.data);
});
RestangularProvider.setRequestSuffix('.json');
RestangularProvider.setRequestInterceptor(function (element, operation, route, url) {
});
RestangularProvider.addElementTransformer('accounts', false, function (elem: any) {
elem.accountName = 'Changed';
return elem;
});
RestangularProvider.setRestangularFields({
id: "_id",
route: "restangularRoute",
selfLink: "self.href"
});
RestangularProvider.addRequestInterceptor(function(element, operation, route, url) {
delete element.name;
return element;
});
RestangularProvider.setFullRequestInterceptor(function(element, operation, route, url, headers, params, httpConfig) {
delete element.name;
return {
element: element,
params: params,
headers: headers,
httpConfig: httpConfig
};
});
});
interface MyAppScope extends angular.IScope {
accounts: string[];
allAccounts: any[];
account: any;
buildings: restangular.ICollectionPromise<any>;
loggedInPlaces: restangular.ICollectionPromise<any>;
userFromServer: restangular.IPromise<any>;
}
myApp.controller('TestCtrl', (
$scope: MyAppScope,
Restangular: restangular.IService
) => {
var baseAccounts = Restangular.all('accounts');
baseAccounts.getList().then(function(accounts) {
$scope.allAccounts = accounts;
});
$scope.accounts = Restangular.all('accounts').getList().$object;
var newAccount = {name: "Gonto's account"};
baseAccounts.post(newAccount);
Restangular.allUrl('googlers', 'http://www.google.com/').getList();
Restangular.allUrl('googlers', 'http://www.google.com/').getList<String>();
Restangular.oneUrl('googlers', 'http://www.google.com/1').get();
Restangular.oneUrl('googlers', 'http://www.google.com/1').get<String>();
Restangular.one('accounts', 123).one('buildings', 456).get();
Restangular.one('accounts', 123).one('buildings', 456).get<String>();
Restangular.one('accounts', 123).getList('buildings');
Restangular.one('accounts', 123).getList<String>('buildings');
Restangular.setBaseUrl('/api/v1');
Restangular.setExtraFields(['name']);
Restangular.setResponseExtractor(function (response, operation) {
return response.data;
});
Restangular.setDefaultHttpFields({ cache: true });
Restangular.setMethodOverriders(["put", "patch"]);
Restangular.setErrorInterceptor(function (response) {
let location: string = response.headers('Location');
console.error('' + response.status + ' ' + response.data + ' ' + location);
});
Restangular.setRequestSuffix('.json');
Restangular.setRequestInterceptor(function (element, operation, route, url) {
});
Restangular.addElementTransformer('accounts', false, function (elem: any) {
elem.accountName = 'Changed';
return elem;
});
Restangular.setRestangularFields({
id: "_id",
route: "restangularRoute",
selfLink: "self.href"
});
Restangular.addRequestInterceptor(function(element, operation, route, url) {
delete element.name;
return element;
});
Restangular.setFullRequestInterceptor(function(element, operation, route, url, headers, params, httpConfig) {
delete element.name;
return {
element: element,
params: params,
headers: headers,
httpConfig: httpConfig
};
});
var accountData = Restangular.one('accounts', 123).plain();
var accountClone: restangular.IElement = Restangular.one('accounts', 123).clone();
baseAccounts.getList().then(function (accounts) {
var firstAccount = accounts[0];
$scope.buildings = firstAccount.getList("buildings");
$scope.loggedInPlaces = firstAccount.getList("places", {query: "param"}, {'x-user': 'mgonto'});
firstAccount.name = "Gonto";
var editFirstAccount = Restangular.copy(firstAccount);
firstAccount.put();
editFirstAccount.put();
firstAccount.save();
firstAccount.remove();
var myBuilding = {
name: "Gonto's Building",
place: "Argentina"
};
firstAccount.post("Buildings", myBuilding).then(function() {
console.log("Object saved OK");
}, function() {
console.log("There was an error saving");
});
firstAccount.getList("users", {query: "params"}).then(function(users: any) {
users.post({userName: 'unknown'});
users.customGET("messages", {param: "myParam"});
var firstUser = users[0];
$scope.userFromServer = firstUser.get();
firstUser.head()
});
}, function errorCallback() {
alert("Oops error from server :(");
});
var account = Restangular.one("accounts", 123);
$scope.account = account.get({single: true});
account.customPOST({name: "My Message"}, "messages", {param: "myParam"}, {});
Restangular.one('accounts', 123).withHttpConfig({timeout: 100}).getList('buildings');
$scope.account = Restangular.one('accounts', 123);
$scope.account.withHttpConfig({timeout: 100}).put();
var myRestangular = Restangular.withConfig((configurer: restangular.IProvider) => {
configurer.setBaseUrl('/api/v1');
configurer.setExtraFields(['name']);
configurer.setErrorInterceptor(function (response) {
console.error('' + response.status + ' ' + response.data);
});
configurer.setResponseExtractor(function (response, operation) {
return response.data;
});
configurer.setDefaultHttpFields({ cache: true });
configurer.setMethodOverriders(["put", "patch"]);
configurer.setRestangularFields({
id: "_id",
route: "restangularRoute"
});
configurer.setRequestSuffix('.json');
configurer.setRequestInterceptor(function (element, operation, route, url) {
});
configurer.addElementTransformer('accounts', false, function (elem: any) {
elem.accountName = 'Changed';
return elem;
});
});
});
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"restangular-tests.ts"
]
}