Merge pull request #23668 from many20/update-odata-o.js

update odata definition
This commit is contained in:
Daniel Rosenwasser
2018-02-16 16:09:35 -08:00
committed by GitHub
2 changed files with 28 additions and 13 deletions
+13 -8
View File
@@ -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 <https://github.com/janhommes>, Jean-Christophe Chalte <https://github.com/jcchalte>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -26,14 +26,16 @@ declare module 'odata' {
}
interface OHandler<T> {
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<T>(options ?: Options) : OHandler<T>
progress<T>(callback : () => any) : OHandler<T>
get<T>(callback ?: (data : T) => void) : Q.Promise<OHandler<T>>
save<T>(callback ?: (data : T) => void) : Q.Promise<OHandler<T>>
get<T>(callback ?: (data : T) => void, errorCallback?: (status: number) => void) : Q.Promise<OHandler<T>>
save<T>(callback ?: (data : T) => void, errorCallback?: (status: number) => void) : Q.Promise<OHandler<T>>
query: () => string;
post<T>(params : any) : OHandler<T>
patch<T>(params : any) : OHandler<T>
@@ -78,11 +80,14 @@ declare module 'odata' {
deleteRef<T>(resource : string, id : string | number) : OHandler<T>
}
interface OFn<T> extends OHandler<T> {
(options ?: string | Options) : OHandler<T>
interface OHandlerStatic {
(): OHandlerStatic;
(options?: string | Options): OHandler<{}>;
config: (config: Options) => OHandlerStatic;
isEndpoint: () => boolean;
}
var o : OFn<{}>;
var o : OHandlerStatic;
export = o
}
+15 -5
View File
@@ -20,6 +20,8 @@ interface Category {
o('http://services.odata.org/V4/OData/OData.svc/Products')
.get<Product>(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<Product>()
.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<Product>()
.then(function(oHandler) {
oHandler.data.Name="NewName";
return(o.save<Product>());
}).then(function(oHandler) {
return(oHandler.save<Product>());
})
.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<Product>(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({