refactor(federation): 🚚 Rename validators back to schemas, fix barrel file

This commit is contained in:
Jesse Wierzbinski 2024-09-23 09:44:20 +02:00
parent d43775ec6e
commit ce9be7e857
No known key found for this signature in database
20 changed files with 58 additions and 81 deletions

View file

@ -2,7 +2,7 @@ import dts from "bun-plugin-dts";
import ora from "ora"; import ora from "ora";
const entrypoints = { const entrypoints = {
federation: ["index.ts", "validators.ts", "types.ts"], federation: ["index.ts", "schemas.ts", "types.ts"],
client: ["index.ts", "types.ts"], client: ["index.ts", "types.ts"],
}; };

View file

@ -2,7 +2,7 @@
* @file index.ts * @file index.ts
* @fileoverview Main entrypoint and export for the module * @fileoverview Main entrypoint and export for the module
* @module federation * @module federation
* @see module:federation/validators/base * @see module:federation/schemas/base
*/ */
import type { ValidationError } from "zod-validation-error"; import type { ValidationError } from "zod-validation-error";

View file

@ -5,6 +5,6 @@
"exports": { "exports": {
".": "./index.ts", ".": "./index.ts",
"./types": "./types.ts", "./types": "./types.ts",
"./validators": "./validators.ts" "./schemas": "./schemas.ts"
} }
} }

View file

