mirror of
https://github.com/versia-pub/api.git
synced 2025-12-06 08:28:19 +01:00
docs(federation): 📝 Document RequestParserHandler
This commit is contained in:
parent
7c5c2d9f70
commit
80130a1f22
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
* },
|
||||
* ...
|
||||
|
|
|
|||
Loading…
Reference in a new issue