diff --git a/federation/http.ts b/federation/http.ts index 05da75b..9c67ac2 100644 --- a/federation/http.ts +++ b/federation/http.ts @@ -1,18 +1,18 @@ import type { Delete, - Dislike, + DislikeExtension, Follow, FollowAccept, FollowReject, Group, InstanceMetadata, - Like, + LikeExtension, Note, - Reaction, - Share, + PollVoteExtension, + ReactionExtension, + ShareExtension, Unfollow, User, - Vote, } from "./schemas"; import type { EntityValidator } from "./validator"; @@ -24,14 +24,16 @@ type ParserCallbacks = { followAccept: (followAccept: FollowAccept) => MaybePromise; followReject: (followReject: FollowReject) => MaybePromise; user: (user: User) => MaybePromise; - like: (like: Like) => MaybePromise; - dislike: (dislike: Dislike) => MaybePromise; + "pub.versia:likes/Like": (like: LikeExtension) => MaybePromise; + "pub.versia:likes/Dislike": (dislike: DislikeExtension) => MaybePromise; delete: (undo: Delete) => MaybePromise; instanceMetadata: (instanceMetadata: InstanceMetadata) => MaybePromise; group: (group: Group) => MaybePromise; - reaction: (reaction: Reaction) => MaybePromise; - share: (share: Share) => MaybePromise; - vote: (vote: Vote) => MaybePromise; + "pub.versia:reactions/Reaction": ( + reaction: ReactionExtension, + ) => MaybePromise; + "pub.versia:share/Share": (share: ShareExtension) => MaybePromise; + "pub.versia:polls/Vote": (vote: PollVoteExtension) => MaybePromise; unfollow: (unfollow: Unfollow) => MaybePromise; unknown: (data: unknown) => MaybePromise; }; @@ -140,19 +142,21 @@ export class RequestParserHandler { break; } case "Like": { - const like = await this.validator.Like(this.body); + const like = await this.validator.LikeExtension(this.body); - if (callbacks.like) { - return await callbacks.like(like); + if (callbacks["pub.versia:likes/Like"]) { + return await callbacks["pub.versia:likes/Like"](like); } break; } case "Dislike": { - const dislike = await this.validator.Dislike(this.body); + const dislike = await this.validator.DislikeExtension( + this.body, + ); - if (callbacks.dislike) { - return await callbacks.dislike(dislike); + if (callbacks["pub.versia:likes/Dislike"]) { + return await callbacks["pub.versia:likes/Dislike"](dislike); } break; @@ -188,28 +192,32 @@ export class RequestParserHandler { break; } case "Reaction": { - const reaction = await this.validator.Reaction(this.body); + const reaction = await this.validator.ReactionExtension( + this.body, + ); - if (callbacks.reaction) { - return await callbacks.reaction(reaction); + if (callbacks["pub.versia:reactions/Reaction"]) { + return await callbacks["pub.versia:reactions/Reaction"]( + reaction, + ); } break; } case "Share": { - const share = await this.validator.Share(this.body); + const share = await this.validator.ShareExtension(this.body); - if (callbacks.share) { - return await callbacks.share(share); + if (callbacks["pub.versia:share/Share"]) { + return await callbacks["pub.versia:share/Share"](share); } break; } case "Vote": { - const vote = await this.validator.Vote(this.body); + const vote = await this.validator.PollVoteExtension(this.body); - if (callbacks.vote) { - return await callbacks.vote(vote); + if (callbacks["pub.versia:polls/Vote"]) { + return await callbacks["pub.versia:polls/Vote"](vote); } break; diff --git a/federation/schemas.ts b/federation/schemas.ts index 1e29375..ec70413 100644 --- a/federation/schemas.ts +++ b/federation/schemas.ts @@ -13,16 +13,10 @@ import type { GroupSchema, InstanceMetadataSchema, NoteSchema, - PublicKeyDataSchema, UnfollowSchema, UserSchema, } from "./schemas/base"; -import type { - AudioOnlyContentFormatSchema, - ContentFormatSchema, - ImageOnlyContentFormatSchema, - TextOnlyContentFormatSchema, -} from "./schemas/content_format"; +import type { ContentFormatSchema } from "./schemas/content_format"; import type { ExtensionPropertySchema } from "./schemas/extensions"; import type { CustomEmojiExtensionSchema } from "./schemas/extensions/custom_emojis"; import type { LikeSchema } from "./schemas/extensions/likes"; @@ -37,25 +31,21 @@ type AnyZod = z.ZodType; type InferType = z.infer; export type Note = InferType; -export type ActorPublicKeyData = InferType; -export type ExtensionProperty = InferType; +export type EntityExtensionProperty = InferType; export type VanityExtension = InferType; export type User = InferType; export type Follow = InferType; export type FollowAccept = InferType; export type FollowReject = InferType; export type ContentFormat = InferType; -export type ImageContentFormat = InferType; -export type TextContentFormat = InferType; -export type AudioContentFormat = InferType; export type CustomEmojiExtension = InferType; export type Entity = InferType; export type Delete = InferType; export type Group = InferType; export type InstanceMetadata = InferType; export type Unfollow = InferType; -export type Like = InferType; -export type Dislike = InferType; -export type Vote = InferType; -export type Reaction = InferType; -export type Share = InferType; +export type LikeExtension = InferType; +export type DislikeExtension = InferType; +export type PollVoteExtension = InferType; +export type ReactionExtension = InferType; +export type ShareExtension = InferType; diff --git a/federation/validator.ts b/federation/validator.ts index 35b1594..3df9412 100644 --- a/federation/validator.ts +++ b/federation/validator.ts @@ -1,5 +1,26 @@ import type { z } from "zod"; import { fromError } from "zod-validation-error"; +import type { + ContentFormat, + CustomEmojiExtension, + Delete, + DislikeExtension, + Entity, + EntityExtensionProperty, + Follow, + FollowAccept, + FollowReject, + Group, + InstanceMetadata, + LikeExtension, + Note, + PollVoteExtension, + ReactionExtension, + ShareExtension, + Unfollow, + User, + VanityExtension, +} from "./schemas"; import { DeleteSchema, EntitySchema, @@ -9,7 +30,6 @@ import { GroupSchema, InstanceMetadataSchema, NoteSchema, - PublicKeyDataSchema, UnfollowSchema, UserSchema, } from "./schemas/base"; @@ -75,29 +95,16 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public Note(data: unknown): Promise> { + public Note(data: unknown): Promise { return this.validate(NoteSchema, data); } - /** - * Validates an ActorPublicKeyData entity. - * @param data - The data to validate - * @returns A promise that resolves to the validated data. - */ - public ActorPublicKeyData( - data: unknown, - ): Promise> { - return this.validate(PublicKeyDataSchema, data); - } - /** * Validates a VanityExtension entity. * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public VanityExtension( - data: unknown, - ): Promise> { + public VanityExtension(data: unknown): Promise { return this.validate(VanityExtensionSchema, data); } @@ -106,7 +113,7 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public User(data: unknown): Promise> { + public User(data: unknown): Promise { return this.validate(UserSchema, data); } @@ -115,7 +122,7 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public Follow(data: unknown): Promise> { + public Follow(data: unknown): Promise { return this.validate(FollowSchema, data); } @@ -124,9 +131,7 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public FollowAccept( - data: unknown, - ): Promise> { + public FollowAccept(data: unknown): Promise { return this.validate(FollowAcceptSchema, data); } @@ -135,9 +140,7 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public FollowReject( - data: unknown, - ): Promise> { + public FollowReject(data: unknown): Promise { return this.validate(FollowRejectSchema, data); } @@ -146,9 +149,7 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public ContentFormat( - data: unknown, - ): Promise> { + public ContentFormat(data: unknown): Promise { return this.validate(ContentFormatSchema, data); } @@ -157,9 +158,7 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public CustomEmojiExtension( - data: unknown, - ): Promise> { + public CustomEmojiExtension(data: unknown): Promise { return this.validate(CustomEmojiExtensionSchema, data); } @@ -168,7 +167,7 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public Entity(data: unknown): Promise> { + public Entity(data: unknown): Promise { return this.validate(EntitySchema, data); } @@ -177,9 +176,9 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public ExtensionProperty( + public EntityExtensionProperty( data: unknown, - ): Promise> { + ): Promise { return this.validate(ExtensionPropertySchema, data); } @@ -188,7 +187,7 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public Delete(data: unknown): Promise> { + public Delete(data: unknown): Promise { return this.validate(DeleteSchema, data); } @@ -197,7 +196,7 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public Group(data: unknown): Promise> { + public Group(data: unknown): Promise { return this.validate(GroupSchema, data); } @@ -206,9 +205,7 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public InstanceMetadata( - data: unknown, - ): Promise> { + public InstanceMetadata(data: unknown): Promise { return this.validate(InstanceMetadataSchema, data); } @@ -217,7 +214,7 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public Unfollow(data: unknown): Promise> { + public Unfollow(data: unknown): Promise { return this.validate(UnfollowSchema, data); } @@ -226,7 +223,7 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public Like(data: unknown): Promise> { + public LikeExtension(data: unknown): Promise { return this.validate(LikeSchema, data); } @@ -235,7 +232,7 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public Dislike(data: unknown): Promise> { + public DislikeExtension(data: unknown): Promise { return this.validate(LikeSchema, data); } @@ -244,7 +241,7 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public Vote(data: unknown): Promise> { + public PollVoteExtension(data: unknown): Promise { return this.validate(VoteSchema, data); } @@ -253,7 +250,7 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public Reaction(data: unknown): Promise> { + public ReactionExtension(data: unknown): Promise { return this.validate(ReactionSchema, data); } @@ -262,7 +259,7 @@ export class EntityValidator { * @param data - The data to validate * @returns A promise that resolves to the validated data. */ - public Share(data: unknown): Promise> { + public ShareExtension(data: unknown): Promise { return this.validate(ShareSchema, data); } }