mirror of
https://github.com/versia-pub/api.git
synced 2025-12-06 08:28:19 +01:00
feat(federation): ✨ Expose all Zod schemas in package
This commit is contained in:
parent
a31695d64c
commit
6c15ceb1e9
2
build.ts
2
build.ts
|
|
@ -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", "schemas.ts"],
|
federation: ["index.ts", "schemas.ts", "types.ts"],
|
||||||
client: ["index.ts", "types.ts"],
|
client: ["index.ts", "types.ts"],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import type {
|
||||||
ShareExtension,
|
ShareExtension,
|
||||||
Unfollow,
|
Unfollow,
|
||||||
User,
|
User,
|
||||||
} from "./schemas";
|
} from "./types";
|
||||||
import type { EntityValidator } from "./validator";
|
import type { EntityValidator } from "./validator";
|
||||||
|
|
||||||
type MaybePromise<T> = T | Promise<T>;
|
type MaybePromise<T> = T | Promise<T>;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./index.ts",
|
".": "./index.ts",
|
||||||
"./types": "./schemas.ts"
|
"./types": "./types.ts",
|
||||||
|
"./schemas": "./schemas.ts"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,11 @@
|
||||||
"types": "./dist/index.d.ts"
|
"types": "./dist/index.d.ts"
|
||||||
},
|
},
|
||||||
"./types": {
|
"./types": {
|
||||||
|
"import": "./dist/types.js",
|
||||||
|
"default": "./dist/types.js",
|
||||||
|
"types": "./dist/types.d.ts"
|
||||||
|
},
|
||||||
|
"./schemas": {
|
||||||
"import": "./dist/schemas.js",
|
"import": "./dist/schemas.js",
|
||||||
"default": "./dist/schemas.js",
|
"default": "./dist/schemas.js",
|
||||||
"types": "./dist/schemas.d.ts"
|
"types": "./dist/schemas.d.ts"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { fromZodError } from "zod-validation-error";
|
import { fromZodError } from "zod-validation-error";
|
||||||
import type { SignatureConstructor } from "../cryptography";
|
import type { SignatureConstructor } from "../cryptography";
|
||||||
import type { User } from "../schemas";
|
|
||||||
import { WebFingerSchema } from "../schemas/webfinger";
|
import { WebFingerSchema } from "../schemas/webfinger";
|
||||||
|
import type { User } from "../types";
|
||||||
import { DEFAULT_UA } from "./constants";
|
import { DEFAULT_UA } from "./constants";
|
||||||
|
|
||||||
type HttpVerb = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
type HttpVerb = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
/**
|
/**
|
||||||
* @file TypeScript type definitions
|
* @file Zod schema definitions
|
||||||
* @module federation/types
|
* @module federation/schemas
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { z } from "zod";
|
import {
|
||||||
import type {
|
|
||||||
CollectionSchema,
|
CollectionSchema,
|
||||||
DeleteSchema,
|
DeleteSchema,
|
||||||
EntitySchema,
|
EntitySchema,
|
||||||
|
|
@ -17,37 +16,34 @@ import type {
|
||||||
UnfollowSchema,
|
UnfollowSchema,
|
||||||
UserSchema,
|
UserSchema,
|
||||||
} from "./schemas/base";
|
} from "./schemas/base";
|
||||||
import type { ContentFormatSchema } from "./schemas/content_format";
|
import { ContentFormatSchema } from "./schemas/content_format";
|
||||||
import type { ExtensionPropertySchema } from "./schemas/extensions";
|
import { ExtensionPropertySchema } from "./schemas/extensions";
|
||||||
import type { CustomEmojiExtensionSchema } from "./schemas/extensions/custom_emojis";
|
import { CustomEmojiExtensionSchema } from "./schemas/extensions/custom_emojis";
|
||||||
import type { LikeSchema } from "./schemas/extensions/likes";
|
import { DislikeSchema, LikeSchema } from "./schemas/extensions/likes";
|
||||||
import type { VoteSchema } from "./schemas/extensions/polls";
|
import { VoteSchema } from "./schemas/extensions/polls";
|
||||||
import type { ReactionSchema } from "./schemas/extensions/reactions";
|
import { ReactionSchema } from "./schemas/extensions/reactions";
|
||||||
import type { ShareSchema } from "./schemas/extensions/share";
|
import { ShareSchema } from "./schemas/extensions/share";
|
||||||
import type { VanityExtensionSchema } from "./schemas/extensions/vanity";
|
import { VanityExtensionSchema } from "./schemas/extensions/vanity";
|
||||||
|
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: Used only as a base type
|
export {
|
||||||
type AnyZod = z.ZodType<any, any, any>;
|
NoteSchema as Note,
|
||||||
|
CollectionSchema as Collection,
|
||||||
type InferType<T extends AnyZod> = z.infer<T>;
|
EntitySchema as Entity,
|
||||||
|
FollowSchema as Follow,
|
||||||
export type Note = InferType<typeof NoteSchema>;
|
UnfollowSchema as Unfollow,
|
||||||
export type Collection = InferType<typeof CollectionSchema>;
|
FollowAcceptSchema as FollowAccept,
|
||||||
export type EntityExtensionProperty = InferType<typeof ExtensionPropertySchema>;
|
FollowRejectSchema as FollowReject,
|
||||||
export type VanityExtension = InferType<typeof VanityExtensionSchema>;
|
GroupSchema as Group,
|
||||||
export type User = InferType<typeof UserSchema>;
|
InstanceMetadataSchema as InstanceMetadata,
|
||||||
export type Follow = InferType<typeof FollowSchema>;
|
UserSchema as User,
|
||||||
export type FollowAccept = InferType<typeof FollowAcceptSchema>;
|
ContentFormatSchema as ContentFormat,
|
||||||
export type FollowReject = InferType<typeof FollowRejectSchema>;
|
ExtensionPropertySchema as EntityExtensionProperty,
|
||||||
export type ContentFormat = InferType<typeof ContentFormatSchema>;
|
CustomEmojiExtensionSchema as CustomEmojiExtension,
|
||||||
export type CustomEmojiExtension = InferType<typeof CustomEmojiExtensionSchema>;
|
DeleteSchema as Delete,
|
||||||
export type Entity = InferType<typeof EntitySchema>;
|
VanityExtensionSchema as VanityExtension,
|
||||||
export type Delete = InferType<typeof DeleteSchema>;
|
LikeSchema as LikeExtension,
|
||||||
export type Group = InferType<typeof GroupSchema>;
|
DislikeSchema as DislikeExtension,
|
||||||
export type InstanceMetadata = InferType<typeof InstanceMetadataSchema>;
|
VoteSchema as PollVoteExtension,
|
||||||
export type Unfollow = InferType<typeof UnfollowSchema>;
|
ReactionSchema as ReactionExtension,
|
||||||
export type LikeExtension = InferType<typeof LikeSchema>;
|
ShareSchema as ShareExtension,
|
||||||
export type DislikeExtension = InferType<typeof LikeSchema>;
|
};
|
||||||
export type PollVoteExtension = InferType<typeof VoteSchema>;
|
|
||||||
export type ReactionExtension = InferType<typeof ReactionSchema>;
|
|
||||||
export type ShareExtension = InferType<typeof ShareSchema>;
|
|
||||||
|
|
|
||||||
53
federation/types.ts
Normal file
53
federation/types.ts
Normal 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>;
|
||||||
|
|
@ -1,27 +1,5 @@
|
||||||
import type { z } from "zod";
|
import type { z } from "zod";
|
||||||
import { fromError } from "zod-validation-error";
|
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 {
|
import {
|
||||||
CollectionSchema,
|
CollectionSchema,
|
||||||
DeleteSchema,
|
DeleteSchema,
|
||||||
|
|
@ -43,6 +21,28 @@ import { VoteSchema } from "./schemas/extensions/polls";
|
||||||
import { ReactionSchema } from "./schemas/extensions/reactions";
|
import { ReactionSchema } from "./schemas/extensions/reactions";
|
||||||
import { ShareSchema } from "./schemas/extensions/share";
|
import { ShareSchema } from "./schemas/extensions/share";
|
||||||
import { VanityExtensionSchema } from "./schemas/extensions/vanity";
|
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
|
// 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>;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue