Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(jsdoc): add jsdoc of some modules #2836

Merged
merged 36 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
25d1ade
add jsdoc of .route
EdamAme-x May 27, 2024
d35d643
chore: format
EdamAme-x May 27, 2024
28eed02
add jsdoc of .mount
EdamAme-x May 27, 2024
7c136cb
add
EdamAme-x May 27, 2024
f03021f
chore: format
EdamAme-x May 27, 2024
8952455
chore fix
EdamAme-x May 27, 2024
5563cd1
change to format same as ".mount"
EdamAme-x May 27, 2024
241400b
chore fix
EdamAme-x May 27, 2024
470759a
chore fix
EdamAme-x May 27, 2024
0fe2410
docs: change jsdoc of .basePath
EdamAme-x May 27, 2024
955aff9
docs: change jsdoc of onError
EdamAme-x May 27, 2024
1991877
same as doc
EdamAme-x May 27, 2024
a903386
delete
EdamAme-x May 28, 2024
3e40d5f
docs: change jsdoc of .notFound
EdamAme-x May 28, 2024
a8b2265
docs: change jsdoc of .notFound
EdamAme-x May 28, 2024
8e277ce
docs: change jsdoc of .fetch
EdamAme-x May 28, 2024
021f08f
chore: format
EdamAme-x May 28, 2024
4e75b78
docs: change jsdoc of .fire
EdamAme-x May 28, 2024
a52b218
docs: change jsdoc of .fire
EdamAme-x May 28, 2024
ac7c7b8
docs: change jsdoc of hono-options
EdamAme-x May 28, 2024
482d302
docs: change jsdoc of http-exception
EdamAme-x May 28, 2024
b4da548
docs: change jsdoc of hono-request
EdamAme-x May 28, 2024
7fbd076
docs: change jsdoc of context
EdamAme-x May 28, 2024
9c6a25c
delete missing jsdoc
EdamAme-x May 28, 2024
4ad4398
Merge pull request #1 from EdamAme-x/jsdoc-base-path
EdamAme-x May 28, 2024
05e6f60
Merge pull request #2 from EdamAme-x/jsdoc-not-found
EdamAme-x May 28, 2024
25f10d9
Merge pull request #3 from EdamAme-x/jsdoc-on-error
EdamAme-x May 28, 2024
e67cb57
Merge pull request #4 from EdamAme-x/jsdoc-fetch
EdamAme-x May 28, 2024
041229b
Merge pull request #5 from EdamAme-x/jsdoc-fire
EdamAme-x May 28, 2024
c9e2364
Merge pull request #6 from EdamAme-x/jsdoc-for-mount
EdamAme-x May 30, 2024
fc2ba4c
Merge pull request #7 from EdamAme-x/jsdoc
EdamAme-x May 30, 2024
ba48855
Merge pull request #8 from EdamAme-x/jsdoc-context
EdamAme-x May 30, 2024
f2ff88a
Merge pull request #9 from EdamAme-x/jsdoc-hono-request
EdamAme-x May 30, 2024
5e1af0f
Merge pull request #10 from EdamAme-x/jsdoc-http-exception
EdamAme-x May 30, 2024
225a968
Merge pull request #11 from EdamAme-x/jsdoc-options
EdamAme-x May 30, 2024
3183826
Merge branch 'main' into main
EdamAme-x May 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 42 additions & 20 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,20 +223,25 @@ export class Context<
req: HonoRequest<P, I['out']>
/**
* `.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
* app.get('*', async c => {
* 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) => {
Expand All @@ -246,7 +251,6 @@ export class Context<
* }
* })
* ```
* @see https://hono.dev/api/context#error
*/
error: Error | undefined = undefined

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -343,15 +344,16 @@ 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
* app.get('/', (c) => {
* return c.render('Hello!')
* })
* ```
* @see https://hono.dev/api/context#render-setrenderer
*/
render: Renderer = (...args) => this.renderer(...args)

Expand All @@ -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) => {
Expand All @@ -393,14 +398,16 @@ export class Context<
* await next()
* })
* ```
* @see https://hono.dev/api/context#render-setrenderer
*/
setRenderer = (renderer: Renderer) => {
this.renderer = renderer
}