@ -48,10 +48,10 @@
"default": "./dist/types.js", "default": "./dist/types.js",
"types": "./dist/types.d.ts" "types": "./dist/types.d.ts"
}, },
"./validators": { "./schemas": {
"import": "./dist/validators.js", "import": "./dist/schemas.js",
"default": "./dist/validators.js", "default": "./dist/schemas.js",
"types": "./dist/validators.d.ts" "types": "./dist/schemas.d.ts"
} }
}, },
"funding": { "funding": {

View file

@ -1,6 +1,6 @@
import { fromZodError } from "zod-validation-error"; import { fromZodError } from "zod-validation-error";
import type { SignatureConstructor } from "../cryptography/index.ts"; import type { SignatureConstructor } from "../cryptography/index.ts";
import { WebFingerSchema } from "../validators/webfinger.ts"; import { WebFingerSchema } from "../schemas/webfinger.ts";
import type { User } from "../types.ts"; import type { User } from "../types.ts";
import { DEFAULT_UA } from "./constants.ts"; import { DEFAULT_UA } from "./constants.ts";

31
federation/schemas.ts Normal file
View file

@ -0,0 +1,31 @@
/**
* @file Zod schema definitions
* @module federation/schemas
*/
// biome-ignore lint/performance/noBarrelFile: library export
export {
CollectionSchema as Collection,
DeleteSchema as Delete,
EntitySchema as Entity,
FollowAcceptSchema as FollowAccept,
FollowRejectSchema as FollowReject,
FollowSchema as Follow,
GroupSchema as Group,
InstanceMetadataSchema as InstanceMetadata,
NoteSchema as Note,
UnfollowSchema as Unfollow,
UserSchema as User,
} from "./schemas/base.ts";
export { ContentFormatSchema as ContentFormat } from "./schemas/content_format.ts";
export { ExtensionPropertySchema as EntityExtensionProperty } from "./schemas/extensions.ts";
export { CustomEmojiExtensionSchema as CustomEmojiExtension } from "./schemas/extensions/custom_emojis.ts";
export {
DislikeSchema as DislikeExtension,
LikeSchema as LikeExtension,
} from "./schemas/extensions/likes.ts";
export { VoteSchema as PollVoteExtension } from "./schemas/extensions/polls.ts";
export { ReactionSchema as ReactionExtension } from "./schemas/extensions/reactions.ts";
export { ShareSchema as ShareExtension } from "./schemas/extensions/share.ts";
export { VanityExtensionSchema as VanityExtension } from "./schemas/extensions/vanity.ts";
export { WebFingerSchema as WebFinger } from "./schemas/webfinger.ts";

View file

@ -16,18 +16,15 @@ import type {
NoteSchema, NoteSchema,
UnfollowSchema, UnfollowSchema,
UserSchema, UserSchema,
} from "./validators/base.ts"; } from "./schemas/base.ts";
import type { ContentFormatSchema } from "./validators/content_format.ts"; import type { ContentFormatSchema } from "./schemas/content_format.ts";
import type { ExtensionPropertySchema } from "./validators/extensions.ts"; import type { ExtensionPropertySchema } from "./schemas/extensions.ts";
import type { CustomEmojiExtensionSchema } from "./validators/extensions/custom_emojis.ts"; import type { CustomEmojiExtensionSchema } from "./schemas/extensions/custom_emojis.ts";
import type { import type { DislikeSchema, LikeSchema } from "./schemas/extensions/likes.ts";
DislikeSchema, import type { VoteSchema } from "./schemas/extensions/polls.ts";
LikeSchema, import type { ReactionSchema } from "./schemas/extensions/reactions.ts";
} from "./validators/extensions/likes.ts"; import type { ShareSchema } from "./schemas/extensions/share.ts";
import type { VoteSchema } from "./validators/extensions/polls.ts"; import type { VanityExtensionSchema } from "./schemas/extensions/vanity.ts";
import type { ReactionSchema } from "./validators/extensions/reactions.ts";
import type { ShareSchema } from "./validators/extensions/share.ts";
import type { VanityExtensionSchema } from "./validators/extensions/vanity.ts";
// biome-ignore lint/suspicious/noExplicitAny: Used only as a base type // biome-ignore lint/suspicious/noExplicitAny: Used only as a base type
type AnyZod = z.ZodType<any, any, any>; type AnyZod = z.ZodType<any, any, any>;

View file

@ -12,15 +12,15 @@ import {
NoteSchema, NoteSchema,
UnfollowSchema, UnfollowSchema,
UserSchema, UserSchema,
} from "./validators/base.ts"; } from "./schemas/base.ts";
import { ContentFormatSchema } from "./validators/content_format.ts"; import { ContentFormatSchema } from "./schemas/content_format.ts";
import { ExtensionPropertySchema } from "./validators/extensions.ts"; import { ExtensionPropertySchema } from "./schemas/extensions.ts";
import { CustomEmojiExtensionSchema } from "./validators/extensions/custom_emojis.ts"; import { CustomEmojiExtensionSchema } from "./schemas/extensions/custom_emojis.ts";
import { DislikeSchema, LikeSchema } from "./validators/extensions/likes.ts"; import { DislikeSchema, LikeSchema } from "./schemas/extensions/likes.ts";
import { VoteSchema } from "./validators/extensions/polls.ts"; import { VoteSchema } from "./schemas/extensions/polls.ts";
import { ReactionSchema } from "./validators/extensions/reactions.ts"; import { ReactionSchema } from "./schemas/extensions/reactions.ts";
import { ShareSchema } from "./validators/extensions/share.ts"; import { ShareSchema } from "./schemas/extensions/share.ts";
import { VanityExtensionSchema } from "./validators/extensions/vanity.ts"; import { VanityExtensionSchema } from "./schemas/extensions/vanity.ts";
import type { import type {
Collection, Collection,
ContentFormat, ContentFormat,
@ -52,7 +52,7 @@ type InferType<T extends AnyZod> = z.infer<T>;
/** /**
* Validates entities against their respective schemas. * Validates entities against their respective schemas.
* @module federation/validator * @module federation/validator
* @see module:federation/validators/base * @see module:federation/schemas/base
* @example * @example
* import { EntityValidator, type ValidationError } from "@versia/federation"; * import { EntityValidator, type ValidationError } from "@versia/federation";
* const validator = new EntityValidator(); * const validator = new EntityValidator();

View file

@ -1,51 +0,0 @@
/**
* @file Zod schema definitions
* @module federation/schemas
*/
import {
CollectionSchema,
DeleteSchema,
EntitySchema,
FollowAcceptSchema,
FollowRejectSchema,
FollowSchema,
GroupSchema,
InstanceMetadataSchema,
NoteSchema,
UnfollowSchema,
UserSchema,
} from "./validators/base.ts";
import { ContentFormatSchema } from "./validators/content_format.ts";
import { ExtensionPropertySchema } from "./validators/extensions.ts";
import { CustomEmojiExtensionSchema } from "./validators/extensions/custom_emojis.ts";
import { DislikeSchema, LikeSchema } from "./validators/extensions/likes.ts";
import { VoteSchema } from "./validators/extensions/polls.ts";
import { ReactionSchema } from "./validators/extensions/reactions.ts";
import { ShareSchema } from "./validators/extensions/share.ts";
import { VanityExtensionSchema } from "./validators/extensions/vanity.ts";
import { WebFingerSchema } from "./validators/webfinger.ts";
export {
NoteSchema as Note,
CollectionSchema as Collection,
EntitySchema as Entity,
FollowSchema as Follow,
UnfollowSchema as Unfollow,
FollowAcceptSchema as FollowAccept,
FollowRejectSchema as FollowReject,
GroupSchema as Group,
InstanceMetadataSchema as InstanceMetadata,
UserSchema as User,
ContentFormatSchema as ContentFormat,
ExtensionPropertySchema as EntityExtensionProperty,
CustomEmojiExtensionSchema as CustomEmojiExtension,
DeleteSchema as Delete,
VanityExtensionSchema as VanityExtension,
LikeSchema as LikeExtension,
DislikeSchema as DislikeExtension,
VoteSchema as PollVoteExtension,
ReactionSchema as ReactionExtension,
ShareSchema as ShareExtension,
WebFingerSchema as WebFinger,
};