Skip to content

Commit 70cd00c

Browse files
committed
refactor(federation): ⬆️ Use @lysand-org/federation v2.0.0
1 parent 47ce604 commit 70cd00c

File tree

17 files changed

+56
-60
lines changed

17 files changed

+56
-60
lines changed

bun.lockb

0 Bytes
Binary file not shown.

database/entities/federation.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { debugRequest } from "@/api";
2-
import {
3-
type EntityValidator,
4-
SignatureConstructor,
5-
} from "@lysand-org/federation";
2+
import { SignatureConstructor } from "@lysand-org/federation";
3+
import type { Entity, Undo } from "@lysand-org/federation/types";
64
import { config } from "config-manager";
75
import type { User } from "~/packages/database-interface/user";
86
import { LogLevel, LogManager } from "~/packages/log-manager";
@@ -11,7 +9,7 @@ export const localObjectUri = (id: string) =>
119
new URL(`/objects/${id}`, config.http.base_url).toString();
1210

1311
export const objectToInboxRequest = async (
14-
object: typeof EntityValidator.$Entity,
12+
object: Entity,
1513
author: User,
1614
userToSendTo: User,
1715
): Promise<Request> => {
@@ -68,10 +66,7 @@ export const objectToInboxRequest = async (
6866
return signed;
6967
};
7068

71-
export const undoFederationRequest = (
72-
undoer: User,
73-
uri: string,
74-
): typeof EntityValidator.$Undo => {
69+
export const undoFederationRequest = (undoer: User, uri: string): Undo => {
7570
const id = crypto.randomUUID();
7671
return {
7772
type: "Undo",

database/entities/instance.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EntityValidator } from "@lysand-org/federation";
1+
import type { ServerMetadata } from "@lysand-org/federation/types";
22
import { db } from "~/drizzle/db";
33
import { Instances } from "~/drizzle/schema";
44

@@ -26,7 +26,7 @@ export const addInstanceIfNotExists = async (url: string) => {
2626
// Fetch the instance configuration
2727
const metadata = (await fetch(new URL("/.well-known/lysand", origin)).then(
2828
(res) => res.json(),
29-
)) as typeof EntityValidator.$ServerMetadata;
29+
)) as ServerMetadata;
3030

3131
if (metadata.type !== "ServerMetadata") {
3232
throw new Error("Invalid instance metadata (wrong type)");

database/entities/like.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import type { EntityValidator } from "@lysand-org/federation";
1+
import type { Like } from "@lysand-org/federation/types";
22
import { config } from "config-manager";
33
import { type InferSelectModel, and, eq } from "drizzle-orm";
44
import { db } from "~/drizzle/db";
55
import { Likes, Notifications } from "~/drizzle/schema";
66
import type { Note } from "~/packages/database-interface/note";
77
import type { User } from "~/packages/database-interface/user";
88

9-
export type Like = InferSelectModel<typeof Likes>;
9+
export type LikeType = InferSelectModel<typeof Likes>;
1010

1111
/**
1212
* Represents a Like entity in the database.
1313
*/
14-
export const likeToLysand = (like: Like): typeof EntityValidator.$Like => {
14+
export const likeToLysand = (like: LikeType): Like => {
1515
return {
1616
id: like.id,
1717
// biome-ignore lint/suspicious/noExplicitAny: to be rewritten

database/entities/status.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { mentionValidator } from "@/api";
22
import { dualLogger } from "@/loggers";
33
import { sanitizeHtml, sanitizeHtmlInline } from "@/sanitization";
44
import markdownItTaskLists from "@hackmd/markdown-it-task-lists";
5-
import type { EntityValidator } from "@lysand-org/federation";
5+
import type { ContentFormat } from "@lysand-org/federation/types";
66
import { config } from "config-manager";
77
import {
88
type InferSelectModel,
@@ -373,7 +373,7 @@ export const replaceTextMentions = (text: string, mentions: User[]) => {
373373
};
374374

375375
export const contentToHtml = async (
376-
content: typeof EntityValidator.$ContentFormat,
376+
content: ContentFormat,
377377
mentions: User[] = [],
378378
inline = false,
379379
): Promise<string> => {

database/entities/user.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { dualLogger } from "@/loggers";
2-
import type { EntityValidator } from "@lysand-org/federation";
2+
import type {
3+
Follow,
4+
FollowAccept,
5+
FollowReject,
6+
} from "@lysand-org/federation/types";
37
import { config } from "config-manager";
48
import { type InferSelectModel, and, eq, sql } from "drizzle-orm";
59
import { db } from "~/drizzle/db";
@@ -505,7 +509,7 @@ export const getRelationshipToOtherUser = async (
505509
export const followRequestToLysand = (
506510
follower: User,
507511
followee: User,
508-
): typeof EntityValidator.$Follow => {
512+
): Follow => {
509513
if (follower.isRemote()) {
510514
throw new Error("Follower must be a local user");
511515
}
@@ -533,7 +537,7 @@ export const followRequestToLysand = (
533537
export const followAcceptToLysand = (
534538
follower: User,
535539
followee: User,
536-
): typeof EntityValidator.$FollowAccept => {
540+
): FollowAccept => {
537541
if (!follower.isRemote()) {
538542
throw new Error("Follower must be a remote user");
539543
}
@@ -561,7 +565,7 @@ export const followAcceptToLysand = (
561565
export const followRejectToLysand = (
562566
follower: User,
563567
followee: User,
564-
): typeof EntityValidator.$FollowReject => {
568+
): FollowReject => {
565569
return {
566570
...followAcceptToLysand(follower, followee),
567571
type: "FollowReject",

drizzle/schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EntityValidator } from "@lysand-org/federation";
1+
import type { ContentFormat } from "@lysand-org/federation/types";
22
import type { Challenge } from "altcha-lib/types";
33
import { relations, sql } from "drizzle-orm";
44
import {
@@ -375,8 +375,8 @@ export const Users = pgTable(
375375
passwordResetToken: text("password_reset_token"),
376376
fields: jsonb("fields").notNull().default("[]").$type<
377377
{
378-
key: typeof EntityValidator.$ContentFormat;
379-
value: typeof EntityValidator.$ContentFormat;
378+
key: ContentFormat;
379+
value: ContentFormat;
380380
}[]
381381
>(),
382382
endpoints: jsonb("endpoints").$type<Partial<{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"@inquirer/confirm": "^3.1.10",
101101
"@inquirer/input": "^2.1.10",
102102
"@json2csv/plainjs": "^7.0.6",
103-
"@lysand-org/federation": "^1.2.0",
103+
"@lysand-org/federation": "^2.0.0",
104104
"@oclif/core": "^4.0.6",
105105
"@tufjs/canonical-json": "^2.0.0",
106106
"altcha-lib": "^0.3.0",

packages/database-interface/attachment.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { proxyUrl } from "@/response";
2-
import type { EntityValidator } from "@lysand-org/federation";
2+
import type { ContentFormat } from "@lysand-org/federation/types";
33
import {
44
type InferInsertModel,
55
type InferSelectModel,
@@ -183,7 +183,7 @@ export class Attachment extends BaseInterface<typeof Attachments> {
183183
};
184184
}
185185

186-
public toLysand(): typeof EntityValidator.$ContentFormat {
186+
public toLysand(): ContentFormat {
187187
return {
188188
[this.data.mimeType]: {
189189
content: this.data.url,
@@ -204,7 +204,7 @@ export class Attachment extends BaseInterface<typeof Attachments> {
204204
}
205205

206206
public static fromLysand(
207-
attachmentToConvert: typeof EntityValidator.$ContentFormat,
207+
attachmentToConvert: ContentFormat,
208208
): Promise<Attachment> {
209209
const key = Object.keys(attachmentToConvert)[0];
210210
const value = attachmentToConvert[key];

packages/database-interface/emoji.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { proxyUrl } from "@/response";
2-
import type { EntityValidator } from "@lysand-org/federation";
2+
import type { CustomEmojiExtension } from "@lysand-org/federation/types";
33
import {
44
type InferInsertModel,
55
type SQL,
@@ -118,7 +118,7 @@ export class Emoji extends BaseInterface<typeof Emojis, EmojiWithInstance> {
118118
}
119119

120120
public static async fetchFromRemote(
121-
emojiToFetch: (typeof EntityValidator.$CustomEmojiExtension)["emojis"][0],
121+
emojiToFetch: CustomEmojiExtension["emojis"][0],
122122
host?: string,
123123
): Promise<Emoji> {
124124
const existingEmoji = await db
@@ -164,7 +164,7 @@ export class Emoji extends BaseInterface<typeof Emojis, EmojiWithInstance> {
164164
};
165165
}
166166

167-
public toLysand(): (typeof EntityValidator.$CustomEmojiExtension)["emojis"][0] {
167+
public toLysand(): CustomEmojiExtension["emojis"][0] {
168168
return {
169169
name: this.data.shortcode,
170170
url: {
@@ -177,7 +177,7 @@ export class Emoji extends BaseInterface<typeof Emojis, EmojiWithInstance> {
177177
}
178178

179179
public static fromLysand(
180-
emoji: (typeof EntityValidator.$CustomEmojiExtension)["emojis"][0],
180+
emoji: CustomEmojiExtension["emojis"][0],
181181
instanceId: string | null,
182182
): Promise<Emoji> {
183183
return Emoji.insert({

0 commit comments

Comments
 (0)