dahlia / fedify

ActivityPub server framework in TypeScript
https://fedify.dev/
MIT License
493 stars 19 forks source link

Use zod #38

Closed alexgleason closed 5 months ago

alexgleason commented 5 months ago

This library would benefit a lot from zod schemas.

I've built some here: https://gitlab.com/soapbox-pub/mostr/-/blob/main/src/activitypub/schema.ts

It's needed to ensure the response actually matches the interface.

dahlia commented 5 months ago

Fedify doesn't just treat Activity Vocabulary as JSON, but rather as JSON-LD. Internally, it normalizes JSON to JSON-LD expanded form. Different ActivityPub implementations have slightly different JSON schema, and normalization allows for interoperability.

Zod takes the approach that the identifiers used in the input and output JSON are used in the program, which is too long and cumbersome for JSON-LD expanded form because the identifiers are IRIs.

Validation, the main problem Zod solves, is already in place in the @fedify/fedify/vocab module, so you don't have to worry about it.

alexgleason commented 5 months ago

Thank you for the explanation, that makes sense!

You could possibly use it for the Webfinger lookup, still.

Also, I wanted to tell you that your work inspired me so much that I shamelessly copied it! https://nostrify.dev/

Thank you for introducing me to Vitepress, it's an amazing super power. And I thought the name was great too. So, I created the sister project. :smiley:

dahlia commented 5 months ago

You could possibly use it for the Webfinger lookup, still.

Alright, so I'll consider using Zod for the WebFinger schema.

Also, I wanted to tell you that your work inspired me so much that I shamelessly copied it! https://nostrify.dev/

Cool project, I'll keep an eye on it.