o.js: Provides its own types (#39485)

This commit is contained in:
Alexander T 2019-10-26 17:47:58 +03:00 committed by Nathan Shively-Sanders
parent 70b8180142
commit a2bceed52a
5 changed files with 6 additions and 348 deletions

View File

@ -2286,6 +2286,12 @@
"sourceRepoURL": "https://github.com/foretagsplatsen/numbro/",
"asOfVersion": "1.9.3"
},
{
"libraryName": "o.js",
"typingsPackageName": "o.js",
"sourceRepoURL": "https://github.com/janhommes/o.js",
"asOfVersion": "1.0.3"
},
{
"libraryName": "on-change",
"typingsPackageName": "on-change",

88
types/o.js/index.d.ts vendored
View File

@ -1,88 +0,0 @@
// Type definitions for o.js v0.3.4
// Project: https://github.com/janhommes/o.js
// Definitions by: Matteo Antony Mistretta <https://github.com/IceOnFire>, Brad Zacher <https://github.com/bradzacher>, Jan Hommes <https://github.com/janhommes>, Jean-Christophe Chalte <https://github.com/jcchalte>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
declare module 'o.js' {
import Q = require("q");
interface Options {
endpoint : string
format ?: string
autoFormat ?: boolean
version ?: number
strictMode ?: boolean
start ?: () => any
ready ?: () => any
error ?: () => any
headers ?: { name: string, value: string }[]
username ?: string
password ?: string
isAsync ?: boolean
isCors ?: boolean
isHashRoute ?: boolean
appending ?: string
}
interface OHandler<T> {
inlinecount : number
data : T
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>>
post<T>(params : any) : OHandler<T>
patch<T>(params : any) : OHandler<T>
put<T>(params : any) : OHandler<T>
remove<T>(params ?: any) : OHandler<T>
routes<T>(path : string, callback ?: (data : T) => void) : OHandler<T>
route<T>(path : string, callback ?: (data : T) => void) : OHandler<T>
triggerRoute(hash : string) : OHandler<T>
beforeRouting(callback : (routeParams : any) => boolean) : OHandler<T>
isEndpoint() : boolean
loading<T>(startFn : () => any | boolean, endFn : () => any) : OHandler<T>
find<T>(selector : string|number) : OHandler<T>
top<T>(quantity : number) : OHandler<T>
take<T>(quantity : number) : OHandler<T>
skip<T>(quantity : number) : OHandler<T>
first<T>() : OHandler<T>
include<T>(column : string, data : string) : OHandler<T>
exclude<T>(column : string, data : string) : OHandler<T>
filterByList<T>(column : string, data : string) : OHandler<T>
filter<T>(filter : string) : OHandler<T>
where<T>(filter : string) : OHandler<T>
any<T>(filter : string, resource : string) : OHandler<T>
search<T>(columns : string[], term : string) : OHandler<T>
orderBy<T>(column : string, direction ?: boolean) : OHandler<T>
orderByDesc<T>(column : string) : OHandler<T>
select<T>(selectStr : string) : OHandler<T>
count<T>() : OHandler<T>
inlineCount<T>(paramName ?: string) : OHandler<T>
batch<T>(resource : string) : OHandler<T>
expand<T>(resource : string) : OHandler<T>
ref<T>(resource : string, id : string | number) : OHandler<T>
removeRef<T>(resource : string, id : string | number) : OHandler<T>
deleteRef<T>(resource : string, id : string | number) : OHandler<T>
}
interface OFn<T> extends OHandler<T> {
(options ?: string | Options) : OHandler<T>
}
var o : OFn<{}>;
export = o
}

View File

@ -1,151 +0,0 @@
import o = require('o.js');
import * as Q from "q";
interface Product {
ID : number;
Name : string;
Description : string;
ReleaseDate : string;
DiscontinuedDate : Date;
Rating: number;
Price: number;
}
interface Category {
ID : number;
Name : string;
}
// copy pasta all the examples from the readme!
o('http://services.odata.org/V4/OData/OData.svc/Products')
.get<Product>(function(data) {
console.log(data); //returns an array of Product data
});
o('http://services.odata.org/V4/OData/OData.svc/Products')
.take(5)
.skip(2)
.get<Product>(function(data) {
console.log(data); //An array of 5 products skiped by 2
});
o('http://services.odata.org/V4/OData/OData.svc/Products')
.find(':0')
.route<Product>('Product/Detail/:0/:1',function(data) {
console.log('Route Product/Detail/'+this.param[0]+'/'+this.param[1]+' triggered. Result:');
console.log(data);
});
var oHandler = o('http://services.odata.org/V4/OData/OData.svc/Products');
//do somehtting
oHandler.find(1);
// do some more................
//get the data
oHandler.get<Product>(function(data) {
console.log(data);
//or the saved var also contains the data:
console.log(oHandler.data);
});
Q.all<any>([
o('http://services.odata.org/V4/OData/OData.svc/Products(4)').get<Product>(),
o('http://services.odata.org/V4/OData/OData.svc/Categories').take(2).get<Category[]>()
]).then(function(oHandlerArray) {
//The oHandler array contains the Product oHandler and the Group oHandler:
console.log(oHandlerArray[0].data); // 1 Product with id 4
console.log(oHandlerArray[1].data.length); // 2 Categories
});
o('http://services.odata.org/V4/OData/OData.svc/Products(2)')
.get<Product>()
.then(function(oHandler) {
console.log(oHandler.data);
}).fail(function(ex) {
console.log(ex);
});
o('http://services.odata.org/V4/OData/OData.svc/Products')
.post({Name:'Example 1',Description:'a'})
.post({Name:'Example 2',Description:'b'})
.save<Product>(function(data) {
console.log("Two Products added");
});
o('http://services.odata.org/V4/OData/OData.svc/Products(1)')
.patch({Name:'NewName'})
.save<Product>(function(data) {
console.log("Product Name changed");
});
o('http://services.odata.org/V4/OData/OData.svc/Products(1)')
.remove()
.save<Product>(function(data) {
console.log("Product deleted");
});
o('http://services.odata.org/V4/OData/OData.svc/Products(1)')
.ref('Categories', 2)
.save<Product>(function(data) {
console.log("Product(1) associated with Categories(2)");
});
o('http://services.odata.org/V4/OData/OData.svc/Products')
.find(2)
.get<Product>()
.then(function(oHandler) {
oHandler.data.Name="NewName";
return(o.save<Product>());
}).then(function(oHandler) {
console.log(oHandler.data.Name); //NewName
}).fail(function(ex) {
console.log("error");
});
// set an endpoint
o().config({
endpoint:'http://services.odata.org/V4/OData/OData.svc'
});
// after you have set an endpoint, you can shorten your queries:
o('Products').get<Product>(function(data) {
//same result like the first example on this page
});
//basic config
o().config({
endpoint:null, // your odata endpoint for the service
format:'json', // currently only json is supported
autoFormat: false,
version:4, // oData version (currently supported version 4. However most also work with version 3.)
strictMode:true, // strict mode throws exception, non strict mode only logs them
start:null, // a function which is executed on loading
ready:null, // a function which is executed on ready
error:null, // a function which is executed on error
headers:[{name: '', value: ''}], // a array of additional headers e.g.: [{name:'headername',value:'headervalue'}]
username:null, // a basic auth username
password:null, // a basic auth password
isAsync:true //set this to false to make synced (a)jax calls. (dosn't work with basic auth!)
});

View File

@ -1,29 +0,0 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": false,
"strictNullChecks": false,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"q": [
"q/v0"
]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"o.js-tests.ts"
]
}

View File

@ -1,80 +0,0 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"npm-naming": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
}
}