diff --git a/federation/README.md b/federation/README.md index 6773f2f..a3c7e30 100644 --- a/federation/README.md +++ b/federation/README.md @@ -52,6 +52,30 @@ const validNote = await validator.Note(validNoteObject); Your editor's IntelliSense should provide you with every method and property available, which all match the [**Lysand**](https://lysand.org) specification names. +#### Validation Helper + +`RequestParserHandler` is a class to parse the body of a request and call the appropriate callback. It is a helper for the `EntityValidator` class. + +```typescript +const body = { ... }; +const validator = new EntityValidator(); +const parser = new RequestParserHandler(body, validator); + +// Throws an error if the object is invalid +// Same error as above +await parser.parseBody({ + note: (note) => { + // If the object is a Note, this will be called + console.log(note); + }, + follow: (follow) => { + // If the object is a Follow, this will be called + console.log(follow); + }, + ... +}); +``` + #### Cryptography The cryptography module provides two main classes: [`SignatureConstructor`](federation/cryptography/index.ts) and [`SignatureValidator`](federation/cryptography/index.ts). These classes are used to construct and validate signatures for requests, respectively. diff --git a/federation/http/index.ts b/federation/http/index.ts index 8cb6421..8d7ccac 100644 --- a/federation/http/index.ts +++ b/federation/http/index.ts @@ -32,13 +32,17 @@ type ParserCallbacks = { /** * A class to parse the body of a request and call the appropriate callback. * @example + * const body = { ... }; + * const validator = new EntityValidator(); * const parser = new RequestParserHandler(body, validator); * * await parser.parseBody({ * note: (note) => { + * // If the object is a Note, this will be called * console.log(note); * }, * follow: (follow) => { + * // If the object is a Follow, this will be called * console.log(follow); * }, * ...