mirror of
https://github.com/versia-pub/api.git
synced 2025-12-06 16:38:20 +01:00
feat(federation): ✨ Add Collections
This commit is contained in:
parent
1cffb93d52
commit
1203269531
|
|
@ -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>;
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue