Options
All
  • Public
  • Public/Protected
  • All
Menu

koa-hooks

Index

Type aliases

Next

Next<T>: (value?: T) => TaskResult<any>

Type parameters

  • T

Type declaration

ParallelTask

ParallelTask<T>: (value: T) => TaskResult<any>

Type parameters

  • T

Type declaration

RequestMiddleware

RequestMiddleware: SeriesTask<RequestContext>

请求中间件

SeriesTask

SeriesTask<T>: (value: T, next: Next<T>) => TaskResult<any>

串行任务处理函数

Type parameters

  • T

Type declaration

SyncNext

SyncNext<T>: (value: T) => T

Type parameters

  • T

Type declaration

    • (value: T): T
    • Parameters

      • value: T

      Returns T

SyncParallelTask

SyncParallelTask<T>: (value: T) => T

Type parameters

  • T

Type declaration

    • (value: T): T
    • Parameters

      • value: T

      Returns T

SyncSeriesTask

SyncSeriesTask<T>: (value: T, next: SyncNext<T>) => T

Type parameters

  • T

Type declaration

    • Parameters

      Returns T

SyncTask

SyncTask<T>: (value: T, next: SyncNext<T>) => T

Type parameters

  • T

Type declaration

    • Parameters

      Returns T

Task

Task<T>: (value: T, next: Next<T>) => TaskResult<any>

Type parameters

  • T

Type declaration

TaskResult

TaskResult<T>: T | Promise<T>

Type parameters

  • T

URLForOptions

URLForOptions: { query: string | Record<string | number, any> }

Type declaration

  • query: string | Record<string | number, any>

Variables

Const map

map: Map<number, Runtime> = new Map<number, Runtime>()

当前请求上下文

mdn 上介绍说 map 比 object 在频繁增删键值对的场景下表现更好。

see:

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Map

Const middlewares

middlewares: RequestMiddleware[] = []

中间件

Const namedRoutes

namedRoutes: Record<string, PathFunction>

命名路由规则

Functions

assertStatusCode

  • assertStatusCode(statusCode: number): void

createContext

  • createContext(req: IncomingMessage, res: ServerResponse): RequestContext

destroy

  • destroy(asyncId: number): void

dispatch

  • dispatch(req: IncomingMessage, res: ServerResponse): Promise<void>

errorHandler

flatten

  • flatten<T>(args: (T | T[])[]): T[]

get

  • get<Key>(key: Key): Runtime[Key]

init

isNoContentStatusCode

  • isNoContentStatusCode(statusCode: number): boolean

listen

  • listen(port?: undefined | number, hostname?: undefined | string, backlog?: undefined | number, callback?: undefined | (() => void)): Server
  • listen(port?: undefined | number, hostname?: undefined | string, callback?: undefined | (() => void)): Server
  • listen(port?: undefined | number, backlog?: undefined | number, callback?: undefined | (() => void)): Server
  • listen(port?: undefined | number, callback?: undefined | (() => void)): Server
  • listen(path: string, backlog?: undefined | number, callback?: undefined | (() => void)): Server
  • listen(path: string, callback?: undefined | (() => void)): Server
  • listen(options: ListenOptions, callback?: undefined | (() => void)): Server
  • 监听端口号

    Parameters

    • Optional port: undefined | number

      端口号

    • Optional hostname: undefined | string

      主机名称

    • Optional backlog: undefined | number

      指定待连接队列的最大长度

    • Optional callback: undefined | (() => void)

      回调函数

    Returns Server

  • 监听端口号

    Parameters

    • Optional port: undefined | number

      端口号

    • Optional hostname: undefined | string

      主机名称

    • Optional callback: undefined | (() => void)

      回调函数

    Returns Server

  • 监听端口号

    Parameters

    • Optional port: undefined | number

      端口号

    • Optional backlog: undefined | number

      指定待连接队列的最大长度

    • Optional callback: undefined | (() => void)

      回调函数

    Returns Server

  • 监听端口号

    Parameters

    • Optional port: undefined | number

      端口号

    • Optional callback: undefined | (() => void)

      回调函数

    Returns Server

  • 监听端口号

    Parameters

    • path: string

      路径

    • Optional backlog: undefined | number

      指定待连接队列的最大长度

    • Optional callback: undefined | (() => void)

      回调函数

    Returns Server

  • 监听端口号

    Parameters

    • path: string

      路径

    • Optional callback: undefined | (() => void)

      回调函数

    Returns Server

  • 监听端口号

    Parameters

    • options: ListenOptions

      监听配置

    • Optional callback: undefined | (() => void)

      回调函数

    Returns Server

makeEmptyResponse

  • makeEmptyResponse(res: ServerResponse, statusCode?: number): void
  • 创建空的响应输出

    Parameters

    • res: ServerResponse

      响应对象

    • Default value statusCode: number = 204

      http 状态码

    Returns void

makeResponse

memo

  • memo<Result, Args>(callback: (...args: any[]) => Result | any): (Anonymous function)
  • 缓存回调函数的执行结果

    Type parameters

    • Result

    • Args

    Parameters

    • callback: (...args: any[]) => Result | any

      回调函数

        • (...args: any[]): Result | any
        • Parameters

          • Rest ...args: any[]

          Returns Result | any

    Returns (Anonymous function)

onerror

  • onerror(err: Error): void

parallel

redirect

  • redirect(location: string, code?: 301 | 302): void

route

runSyncTasks

runTasks

  • runTasks<T>(tasks: SeriesTask<T>[], initialValue?: T): Promise<T>

series

seriesSync

  • seriesSync<T>(...handlers: (((value: T, next: SyncNext<T>) => T) | ((value: T, next: SyncNext<T>) => T)[])[]): (value: T, next?: SyncNext<T>) => any

sleep

  • sleep(ms: number): Promise<void>

urlFor

  • urlFor(name: string, params?: Record<string, any>, options?: URLForOptions): string

use

useContext

  • useContext<Key>(): RequestContext
  • useContext<Key>(key: Key): RequestContext[Key]

useEffect

  • useEffect(_callback: () => void | Promise<void>): void
  • 每次请求结束时执行

    Parameters

    • _callback: () => void | Promise<void>
        • (): void | Promise<void>
        • Returns void | Promise<void>

    Returns void

Object literals

Const context

context: object

finished

writable

Generated using TypeDoc