refactor: ⬆️ Upgrade to Zod v4 and hono-openapi 0.5.0

This commit is contained in:
Jesse Wierzbinski 2025-07-07 03:42:35 +02:00
parent add2429606
commit 24d4150da4
No known key found for this signature in database
209 changed files with 1331 additions and 1622 deletions

View file

@ -1,4 +1,4 @@
import type { z } from "zod";
import type { z } from "zod/v4";
import {
CollectionSchema,
URICollectionSchema,

View file

@ -1,4 +1,4 @@
import type { z } from "zod";
import type { z } from "zod/v4";
import {
AudioContentFormatSchema,
ContentFormatSchema,

View file

@ -1,4 +1,4 @@
import type { z } from "zod";
import type { z } from "zod/v4";
import { DeleteSchema } from "../schemas/delete.ts";
import type { JSONObject } from "../types.ts";
import { Entity } from "./entity.ts";

View file

@ -1,4 +1,4 @@
import type { z } from "zod";
import type { z } from "zod/v4";
import { DislikeSchema, LikeSchema } from "../../schemas/extensions/likes.ts";
import type { JSONObject } from "../../types.ts";
import { Entity } from "../entity.ts";

View file

@ -1,4 +1,4 @@
import type { z } from "zod";
import type { z } from "zod/v4";
import { VoteSchema } from "../../schemas/extensions/polls.ts";
import type { JSONObject } from "../../types.ts";
import { Entity } from "../entity.ts";

View file

@ -1,4 +1,4 @@
import type { z } from "zod";
import type { z } from "zod/v4";
import { ReactionSchema } from "../../schemas/extensions/reactions.ts";
import type { JSONObject } from "../../types.ts";
import { Entity } from "../entity.ts";

View file

@ -1,4 +1,4 @@
import type { z } from "zod";
import type { z } from "zod/v4";
import { ReportSchema } from "../../schemas/extensions/reports.ts";
import type { JSONObject } from "../../types.ts";
import { Entity } from "../entity.ts";

View file

@ -1,4 +1,4 @@
import type { z } from "zod";
import type { z } from "zod/v4";
import { ShareSchema } from "../../schemas/extensions/share.ts";
import type { JSONObject } from "../../types.ts";
import { Entity } from "../entity.ts";

View file

@ -1,4 +1,4 @@
import type { z } from "zod";
import type { z } from "zod/v4";
import {
FollowAcceptSchema,
FollowRejectSchema,

View file

@ -1,4 +1,4 @@
import type { z } from "zod";
import type { z } from "zod/v4";
import { InstanceMetadataSchema } from "../schemas/instance.ts";
import type { JSONObject } from "../types.ts";
import { ImageContentFormat } from "./contentformat.ts";

View file

@ -1,4 +1,4 @@
import type { z } from "zod";
import type { z } from "zod/v4";
import { NoteSchema } from "../schemas/note.ts";
import type { JSONObject } from "../types.ts";
import { NonTextContentFormat, TextContentFormat } from "./contentformat.ts";

View file

@ -1,4 +1,4 @@
import type { z } from "zod";
import type { z } from "zod/v4";
import { UserSchema } from "../schemas/user.ts";
import type { JSONObject } from "../types.ts";
import { ImageContentFormat, TextContentFormat } from "./contentformat.ts";

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { u64, url } from "./common.ts";
export const CollectionSchema = z.strictObject({

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
export const f64 = z
.number()
@ -11,4 +11,4 @@ export const u64 = z
.nonnegative()
.max(2 ** 64 - 1);
export const url = z.string().url();
export const url = z.url();

View file

@ -1,5 +1,5 @@
import { types } from "mime-types";
import { z } from "zod";
import { z } from "zod/v4";
import { f64, u64 } from "./common.ts";
const hashSizes = {
@ -39,10 +39,10 @@ const audioMimeTypes = Object.values(types).filter((v) =>
v.startsWith("audio/"),
) as [string, ...string[]];
export const ContentFormatSchema = z.record(
export const ContentFormatSchema = z.partialRecord(
z.enum(allMimeTypes),
z.strictObject({
content: z.string().or(z.string().url()),
content: z.string().or(z.url()),
remote: z.boolean(),
description: z.string().nullish(),
size: u64.nullish(),
@ -64,9 +64,9 @@ export const ContentFormatSchema = z.record(
}),
);
export const TextContentFormatSchema = z.record(
export const TextContentFormatSchema = z.partialRecord(
z.enum(textMimeTypes),
ContentFormatSchema.valueSchema
ContentFormatSchema.valueType
.pick({
content: true,
remote: true,
@ -77,9 +77,9 @@ export const TextContentFormatSchema = z.record(
}),
);
export const NonTextContentFormatSchema = z.record(
export const NonTextContentFormatSchema = z.partialRecord(
z.enum(nonTextMimeTypes),
ContentFormatSchema.valueSchema
ContentFormatSchema.valueType
.pick({
content: true,
remote: true,
@ -91,27 +91,27 @@ export const NonTextContentFormatSchema = z.record(
height: true,
})
.extend({
content: z.string().url(),
content: z.url(),
remote: z.literal(true),
}),
);
export const ImageContentFormatSchema = z.record(
export const ImageContentFormatSchema = z.partialRecord(
z.enum(imageMimeTypes),
NonTextContentFormatSchema.valueSchema,
NonTextContentFormatSchema.valueType,
);
export const VideoContentFormatSchema = z.record(
export const VideoContentFormatSchema = z.partialRecord(
z.enum(videoMimeTypes),
NonTextContentFormatSchema.valueSchema.extend({
duration: ContentFormatSchema.valueSchema.shape.duration,
fps: ContentFormatSchema.valueSchema.shape.fps,
NonTextContentFormatSchema.valueType.extend({
duration: ContentFormatSchema.valueType.shape.duration,
fps: ContentFormatSchema.valueType.shape.fps,
}),
);
export const AudioContentFormatSchema = z.record(
export const AudioContentFormatSchema = z.partialRecord(
z.enum(audioMimeTypes),
NonTextContentFormatSchema.valueSchema.extend({
duration: ContentFormatSchema.valueSchema.shape.duration,
NonTextContentFormatSchema.valueType.extend({
duration: ContentFormatSchema.valueType.shape.duration,
}),
);

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { url } from "./common.ts";
import { EntitySchema } from "./entity.ts";

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { isISOString } from "../regex.ts";
import { url } from "./common.ts";
import { CustomEmojiExtensionSchema } from "./extensions/emojis.ts";
@ -12,7 +12,7 @@ export const ExtensionPropertySchema = z
export const EntitySchema = z.strictObject({
// biome-ignore lint/style/useNamingConvention: required for JSON schema
$schema: z.string().url().nullish(),
$schema: z.url().nullish(),
id: z.string().max(512),
created_at: z
.string()

View file

@ -4,7 +4,7 @@
* @see module:federation/schemas/base
* @see https://versia.pub/extensions/custom-emojis
*/
import { z } from "zod";
import { z } from "zod/v4";
import { emojiRegex } from "../../regex.ts";
import { ImageContentFormatSchema } from "../contentformat.ts";

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { url } from "../common.ts";
import { TextContentFormatSchema } from "../contentformat.ts";
import { EntitySchema } from "../entity.ts";

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { url } from "../common.ts";
import { EntitySchema } from "../entity.ts";

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { url } from "../common.ts";
import { EntitySchema } from "../entity.ts";

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { isISOString } from "../../regex.ts";
import { u64, url } from "../common.ts";
import { TextContentFormatSchema } from "../contentformat.ts";

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { url } from "../common.ts";
import { EntitySchema } from "../entity.ts";

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { url } from "../common.ts";
import { EntitySchema } from "../entity.ts";

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { url } from "../common.ts";
import { EntitySchema } from "../entity.ts";

View file

@ -5,7 +5,7 @@
* @see https://versia.pub/extensions/vanity
*/
import { z } from "zod";
import { z } from "zod/v4";
import { ianaTimezoneRegex, isISOString } from "../../regex.ts";
import { url } from "../common.ts";
import {

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { url } from "./common.ts";
import { EntitySchema } from "./entity.ts";

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { extensionRegex, semverRegex } from "../regex.ts";
import { url } from "./common.ts";
import { ImageContentFormatSchema } from "./contentformat.ts";

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { url } from "./common.ts";
import {
NonTextContentFormatSchema,

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { url } from "./common.ts";
import {
ImageContentFormatSchema,

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { url } from "./common.ts";
export const WebFingerSchema = z.object({