docs(federation): 📝 Document RequestParserHandler

This commit is contained in:
Jesse Wierzbinski 2024-06-25 19:34:54 -10:00
parent 7c5c2d9f70
commit 80130a1f22
No known key found for this signature in database
2 changed files with 28 additions and 0 deletions

View file

@ -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.

View file

@ -32,13 +32,17 @@ type ParserCallbacks<T> = {
/**
* 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);
* },
* ...