mirror of
https://github.com/versia-pub/api.git
synced 2025-12-06 08:28:19 +01:00
refactor(federation): ♻️ Avoid barrel files
This commit is contained in:
parent
c9f4885c72
commit
737c8515da
|
|
@ -7,11 +7,8 @@ import type { z } from "zod";
|
|||
import type {
|
||||
ActionSchema,
|
||||
ActorPublicKeyDataSchema,
|
||||
ContentFormatSchema,
|
||||
CustomEmojiExtensionSchema,
|
||||
DislikeSchema,
|
||||
EntitySchema,
|
||||
ExtensionPropertySchema,
|
||||
ExtensionSchema,
|
||||
FollowAcceptSchema,
|
||||
FollowRejectSchema,
|
||||
|
|
@ -24,9 +21,12 @@ import type {
|
|||
ServerMetadataSchema,
|
||||
UndoSchema,
|
||||
UserSchema,
|
||||
VanityExtensionSchema,
|
||||
VisibilitySchema,
|
||||
} from "./schemas/base";
|
||||
import type { ContentFormatSchema } from "./schemas/content_format";
|
||||
import type { ExtensionPropertySchema } from "./schemas/extensions";
|
||||
import type { CustomEmojiExtensionSchema } from "./schemas/extensions/custom_emojis";
|
||||
import type { VanityExtensionSchema } from "./schemas/extensions/vanity";
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: Used only as a base type
|
||||
type AnyZod = z.ZodType<any, any, any>;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import { z } from "zod";
|
||||
import { ContentFormatSchema } from "./content_format";
|
||||
import { ExtensionPropertySchema } from "./extensions";
|
||||
import { CustomEmojiExtensionSchema } from "./extensions/custom_emojis";
|
||||
import { VanityExtensionSchema } from "./extensions/vanity";
|
||||
import { extensionTypeRegex } from "./regex";
|
||||
|
||||
const EntitySchema = z.object({
|
||||
export const EntitySchema = z.object({
|
||||
id: z.string().uuid(),
|
||||
created_at: z.string(),
|
||||
uri: z.string().url(),
|
||||
|
|
@ -13,9 +12,14 @@ const EntitySchema = z.object({
|
|||
extensions: ExtensionPropertySchema.optional().nullable().nullable(),
|
||||
});
|
||||
|
||||
const VisibilitySchema = z.enum(["public", "unlisted", "private", "direct"]);
|
||||
export const VisibilitySchema = z.enum([
|
||||
"public",
|
||||
"unlisted",
|
||||
"private",
|
||||
"direct",
|
||||
]);
|
||||
|
||||
const PublicationSchema = EntitySchema.extend({
|
||||
export const PublicationSchema = EntitySchema.extend({
|
||||
type: z.enum(["Note", "Patch"]),
|
||||
author: z.string().url(),
|
||||
content: ContentFormatSchema.optional().nullable(),
|
||||
|
|
@ -49,22 +53,22 @@ const PublicationSchema = EntitySchema.extend({
|
|||
.nullable(),
|
||||
});
|
||||
|
||||
const NoteSchema = PublicationSchema.extend({
|
||||
export const NoteSchema = PublicationSchema.extend({
|
||||
type: z.literal("Note"),
|
||||
});
|
||||
|
||||
const PatchSchema = PublicationSchema.extend({
|
||||
export const PatchSchema = PublicationSchema.extend({
|
||||
type: z.literal("Patch"),
|
||||
patched_id: z.string().uuid(),
|
||||
patched_at: z.string(),
|
||||
});
|
||||
|
||||
const ActorPublicKeyDataSchema = z.object({
|
||||
export const ActorPublicKeyDataSchema = z.object({
|
||||
public_key: z.string(),
|
||||
actor: z.string().url(),
|
||||
});
|
||||
|
||||
const UserSchema = EntitySchema.extend({
|
||||
export const UserSchema = EntitySchema.extend({
|
||||
type: z.literal("User"),
|
||||
display_name: z.string().optional().nullable(),
|
||||
username: z.string(),
|
||||
|
|
@ -96,7 +100,7 @@ const UserSchema = EntitySchema.extend({
|
|||
.nullable(),
|
||||
});
|
||||
|
||||
const ActionSchema = EntitySchema.extend({
|
||||
export const ActionSchema = EntitySchema.extend({
|
||||
type: z.union([
|
||||
z.literal("Like"),
|
||||
z.literal("Dislike"),
|
||||
|
|
@ -109,37 +113,37 @@ const ActionSchema = EntitySchema.extend({
|
|||
author: z.string().url(),
|
||||
});
|
||||
|
||||
const LikeSchema = ActionSchema.extend({
|
||||
export const LikeSchema = ActionSchema.extend({
|
||||
type: z.literal("Like"),
|
||||
object: z.string().url(),
|
||||
});
|
||||
|
||||
const UndoSchema = ActionSchema.extend({
|
||||
export const UndoSchema = ActionSchema.extend({
|
||||
type: z.literal("Undo"),
|
||||
object: z.string().url(),
|
||||
});
|
||||
|
||||
const DislikeSchema = ActionSchema.extend({
|
||||
export const DislikeSchema = ActionSchema.extend({
|
||||
type: z.literal("Dislike"),
|
||||
object: z.string().url(),
|
||||
});
|
||||
|
||||
const FollowSchema = ActionSchema.extend({
|
||||
export const FollowSchema = ActionSchema.extend({
|
||||
type: z.literal("Follow"),
|
||||
followee: z.string().url(),
|
||||
});
|
||||
|
||||
const FollowAcceptSchema = ActionSchema.extend({
|
||||
export const FollowAcceptSchema = ActionSchema.extend({
|
||||
type: z.literal("FollowAccept"),
|
||||
follower: z.string().url(),
|
||||
});
|
||||
|
||||
const FollowRejectSchema = ActionSchema.extend({
|
||||
export const FollowRejectSchema = ActionSchema.extend({
|
||||
type: z.literal("FollowReject"),
|
||||
follower: z.string().url(),
|
||||
});
|
||||
|
||||
const ExtensionSchema = EntitySchema.extend({
|
||||
export const ExtensionSchema = EntitySchema.extend({
|
||||
type: z.literal("Extension"),
|
||||
extension_type: z
|
||||
.string()
|
||||
|
|
@ -149,14 +153,14 @@ const ExtensionSchema = EntitySchema.extend({
|
|||
),
|
||||
});
|
||||
|
||||
const ReportSchema = ExtensionSchema.extend({
|
||||
export const ReportSchema = ExtensionSchema.extend({
|
||||
extension_type: z.literal("org.lysand:reports/Report"),
|
||||
objects: z.array(z.string().url()),
|
||||
reason: z.string(),
|
||||
comment: z.string().optional().nullable(),
|
||||
});
|
||||
|
||||
const ServerMetadataSchema = EntitySchema.omit({
|
||||
export const ServerMetadataSchema = EntitySchema.omit({
|
||||
created_at: true,
|
||||
id: true,
|
||||
uri: true,
|
||||
|
|
@ -173,27 +177,3 @@ const ServerMetadataSchema = EntitySchema.omit({
|
|||
supported_extensions: z.array(z.string()),
|
||||
extensions: z.record(z.string(), z.any()).optional().nullable(),
|
||||
});
|
||||
|
||||
export {
|
||||
EntitySchema,
|
||||
VisibilitySchema,
|
||||
PublicationSchema,
|
||||
NoteSchema,
|
||||
PatchSchema,
|
||||
ActorPublicKeyDataSchema,
|
||||
VanityExtensionSchema,
|
||||
UserSchema,
|
||||
ActionSchema,
|
||||
LikeSchema,
|
||||
UndoSchema,
|
||||
DislikeSchema,
|
||||
FollowSchema,
|
||||
FollowAcceptSchema,
|
||||
FollowRejectSchema,
|
||||
ExtensionSchema,
|
||||
ReportSchema,
|
||||
ServerMetadataSchema,
|
||||
ContentFormatSchema,
|
||||
CustomEmojiExtensionSchema,
|
||||
ExtensionPropertySchema,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,11 +3,8 @@ import { fromError } from "zod-validation-error";
|
|||
import {
|
||||
ActionSchema,
|
||||
ActorPublicKeyDataSchema,
|
||||
ContentFormatSchema,
|
||||
CustomEmojiExtensionSchema,
|
||||
DislikeSchema,
|
||||
EntitySchema,
|
||||
ExtensionPropertySchema,
|
||||
ExtensionSchema,
|
||||
FollowAcceptSchema,
|
||||
FollowRejectSchema,
|
||||
|
|
@ -20,9 +17,12 @@ import {
|
|||
ServerMetadataSchema,
|
||||
UndoSchema,
|
||||
UserSchema,
|
||||
VanityExtensionSchema,
|
||||
VisibilitySchema,
|
||||
} from "./schemas/base";
|
||||
import { ContentFormatSchema } from "./schemas/content_format";
|
||||
import { ExtensionPropertySchema } from "./schemas/extensions";
|
||||
import { CustomEmojiExtensionSchema } from "./schemas/extensions/custom_emojis";
|
||||
import { VanityExtensionSchema } from "./schemas/extensions/vanity";
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: Used only as a base type
|
||||
type AnyZod = z.ZodType<any, any, any>;
|
||||
|
|
|
|||
Loading…
Reference in a new issue