diff --git a/types/odata/index.d.ts b/types/odata/index.d.ts index 349d48763b..e56ac4296c 100644 --- a/types/odata/index.d.ts +++ b/types/odata/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for odata v0.3.4 +// Type definitions for odata v0.3 // Project: https://github.com/janhommes/odata // Definitions by: Jan Hommes , Jean-Christophe Chalte // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -26,14 +26,16 @@ declare module 'odata' { } interface OHandler { - inlinecount : number - data : T + inlinecount: number; // if inlinecount is set, here the counting is gold + data: T; // holds the data after an callback + param: {}; // this object holds all parameter for a route config(options ?: Options) : OHandler progress(callback : () => any) : OHandler - get(callback ?: (data : T) => void) : Q.Promise> - save(callback ?: (data : T) => void) : Q.Promise> + get(callback ?: (data : T) => void, errorCallback?: (status: number) => void) : Q.Promise> + save(callback ?: (data : T) => void, errorCallback?: (status: number) => void) : Q.Promise> + query: () => string; post(params : any) : OHandler patch(params : any) : OHandler @@ -78,11 +80,14 @@ declare module 'odata' { deleteRef(resource : string, id : string | number) : OHandler } - interface OFn extends OHandler { - (options ?: string | Options) : OHandler + interface OHandlerStatic { + (): OHandlerStatic; + (options?: string | Options): OHandler<{}>; + config: (config: Options) => OHandlerStatic; + isEndpoint: () => boolean; } - var o : OFn<{}>; + var o : OHandlerStatic; export = o } \ No newline at end of file diff --git a/types/odata/odata-tests.ts b/types/odata/odata-tests.ts index 58e1505f21..743c5cd906 100644 --- a/types/odata/odata-tests.ts +++ b/types/odata/odata-tests.ts @@ -20,6 +20,8 @@ interface Category { o('http://services.odata.org/V4/OData/OData.svc/Products') .get(function(data) { console.log(data); //returns an array of Product data + }, function(status) { + console.error(status); // error with status }); @@ -70,7 +72,8 @@ o('http://services.odata.org/V4/OData/OData.svc/Products(2)') .get() .then(function(oHandler) { console.log(oHandler.data); - }).fail(function(ex) { + }) + .fail(function(ex) { console.log(ex); }); @@ -114,10 +117,12 @@ o('http://services.odata.org/V4/OData/OData.svc/Products') .get() .then(function(oHandler) { oHandler.data.Name="NewName"; - return(o.save()); - }).then(function(oHandler) { + return(oHandler.save()); + }) + .then(function(oHandler) { console.log(oHandler.data.Name); //NewName - }).fail(function(ex) { + }) + .fail(function(ex) { console.log("error"); }); @@ -132,7 +137,12 @@ o('Products').get(function(data) { //same result like the first example on this page }); - +const oEequest = o('http://services.odata.org/V4/OData/OData.svc/Products') + .find(2); +const queryString = oEequest.query(); +if (queryString !== 'http://services.odata.org/V4/OData/OData.svc/Products(2)') { + throw new Error('assert error'); +} //basic config o().config({