mirror of
https://github.com/versia-pub/api.git
synced 2025-12-06 08:28:19 +01:00
fix(federation): 🐛 Fix extensions schema being incorrectly non-optional
This commit is contained in:
parent
f6b3741e22
commit
071a149d3e
|
|
@ -15,6 +15,7 @@ import {
|
|||
CustomEmojiExtension,
|
||||
DislikeSchema,
|
||||
EntitySchema,
|
||||
ExtensionPropertySchema,
|
||||
ExtensionSchema,
|
||||
FollowAcceptSchema,
|
||||
FollowRejectSchema,
|
||||
|
|
@ -83,6 +84,9 @@ class EntityValidator {
|
|||
declare static $ActorPublicKeyData: InferType<
|
||||
typeof ActorPublicKeyDataSchema
|
||||
>;
|
||||
declare static $ExtensionProperty: InferType<
|
||||
typeof ExtensionPropertySchema
|
||||
>;
|
||||
declare static $VanityExtension: InferType<typeof VanityExtensionSchema>;
|
||||
declare static $User: InferType<typeof UserSchema>;
|
||||
declare static $Action: InferType<typeof ActionSchema>;
|
||||
|
|
@ -302,6 +306,17 @@ class EntityValidator {
|
|||
public Entity(data: unknown): Promise<InferType<typeof EntitySchema>> {
|
||||
return this.validate(EntitySchema, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates an ExtensionProperty.
|
||||
* @param data - The data to validate
|
||||
* @returns A promise that resolves to the validated data.
|
||||
*/
|
||||
public ExtensionProperty(
|
||||
data: unknown,
|
||||
): Promise<InferType<typeof ExtensionPropertySchema>> {
|
||||
return this.validate(ExtensionPropertySchema, data);
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { z } from "zod";
|
||||
import { ContentFormatSchema } from "./content_format";
|
||||
import { ExtensionPropertySchema } from "./extensions";
|
||||
import { CustomEmojiExtension } from "./extensions/custom_emojis";
|
||||
import { VanityExtensionSchema } from "./extensions/vanity";
|
||||
import { extensionTypeRegex } from "./regex";
|
||||
|
|
@ -9,9 +10,7 @@ const EntitySchema = z.object({
|
|||
created_at: z.string(),
|
||||
uri: z.string().url(),
|
||||
type: z.string(),
|
||||
extensions: z.object({
|
||||
"org.lysand:custom_emojis": CustomEmojiExtension.optional(),
|
||||
}),
|
||||
extensions: ExtensionPropertySchema.optional(),
|
||||
});
|
||||
|
||||
const VisibilitySchema = z.enum(["public", "unlisted", "private", "direct"]);
|
||||
|
|
@ -27,7 +26,7 @@ const PublicationSchema = EntitySchema.extend({
|
|||
subject: z.string().optional(),
|
||||
is_sensitive: z.boolean().optional(),
|
||||
visibility: VisibilitySchema,
|
||||
extensions: EntitySchema.shape.extensions.extend({
|
||||
extensions: ExtensionPropertySchema.extend({
|
||||
"org.lysand:reactions": z
|
||||
.object({
|
||||
reactions: z.string(),
|
||||
|
|
@ -43,7 +42,7 @@ const PublicationSchema = EntitySchema.extend({
|
|||
}),
|
||||
})
|
||||
.optional(),
|
||||
}),
|
||||
}).optional(),
|
||||
});
|
||||
|
||||
const NoteSchema = PublicationSchema.extend({
|
||||
|
|
@ -85,9 +84,9 @@ const UserSchema = EntitySchema.extend({
|
|||
dislikes: z.string().url(),
|
||||
inbox: z.string().url(),
|
||||
outbox: z.string().url(),
|
||||
extensions: EntitySchema.shape.extensions.extend({
|
||||
extensions: ExtensionPropertySchema.extend({
|
||||
"org.lysand:vanity": VanityExtensionSchema.optional(),
|
||||
}),
|
||||
}).optional(),
|
||||
});
|
||||
|
||||
const ActionSchema = EntitySchema.extend({
|
||||
|
|
@ -185,4 +184,5 @@ export {
|
|||
ServerMetadataSchema,
|
||||
ContentFormatSchema,
|
||||
CustomEmojiExtension,
|
||||
ExtensionPropertySchema,
|
||||
};
|
||||
|
|
|
|||
6
federation/schemas/extensions.ts
Normal file
6
federation/schemas/extensions.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import { z } from "zod";
|
||||
import { CustomEmojiExtension } from "./extensions/custom_emojis";
|
||||
|
||||
export const ExtensionPropertySchema = z.object({
|
||||
"org.lysand:custom_emojis": CustomEmojiExtension.optional(),
|
||||
});
|
||||
Loading…
Reference in a new issue