feat(federation): Add Collections

This commit is contained in:
Jesse Wierzbinski 2024-08-26 19:30:56 +02:00
parent 1cffb93d52
commit 1203269531
No known key found for this signature in database
3 changed files with 27 additions and 0 deletions

View file

@ -5,6 +5,7 @@
import type { z } from "zod";
import type {
CollectionSchema,
DeleteSchema,
EntitySchema,
FollowAcceptSchema,
@ -31,6 +32,7 @@ type AnyZod = z.ZodType<any, any, any>;
type InferType<T extends AnyZod> = z.infer<T>;
export type Note = InferType<typeof NoteSchema>;
export type Collection = InferType<typeof CollectionSchema>;
export type EntityExtensionProperty = InferType<typeof ExtensionPropertySchema>;
export type VanityExtension = InferType<typeof VanityExtensionSchema>;
export type User = InferType<typeof UserSchema>;

View file

@ -105,6 +105,20 @@ export const NoteSchema = EntitySchema.extend({
.nullable(),
});
export const CollectionSchema = z.object({
author: z.string().url().nullable(),
first: z.string().url(),
last: z.string().url(),
total: z
.number()
.int()
.nonnegative()
.max(2 ** 64 - 1),
next: z.string().url().nullable(),
previous: z.string().url().nullable(),
items: z.array(z.any()),
});
export const PublicKeyDataSchema = z
.object({
key: z.string().min(1),

View file

@ -1,6 +1,7 @@
import type { z } from "zod";
import { fromError } from "zod-validation-error";
import type {
Collection,
ContentFormat,
CustomEmojiExtension,
Delete,
@ -22,6 +23,7 @@ import type {
VanityExtension,
} from "./schemas";
import {
CollectionSchema,
DeleteSchema,
EntitySchema,
FollowAcceptSchema,
@ -99,6 +101,15 @@ export class EntityValidator {
return this.validate(NoteSchema, data);
}
/**
* Validates a Collection entity.
* @param data - The data to validate
* @returns A promise that resolves to the validated data.
*/
public Collection(data: unknown): Promise<Collection> {
return this.validate(CollectionSchema, data);
}
/**
* Validates a VanityExtension entity.
* @param data - The data to validate