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,
|
CustomEmojiExtension,
|
||||||
DislikeSchema,
|
DislikeSchema,
|
||||||
EntitySchema,
|
EntitySchema,
|
||||||
|
ExtensionPropertySchema,
|
||||||
ExtensionSchema,
|
ExtensionSchema,
|
||||||
FollowAcceptSchema,
|
FollowAcceptSchema,
|
||||||
FollowRejectSchema,
|
FollowRejectSchema,
|
||||||
|
|
@ -83,6 +84,9 @@ class EntityValidator {
|
||||||
declare static $ActorPublicKeyData: InferType<
|
declare static $ActorPublicKeyData: InferType<
|
||||||
typeof ActorPublicKeyDataSchema
|
typeof ActorPublicKeyDataSchema
|
||||||
>;
|
>;
|
||||||
|
declare static $ExtensionProperty: InferType<
|
||||||
|
typeof ExtensionPropertySchema
|
||||||
|
>;
|
||||||
declare static $VanityExtension: InferType<typeof VanityExtensionSchema>;
|
declare static $VanityExtension: InferType<typeof VanityExtensionSchema>;
|
||||||
declare static $User: InferType<typeof UserSchema>;
|
declare static $User: InferType<typeof UserSchema>;
|
||||||
declare static $Action: InferType<typeof ActionSchema>;
|
declare static $Action: InferType<typeof ActionSchema>;
|
||||||
|
|
@ -302,6 +306,17 @@ class EntityValidator {
|
||||||
public Entity(data: unknown): Promise<InferType<typeof EntitySchema>> {
|
public Entity(data: unknown): Promise<InferType<typeof EntitySchema>> {
|
||||||
return this.validate(EntitySchema, data);
|
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 {
|
export {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ContentFormatSchema } from "./content_format";
|
import { ContentFormatSchema } from "./content_format";
|
||||||
|
import { ExtensionPropertySchema } from "./extensions";
|
||||||
import { CustomEmojiExtension } from "./extensions/custom_emojis";
|
import { CustomEmojiExtension } from "./extensions/custom_emojis";
|
||||||
import { VanityExtensionSchema } from "./extensions/vanity";
|
import { VanityExtensionSchema } from "./extensions/vanity";
|
||||||
import { extensionTypeRegex } from "./regex";
|
import { extensionTypeRegex } from "./regex";
|
||||||
|
|
@ -9,9 +10,7 @@ const EntitySchema = z.object({
|
||||||
created_at: z.string(),
|
created_at: z.string(),
|
||||||
uri: z.string().url(),
|
uri: z.string().url(),
|
||||||
type: z.string(),
|
type: z.string(),
|
||||||
extensions: z.object({
|
extensions: ExtensionPropertySchema.optional(),
|
||||||
"org.lysand:custom_emojis": CustomEmojiExtension.optional(),
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const VisibilitySchema = z.enum(["public", "unlisted", "private", "direct"]);
|
const VisibilitySchema = z.enum(["public", "unlisted", "private", "direct"]);
|
||||||
|
|
@ -27,7 +26,7 @@ const PublicationSchema = EntitySchema.extend({
|
||||||
subject: z.string().optional(),
|
subject: z.string().optional(),
|
||||||
is_sensitive: z.boolean().optional(),
|
is_sensitive: z.boolean().optional(),
|
||||||
visibility: VisibilitySchema,
|
visibility: VisibilitySchema,
|
||||||
extensions: EntitySchema.shape.extensions.extend({
|
extensions: ExtensionPropertySchema.extend({
|
||||||
"org.lysand:reactions": z
|
"org.lysand:reactions": z
|
||||||
.object({
|
.object({
|
||||||
reactions: z.string(),
|
reactions: z.string(),
|
||||||
|
|
@ -43,7 +42,7 @@ const PublicationSchema = EntitySchema.extend({
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
}),
|
}).optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const NoteSchema = PublicationSchema.extend({
|
const NoteSchema = PublicationSchema.extend({
|
||||||
|
|
@ -85,9 +84,9 @@ const UserSchema = EntitySchema.extend({
|
||||||
dislikes: z.string().url(),
|
dislikes: z.string().url(),
|
||||||
inbox: z.string().url(),
|
inbox: z.string().url(),
|
||||||
outbox: z.string().url(),
|
outbox: z.string().url(),
|
||||||
extensions: EntitySchema.shape.extensions.extend({
|
extensions: ExtensionPropertySchema.extend({
|
||||||
"org.lysand:vanity": VanityExtensionSchema.optional(),
|
"org.lysand:vanity": VanityExtensionSchema.optional(),
|
||||||
}),
|
}).optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const ActionSchema = EntitySchema.extend({
|
const ActionSchema = EntitySchema.extend({
|
||||||
|
|
@ -185,4 +184,5 @@ export {
|
||||||
ServerMetadataSchema,
|
ServerMetadataSchema,
|
||||||
ContentFormatSchema,
|
ContentFormatSchema,
|
||||||
CustomEmojiExtension,
|
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