From 97c54e5eea9ce2f9a3c555fb76881328304e57cf Mon Sep 17 00:00:00 2001 From: ishen7 Date: Thu, 1 Aug 2019 07:00:33 +0800 Subject: [PATCH] [koa-proxy] new type definitions (#37264) --- types/koa-proxy/index.d.ts | 29 +++++++++++++++++++++++++++++ types/koa-proxy/koa-proxy-tests.ts | 9 +++++++++ types/koa-proxy/tsconfig.json | 23 +++++++++++++++++++++++ types/koa-proxy/tslint.json | 1 + 4 files changed, 62 insertions(+) create mode 100644 types/koa-proxy/index.d.ts create mode 100644 types/koa-proxy/koa-proxy-tests.ts create mode 100644 types/koa-proxy/tsconfig.json create mode 100644 types/koa-proxy/tslint.json diff --git a/types/koa-proxy/index.d.ts b/types/koa-proxy/index.d.ts new file mode 100644 index 0000000000..d93543fc5b --- /dev/null +++ b/types/koa-proxy/index.d.ts @@ -0,0 +1,29 @@ +// Type definitions for koa-proxy 1.0 +// Project: https://github.com/edorivai/koa-proxy#readme +// Definitions by: ishen7 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import * as Koa from 'koa'; + +declare namespace proxy { + type RequestOptionFunc = (request: Koa.Request, opts: any) => any; + + interface Options { + host?: string; + url?: string; + map?: { [key: string]: string }; + match?: RegExp; + jar?: boolean; + suppressRequestHeaders?: string[]; // case-insensitive + suppressResponseHeaders?: string[]; // case-insensitive + overrideResponseHeaders?: any; + requestOptions?: RequestOptionFunc | { [key: string]: string }; + followRedirect?: boolean; + yieldNext?: boolean; + } +} + +declare function proxy(options?: proxy.Options): Koa.Middleware; + +export = proxy; diff --git a/types/koa-proxy/koa-proxy-tests.ts b/types/koa-proxy/koa-proxy-tests.ts new file mode 100644 index 0000000000..6012b117f9 --- /dev/null +++ b/types/koa-proxy/koa-proxy-tests.ts @@ -0,0 +1,9 @@ +import Koa = require('koa'); +import proxy = require('koa-proxy'); + +const app = new Koa(); +app.use(proxy({ + host: 'https://api.github.com', + match: /^\/repos\// +})); +app.listen(3000); diff --git a/types/koa-proxy/tsconfig.json b/types/koa-proxy/tsconfig.json new file mode 100644 index 0000000000..770a87d83c --- /dev/null +++ b/types/koa-proxy/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "strictFunctionTypes": true, + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "koa-proxy-tests.ts" + ] +} \ No newline at end of file diff --git a/types/koa-proxy/tslint.json b/types/koa-proxy/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/koa-proxy/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }