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 {
|
import type {
|
||||||
ActionSchema,
|
ActionSchema,
|
||||||
ActorPublicKeyDataSchema,
|
ActorPublicKeyDataSchema,
|
||||||
ContentFormatSchema,
|
|
||||||
CustomEmojiExtensionSchema,
|
|
||||||
DislikeSchema,
|
DislikeSchema,
|
||||||
EntitySchema,
|
EntitySchema,
|
||||||
ExtensionPropertySchema,
|
|
||||||
ExtensionSchema,
|
ExtensionSchema,
|
||||||
FollowAcceptSchema,
|
FollowAcceptSchema,
|
||||||
FollowRejectSchema,
|
FollowRejectSchema,
|
||||||
|
|
@ -24,9 +21,12 @@ import type {
|
||||||
ServerMetadataSchema,
|
ServerMetadataSchema,
|
||||||
UndoSchema,
|
UndoSchema,
|
||||||
UserSchema,
|
UserSchema,
|
||||||
VanityExtensionSchema,
|
|
||||||
VisibilitySchema,
|
VisibilitySchema,
|
||||||
} from "./schemas/base";
|
} 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
|
// biome-ignore lint/suspicious/noExplicitAny: Used only as a base type
|
||||||
type AnyZod = z.ZodType<any, any, any>;
|
type AnyZod = z.ZodType<any, any, any>;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ContentFormatSchema } from "./content_format";
|
import { ContentFormatSchema } from "./content_format";
|
||||||
import { ExtensionPropertySchema } from "./extensions";
|
import { ExtensionPropertySchema } from "./extensions";
|
||||||
import { CustomEmojiExtensionSchema } from "./extensions/custom_emojis";
|
|
||||||
import { VanityExtensionSchema } from "./extensions/vanity";
|
import { VanityExtensionSchema } from "./extensions/vanity";
|
||||||
import { extensionTypeRegex } from "./regex";
|
import { extensionTypeRegex } from "./regex";
|
||||||
|
|
||||||
const EntitySchema = z.object({
|
export const EntitySchema = z.object({
|
||||||
id: z.string().uuid(),
|
id: z.string().uuid(),
|
||||||
created_at: z.string(),
|
created_at: z.string(),
|
||||||
uri: z.string().url(),
|
uri: z.string().url(),
|
||||||
|
|
@ -13,9 +12,14 @@ const EntitySchema = z.object({
|
||||||
extensions: ExtensionPropertySchema.optional().nullable().nullable(),
|
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"]),
|
type: z.enum(["Note", "Patch"]),
|
||||||
author: z.string().url(),
|
author: z.string().url(),
|
||||||
content: ContentFormatSchema.optional().nullable(),
|
content: ContentFormatSchema.optional().nullable(),
|
||||||
|
|
@ -49,22 +53,22 @@ const PublicationSchema = EntitySchema.extend({
|
||||||
.nullable(),
|
.nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const NoteSchema = PublicationSchema.extend({
|
export const NoteSchema = PublicationSchema.extend({
|
||||||
type: z.literal("Note"),
|
type: z.literal("Note"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const PatchSchema = PublicationSchema.extend({
|
export const PatchSchema = PublicationSchema.extend({
|
||||||
type: z.literal("Patch"),
|
type: z.literal("Patch"),
|
||||||
patched_id: z.string().uuid(),
|
patched_id: z.string().uuid(),
|
||||||
patched_at: z.string(),
|
patched_at: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const ActorPublicKeyDataSchema = z.object({
|
export const ActorPublicKeyDataSchema = z.object({
|
||||||
public_key: z.string(),
|
public_key: z.string(),
|
||||||
actor: z.string().url(),
|
actor: z.string().url(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const UserSchema = EntitySchema.extend({
|
export const UserSchema = EntitySchema.extend({
|
||||||
type: z.literal("User"),
|
type: z.literal("User"),
|
||||||
display_name: z.string().optional().nullable(),
|
display_name: z.string().optional().nullable(),
|
||||||
username: z.string(),
|
username: z.string(),
|
||||||
|
|
@ -96,7 +100,7 @@ const UserSchema = EntitySchema.extend({
|
||||||
.nullable(),
|
.nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const ActionSchema = EntitySchema.extend({
|
export const ActionSchema = EntitySchema.extend({
|
||||||
type: z.union([
|
type: z.union([
|
||||||
z.literal("Like"),
|
z.literal("Like"),
|
||||||
z.literal("Dislike"),
|
z.literal("Dislike"),
|
||||||
|
|
@ -109,37 +113,37 @@ const ActionSchema = EntitySchema.extend({
|
||||||
author: z.string().url(),
|
author: z.string().url(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const LikeSchema = ActionSchema.extend({
|
export const LikeSchema = ActionSchema.extend({
|
||||||
type: z.literal("Like"),
|
type: z.literal("Like"),
|
||||||
object: z.string().url(),
|
object: z.string().url(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const UndoSchema = ActionSchema.extend({
|
export const UndoSchema = ActionSchema.extend({
|
||||||
type: z.literal("Undo"),
|
type: z.literal("Undo"),
|
||||||
object: z.string().url(),
|
object: z.string().url(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const DislikeSchema = ActionSchema.extend({
|
export const DislikeSchema = ActionSchema.extend({
|
||||||
type: z.literal("Dislike"),
|
type: z.literal("Dislike"),
|
||||||
object: z.string().url(),
|
object: z.string().url(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const FollowSchema = ActionSchema.extend({
|
export const FollowSchema = ActionSchema.extend({
|
||||||
type: z.literal("Follow"),
|
type: z.literal("Follow"),
|
||||||
followee: z.string().url(),
|
followee: z.string().url(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const FollowAcceptSchema = ActionSchema.extend({
|
export const FollowAcceptSchema = ActionSchema.extend({
|
||||||
type: z.literal("FollowAccept"),
|
type: z.literal("FollowAccept"),
|
||||||
follower: z.string().url(),
|
follower: z.string().url(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const FollowRejectSchema = ActionSchema.extend({
|
export const FollowRejectSchema = ActionSchema.extend({
|
||||||
type: z.literal("FollowReject"),
|
type: z.literal("FollowReject"),
|
||||||
follower: z.string().url(),
|
follower: z.string().url(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const ExtensionSchema = EntitySchema.extend({
|
export const ExtensionSchema = EntitySchema.extend({
|
||||||
type: z.literal("Extension"),
|
type: z.literal("Extension"),
|
||||||
extension_type: z
|
extension_type: z
|
||||||
.string()
|
.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"),
|
extension_type: z.literal("org.lysand:reports/Report"),
|
||||||
objects: z.array(z.string().url()),
|
objects: z.array(z.string().url()),
|
||||||
reason: z.string(),
|
reason: z.string(),
|
||||||
comment: z.string().optional().nullable(),
|
comment: z.string().optional().nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const ServerMetadataSchema = EntitySchema.omit({
|
export const ServerMetadataSchema = EntitySchema.omit({
|
||||||
created_at: true,
|
created_at: true,
|
||||||
id: true,
|
id: true,
|
||||||
uri: true,
|
uri: true,
|
||||||
|
|
@ -173,27 +177,3 @@ const ServerMetadataSchema = EntitySchema.omit({
|
||||||
supported_extensions: z.array(z.string()),
|
supported_extensions: z.array(z.string()),
|
||||||
extensions: z.record(z.string(), z.any()).optional().nullable(),
|
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 {
|
import {
|
||||||
ActionSchema,
|
ActionSchema,
|
||||||
ActorPublicKeyDataSchema,
|
ActorPublicKeyDataSchema,
|
||||||
ContentFormatSchema,
|
|
||||||
CustomEmojiExtensionSchema,
|
|
||||||
DislikeSchema,
|
DislikeSchema,
|
||||||
EntitySchema,
|
EntitySchema,
|
||||||
ExtensionPropertySchema,
|
|
||||||
ExtensionSchema,
|
ExtensionSchema,
|
||||||
FollowAcceptSchema,
|
FollowAcceptSchema,
|
||||||
FollowRejectSchema,
|
FollowRejectSchema,
|
||||||
|
|
@ -20,9 +17,12 @@ import {
|
||||||
ServerMetadataSchema,
|
ServerMetadataSchema,
|
||||||
UndoSchema,
|
UndoSchema,
|
||||||
UserSchema,
|
UserSchema,
|
||||||
VanityExtensionSchema,
|
|
||||||
VisibilitySchema,
|
VisibilitySchema,
|
||||||
} from "./schemas/base";
|
} 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
|
// biome-ignore lint/suspicious/noExplicitAny: Used only as a base type
|
||||||
type AnyZod = z.ZodType<any, any, any>;
|
type AnyZod = z.ZodType<any, any, any>;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue