From 3ed54a7c21e69b79b410bac687f30f47d75e5397 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Tue, 28 May 2024 14:22:30 -1000 Subject: [PATCH] docs(federation): :memo: Add some docs to new request parser classes --- federation/http/index.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/federation/http/index.ts b/federation/http/index.ts index bc8801b..42617fa 100644 --- a/federation/http/index.ts +++ b/federation/http/index.ts @@ -23,6 +23,21 @@ type ParserCallbacks = { ) => MaybePromise; }; +/** + * A class to parse the body of a request and call the appropriate callback. + * @example + * const parser = new RequestParserHandler(body, validator); + * + * await parser.parseBody({ + * note: (note) => { + * console.log(note); + * }, + * follow: (follow) => { + * console.log(follow); + * }, + * ... + * }); + */ export class RequestParserHandler { constructor( private readonly body: Record< @@ -35,8 +50,20 @@ export class RequestParserHandler { /** * Parse the body of the request and call the appropriate callback. * To change the return type, edit the ReturnType generic parameter. + * const parser = new RequestParserHandler(body, validator); * @param callbacks The callbacks to call when a specific entity is found. * @returns A promise that resolves when the body has been parsed, and the callbacks have finished executing. + * @throws If the type field is missing or invalid + * @example + * await parser.parseBody({ + * note: (note) => { + * console.log(note); + * }, + * follow: (follow) => { + * console.log(follow); + * }, + * ... + * }); */ public async parseBody( callbacks: Partial>,