feat(federation): Expose all Zod schemas in package

This commit is contained in:
Jesse Wierzbinski 2024-09-16 12:44:11 +02:00
parent a31695d64c
commit 6c15ceb1e9
No known key found for this signature in database
8 changed files with 118 additions and 63 deletions

View file

@ -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"],
};

View file

@ -13,7 +13,7 @@ import type {
ShareExtension,
Unfollow,
User,
} from "./schemas";
} from "./types";
import type { EntityValidator } from "./validator";
type MaybePromise<T> = T | Promise<T>;

View file

@ -4,6 +4,7 @@
"version": "0.1.0",
"exports": {
".": "./index.ts",
"./types": "./schemas.ts"
"./types": "./types.ts",
"./schemas": "./schemas.ts"
}
}

View file

@ -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"

View file

@ -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";

View file

@ -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<any, any, any>;
type InferType<T extends AnyZod> = z.infer<T>;
export type Note = InferType<typeof NoteSchema>;
export type Collection = InferType<typeof CollectionSchema>;
export type EntityExtensionProperty = InferType<typeof ExtensionPropertySchema>;
export type VanityExtension = InferType<typeof VanityExtensionSchema>;
export type User = InferType<typeof UserSchema>;
export type Follow = InferType<typeof FollowSchema>;
export type FollowAccept = InferType<typeof FollowAcceptSchema>;
export type FollowReject = InferType<typeof FollowRejectSchema>;
export type ContentFormat = InferType<typeof ContentFormatSchema>;
export type CustomEmojiExtension = InferType<typeof CustomEmojiExtensionSchema>;
export type Entity = InferType<typeof EntitySchema>;
export type Delete = InferType<typeof DeleteSchema>;
export type Group = InferType<typeof GroupSchema>;
export type InstanceMetadata = InferType<typeof InstanceMetadataSchema>;
export type Unfollow = InferType<typeof UnfollowSchema>;
export type LikeExtension = InferType<typeof LikeSchema>;
export type DislikeExtension = InferType<typeof LikeSchema>;
export type PollVoteExtension = InferType<typeof VoteSchema>;
export type ReactionExtension = InferType<typeof ReactionSchema>;
export type ShareExtension = InferType<typeof ShareSchema>;
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,
};

53
federation/types.ts Normal file
View file

@ -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<any, any, any>;
type InferType<T extends AnyZod> = z.infer<T>;
export type Note = InferType<typeof NoteSchema>;
export type Collection = InferType<typeof CollectionSchema>;
export type EntityExtensionProperty = InferType<typeof ExtensionPropertySchema>;
export type VanityExtension = InferType<typeof VanityExtensionSchema>;
export type User = InferType<typeof UserSchema>;
export type Follow = InferType<typeof FollowSchema>;
export type FollowAccept = InferType<typeof FollowAcceptSchema>;
export type FollowReject = InferType<typeof FollowRejectSchema>;
export type ContentFormat = InferType<typeof ContentFormatSchema>;
export type CustomEmojiExtension = InferType<typeof CustomEmojiExtensionSchema>;
export type Entity = InferType<typeof EntitySchema>;
export type Delete = InferType<typeof DeleteSchema>;
export type Group = InferType<typeof GroupSchema>;
export type InstanceMetadata = InferType<typeof InstanceMetadataSchema>;
export type Unfollow = InferType<typeof UnfollowSchema>;
export type LikeExtension = InferType<typeof LikeSchema>;
export type DislikeExtension = InferType<typeof DislikeSchema>;
export type PollVoteExtension = InferType<typeof VoteSchema>;
export type ReactionExtension = InferType<typeof ReactionSchema>;
export type ShareExtension = InferType<typeof ShareSchema>;

View file

@ -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<any, any, any>;