add editorconfig
This commit is contained in:
9
.editorconfig
Normal file
9
.editorconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = false
|
||||
|
||||
[src/**.ts]
|
||||
charset = utf-8
|
||||
indent_style = tab
|
||||
138
src/index.ts
138
src/index.ts
@@ -1,26 +1,26 @@
|
||||
/**
|
||||
* Route Object
|
||||
*
|
||||
* @typedef Route
|
||||
* @property {string} method HTTP request method
|
||||
* @property {string} url URL String
|
||||
* @property {RouterHandler[]} handlers Array of handler functions
|
||||
*/
|
||||
export interface Route<TEnv> {
|
||||
* Route Object
|
||||
*
|
||||
* @typedef Route
|
||||
* @property {string} method HTTP request method
|
||||
* @property {string} url URL String
|
||||
* @property {RouterHandler[]} handlers Array of handler functions
|
||||
*/
|
||||
export interface Route<TEnv> {
|
||||
method: string
|
||||
url: string
|
||||
handlers: RouterHandler<TEnv>[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Router Context
|
||||
*
|
||||
* @typedef RouterContext
|
||||
* @property {RouterEnv} env Environment
|
||||
* @property {RouterRequest} req Request Object
|
||||
* @property {RouterResponse} res Response Object
|
||||
* @property {RouterNext} next Next Handler
|
||||
*/
|
||||
* Router Context
|
||||
*
|
||||
* @typedef RouterContext
|
||||
* @property {RouterEnv} env Environment
|
||||
* @property {RouterRequest} req Request Object
|
||||
* @property {RouterResponse} res Response Object
|
||||
* @property {RouterNext} next Next Handler
|
||||
*/
|
||||
export interface RouterContext<TEnv> {
|
||||
env: TEnv
|
||||
req: RouterRequest
|
||||
@@ -29,17 +29,17 @@ export interface RouterContext<TEnv> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Request Object
|
||||
*
|
||||
* @typedef RouterRequest
|
||||
* @property {string} url URL
|
||||
* @property {string} method HTTP request method
|
||||
* @property {RouterRequestParams} params Object containing all parameters defined in the url string
|
||||
* @property {RouterRequestQuery} query Object containing all query parameters
|
||||
* @property {Headers} headers Request headers object
|
||||
* @property {string | any} body Only available if method is `POST`, `PUT`, `PATCH` or `DELETE`. Contains either the received body string or a parsed object if valid JSON was sent.
|
||||
* @property {IncomingRequestCfProperties} [cf] object containing custom Cloudflare properties. (https://developers.cloudflare.com/workers/examples/accessing-the-cloudflare-object)
|
||||
*/
|
||||
* Request Object
|
||||
*
|
||||
* @typedef RouterRequest
|
||||
* @property {string} url URL
|
||||
* @property {string} method HTTP request method
|
||||
* @property {RouterRequestParams} params Object containing all parameters defined in the url string
|
||||
* @property {RouterRequestQuery} query Object containing all query parameters
|
||||
* @property {Headers} headers Request headers object
|
||||
* @property {string | any} body Only available if method is `POST`, `PUT`, `PATCH` or `DELETE`. Contains either the received body string or a parsed object if valid JSON was sent.
|
||||
* @property {IncomingRequestCfProperties} [cf] object containing custom Cloudflare properties. (https://developers.cloudflare.com/workers/examples/accessing-the-cloudflare-object)
|
||||
*/
|
||||
export interface RouterRequest {
|
||||
url: string
|
||||
method: string
|
||||
@@ -52,32 +52,32 @@ export interface RouterRequest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Request Parameters
|
||||
*
|
||||
* @typedef RouterRequestParams
|
||||
*/
|
||||
* Request Parameters
|
||||
*
|
||||
* @typedef RouterRequestParams
|
||||
*/
|
||||
export interface RouterRequestParams {
|
||||
[key: string]: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Request Query
|
||||
*
|
||||
* @typedef RouterRequestQuery
|
||||
*/
|
||||
* Request Query
|
||||
*
|
||||
* @typedef RouterRequestQuery
|
||||
*/
|
||||
export interface RouterRequestQuery {
|
||||
[key: string]: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Response Object
|
||||
*
|
||||
* @typedef RouterResponse
|
||||
* @property {Headers} headers Response headers object
|
||||
* @property {number} [status=204] Return status code (default: `204`)
|
||||
* @property {string | any} [body] Either an `object` (will be converted to JSON) or a string
|
||||
* @property {Response} [raw] A response object that is to be returned, this will void all other res properties and return this as is.
|
||||
*/
|
||||
* Response Object
|
||||
*
|
||||
* @typedef RouterResponse
|
||||
* @property {Headers} headers Response headers object
|
||||
* @property {number} [status=204] Return status code (default: `204`)
|
||||
* @property {string | any} [body] Either an `object` (will be converted to JSON) or a string
|
||||
* @property {Response} [raw] A response object that is to be returned, this will void all other res properties and return this as is.
|
||||
*/
|
||||
export interface RouterResponse {
|
||||
headers: Headers
|
||||
status?: number
|
||||
@@ -87,36 +87,36 @@ export interface RouterResponse {
|
||||
}
|
||||
|
||||
/**
|
||||
* Next Function
|
||||
*
|
||||
* @callback RouterNext
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
* Next Function
|
||||
*
|
||||
* @callback RouterNext
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export interface RouterNext {
|
||||
(): Promise<void>
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler Function
|
||||
*
|
||||
* @callback RouterHandler
|
||||
* @param {RouterContext} ctx
|
||||
* @returns {Promise<void> | void}
|
||||
*/
|
||||
* Handler Function
|
||||
*
|
||||
* @callback RouterHandler
|
||||
* @param {RouterContext} ctx
|
||||
* @returns {Promise<void> | void}
|
||||
*/
|
||||
export interface RouterHandler<TEnv = any> {
|
||||
(ctx: RouterContext<TEnv>): Promise<void> | void
|
||||
}
|
||||
|
||||
/**
|
||||
* CORS Config
|
||||
*
|
||||
* @typedef RouterCorsConfig
|
||||
* @property {string} [allowOrigin="*"] Access-Control-Allow-Origin (default: `*`)
|
||||
* @property {string} [allowMethods="*"] Access-Control-Allow-Methods (default: `*`)
|
||||
* @property {string} [allowHeaders="*"] Access-Control-Allow-Headers (default: `*`)
|
||||
* @property {number} [maxAge=86400] Access-Control-Max-Age (default: `86400`)
|
||||
* @property {number} [optionsSuccessStatus=204] Return status code for OPTIONS request (default: `204`)
|
||||
*/
|
||||
* CORS Config
|
||||
*
|
||||
* @typedef RouterCorsConfig
|
||||
* @property {string} [allowOrigin="*"] Access-Control-Allow-Origin (default: `*`)
|
||||
* @property {string} [allowMethods="*"] Access-Control-Allow-Methods (default: `*`)
|
||||
* @property {string} [allowHeaders="*"] Access-Control-Allow-Headers (default: `*`)
|
||||
* @property {number} [maxAge=86400] Access-Control-Max-Age (default: `86400`)
|
||||
* @property {number} [optionsSuccessStatus=204] Return status code for OPTIONS request (default: `204`)
|
||||
*/
|
||||
export interface RouterCorsConfig {
|
||||
allowOrigin?: string
|
||||
allowMethods?: string
|
||||
@@ -126,11 +126,11 @@ export interface RouterCorsConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* Router
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
*/
|
||||
* Router
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
*/
|
||||
export class Router<TEnv = any> {
|
||||
|
||||
/**
|
||||
@@ -167,7 +167,7 @@ export class Router<TEnv = any> {
|
||||
|
||||
/**
|
||||
* CORS enabled
|
||||
*-
|
||||
*
|
||||
* @protected
|
||||
* @type {boolean}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user