/**
* `.header()` can set headers.
*
* @see {@link https://hono.dev/api/context#body}
*
* @example
* ```ts
* app.get('/welcome', (c) => {
Expand All @@ -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
Expand Down Expand Up @@ -459,14 +465,16 @@ 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) => {
* c.set('message', 'Hono is cool!!')
* await next()
* })
* ```
* @see https://hono.dev/api/context#set-get
```
*/
set: Set<E> = (key: string, value: unknown) => {
Expand All @@ -476,26 +484,30 @@ export class Context<

/**
* `.get()` can use the value specified by the key.
*
* @see {@link https://hono.dev/api/context#set-get}
*
* @example
* ```ts
* app.get('/', (c) => {
* const message = c.get('message')
* return c.text(`The message is "${message}"`)
* })
* ```
* @see https://hono.dev/api/context#set-get
*/
get: Get<E> = (key: string) => {
return this._var ? this._var[key] : undefined
}

/**
* `.var` can access the value of a variable.
*
* @see {@link https://hono.dev/api/context#var}
*
* @example
* ```ts
* const result = c.var.client.oneMethod()
* ```
* @see https://hono.dev/api/context#var
*/
// c.var.propName is a read-only
get var(): Readonly<
Expand Down Expand Up @@ -575,6 +587,9 @@ export class Context<
* `.body()` can return the HTTP response.
* You can set headers with `.header()` and set HTTP status code with `.status`.
* This can also be set in `.text()`, `.json()` and so on.
*
* @see {@link https://hono.dev/api/context#body}
*
* @example
* ```ts
* app.get('/welcome', (c) => {
Expand All @@ -588,7 +603,6 @@ export class Context<
* return c.body('Thank you for coming')
* })
* ```
* @see https://hono.dev/api/context#body
*/
body: BodyRespond = (
data: Data | null,
Expand All @@ -602,13 +616,15 @@ export class Context<

/**
* `.text()` can render text as `Content-Type:text/plain`.
*
* @see {@link https://hono.dev/api/context#text}
*
* @example
* ```ts
* app.get('/say', (c) => {
* return c.text('Hello!')
* })
* ```
* @see https://hono.dev/api/context#text
*/
text: TextRespond = (
text: string,
Expand All @@ -633,13 +649,15 @@ export class Context<

/**
* `.json()` can render JSON as `Content-Type:application/json`.
*
* @see {@link https://hono.dev/api/context#json}
*
* @example
* ```ts
* app.get('/api', (c) => {
* return c.json({ message: 'Hello!' })
* })
* ```
* @see https://hono.dev/api/context#json
*/
json: JSONRespond = <T extends JSONValue | Simplify<unknown>, U extends StatusCode>(
object: T,
Expand Down Expand Up @@ -685,6 +703,9 @@ export class Context<

/**
* `.redirect()` can Redirect, default status code is 302.
*
* @see {@link https://hono.dev/api/context#redirect}
*
* @example
* ```ts
* app.get('/redirect', (c) => {
Expand All @@ -694,7 +715,6 @@ export class Context<
* return c.redirect('/', 301)
* })
* ```
* @see https://hono.dev/api/context#redirect
*/
redirect = (location: string, status: RedirectStatusCode = 302): Response => {
this.#headers ??= new Headers()
Expand All @@ -704,13 +724,15 @@ export class Context<

/**
* `.notFound()` can return the Not Found Response.
*
* @see {@link https://hono.dev/api/context#notfound}
*
* @example
* ```ts
* app.get('/notfound', (c) => {
* return c.notFound()
* })
* ```
* @see https://hono.dev/api/context#notfound
*/
notFound = (): Response | Promise<Response> => {
return this.notFoundHandler(this)
Expand Down
Loading