mirror of
https://github.com/versia-pub/api.git
synced 2025-12-06 08:28:19 +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 { z } from "zod";
|
||||||
import type {
|
import type {
|
||||||
|
CollectionSchema,
|
||||||
DeleteSchema,
|
DeleteSchema,
|
||||||
EntitySchema,
|
EntitySchema,
|
||||||
FollowAcceptSchema,
|
FollowAcceptSchema,
|
||||||
|
|
@ -31,6 +32,7 @@ type AnyZod = z.ZodType<any, any, any>;
|
||||||
type InferType<T extends AnyZod> = z.infer<T>;
|
type InferType<T extends AnyZod> = z.infer<T>;
|
||||||
|
|
||||||
export type Note = InferType<typeof NoteSchema>;
|
export type Note = InferType<typeof NoteSchema>;
|
||||||
|
export type Collection = InferType<typeof CollectionSchema>;
|
||||||
export type EntityExtensionProperty = InferType<typeof ExtensionPropertySchema>;
|
export type EntityExtensionProperty = InferType<typeof ExtensionPropertySchema>;
|
||||||
export type VanityExtension = InferType<typeof VanityExtensionSchema>;
|
export type VanityExtension = InferType<typeof VanityExtensionSchema>;
|
||||||
export type User = InferType<typeof UserSchema>;
|
export type User = InferType<typeof UserSchema>;
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,20 @@ export const NoteSchema = EntitySchema.extend({
|
||||||
.nullable(),
|
.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
|
export const PublicKeyDataSchema = z
|
||||||
.object({
|
.object({
|
||||||
key: z.string().min(1),
|
key: z.string().min(1),
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import type { z } from "zod";
|
import type { z } from "zod";
|
||||||
import { fromError } from "zod-validation-error";
|
import { fromError } from "zod-validation-error";
|
||||||
import type {
|
import type {
|
||||||
|
Collection,
|
||||||
ContentFormat,
|
ContentFormat,
|
||||||
CustomEmojiExtension,
|
CustomEmojiExtension,
|
||||||
Delete,
|
Delete,
|
||||||
|
|
@ -22,6 +23,7 @@ import type {
|
||||||
VanityExtension,
|
VanityExtension,
|
||||||
} from "./schemas";
|
} from "./schemas";
|
||||||
import {
|
import {
|
||||||
|
CollectionSchema,
|
||||||
DeleteSchema,
|
DeleteSchema,
|
||||||
EntitySchema,
|
EntitySchema,
|
||||||
FollowAcceptSchema,
|
FollowAcceptSchema,
|
||||||
|
|
@ -99,6 +101,15 @@ export class EntityValidator {
|
||||||
return this.validate(NoteSchema, data);
|
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.
|
* Validates a VanityExtension entity.
|
||||||
* @param data - The data to validate
|
* @param data - The data to validate
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue