server/packages/sdk/entities/user.ts

42 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-11-21 08:31:02 +01:00
import type { z } from "zod";
import { UserSchema } from "../schemas/user.ts";
import type { JSONObject } from "../types.ts";
import { ImageContentFormat, TextContentFormat } from "./contentformat.ts";
import { Entity } from "./entity.ts";
export class User extends Entity {
public static override name = "User";
public constructor(
public override data: z.infer<typeof UserSchema>,
instanceDomain: string,
) {
super(data, instanceDomain);
}
public static override fromJSON(
json: JSONObject,
instanceDomain: string,
): Promise<User> {
return UserSchema.parseAsync(json).then(
(u) => new User(u, instanceDomain),
);
}
public get avatar(): ImageContentFormat | undefined {
return this.data.avatar
? new ImageContentFormat(this.data.avatar)
: undefined;
}
public get header(): ImageContentFormat | undefined {
return this.data.header
? new ImageContentFormat(this.data.header)
: undefined;
}
public get bio(): TextContentFormat | undefined {
return this.data.bio ? new TextContentFormat(this.data.bio) : undefined;
}
}