mirror of
https://github.com/versia-pub/api.git
synced 2026-03-13 04:09:15 +01:00
feat(federation): 👽 Update to Versia 0.5
This commit is contained in:
parent
afec384a51
commit
5114df4454
8 changed files with 220 additions and 31 deletions
|
|
@ -10,6 +10,8 @@ import { extensionRegex, isISOString, semverRegex } from "./regex.ts";
|
|||
|
||||
export const EntitySchema = z
|
||||
.object({
|
||||
// biome-ignore lint/style/useNamingConvention:
|
||||
$schema: z.string().url().optional().nullable(),
|
||||
id: z.string().max(512),
|
||||
created_at: z
|
||||
.string()
|
||||
|
|
@ -37,6 +39,17 @@ export const NoteSchema = EntitySchema.extend({
|
|||
.optional()
|
||||
.nullable(),
|
||||
content: TextOnlyContentFormatSchema.optional().nullable(),
|
||||
collections: z.object({
|
||||
replies: z.string().url(),
|
||||
quotes: z.string().url(),
|
||||
"pub.versia:reactions/Reactions": z
|
||||
.string()
|
||||
.url()
|
||||
.optional()
|
||||
.nullable(),
|
||||
"pub.versia:likes/Likes": z.string().url().optional().nullable(),
|
||||
"pub.versia:likes/Dislikes": z.string().url().optional().nullable(),
|
||||
}),
|
||||
device: z
|
||||
.object({
|
||||
name: z.string(),
|
||||
|
|
@ -72,13 +85,6 @@ export const NoteSchema = EntitySchema.extend({
|
|||
replies_to: z.string().url().optional().nullable(),
|
||||
subject: z.string().optional().nullable(),
|
||||
extensions: ExtensionPropertySchema.extend({
|
||||
"pub.versia:reactions": z
|
||||
.object({
|
||||
reactions: z.string().url(),
|
||||
})
|
||||
.strict()
|
||||
.optional()
|
||||
.nullable(),
|
||||
"pub.versia:polls": z
|
||||
.object({
|
||||
options: z.array(TextOnlyContentFormatSchema),
|
||||
|
|
@ -119,6 +125,10 @@ export const CollectionSchema = z.object({
|
|||
items: z.array(z.any()),
|
||||
});
|
||||
|
||||
export const URICollectionSchema = CollectionSchema.extend({
|
||||
items: z.array(z.string().url()),
|
||||
});
|
||||
|
||||
export const PublicKeyDataSchema = z
|
||||
.object({
|
||||
key: z.string().min(1),
|
||||
|
|
@ -147,8 +157,8 @@ export const UserSchema = EntitySchema.extend({
|
|||
.string()
|
||||
.min(1)
|
||||
.regex(
|
||||
/^[a-z0-9_-]+$/,
|
||||
"must be lowercase, alphanumeric, and may contain _ or -",
|
||||
/^[a-zA-Z0-9_-]+$/,
|
||||
"must be alphanumeric, and may contain _ or -",
|
||||
),
|
||||
header: ImageOnlyContentFormatSchema.optional().nullable(),
|
||||
public_key: PublicKeyDataSchema,
|
||||
|
|
@ -208,14 +218,6 @@ export const UnfollowSchema = EntitySchema.extend({
|
|||
followee: z.string().url(),
|
||||
});
|
||||
|
||||
export const GroupSchema = EntitySchema.extend({
|
||||
type: z.literal("Group"),
|
||||
name: TextOnlyContentFormatSchema.optional().nullable(),
|
||||
description: TextOnlyContentFormatSchema.optional().nullable(),
|
||||
members: z.string().url(),
|
||||
notes: z.string().url().optional().nullable(),
|
||||
});
|
||||
|
||||
export const InstanceMetadataSchema = EntitySchema.extend({
|
||||
type: z.literal("InstanceMetadata"),
|
||||
id: z.null().optional(),
|
||||
|
|
|
|||
40
federation/schemas/extensions/groups.ts
Normal file
40
federation/schemas/extensions/groups.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { z } from "zod";
|
||||
import { EntitySchema } from "../base.ts";
|
||||
import { TextOnlyContentFormatSchema } from "../content_format.ts";
|
||||
|
||||
export const GroupSchema = EntitySchema.extend({
|
||||
type: z.literal("pub.versia:groups/Group"),
|
||||
name: TextOnlyContentFormatSchema.optional().nullable(),
|
||||
description: TextOnlyContentFormatSchema.optional().nullable(),
|
||||
open: z.boolean().optional().nullable(),
|
||||
members: z.string().url(),
|
||||
notes: z.string().url().optional().nullable(),
|
||||
});
|
||||
|
||||
export const GroupSubscribeSchema = EntitySchema.extend({
|
||||
type: z.literal("pub.versia:groups/Subscribe"),
|
||||
uri: z.null().optional(),
|
||||
subscriber: z.string().url(),
|
||||
group: z.string().url(),
|
||||
});
|
||||
|
||||
export const GroupUnsubscribeSchema = EntitySchema.extend({
|
||||
type: z.literal("pub.versia:groups/Unsubscribe"),
|
||||
uri: z.null().optional(),
|
||||
subscriber: z.string().url(),
|
||||
group: z.string().url(),
|
||||
});
|
||||
|
||||
export const GroupSubscribeAcceptSchema = EntitySchema.extend({
|
||||
type: z.literal("pub.versia:groups/SubscribeAccept"),
|
||||
uri: z.null().optional(),
|
||||
subscriber: z.string().url(),
|
||||
group: z.string().url(),
|
||||
});
|
||||
|
||||
export const GroupSubscribeRejectSchema = EntitySchema.extend({
|
||||
type: z.literal("pub.versia:groups/SubscribeReject"),
|
||||
uri: z.null().optional(),
|
||||
subscriber: z.string().url(),
|
||||
group: z.string().url(),
|
||||
});
|
||||
|
|
@ -10,7 +10,7 @@ import {
|
|||
AudioOnlyContentFormatSchema,
|
||||
ImageOnlyContentFormatSchema,
|
||||
} from "../content_format.ts";
|
||||
import { isISOString } from "../regex.ts";
|
||||
import { ianaTimezoneRegex, isISOString } from "../regex.ts";
|
||||
|
||||
/**
|
||||
* @description Vanity extension entity
|
||||
|
|
@ -103,5 +103,10 @@ export const VanityExtensionSchema = z
|
|||
.nullable(),
|
||||
location: z.string().optional().nullable(),
|
||||
aliases: z.array(z.string().url()).optional().nullable(),
|
||||
timezone: z
|
||||
.string()
|
||||
.regex(ianaTimezoneRegex, "must be a valid IANA timezone")
|
||||
.optional()
|
||||
.nullable(),
|
||||
})
|
||||
.strict();
|
||||
|
|
|
|||
|
|
@ -66,3 +66,5 @@ export const isISOString = (val: string | Date) => {
|
|||
const d = new Date(val);
|
||||
return !Number.isNaN(d.valueOf());
|
||||
};
|
||||
|
||||
export const ianaTimezoneRegex = /^(?:[A-Za-z]+(?:\/[A-Za-z_]+)+|UTC)$/;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue