From 1af21196f1ef7de01179ce65ca56652d7ea8aad0 Mon Sep 17 00:00:00 2001 From: Stefan Reichel Date: Sun, 27 Nov 2016 02:32:53 +0100 Subject: [PATCH 1/2] Added type declarations for raw-body --- raw-body/index.d.ts | 38 ++++++++++++++++++++++++++++++++++++++ raw-body/raw-body-tests.ts | 27 +++++++++++++++++++++++++++ raw-body/tsconfig.json | 19 +++++++++++++++++++ raw-body/tslint.json | 1 + 4 files changed, 85 insertions(+) create mode 100644 raw-body/index.d.ts create mode 100644 raw-body/raw-body-tests.ts create mode 100644 raw-body/tsconfig.json create mode 100644 raw-body/tslint.json diff --git a/raw-body/index.d.ts b/raw-body/index.d.ts new file mode 100644 index 0000000000..9d80a61f0c --- /dev/null +++ b/raw-body/index.d.ts @@ -0,0 +1,38 @@ +// Type definitions for raw-body +// Project: https://github.com/stream-utils/raw-body +// Definitions by: Stefan Reichel +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +import { Readable } from "stream"; + +declare namespace getRawBody { + export interface Options { + length?: number; + limit?: number; + encoding?: string; + } + + export interface RawBodyError extends Error { + limit?: number; + length?: number; + expected?: number; + received?: number; + encoding?: string; + status?: number; + statusCode?: number; + type?: string; + } + + export interface Callback { + (err: RawBodyError, res: string | Buffer): void; + } +} + + +declare function getRawBody(stream: Readable, callback: getRawBody.Callback): void; +declare function getRawBody(stream: Readable, options: getRawBody.Options | string, callback: getRawBody.Callback): void; + +declare function getRawBody(stream: Readable, options?: getRawBody.Options | string): Promise; + +export = getRawBody; diff --git a/raw-body/raw-body-tests.ts b/raw-body/raw-body-tests.ts new file mode 100644 index 0000000000..f23160c876 --- /dev/null +++ b/raw-body/raw-body-tests.ts @@ -0,0 +1,27 @@ +import getRawBody = require("raw-body"); + +const stream: any = {}; + +const simple = getRawBody(stream); + +const withEncoding = getRawBody(stream, "utf-8"); + +const withOptions = getRawBody(stream, { + encoding: "utf-8", + length: 1024, + limit: 512 +}); + +getRawBody(stream, (err, res) => { + if(err) console.error(err); + else console.log(res); +}); + +getRawBody(stream, { + encoding: "utf-8", + length: 1024, + limit: 512 +}, (err, res) => { + if(err) console.error(err); + else console.log(res); +}); diff --git a/raw-body/tsconfig.json b/raw-body/tsconfig.json new file mode 100644 index 0000000000..d7a3d0c387 --- /dev/null +++ b/raw-body/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "raw-body-tests.ts" + ] +} diff --git a/raw-body/tslint.json b/raw-body/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/raw-body/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } From 16a23685429d1eabf8da7efc0ee14c588d2311d8 Mon Sep 17 00:00:00 2001 From: Stefan Reichel Date: Sun, 27 Nov 2016 02:48:06 +0100 Subject: [PATCH 2/2] Fixed deprecation error. --- raw-body/index.d.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/raw-body/index.d.ts b/raw-body/index.d.ts index 9d80a61f0c..ffe61856c8 100644 --- a/raw-body/index.d.ts +++ b/raw-body/index.d.ts @@ -24,9 +24,7 @@ declare namespace getRawBody { type?: string; } - export interface Callback { - (err: RawBodyError, res: string | Buffer): void; - } + export type Callback = (err: RawBodyError, res: string | Buffer) => void; }