mirror of
https://github.com/versia-pub/api.git
synced 2025-12-06 16:38:20 +01:00
refactor(federation): ♻️ Move around code to get better TypeScript output
This commit is contained in:
parent
283e000498
commit
115bfc7f0d
12
build.ts
12
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", "requester.ts"],
|
federation: ["index.ts", "schemas.ts"],
|
||||||
client: ["index.ts", "types.ts"],
|
client: ["index.ts", "types.ts"],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -15,11 +15,17 @@ for (const pkg of ["federation", "client"]) {
|
||||||
),
|
),
|
||||||
outdir: `${pkg}/dist`,
|
outdir: `${pkg}/dist`,
|
||||||
format: "esm",
|
format: "esm",
|
||||||
minify: true,
|
minify: false,
|
||||||
sourcemap: "external",
|
sourcemap: "external",
|
||||||
splitting: true,
|
splitting: true,
|
||||||
target: "browser",
|
target: "browser",
|
||||||
plugins: [dts()],
|
plugins: [
|
||||||
|
dts({
|
||||||
|
output: {
|
||||||
|
noBanner: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
}).then((output) => {
|
}).then((output) => {
|
||||||
if (!output.success) {
|
if (!output.success) {
|
||||||
subSpinner.fail(`Failed to build ${pkg} module`);
|
subSpinner.fail(`Failed to build ${pkg} module`);
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,7 @@ Your editor's IntelliSense should provide you with every method and property ava
|
||||||
A `FederationRequester` class is provided to make requests to a remote server. It sets the correct headers and has multiple methods to make requesters easier.
|
A `FederationRequester` class is provided to make requests to a remote server. It sets the correct headers and has multiple methods to make requesters easier.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { FederationRequester } from "@lysand-org/federation/requester";
|
import { FederationRequester, SignatureConstructor } from "@lysand-org/federation";
|
||||||
import { SignatureConstructor } from "@lysand-org/federation/cryptography";
|
|
||||||
|
|
||||||
const requester = new FederationRequester(
|
const requester = new FederationRequester(
|
||||||
new URL("https://example.com"),
|
new URL("https://example.com"),
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ import type {
|
||||||
ServerMetadata,
|
ServerMetadata,
|
||||||
Undo,
|
Undo,
|
||||||
User,
|
User,
|
||||||
} from "../schemas";
|
} from "@/federation/schemas";
|
||||||
import type { EntityValidator } from "../validator/index";
|
import type { EntityValidator } from "@/federation/validator/index";
|
||||||
|
|
||||||
type MaybePromise<T> = T | Promise<T>;
|
type MaybePromise<T> = T | Promise<T>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,18 @@
|
||||||
* @see module:federation/schemas/base
|
* @see module:federation/schemas/base
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
SignatureConstructor,
|
||||||
|
SignatureValidator,
|
||||||
|
} from "@/federation/cryptography";
|
||||||
|
import { RequestParserHandler } from "@/federation/http";
|
||||||
|
import {
|
||||||
|
FederationRequester,
|
||||||
|
type Output,
|
||||||
|
ResponseError,
|
||||||
|
} from "@/federation/requester/index";
|
||||||
|
import { EntityValidator } from "@/federation/validator";
|
||||||
import type { ValidationError } from "zod-validation-error";
|
import type { ValidationError } from "zod-validation-error";
|
||||||
import { SignatureConstructor, SignatureValidator } from "./cryptography";
|
|
||||||
import { RequestParserHandler } from "./http";
|
|
||||||
import { EntityValidator } from "./validator";
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
EntityValidator,
|
EntityValidator,
|
||||||
|
|
@ -16,4 +24,7 @@ export {
|
||||||
SignatureConstructor,
|
SignatureConstructor,
|
||||||
SignatureValidator,
|
SignatureValidator,
|
||||||
RequestParserHandler,
|
RequestParserHandler,
|
||||||
|
type Output,
|
||||||
|
ResponseError,
|
||||||
|
FederationRequester,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./index.ts",
|
".": "./index.ts",
|
||||||
"./types": "./schemas.ts",
|
"./types": "./schemas.ts"
|
||||||
"./requester": "./requester.ts"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,6 @@
|
||||||
"default": "./dist/index.js",
|
"default": "./dist/index.js",
|
||||||
"types": "./dist/index.d.ts"
|
"types": "./dist/index.d.ts"
|
||||||
},
|
},
|
||||||
"./requester": {
|
|
||||||
"import": "./dist/requester.js",
|
|
||||||
"default": "./dist/requester.js",
|
|
||||||
"types": "./dist/requester.d.ts"
|
|
||||||
},
|
|
||||||
"./types": {
|
"./types": {
|
||||||
"import": "./dist/schemas.js",
|
"import": "./dist/schemas.js",
|
||||||
"default": "./dist/schemas.js",
|
"default": "./dist/schemas.js",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
import {
|
|
||||||
FederationRequester,
|
|
||||||
type Output,
|
|
||||||
ResponseError,
|
|
||||||
} from "./requester/index";
|
|
||||||
|
|
||||||
export { type Output, ResponseError, FederationRequester };
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
import pkg from "../package.json" with { type: "json" };
|
import pkg from "@/federation/package.json" with { type: "json" };
|
||||||
|
|
||||||
export const DEFAULT_UA = `LysandFederation/${pkg.version} (+${pkg.homepage})`;
|
export const DEFAULT_UA = `LysandFederation/${pkg.version} (+${pkg.homepage})`;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
|
import type { SignatureConstructor } from "@/federation/cryptography";
|
||||||
|
import { DEFAULT_UA } from "@/federation/requester/constants";
|
||||||
|
import type { User } from "@/federation/schemas";
|
||||||
|
import { WebFingerSchema } from "@/federation/schemas/webfinger";
|
||||||
import { fromZodError } from "zod-validation-error";
|
import { fromZodError } from "zod-validation-error";
|
||||||
import type { SignatureConstructor } from "../cryptography";
|
|
||||||
import type { User } from "../schemas";
|
|
||||||
import { WebFingerSchema } from "../schemas/webfinger";
|
|
||||||
import { DEFAULT_UA } from "./constants";
|
|
||||||
|
|
||||||
type HttpVerb = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
type HttpVerb = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import type { z } from "zod";
|
|
||||||
import type {
|
import type {
|
||||||
ActionSchema,
|
ActionSchema,
|
||||||
ActorPublicKeyDataSchema,
|
ActorPublicKeyDataSchema,
|
||||||
|
|
@ -21,7 +20,8 @@ import type {
|
||||||
UserSchema,
|
UserSchema,
|
||||||
VanityExtensionSchema,
|
VanityExtensionSchema,
|
||||||
VisibilitySchema,
|
VisibilitySchema,
|
||||||
} from "./schemas/base";
|
} from "@/federation/schemas/base";
|
||||||
|
import type { z } from "zod";
|
||||||
|
|
||||||
// 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>;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
|
import { ContentFormatSchema } from "@/federation/schemas/content_format";
|
||||||
|
import { ExtensionPropertySchema } from "@/federation/schemas/extensions";
|
||||||
|
import { CustomEmojiExtensionSchema } from "@/federation/schemas/extensions/custom_emojis";
|
||||||
|
import { VanityExtensionSchema } from "@/federation/schemas/extensions/vanity";
|
||||||
|
import { extensionTypeRegex } from "@/federation/schemas/regex";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ContentFormatSchema } from "./content_format";
|
|
||||||
import { ExtensionPropertySchema } from "./extensions";
|
|
||||||
import { CustomEmojiExtensionSchema } from "./extensions/custom_emojis";
|
|
||||||
import { VanityExtensionSchema } from "./extensions/vanity";
|
|
||||||
import { extensionTypeRegex } from "./regex";
|
|
||||||
|
|
||||||
const EntitySchema = z.object({
|
const EntitySchema = z.object({
|
||||||
id: z.string().uuid(),
|
id: z.string().uuid(),
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
|
import { CustomEmojiExtensionSchema } from "@/federation/schemas/extensions/custom_emojis";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { CustomEmojiExtensionSchema } from "./extensions/custom_emojis";
|
|
||||||
|
|
||||||
export const ExtensionPropertySchema = z.object({
|
export const ExtensionPropertySchema = z.object({
|
||||||
"org.lysand:custom_emojis":
|
"org.lysand:custom_emojis":
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { ContentFormatSchema } from "@/federation/schemas/content_format";
|
||||||
|
import { emojiRegex } from "@/federation/schemas/regex";
|
||||||
/**
|
/**
|
||||||
* Custom emojis extension.
|
* Custom emojis extension.
|
||||||
* @module federation/schemas/extensions/custom_emojis
|
* @module federation/schemas/extensions/custom_emojis
|
||||||
|
|
@ -5,8 +7,6 @@
|
||||||
* @see https://lysand.org/extensions/custom-emojis
|
* @see https://lysand.org/extensions/custom-emojis
|
||||||
*/
|
*/
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ContentFormatSchema } from "../content_format";
|
|
||||||
import { emojiRegex } from "../regex";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Used to validate the properties the extension's custom field
|
* @description Used to validate the properties the extension's custom field
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { ExtensionSchema } from "@/federation/schemas/base";
|
||||||
|
import { ContentFormatSchema } from "@/federation/schemas/content_format";
|
||||||
/**
|
/**
|
||||||
* Polls extension
|
* Polls extension
|
||||||
* @module federation/schemas/extensions/polls
|
* @module federation/schemas/extensions/polls
|
||||||
|
|
@ -5,8 +7,6 @@
|
||||||
* @see https://lysand.org/extensions/polls
|
* @see https://lysand.org/extensions/polls
|
||||||
*/
|
*/
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ExtensionSchema } from "../base";
|
|
||||||
import { ContentFormatSchema } from "../content_format";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Poll extension entity
|
* @description Poll extension entity
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { ExtensionSchema } from "@/federation/schemas/base";
|
||||||
/**
|
/**
|
||||||
* Reactions extension
|
* Reactions extension
|
||||||
* @module federation/schemas/extensions/reactions
|
* @module federation/schemas/extensions/reactions
|
||||||
|
|
@ -5,7 +6,6 @@
|
||||||
* @see https://lysand.org/extensions/reactions
|
* @see https://lysand.org/extensions/reactions
|
||||||
*/
|
*/
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ExtensionSchema } from "../base";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Reaction extension entity
|
* @description Reaction extension entity
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
* @see https://lysand.org/extensions/vanity
|
* @see https://lysand.org/extensions/vanity
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { ContentFormatSchema } from "@/federation/schemas/content_format";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ContentFormatSchema } from "../content_format";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Vanity extension entity
|
* @description Vanity extension entity
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import type { z } from "zod";
|
|
||||||
import { fromError } from "zod-validation-error";
|
|
||||||
import {
|
import {
|
||||||
ActionSchema,
|
ActionSchema,
|
||||||
ActorPublicKeyDataSchema,
|
ActorPublicKeyDataSchema,
|
||||||
|
|
@ -22,7 +20,9 @@ import {
|
||||||
UserSchema,
|
UserSchema,
|
||||||
VanityExtensionSchema,
|
VanityExtensionSchema,
|
||||||
VisibilitySchema,
|
VisibilitySchema,
|
||||||
} from "../schemas/base";
|
} from "@/federation/schemas/base";
|
||||||
|
import type { z } from "zod";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
|
||||||
// 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>;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,11 @@
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"verbatimModuleSyntax": true,
|
"verbatimModuleSyntax": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"noUnusedParameters": true
|
"noUnusedParameters": true,
|
||||||
|
"paths": {
|
||||||
|
"@/federation/*": ["./federation/*"],
|
||||||
|
"@/client/*": ["./client/*"]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"include": ["*.ts", "*.d.ts", "**/*.ts", "**/*.d.ts"]
|
"include": ["*.ts", "*.d.ts", "**/*.ts", "**/*.d.ts"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue