mirror of
https://github.com/versia-pub/api.git
synced 2025-12-06 08:28:19 +01:00
feat(federation): ♻️ Make all optional fields also nullable
This commit is contained in:
parent
bbcc362bc1
commit
13e7027c37
|
|
@ -10,7 +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: ExtensionPropertySchema.optional(),
|
extensions: ExtensionPropertySchema.optional().nullable().nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const VisibilitySchema = z.enum(["public", "unlisted", "private", "direct"]);
|
const VisibilitySchema = z.enum(["public", "unlisted", "private", "direct"]);
|
||||||
|
|
@ -18,31 +18,35 @@ const VisibilitySchema = z.enum(["public", "unlisted", "private", "direct"]);
|
||||||
const PublicationSchema = EntitySchema.extend({
|
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(),
|
content: ContentFormatSchema.optional().nullable(),
|
||||||
attachments: z.array(ContentFormatSchema).optional(),
|
attachments: z.array(ContentFormatSchema).optional().nullable(),
|
||||||
replies_to: z.string().url().optional(),
|
replies_to: z.string().url().optional().nullable(),
|
||||||
quotes: z.string().url().optional(),
|
quotes: z.string().url().optional().nullable(),
|
||||||
mentions: z.array(z.string().url()).optional(),
|
mentions: z.array(z.string().url()).optional().nullable(),
|
||||||
subject: z.string().optional(),
|
subject: z.string().optional().nullable(),
|
||||||
is_sensitive: z.boolean().optional(),
|
is_sensitive: z.boolean().optional().nullable(),
|
||||||
visibility: VisibilitySchema,
|
visibility: VisibilitySchema,
|
||||||
extensions: ExtensionPropertySchema.extend({
|
extensions: ExtensionPropertySchema.extend({
|
||||||
"org.lysand:reactions": z
|
"org.lysand:reactions": z
|
||||||
.object({
|
.object({
|
||||||
reactions: z.string(),
|
reactions: z.string(),
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional()
|
||||||
|
.nullable(),
|
||||||
"org.lysand:polls": z
|
"org.lysand:polls": z
|
||||||
.object({
|
.object({
|
||||||
poll: z.object({
|
poll: z.object({
|
||||||
options: z.array(ContentFormatSchema),
|
options: z.array(ContentFormatSchema),
|
||||||
votes: z.array(z.number().int().nonnegative()),
|
votes: z.array(z.number().int().nonnegative()),
|
||||||
multiple_choice: z.boolean().optional(),
|
multiple_choice: z.boolean().optional().nullable(),
|
||||||
expires_at: z.string(),
|
expires_at: z.string(),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional()
|
||||||
}).optional(),
|
.nullable(),
|
||||||
|
})
|
||||||
|
.optional()
|
||||||
|
.nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const NoteSchema = PublicationSchema.extend({
|
const NoteSchema = PublicationSchema.extend({
|
||||||
|
|
@ -62,13 +66,13 @@ const ActorPublicKeyDataSchema = z.object({
|
||||||
|
|
||||||
const UserSchema = EntitySchema.extend({
|
const UserSchema = EntitySchema.extend({
|
||||||
type: z.literal("User"),
|
type: z.literal("User"),
|
||||||
display_name: z.string().optional(),
|
display_name: z.string().optional().nullable(),
|
||||||
username: z.string(),
|
username: z.string(),
|
||||||
avatar: ContentFormatSchema.optional(),
|
avatar: ContentFormatSchema.optional().nullable(),
|
||||||
header: ContentFormatSchema.optional(),
|
header: ContentFormatSchema.optional().nullable(),
|
||||||
indexable: z.boolean(),
|
indexable: z.boolean(),
|
||||||
public_key: ActorPublicKeyDataSchema,
|
public_key: ActorPublicKeyDataSchema,
|
||||||
bio: ContentFormatSchema.optional(),
|
bio: ContentFormatSchema.optional().nullable(),
|
||||||
fields: z
|
fields: z
|
||||||
.array(
|
.array(
|
||||||
z.object({
|
z.object({
|
||||||
|
|
@ -76,7 +80,8 @@ const UserSchema = EntitySchema.extend({
|
||||||
value: ContentFormatSchema,
|
value: ContentFormatSchema,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.optional(),
|
.optional()
|
||||||
|
.nullable(),
|
||||||
featured: z.string().url(),
|
featured: z.string().url(),
|
||||||
followers: z.string().url(),
|
followers: z.string().url(),
|
||||||
following: z.string().url(),
|
following: z.string().url(),
|
||||||
|
|
@ -85,8 +90,10 @@ const UserSchema = EntitySchema.extend({
|
||||||
inbox: z.string().url(),
|
inbox: z.string().url(),
|
||||||
outbox: z.string().url(),
|
outbox: z.string().url(),
|
||||||
extensions: ExtensionPropertySchema.extend({
|
extensions: ExtensionPropertySchema.extend({
|
||||||
"org.lysand:vanity": VanityExtensionSchema.optional(),
|
"org.lysand:vanity": VanityExtensionSchema.optional().nullable(),
|
||||||
}).optional(),
|
})
|
||||||
|
.optional()
|
||||||
|
.nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const ActionSchema = EntitySchema.extend({
|
const ActionSchema = EntitySchema.extend({
|
||||||
|
|
@ -146,7 +153,7 @@ 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(),
|
comment: z.string().optional().nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const ServerMetadataSchema = EntitySchema.omit({
|
const ServerMetadataSchema = EntitySchema.omit({
|
||||||
|
|
@ -157,14 +164,14 @@ const ServerMetadataSchema = EntitySchema.omit({
|
||||||
type: z.literal("ServerMetadata"),
|
type: z.literal("ServerMetadata"),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
version: z.string(),
|
version: z.string(),
|
||||||
description: z.string().optional(),
|
description: z.string().optional().nullable(),
|
||||||
website: z.string().optional(),
|
website: z.string().optional().nullable(),
|
||||||
moderators: z.array(z.string()).optional(),
|
moderators: z.array(z.string()).optional().nullable(),
|
||||||
admins: z.array(z.string()).optional(),
|
admins: z.array(z.string()).optional().nullable(),
|
||||||
logo: ContentFormatSchema.optional(),
|
logo: ContentFormatSchema.optional().nullable(),
|
||||||
banner: ContentFormatSchema.optional(),
|
banner: ContentFormatSchema.optional().nullable(),
|
||||||
supported_extensions: z.array(z.string()),
|
supported_extensions: z.array(z.string()),
|
||||||
extensions: z.record(z.string(), z.any()).optional(),
|
extensions: z.record(z.string(), z.any()).optional().nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@ export const ContentFormatSchema = z.record(
|
||||||
z.enum(Object.values(types) as [string, ...string[]]),
|
z.enum(Object.values(types) as [string, ...string[]]),
|
||||||
z.object({
|
z.object({
|
||||||
content: z.string(),
|
content: z.string(),
|
||||||
description: z.string().optional(),
|
description: z.string().optional().nullable(),
|
||||||
size: z.number().int().nonnegative().optional(),
|
size: z.number().int().nonnegative().optional().nullable(),
|
||||||
hash: z.record(z.string(), z.string()).optional(),
|
hash: z.record(z.string(), z.string()).optional().nullable(),
|
||||||
blurhash: z.string().optional(),
|
blurhash: z.string().optional().nullable(),
|
||||||
fps: z.number().int().nonnegative().optional(),
|
fps: z.number().int().nonnegative().optional().nullable(),
|
||||||
width: z.number().int().nonnegative().optional(),
|
width: z.number().int().nonnegative().optional().nullable(),
|
||||||
height: z.number().int().nonnegative().optional(),
|
height: z.number().int().nonnegative().optional().nullable(),
|
||||||
duration: z.number().nonnegative().optional(),
|
duration: z.number().nonnegative().optional().nullable(),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,6 @@ import { z } from "zod";
|
||||||
import { CustomEmojiExtensionSchema } from "./extensions/custom_emojis";
|
import { CustomEmojiExtensionSchema } from "./extensions/custom_emojis";
|
||||||
|
|
||||||
export const ExtensionPropertySchema = z.object({
|
export const ExtensionPropertySchema = z.object({
|
||||||
"org.lysand:custom_emojis": CustomEmojiExtensionSchema.optional(),
|
"org.lysand:custom_emojis":
|
||||||
|
CustomEmojiExtensionSchema.optional().nullable(),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ export const PollSchema = ExtensionSchema.extend({
|
||||||
extension_type: z.literal("org.lysand:polls/Poll"),
|
extension_type: z.literal("org.lysand:polls/Poll"),
|
||||||
options: z.array(ContentFormatSchema),
|
options: z.array(ContentFormatSchema),
|
||||||
votes: z.array(z.number().int().nonnegative()),
|
votes: z.array(z.number().int().nonnegative()),
|
||||||
multiple_choice: z.boolean().optional(),
|
multiple_choice: z.boolean().optional().nullable(),
|
||||||
expires_at: z.string(),
|
expires_at: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,10 +68,10 @@ import { ContentFormatSchema } from "../content_format";
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
export const VanityExtensionSchema = z.object({
|
export const VanityExtensionSchema = z.object({
|
||||||
avatar_overlay: ContentFormatSchema.optional(),
|
avatar_overlay: ContentFormatSchema.optional().nullable(),
|
||||||
avatar_mask: ContentFormatSchema.optional(),
|
avatar_mask: ContentFormatSchema.optional().nullable(),
|
||||||
background: ContentFormatSchema.optional(),
|
background: ContentFormatSchema.optional().nullable(),
|
||||||
audio: ContentFormatSchema.optional(),
|
audio: ContentFormatSchema.optional().nullable(),
|
||||||
pronouns: z.record(
|
pronouns: z.record(
|
||||||
z.string(),
|
z.string(),
|
||||||
z.array(
|
z.array(
|
||||||
|
|
@ -87,7 +87,7 @@ export const VanityExtensionSchema = z.object({
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
birthday: z.string().optional(),
|
birthday: z.string().optional().nullable(),
|
||||||
location: z.string().optional(),
|
location: z.string().optional().nullable(),
|
||||||
activitypub: z.string().optional(),
|
activitypub: z.string().optional().nullable(),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue