diff --git a/src/context.ts b/src/context.ts index 3d656d07..6f35b5ee 100644 --- a/src/context.ts +++ b/src/context.ts @@ -223,6 +223,9 @@ export class Context< req: HonoRequest
/**
* `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
+ *
+ * @see {@link https://hono.dev/api/context#env}
+ *
* @example
* ```ts
* // Environment object for Cloudflare Workers
@@ -230,13 +233,15 @@ export class Context<
* const counter = c.env.COUNTER
* })
* ```
- * @see https://hono.dev/api/context#env
*/
env: E['Bindings'] = {}
private _var: E['Variables'] = {}
finalized: boolean = false
/**
* `.error` can get the error object from the middleware if the Handler throws an error.
+ *
+ * @see {@link https://hono.dev/api/context#error}
+ *
* @example
* ```ts
* app.use('*', async (c, next) => {
@@ -246,7 +251,6 @@ export class Context<
* }
* })
* ```
- * @see https://hono.dev/api/context#error
*/
error: Error | undefined = undefined
@@ -278,11 +282,10 @@ export class Context<
}
/**
+ * @see {@link https://hono.dev/api/context#event}
* The FetchEvent associated with the current request.
*
* @throws Will throw an error if the context does not have a FetchEvent.
- *
- * @see https://hono.dev/api/context#event
*/
get event(): FetchEventLike {
if (this.#executionCtx && 'respondWith' in this.#executionCtx) {
@@ -293,11 +296,10 @@ export class Context<
}
/**
+ * @see {@link https://hono.dev/api/context#executionctx}
* The ExecutionContext associated with the current request.
*
* @throws Will throw an error if the context does not have an ExecutionContext.
- *
- * @see https://hono.dev/api/context#executionctx
*/
get executionCtx(): ExecutionContext {
if (this.#executionCtx) {
@@ -308,9 +310,8 @@ export class Context<
}
/**
+ * @see {@link https://hono.dev/api/context#res}
* The Response object for the current request.
- *
- * @see https://hono.dev/api/context#res
*/
get res(): Response {
this.#isFresh = false
@@ -343,7 +344,9 @@ export class Context<
}
/**
- * Renders a response within a layout.
+ * `.render()` can create a response within a layout.
+ *
+ * @see {@link https://hono.dev/api/context#render-setrenderer}
*
* @example
* ```ts
@@ -351,7 +354,6 @@ export class Context<
* return c.render('Hello!')
* })
* ```
- * @see https://hono.dev/api/context#render-setrenderer
*/
render: Renderer = (...args) => this.renderer(...args)
@@ -378,6 +380,9 @@ export class Context<
/**
* `.setRenderer()` can set the layout in the custom middleware.
+ *
+ * @see {@link https://hono.dev/api/context#render-setrenderer}
+ *
* @example
* ```tsx
* app.use('*', async (c, next) => {
@@ -393,7 +398,6 @@ export class Context<
* await next()
* })
* ```
- * @see https://hono.dev/api/context#render-setrenderer
*/
setRenderer = (renderer: Renderer): void => {
this.renderer = renderer
@@ -401,6 +405,9 @@ export class Context<
/**
* `.header()` can set headers.
+ *
+ * @see {@link https://hono.dev/api/context#body}
+ *
* @example
* ```ts
* app.get('/welcome', (c) => {
@@ -411,7 +418,6 @@ export class Context<
* return c.body('Thank you for coming')
* })
* ```
- * @see https://hono.dev/api/context#body
*/
header = (name: string, value: string | undefined, options?: { append?: boolean }): void => {
// Clear the header
@@ -459,6 +465,9 @@ export class Context<
/**
* `.set()` can set the value specified by the key.
+ *
+ * @see {@link https://hono.dev/api/context#set-get}
+ *
* @example
* ```ts
* app.use('*', async (c, next) => {
@@ -466,7 +475,6 @@ export class Context<
* await next()
* })
* ```
- * @see https://hono.dev/api/context#set-get
```
*/
set: Set {
/**
* `.raw` can get the raw Request object.
+ *
+ * @see {@link https://hono.dev/api/request#raw}
+ *
* @example
* ```ts
* // For Cloudflare Workers
@@ -34,7 +37,6 @@ export class HonoRequest {
* ...
* })
* ```
- * @see https://hono.dev/api/request#raw
*/
raw: Request
@@ -43,13 +45,15 @@ export class HonoRequest {
routeIndex: number = 0
/**
* `.path` can get the pathname of the request.
+ *
+ * @see {@link https://hono.dev/api/request#path}
+ *
* @example
* ```ts
* app.get('/about/me', (c) => {
* const pathname = c.req.path // `/about/me`
* })
* ```
- * @see https://hono.dev/api/request#path
*/
path: string
bodyCache: BodyCache = {}
@@ -67,13 +71,15 @@ export class HonoRequest {
/**
* `.req.param()` gets the path parameters.
+ *
+ * @see {@link https://hono.dev/api/routing#path-parameter}
+ *
* @example
* ```ts
* const name = c.req.param('name')
* // or all parameters at once
* const { id, comment_id } = c.req.param()
* ```
- * @see https://hono.dev/api/routing#path-parameter
*/
param >(key: P2 extends `${infer _}?` ? never : P2): string
param {
/**
* `.query()` can get querystring parameters.
+ *
+ * @see {@link https://hono.dev/api/request#query}
+ *
* @example
* ```ts
* // Query params
@@ -124,7 +133,6 @@ export class HonoRequest {
* const { q, limit, offset } = c.req.query()
* })
* ```
- * @see https://hono.dev/api/request#query
*/
query(key: string): string | undefined
query(): Record {
/**
* `.queries()` can get multiple querystring parameter values, e.g. /search?tags=A&tags=B
+ *
+ * @see {@link https://hono.dev/api/request#queries}
+ *
* @example
* ```ts
* app.get('/search', (c) => {
@@ -141,7 +152,6 @@ export class HonoRequest {
* const tags = c.req.queries('tags')
* })
* ```
- * @see https://hono.dev/api/request#queries
*/
queries(key: string): string[] | undefined
queries(): Record {
/**
* `.header()` can get the request header value.
+ *
+ * @see {@link https://hono.dev/api/request#header}
+ *
* @example
* ```ts
* app.get('/', (c) => {
* const userAgent = c.req.header('User-Agent')
* })
* ```
- * @see https://hono.dev/api/request#header
*/
header(name: string): string | undefined
header(): Record {
/**
* `.parseBody()` can parse Request body of type `multipart/form-data` or `application/x-www-form-urlencoded`
+ *
+ * @see {@link https://hono.dev/api/request#parsebody}
+ *
* @example
* ```ts
* app.post('/entry', async (c) => {
* const body = await c.req.parseBody()
* })
* ```
- * @see https://hono.dev/api/request#parsebody
*/
async parseBody {
/**
* `.json()` can parse Request body of type `application/json`
+ *
+ * @see {@link https://hono.dev/api/request#json}
+ *
* @example
* ```ts
* app.post('/entry', async (c) => {
* const body = await c.req.json()
* })
* ```
- * @see https://hono.dev/api/request#json
*/
json {
/**
* `.text()` can parse Request body of type `text/plain`
+ *
+ * @see {@link https://hono.dev/api/request#text}
+ *
* @example
* ```ts
* app.post('/entry', async (c) => {
* const body = await c.req.text()
* })
* ```
- * @see https://hono.dev/api/request#text
*/
text(): Promise {
/**
* `.arrayBuffer()` parse Request body as an `ArrayBuffer`
+ *
+ * @see {@link https://hono.dev/api/request#arraybuffer}
+ *
* @example
* ```ts
* app.post('/entry', async (c) => {
* const body = await c.req.arrayBuffer()
* })
* ```
- * @see https://hono.dev/api/request#arraybuffer
*/
arrayBuffer(): Promise {
/**
* `.url()` can get the request url strings.
+ *
+ * @see {@link https://hono.dev/api/request#url}
+ *
* @example
* ```ts
* app.get('/about/me', (c) => {
@@ -325,7 +348,6 @@ export class HonoRequest {
* ...
* })
* ```
- * @see https://hono.dev/api/request#url
*/
get url(): string {
return this.raw.url
@@ -333,13 +355,15 @@ export class HonoRequest {
/**
* `.method()` can get the method name of the request.
+ *
+ * @see {@link https://hono.dev/api/request#method}
+ *
* @example
* ```ts
* app.get('/about/me', (c) => {
* const method = c.req.method // `GET`
* })
* ```
- * @see https://hono.dev/api/request#method
*/
get method(): string {
return this.raw.method
@@ -347,6 +371,9 @@ export class HonoRequest {
/**
* `.matchedRoutes()` can return a matched route in the handler
+ *
+ * @see {@link https://hono.dev/api/request#matchedroutes}
+ *
* @example
* ```ts
* app.use('*', async function logger(c, next) {
@@ -364,7 +391,6 @@ export class HonoRequest {
* })
* })
* ```
- * @see https://hono.dev/api/request#matchedroutes
*/
get matchedRoutes(): RouterRoute[] {
return this.#matchResult[0].map(([[, route]]) => route)
@@ -372,13 +398,15 @@ export class HonoRequest {
/**
* `routePath()` can retrieve the path registered within the handler
+ *
+ * @see {@link https://hono.dev/api/request#routepath}
+ *
* @example
* ```ts
* app.get('/posts/:id', (c) => {
* return c.json({ path: c.req.routePath })
* })
* ```
- * @see https://hono.dev/api/request#routepath
*/
get routePath(): string {
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path