refactor(federation): ⬆️ Use @lysand-org/federation v2.0.0

This commit is contained in:
Jesse Wierzbinski 2024-06-19 13:21:02 -10:00
parent 47ce60494a
commit 70cd00cfa8
No known key found for this signature in database
17 changed files with 56 additions and 60 deletions

View file

@ -1,5 +1,5 @@
import { proxyUrl } from "@/response";
import type { EntityValidator } from "@lysand-org/federation";
import type { ContentFormat } from "@lysand-org/federation/types";
import {
type InferInsertModel,
type InferSelectModel,
@ -183,7 +183,7 @@ export class Attachment extends BaseInterface<typeof Attachments> {
};
}
public toLysand(): typeof EntityValidator.$ContentFormat {
public toLysand(): ContentFormat {
return {
[this.data.mimeType]: {
content: this.data.url,
@ -204,7 +204,7 @@ export class Attachment extends BaseInterface<typeof Attachments> {
}
public static fromLysand(
attachmentToConvert: typeof EntityValidator.$ContentFormat,
attachmentToConvert: ContentFormat,
): Promise<Attachment> {
const key = Object.keys(attachmentToConvert)[0];
const value = attachmentToConvert[key];

View file

@ -1,5 +1,5 @@
import { proxyUrl } from "@/response";
import type { EntityValidator } from "@lysand-org/federation";
import type { CustomEmojiExtension } from "@lysand-org/federation/types";
import {
type InferInsertModel,
type SQL,
@ -118,7 +118,7 @@ export class Emoji extends BaseInterface<typeof Emojis, EmojiWithInstance> {
}
public static async fetchFromRemote(
emojiToFetch: (typeof EntityValidator.$CustomEmojiExtension)["emojis"][0],
emojiToFetch: CustomEmojiExtension["emojis"][0],
host?: string,
): Promise<Emoji> {
const existingEmoji = await db
@ -164,7 +164,7 @@ export class Emoji extends BaseInterface<typeof Emojis, EmojiWithInstance> {
};
}
public toLysand(): (typeof EntityValidator.$CustomEmojiExtension)["emojis"][0] {
public toLysand(): CustomEmojiExtension["emojis"][0] {
return {
name: this.data.shortcode,
url: {
@ -177,7 +177,7 @@ export class Emoji extends BaseInterface<typeof Emojis, EmojiWithInstance> {
}
public static fromLysand(
emoji: (typeof EntityValidator.$CustomEmojiExtension)["emojis"][0],
emoji: CustomEmojiExtension["emojis"][0],
instanceId: string | null,
): Promise<Emoji> {
return Emoji.insert({

View file

@ -3,6 +3,10 @@ import { dualLogger } from "@/loggers";
import { proxyUrl } from "@/response";
import { sanitizedHtmlStrip } from "@/sanitization";
import { EntityValidator } from "@lysand-org/federation";
import type {
ContentFormat,
Note as LysandNote,
} from "@lysand-org/federation/types";
import {
type InferInsertModel,
type SQL,
@ -302,7 +306,7 @@ export class Note extends BaseInterface<typeof Notes, StatusWithRelations> {
*/
static async fromData(data: {
author: User;
content: typeof EntityValidator.$ContentFormat;
content: ContentFormat;
visibility: APIStatus["visibility"];
isSensitive: boolean;
spoilerText: string;
@ -392,7 +396,7 @@ export class Note extends BaseInterface<typeof Notes, StatusWithRelations> {
*/
async updateFromData(data: {
author?: User;
content?: typeof EntityValidator.$ContentFormat;
content?: ContentFormat;
visibility?: APIStatus["visibility"];
isSensitive?: boolean;
spoilerText?: string;
@ -579,7 +583,7 @@ export class Note extends BaseInterface<typeof Notes, StatusWithRelations> {
* @returns The saved note, or null if the note could not be fetched
*/
static async saveFromRemote(uri: string): Promise<Note | null> {
let note: typeof EntityValidator.$Note | null = null;
let note: LysandNote | null = null;
if (uri) {
if (!URL.canParse(uri)) {
@ -615,10 +619,7 @@ export class Note extends BaseInterface<typeof Notes, StatusWithRelations> {
* @param author Author of the note
* @returns The saved note
*/
static async fromLysand(
note: typeof EntityValidator.$Note,
author: User,
): Promise<Note> {
static async fromLysand(note: LysandNote, author: User): Promise<Note> {
const emojis: Emoji[] = [];
for (const emoji of note.extensions?.["org.lysand:custom_emojis"]
@ -878,7 +879,7 @@ export class Note extends BaseInterface<typeof Notes, StatusWithRelations> {
* Convert a note to the Lysand format
* @returns The note in the Lysand format
*/
toLysand(): typeof EntityValidator.$Note {
toLysand(): LysandNote {
const status = this.data;
return {
type: "Note",

View file

@ -4,6 +4,7 @@ import { randomString } from "@/math";
import { addUserToMeilisearch } from "@/meilisearch";
import { proxyUrl } from "@/response";
import { EntityValidator } from "@lysand-org/federation";
import type { Entity, User as LysandUser } from "@lysand-org/federation/types";
import {
type InferInsertModel,
type InferSelectModel,
@ -254,9 +255,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
},
});
const json = (await response.json()) as Partial<
typeof EntityValidator.$User
>;
const json = (await response.json()) as Partial<LysandUser>;
const validator = new EntityValidator();
@ -299,7 +298,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
}
static async fromLysand(
user: typeof EntityValidator.$User,
user: LysandUser,
instance: InferSelectModel<typeof Instances>,
): Promise<User> {
const data = {
@ -535,7 +534,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
return updated.data;
}
async federateToFollowers(object: typeof EntityValidator.$Entity) {
async federateToFollowers(object: Entity) {
// Get followers
const followers = await User.manyFromSql(
and(
@ -625,7 +624,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
};
}
toLysand(): typeof EntityValidator.$User {
toLysand(): LysandUser {
if (this.isRemote()) {
throw new Error("Cannot convert remote user to Lysand format");
}