diff --git a/types/koa-send/index.d.ts b/types/koa-send/index.d.ts index a15f5b688d..65228c9981 100644 --- a/types/koa-send/index.d.ts +++ b/types/koa-send/index.d.ts @@ -1,24 +1,46 @@ -// Type definitions for koa-send v3.3 +// Type definitions for koa-send 4.1 // Project: https://github.com/koajs/send // Definitions by: Peter Safranek +// Tomek Łaziuk // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 -import * as Koa from 'koa'; +import { + Context, +} from "koa"; -interface ISendOptions { - root?: string; - index?: string; - maxAge?: number; - hidden?: boolean; - format?: boolean; - gzip?: boolean; - setHeaders?: Function; - extensions?: string[]; +import { + Stats, +} from "fs"; + +declare function send(ctx: Context, path: string, opts?: send.SendOptions): Promise; + +declare namespace send { + type SetHeaders = (res: Context["res"], path: string, stats: Stats) => any; + + interface SendOptions { + /** Browser cache max-age in milliseconds. (defaults to 0) */ + maxage?: number; + maxAge?: SendOptions["maxage"]; + /** Tell the browser the resource is immutable and can be cached indefinitely. (defaults to false) */ + immutable?: boolean; + /** Allow transfer of hidden files. (defaults to false) */ + hidden?: boolean; + /** Root directory to restrict file access. (defaults to '') */ + root?: string; + /** Name of the index file to serve automatically when visiting the root location. (defaults to none) */ + index?: string; + /** Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file with .gz extension exists. (defaults to true). */ + gzip?: boolean; + /** Try to serve the brotli version of a file automatically when brotli is supported by a client and if the requested file with .br extension exists. (defaults to true). */ + brotli?: boolean; + /** If not false (defaults to true), format the path to serve static file servers and not require a trailing slash for directories, so that you can do both /directory and /directory/. */ + format?: boolean; + /** Function to set custom headers on response. */ + setHeaders?: SetHeaders; + /** Try to match extensions from passed array to search for file when no extension is sufficed in URL. First found is served. (defaults to false) */ + extensions?: string[] | false; + } } -declare function send(ctx: Koa.Context, path: string, opts?: ISendOptions): Promise; - -declare namespace send {} - export = send; diff --git a/types/koa-send/koa-send-tests.ts b/types/koa-send/koa-send-tests.ts index 88a6f16abb..a3b136ea9a 100644 --- a/types/koa-send/koa-send-tests.ts +++ b/types/koa-send/koa-send-tests.ts @@ -1,4 +1,3 @@ - import * as Koa from 'koa'; import * as send from 'koa-send'; @@ -16,7 +15,7 @@ app.use(async (ctx: Koa.Context) => { hidden: true, format: true, gzip: true, - setHeaders: () => {}, + setHeaders: () => { }, extensions: ['shemp'], }); }); diff --git a/types/koa-send/tslint.json b/types/koa-send/tslint.json index a41bf5d19a..f93cf8562a 100644 --- a/types/koa-send/tslint.json +++ b/types/koa-send/tslint.json @@ -1,79 +1,3 @@ { - "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, - "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 - } + "extends": "dtslint/dt.json" }