diff --git a/types/apicalypse/apicalypse-tests.ts b/types/apicalypse/apicalypse-tests.ts new file mode 100644 index 0000000000..273e89215c --- /dev/null +++ b/types/apicalypse/apicalypse-tests.ts @@ -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> +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 +Apicalypse() + .search('title') + .requestAll('/games'); + +// $ExpectType Promise +Apicalypse() + .search('title') + .requestAll('/games', {}); + +// $ExpectType Promise +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'), +]); diff --git a/types/apicalypse/index.d.ts b/types/apicalypse/index.d.ts new file mode 100644 index 0000000000..ef979b5d8c --- /dev/null +++ b/types/apicalypse/index.d.ts @@ -0,0 +1,39 @@ +// Type definitions for apicalypse 0.1 +// Project: https://github.com/igdb/node-apicalypse +// Definitions by: Susam +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { AxiosRequestConfig, AxiosResponse } from 'axios'; + +export interface Apicalypse { + request(url: string): Promise; + requestAll(url: string, options?: RequestAllConfig): Promise; + + multi(queries: ReadonlyArray): Apicalypse; + query(endpoint: string, name: string): Apicalypse; + + fields(fields: string | ReadonlyArray): Apicalypse; + sort(field: string, direction?: SortDirection): Apicalypse; + limit(limit: number): Apicalypse; + offset(offset: number): Apicalypse; + search(search: string): Apicalypse; + where(filters: string | ReadonlyArray): 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; diff --git a/types/apicalypse/package.json b/types/apicalypse/package.json new file mode 100644 index 0000000000..18cbf3da9c --- /dev/null +++ b/types/apicalypse/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "axios": "^0.19.0" + } +} diff --git a/types/apicalypse/tsconfig.json b/types/apicalypse/tsconfig.json new file mode 100644 index 0000000000..6c17f6be0a --- /dev/null +++ b/types/apicalypse/tsconfig.json @@ -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" + ] +} diff --git a/types/apicalypse/tslint.json b/types/apicalypse/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/apicalypse/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/igdb-api-node/igdb-api-node-tests.ts b/types/igdb-api-node/igdb-api-node-tests.ts new file mode 100644 index 0000000000..d75d5a6d06 --- /dev/null +++ b/types/igdb-api-node/igdb-api-node-tests.ts @@ -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', +}); diff --git a/types/igdb-api-node/index.d.ts b/types/igdb-api-node/index.d.ts new file mode 100644 index 0000000000..e1a5acfc59 --- /dev/null +++ b/types/igdb-api-node/index.d.ts @@ -0,0 +1,11 @@ +// Type definitions for igdb-api-node 4.0 +// Project: https://github.com/igdb/igdb-api-node +// Definitions by: Susam +// 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; diff --git a/types/igdb-api-node/tsconfig.json b/types/igdb-api-node/tsconfig.json new file mode 100644 index 0000000000..fcd72fb408 --- /dev/null +++ b/types/igdb-api-node/tsconfig.json @@ -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" + ] +} diff --git a/types/igdb-api-node/tslint.json b/types/igdb-api-node/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/igdb-api-node/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }