diff --git a/build.ts b/build.ts index 1772fc9..222acf7 100644 --- a/build.ts +++ b/build.ts @@ -2,7 +2,7 @@ import dts from "bun-plugin-dts"; import ora from "ora"; const entrypoints = { - federation: ["index.ts", "schemas.ts"], + federation: ["index.ts", "schemas.ts", "types.ts"], client: ["index.ts", "types.ts"], }; diff --git a/federation/http.ts b/federation/http.ts index 9c67ac2..115807c 100644 --- a/federation/http.ts +++ b/federation/http.ts @@ -13,7 +13,7 @@ import type { ShareExtension, Unfollow, User, -} from "./schemas"; +} from "./types"; import type { EntityValidator } from "./validator"; type MaybePromise = T | Promise; diff --git a/federation/jsr.jsonc b/federation/jsr.jsonc index 7fa5bd0..e6c2f85 100644 --- a/federation/jsr.jsonc +++ b/federation/jsr.jsonc @@ -4,6 +4,7 @@ "version": "0.1.0", "exports": { ".": "./index.ts", - "./types": "./schemas.ts" + "./types": "./types.ts", + "./schemas": "./schemas.ts" } } diff --git a/federation/package.json b/federation/package.json index c387c6d..0bacb9e 100644 --- a/federation/package.json +++ b/federation/package.json @@ -44,6 +44,11 @@ "types": "./dist/index.d.ts" }, "./types": { + "import": "./dist/types.js", + "default": "./dist/types.js", + "types": "./dist/types.d.ts" + }, + "./schemas": { "import": "./dist/schemas.js", "default": "./dist/schemas.js", "types": "./dist/schemas.d.ts" diff --git a/federation/requester/index.ts b/federation/requester/index.ts index 168b8bd..790d94b 100644 --- a/federation/requester/index.ts +++ b/federation/requester/index.ts @@ -1,7 +1,7 @@ import { fromZodError } from "zod-validation-error"; import type { SignatureConstructor } from "../cryptography"; -import type { User } from "../schemas"; import { WebFingerSchema } from "../schemas/webfinger"; +import type { User } from "../types"; import { DEFAULT_UA } from "./constants"; type HttpVerb = "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; diff --git a/federation/schemas.ts b/federation/schemas.ts index 68b621e..e2c5342 100644 --- a/federation/schemas.ts +++ b/federation/schemas.ts @@ -1,10 +1,9 @@ /** - * @file TypeScript type definitions - * @module federation/types + * @file Zod schema definitions + * @module federation/schemas */ -import type { z } from "zod"; -import type { +import { CollectionSchema, DeleteSchema, EntitySchema, @@ -17,37 +16,34 @@ import type { UnfollowSchema, UserSchema, } from "./schemas/base"; -import type { ContentFormatSchema } from "./schemas/content_format"; -import type { ExtensionPropertySchema } from "./schemas/extensions"; -import type { CustomEmojiExtensionSchema } from "./schemas/extensions/custom_emojis"; -import type { LikeSchema } from "./schemas/extensions/likes"; -import type { VoteSchema } from "./schemas/extensions/polls"; -import type { ReactionSchema } from "./schemas/extensions/reactions"; -import type { ShareSchema } from "./schemas/extensions/share"; -import type { VanityExtensionSchema } from "./schemas/extensions/vanity"; +import { ContentFormatSchema } from "./schemas/content_format"; +import { ExtensionPropertySchema } from "./schemas/extensions"; +import { CustomEmojiExtensionSchema } from "./schemas/extensions/custom_emojis"; +import { DislikeSchema, LikeSchema } from "./schemas/extensions/likes"; +import { VoteSchema } from "./schemas/extensions/polls"; +import { ReactionSchema } from "./schemas/extensions/reactions"; +import { ShareSchema } from "./schemas/extensions/share"; +import { VanityExtensionSchema } from "./schemas/extensions/vanity"; -// biome-ignore lint/suspicious/noExplicitAny: Used only as a base type -type AnyZod = z.ZodType; - -type InferType = z.infer; - -export type Note = InferType; -export type Collection = InferType; -export type EntityExtensionProperty = InferType; -export type VanityExtension = InferType; -export type User = InferType; -export type Follow = InferType; -export type FollowAccept = InferType; -export type FollowReject = InferType; -export type ContentFormat = InferType; -export type CustomEmojiExtension = InferType; -export type Entity = InferType; -export type Delete = InferType; -export type Group = InferType; -export type InstanceMetadata = InferType; -export type Unfollow = InferType; -export type LikeExtension = InferType; -export type DislikeExtension = InferType; -export type PollVoteExtension = InferType; -export type ReactionExtension = InferType; -export type ShareExtension = InferType; +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, +}; diff --git a/federation/types.ts b/federation/types.ts new file mode 100644 index 0000000..723ecac --- /dev/null +++ b/federation/types.ts @@ -0,0 +1,53 @@ +/** + * @file TypeScript type definitions + * @module federation/types + */ + +import type { z } from "zod"; +import type { + CollectionSchema, + DeleteSchema, + EntitySchema, + FollowAcceptSchema, + FollowRejectSchema, + FollowSchema, + GroupSchema, + InstanceMetadataSchema, + NoteSchema, + UnfollowSchema, + UserSchema, +} from "./schemas/base"; +import type { ContentFormatSchema } from "./schemas/content_format"; +import type { ExtensionPropertySchema } from "./schemas/extensions"; +import type { CustomEmojiExtensionSchema } from "./schemas/extensions/custom_emojis"; +import type { DislikeSchema, LikeSchema } from "./schemas/extensions/likes"; +import type { VoteSchema } from "./schemas/extensions/polls"; +import type { ReactionSchema } from "./schemas/extensions/reactions"; +import type { ShareSchema } from "./schemas/extensions/share"; +import type { VanityExtensionSchema } from "./schemas/extensions/vanity"; + +// biome-ignore lint/suspicious/noExplicitAny: Used only as a base type +type AnyZod = z.ZodType; + +type InferType = z.infer; + +export type Note = InferType; +export type Collection = InferType; +export type EntityExtensionProperty = InferType; +export type VanityExtension = InferType; +export type User = InferType; +export type Follow = InferType; +export type FollowAccept = InferType; +export type FollowReject = InferType; +export type ContentFormat = InferType; +export type CustomEmojiExtension = InferType; +export type Entity = InferType; +export type Delete = InferType; +export type Group = InferType; +export type InstanceMetadata = InferType; +export type Unfollow = InferType; +export type LikeExtension = InferType; +export type DislikeExtension = InferType; +export type PollVoteExtension = InferType; +export type ReactionExtension = InferType; +export type ShareExtension = InferType; diff --git a/federation/validator.ts b/federation/validator.ts index e1ae058..77fab61 100644 --- a/federation/validator.ts +++ b/federation/validator.ts @@ -1,27 +1,5 @@ import type { z } from "zod"; import { fromError } from "zod-validation-error"; -import type { - Collection, - ContentFormat, - CustomEmojiExtension, - Delete, - DislikeExtension, - Entity, - EntityExtensionProperty, - Follow, - FollowAccept, - FollowReject, - Group, - InstanceMetadata, - LikeExtension, - Note, - PollVoteExtension, - ReactionExtension, - ShareExtension, - Unfollow, - User, - VanityExtension, -} from "./schemas"; import { CollectionSchema, DeleteSchema, @@ -43,6 +21,28 @@ import { VoteSchema } from "./schemas/extensions/polls"; import { ReactionSchema } from "./schemas/extensions/reactions"; import { ShareSchema } from "./schemas/extensions/share"; import { VanityExtensionSchema } from "./schemas/extensions/vanity"; +import type { + Collection, + ContentFormat, + CustomEmojiExtension, + Delete, + DislikeExtension, + Entity, + EntityExtensionProperty, + Follow, + FollowAccept, + FollowReject, + Group, + InstanceMetadata, + LikeExtension, + Note, + PollVoteExtension, + ReactionExtension, + ShareExtension, + Unfollow, + User, + VanityExtension, +} from "./types"; // biome-ignore lint/suspicious/noExplicitAny: Used only as a base type type AnyZod = z.ZodType;