Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit d56ad23

Browse files
committed
Add documentation
1 parent c7c4c4d commit d56ad23

7 files changed

Lines changed: 30 additions & 3 deletions

File tree

src/handler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { IncomingMessage, ServerResponse } from 'http';
1212
*
1313
* The handler may be asynchronous.
1414
*
15+
* @category Core
1516
* @typeparam TCtx A type of HTTP request processing context this handler expects.
1617
*/
1718
export type HatsyHandler<TCtx extends HatsyRequestContext = HatsyRequestContext> =
@@ -35,6 +36,8 @@ export type HatsyHandler<TCtx extends HatsyRequestContext = HatsyRequestContext>
3536
* A context instance is immutable. It can be {@link HatsyRequestContext.Modifications modified} or even
3637
* {@link HatsyRequestContext.Extensions extended} when delegating request processing to the [[next]] handler
3738
* by creating another context based on original one.
39+
*
40+
* @category Core
3841
*/
3942
export interface HatsyRequestContext {
4043

@@ -120,6 +123,7 @@ export namespace HatsyRequestContext {
120123
* It iterates over the given handlers in order and delegates the request processing to them. And stops when
121124
* either response is written, an error thrown, or there is no more handlers.
122125
*
126+
* @category Core
123127
* @typeparam TCtx A type of HTTP request processing context the `handlers` expect.
124128
* @param handlers Either single HTTP request handler or iterable of HTTP request handlers to delegate request
125129
* processing to.

src/handlers/render-error.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { hatsyRenderHtml } from './render-html';
1111
*
1212
* This context is created once error is thrown by one of the handlers before passing it to
1313
* {@link HatsyConfig.errorHandler error handler}.
14+
*
15+
* @category Core
1416
*/
1517
export interface HatsyErrorContext extends HatsyRequestContext {
1618

@@ -26,6 +28,7 @@ export interface HatsyErrorContext extends HatsyRequestContext {
2628
*
2729
* Threats {@link HatsyHttpError HTTP status error} as HTTP status code to set for error page.
2830
*
31+
* @category Core
2932
* @param context HTTP processing error context.
3033
*
3134
* @returns New HTTP request handler.

src/handlers/render-html.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
*/
55
import { HatsyHandler, HatsyRequestContext } from '../handler';
66

7+
/**
8+
* Builds HTTP request handler that renders provided HTML on response.
9+
*
10+
* @category Core
11+
* @param html HTML text to render or its promise.
12+
*
13+
* @returns HTTP request handler.
14+
*/
715
export function hatsyRenderHtml(html: string | PromiseLike<string>): HatsyHandler {
816
return async ({ response }: HatsyRequestContext): Promise<void> => {
917

src/handlers/render-json.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
*/
55
import { HatsyHandler, HatsyRequestContext } from '../handler';
66

7-
export function hatsyRenderJson<T>(value: T | PromiseLike<T>): HatsyHandler {
7+
/**
8+
* Builds HTTP request handler that renders the given value as JSON on response.
9+
*
10+
* @category Core
11+
* @param value A value to render or its promise.
12+
*
13+
* @returns HTTP request handler.
14+
*/
15+
export function hatsyRenderJson(value: any | PromiseLike<any>): HatsyHandler {
816
return async ({ response }: HatsyRequestContext): Promise<void> => {
917

1018
const content = await value;

src/http-error.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* {@link HatsyHandler HTTP handlers} may raise this error. The {@link hatsyRenderError} handler would render
99
* corresponding error page then.
1010
*
11+
* @category Core
1112
* @see {@link HatsyConfig.ignoreErrors}
1213
*/
1314
export class HatsyHttpError extends Error {

src/listener.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { HatsyHttpError } from './http-error';
99

1010
/**
1111
* Hatsy configuration.
12+
*
13+
* @category Core
1214
*/
1315
export interface HatsyConfig {
1416

@@ -48,6 +50,7 @@ export interface HatsyConfig {
4850
/**
4951
* Creates Node.js HTTP request listener by Hatsy HTTP handler(s).
5052
*
53+
* @category Core
5154
* @param handlers Either single HTTP request handler or iterable of HTTP request handlers to delegate request
5255
* processing to.
5356
* @param config Hatsy configuration.

typedoc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"categorizeByGroup": true,
3-
"categoryOrder": ["Core", "State Tracking", "Value Tracking", "DOM Events", "*"],
3+
"categoryOrder": ["Core", "Routing", "*"],
44
"exclude": [
55
"**/index.ts",
66
"**/cli/**/*.ts",
@@ -10,7 +10,7 @@
1010
],
1111
"excludeNotExported": true,
1212
"mode": "modules",
13-
"name": "Functional Event Processor",
13+
"name": "Hatsy",
1414
"out": "./target/typedoc",
1515
"tsconfig": "tsconfig.main.json"
1616
}

0 commit comments

Comments
 (0)