- add type definitions for apicalypse package (#43304)

- add type definitions for igdb-api-node package
This commit is contained in:
susam-projects 2020-03-23 18:50:31 +03:00 committed by GitHub
parent 220266e22c
commit 47dd795052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 175 additions and 0 deletions

View File

@ -0,0 +1,56 @@
import Apicalypse from 'apicalypse';
// $ExpectType Apicalypse
Apicalypse({
baseURL: 'https://my-api.url',
queryMethod: 'url',
auth: {
username: 'user',
password: 'pass',
},
headers: {
Accept: 'application/json',
},
responseType: 'json',
timeout: 30000,
});
// $ExpectType Promise<AxiosResponse<any>>
Apicalypse()
.fields('id,slug,name')
.fields(['rating', 'popularity'])
.sort('rating desc')
.sort('name', 'asc')
.limit(10)
.offset(20)
.where('rating > 0; popularity > 10')
.where(['popularity < 100', 'first_release_date > 788918400'])
.request('/games');
// $ExpectType Promise<any[]>
Apicalypse()
.search('title')
.requestAll('/games');
// $ExpectType Promise<any[]>
Apicalypse()
.search('title')
.requestAll('/games', {});
// $ExpectType Promise<any[]>
Apicalypse()
.search('title')
.requestAll('/games', {
concurrency: 2,
delay: 500,
});
// $ExpectType Apicalypse
Apicalypse().multi([
Apicalypse()
.query('/games', 'game')
.where('id == 1081'),
Apicalypse()
.query('/achievements', 'achievements')
.where('game_id == 1081'),
]);

39
types/apicalypse/index.d.ts vendored Normal file
View File

@ -0,0 +1,39 @@
// Type definitions for apicalypse 0.1
// Project: https://github.com/igdb/node-apicalypse
// Definitions by: Susam <https://github.com/susam-projects>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { AxiosRequestConfig, AxiosResponse } from 'axios';
export interface Apicalypse {
request(url: string): Promise<AxiosResponse>;
requestAll(url: string, options?: RequestAllConfig): Promise<any[]>;
multi(queries: ReadonlyArray<Apicalypse>): Apicalypse;
query(endpoint: string, name: string): Apicalypse;
fields(fields: string | ReadonlyArray<string>): Apicalypse;
sort(field: string, direction?: SortDirection): Apicalypse;
limit(limit: number): Apicalypse;
offset(offset: number): Apicalypse;
search(search: string): Apicalypse;
where(filters: string | ReadonlyArray<string>): Apicalypse;
}
export interface RequestAllConfig {
concurrency?: number;
delay?: number;
}
export type SortDirection = 'asc' | 'desc';
declare function apicalypseFactory(options?: ApicalypseConfig): Apicalypse;
declare function apicalypseFactory(rawQueryString: string, options?: ApicalypseConfig): Apicalypse;
export interface ApicalypseConfig extends AxiosRequestConfig {
queryMethod?: QueryMethod;
}
export type QueryMethod = 'body' | 'url';
export default apicalypseFactory;

View File

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"axios": "^0.19.0"
}
}

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"apicalypse-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

View File

@ -0,0 +1,15 @@
import igdb, { getTagNumber } from 'igdb-api-node';
import { Apicalypse } from 'apicalypse';
// $ExpectType number
getTagNumber(5, 1234);
// $ExpectType Apicalypse
igdb();
// $ExpectType Apicalypse
igdb('test-api-key');
// $ExpectType Apicalypse
igdb('test-api-key', {
queryMethod: 'url',
method: 'get',
});

11
types/igdb-api-node/index.d.ts vendored Normal file
View File

@ -0,0 +1,11 @@
// Type definitions for igdb-api-node 4.0
// Project: https://github.com/igdb/igdb-api-node
// Definitions by: Susam <https://github.com/susam-projects>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { Apicalypse, ApicalypseConfig } from 'apicalypse';
export function getTagNumber(category: number, id: number): number;
declare function igdb(apiKey?: string, opts?: ApicalypseConfig): Apicalypse;
export default igdb;

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"igdb-api-node-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }