chore: ⬆️ Upgrade to new @versia/client

This commit is contained in:
Jesse Wierzbinski 2025-05-26 11:19:15 +02:00
parent 0a157d06f6
commit f807b05784
No known key found for this signature in database
71 changed files with 451 additions and 492 deletions

View file

@ -1,15 +1,16 @@
import type { Client } from "@versia/client";
import type { Account } from "@versia/client/types";
import type { Account } from "@versia/client/schemas";
import type { z } from "zod";
export const useAccount = (
client: MaybeRef<Client | null>,
accountId: MaybeRef<string | null>,
) => {
if (!client) {
return ref(null as Account | null);
return ref(null as z.infer<typeof Account> | null);
}
const output = ref(null as Account | null);
const output = ref(null as z.infer<typeof Account> | null);
watchEffect(() => {
if (toValue(accountId)) {

View file

@ -1,11 +1,15 @@
import type { Client } from "@versia/client";
import type { Account } from "@versia/client/types";
import type { Account } from "@versia/client/schemas";
import type { z } from "zod";
export const useAccountFromAcct = (
client: MaybeRef<Client | null>,
acct: string,
): { account: Ref<Account | null>; isLoading: Ref<boolean> } => {
const output = ref(null as Account | null);
): {
account: Ref<z.infer<typeof Account> | null>;
isLoading: Ref<boolean>;
} => {
const output = ref(null as z.infer<typeof Account> | null);
const isLoading = ref(true);
ref(client)

View file

@ -1,11 +1,12 @@
import type { Client } from "@versia/client";
import type { Account } from "@versia/client/types";
import type { Account } from "@versia/client/schemas";
import type { z } from "zod";
export const useAccountSearch = (
client: MaybeRef<Client | null>,
q: string,
): Ref<Account[] | null> => {
const output = ref(null as Account[] | null);
): Ref<z.infer<typeof Account>[] | null> => {
const output = ref(null as z.infer<typeof Account>[] | null);
ref(client)
.value?.searchAccount(q, {

View file

@ -1,11 +1,12 @@
import type { Client } from "@versia/client";
import type { Status } from "@versia/client/types";
import type { Status } from "@versia/client/schemas";
import type { z } from "zod";
import { type TimelineOptions, useTimeline } from "./Timeline";
export function useAccountTimeline(
client: Client,
accountId: string,
options: Partial<TimelineOptions<Status>> = {},
options: Partial<TimelineOptions<z.infer<typeof Status>>> = {},
) {
return useTimeline(client, {
fetchFunction: (client, opts) =>

View file

@ -1,8 +1,13 @@
import type { ApplicationData } from "@versia/client/types";
import type { CredentialApplication } from "@versia/client/schemas";
import { StorageSerializers } from "@vueuse/core";
import type { z } from "zod";
export const useAppData = () => {
return useLocalStorage<ApplicationData | null>("versia:app_data", null, {
serializer: StorageSerializers.object,
});
return useLocalStorage<z.infer<typeof CredentialApplication> | null>(
"versia:app_data",
null,
{
serializer: StorageSerializers.object,
},
);
};

View file

@ -1,5 +1,5 @@
import type { Client } from "@versia/client";
import type { RolePermission } from "@versia/client/types";
import type { RolePermission } from "@versia/client/schemas";
import { toast } from "vue-sonner";
import * as m from "~/paraglide/messages.js";

View file

@ -1,9 +1,11 @@
import { Client, type Token } from "@versia/client";
import { Client } from "@versia/client";
import type { Token } from "@versia/client/schemas";
import { toast } from "vue-sonner";
import type { z } from "zod";
export const useClient = (
origin?: MaybeRef<URL>,
customToken: MaybeRef<Token | null> = null,
customToken: MaybeRef<z.infer<typeof Token> | null> = null,
): Ref<Client> => {
const apiHost = window.location.origin;
const domain = identity.value?.instance.domain;
@ -15,10 +17,14 @@ export const useClient = (
toValue(customToken)?.access_token ??
identity.value?.tokens.access_token ??
undefined,
(error) => {
toast.error(
error.response.data.error ?? "No error message provided",
);
{
globalCatch: (error) => {
toast.error(
error.response.data.error ??
"No error message provided",
);
},
throwOnError: false,
},
),
) as Ref<Client>;

View file

@ -1,27 +1,28 @@
import type { Account, Attachment, Status } from "@versia/client/types";
import type { Account, Attachment, Status } from "@versia/client/schemas";
import mitt from "mitt";
import type { z } from "zod";
import type { Identity } from "./Identities";
type ApplicationEvents = {
"note:reply": Status;
"note:delete": Status;
"note:edit": Status;
"note:like": Status;
"note:unlike": Status;
"note:reblog": Status;
"note:unreblog": Status;
"note:quote": Status;
"note:report": Status;
"note:reply": z.infer<typeof Status>;
"note:delete": z.infer<typeof Status>;
"note:edit": z.infer<typeof Status>;
"note:like": z.infer<typeof Status>;
"note:unlike": z.infer<typeof Status>;
"note:reblog": z.infer<typeof Status>;
"note:unreblog": z.infer<typeof Status>;
"note:quote": z.infer<typeof Status>;
"note:report": z.infer<typeof Status>;
"composer:open": undefined;
"composer:reply": Status;
"composer:quote": Status;
"composer:edit": Status;
"composer:send": Status;
"composer:send-edit": Status;
"composer:reply": z.infer<typeof Status>;
"composer:quote": z.infer<typeof Status>;
"composer:edit": z.infer<typeof Status>;
"composer:send": z.infer<typeof Status>;
"composer:send-edit": z.infer<typeof Status>;
"composer:close": undefined;
"account:report": Account;
"account:update": Account;
"attachment:view": Attachment;
"account:report": z.infer<typeof Account>;
"account:update": z.infer<typeof Account>;
"attachment:view": z.infer<typeof Attachment>;
"identity:change": Identity;
"preferences:open": undefined;
error: {

View file

@ -1,16 +1,13 @@
import type { Client } from "@versia/client";
type ExtendedDescription = {
updated_at: string;
content: string;
};
import type { ExtendedDescription } from "@versia/client/schemas";
import type { z } from "zod";
export const useExtendedDescription = (client: MaybeRef<Client | null>) => {
if (!ref(client).value) {
return ref(null as ExtendedDescription | null);
return ref(null as z.infer<typeof ExtendedDescription> | null);
}
const output = ref(null as ExtendedDescription | null);
const output = ref(null as z.infer<typeof ExtendedDescription> | null);
ref(client)
.value?.getInstanceExtendedDescription()

View file

@ -1,10 +1,11 @@
import type { Client } from "@versia/client";
import type { Status } from "@versia/client/types";
import type { Status } from "@versia/client/schemas";
import type { z } from "zod";
import { type TimelineOptions, useTimeline } from "./Timeline";
export function useGlobalTimeline(
client: Client,
options: Partial<TimelineOptions<Status>> = {},
options: Partial<TimelineOptions<z.infer<typeof Status>>> = {},
) {
return useTimeline(client, {
// TODO: Implement global timeline in client sdk

View file

@ -1,10 +1,11 @@
import type { Client } from "@versia/client";
import type { Status } from "@versia/client/types";
import type { Status } from "@versia/client/schemas";
import type { z } from "zod";
import { type TimelineOptions, useTimeline } from "./Timeline";
export function useHomeTimeline(
client: Client,
options: Partial<TimelineOptions<Status>> = {},
options: Partial<TimelineOptions<z.infer<typeof Status>>> = {},
) {
return useTimeline(client, {
fetchFunction: (client, opts) => client.getHomeTimeline(opts),

View file

@ -1,23 +1,24 @@
import type { Token } from "@versia/client";
import type {
Account,
Emoji,
CustomEmoji,
Instance,
RolePermission,
} from "@versia/client/types";
Token,
} from "@versia/client/schemas";
import { StorageSerializers, useLocalStorage } from "@vueuse/core";
import { ref, watch } from "vue";
import type { z } from "zod";
/**
* Represents an identity with associated tokens, account, instance, permissions, and emojis.
*/
export interface Identity {
id: string;
tokens: Token;
account: Account;
instance: Instance;
tokens: z.infer<typeof Token>;
account: z.infer<typeof Account>;
instance: z.infer<typeof Instance>;
permissions: RolePermission[];
emojis: Emoji[];
emojis: z.infer<typeof CustomEmoji>[];
}
/**

View file

@ -1,5 +1,6 @@
import type { Client } from "@versia/client";
import type { ExtendedDescription, Instance } from "@versia/client/types";
import type { Instance, TermsOfService } from "@versia/client/schemas";
import type { z } from "zod";
export const useInstance = () => {
return computed(() => identity.value?.instance);
@ -7,10 +8,10 @@ export const useInstance = () => {
export const useInstanceFromClient = (client: MaybeRef<Client>) => {
if (!client) {
return ref(null as Instance | null);
return ref(null as z.infer<typeof Instance> | null);
}
const output = ref(null as Instance | null);
const output = ref(null as z.infer<typeof Instance> | null);
watchEffect(() => {
toValue(client)
@ -25,10 +26,10 @@ export const useInstanceFromClient = (client: MaybeRef<Client>) => {
export const useTos = (client: MaybeRef<Client>) => {
if (!client) {
return ref(null as ExtendedDescription | null);
return ref(null as z.infer<typeof TermsOfService> | null);
}
const output = ref(null as ExtendedDescription | null);
const output = ref(null as z.infer<typeof TermsOfService> | null);
watchEffect(() => {
toValue(client)

View file

@ -1,10 +1,11 @@
import type { Client } from "@versia/client";
import type { Status } from "@versia/client/types";
import type { Status } from "@versia/client/schemas";
import type { z } from "zod";
import { type TimelineOptions, useTimeline } from "./Timeline";
export function useLocalTimeline(
client: Client,
options: Partial<TimelineOptions<Status>> = {},
options: Partial<TimelineOptions<z.infer<typeof Status>>> = {},
) {
return useTimeline(client, {
fetchFunction: (client, opts) => client.getLocalTimeline(opts),

View file

@ -1,15 +1,16 @@
import type { Client } from "@versia/client";
import type { Status } from "@versia/client/types";
import type { Status } from "@versia/client/schemas";
import type { z } from "zod";
export const useNote = (
client: MaybeRef<Client | null>,
noteId: MaybeRef<string | null>,
) => {
if (!(toValue(client) && toValue(noteId))) {
return ref(null as Status | null);
return ref(null as z.infer<typeof Status> | null);
}
const output = ref(null as Status | null);
const output = ref(null as z.infer<typeof Status> | null);
watchEffect(() => {
toValue(noteId) &&

View file

@ -1,15 +1,16 @@
import type { Client } from "@versia/client";
import type { Context } from "@versia/client/types";
import type { Context } from "@versia/client/schemas";
import type { z } from "zod";
export const useNoteContext = (
client: MaybeRef<Client | null>,
noteId: MaybeRef<string | null>,
) => {
if (!ref(client).value) {
return ref(null as Context | null);
return ref(null as z.infer<typeof Context> | null);
}
const output = ref(null as Context | null);
const output = ref(null as z.infer<typeof Context> | null);
watchEffect(() => {
if (toValue(noteId)) {

View file

@ -1,10 +1,11 @@
import type { Client } from "@versia/client";
import type { Notification } from "@versia/client/types";
import type { Notification } from "@versia/client/schemas";
import type { z } from "zod";
import { type TimelineOptions, useTimeline } from "./Timeline";
export function useNotificationTimeline(
client: Client,
options: Partial<TimelineOptions<Notification>> = {},
options: Partial<TimelineOptions<z.infer<typeof Notification>>> = {},
) {
return useTimeline(client, {
fetchFunction: (client, opts) => client.getNotifications(opts),

View file

@ -1,10 +1,11 @@
import type { Client } from "@versia/client";
import type { Status } from "@versia/client/types";
import type { Status } from "@versia/client/schemas";
import type { z } from "zod";
import { type TimelineOptions, useTimeline } from "./Timeline";
export function usePublicTimeline(
client: Client,
options: Partial<TimelineOptions<Status>> = {},
options: Partial<TimelineOptions<z.infer<typeof Status>>> = {},
) {
return useTimeline(client, {
fetchFunction: (client, opts) => client.getPublicTimeline(opts),

View file

@ -1,11 +1,12 @@
import type { Client } from "@versia/client";
import type { Relationship } from "@versia/client/types";
import type { Relationship } from "@versia/client/schemas";
import type { z } from "zod";
export const useRelationship = (
client: MaybeRef<Client | null>,
accountId: MaybeRef<string | null>,
) => {
const relationship = ref(null as Relationship | null);
const relationship = ref(null as z.infer<typeof Relationship> | null);
const isLoading = ref(false);
if (!identity.value) {

View file

@ -1,15 +1,16 @@
import type { Client } from "@versia/client";
import type { Account, Mention } from "@versia/client/types";
import type { Account, Mention } from "@versia/client/schemas";
import type { z } from "zod";
export const useResolveMentions = (
mentions: Ref<Mention[]>,
mentions: Ref<z.infer<typeof Mention>[]>,
client: Client | null,
): Ref<Account[]> => {
): Ref<z.infer<typeof Account>[]> => {
if (!client) {
return ref([]);
}
const output = ref<Account[]>([]);
const output = ref<z.infer<typeof Account>[]>([]);
watch(
mentions,

View file

@ -1,6 +1,9 @@
import type { Instance } from "@versia/client/types";
import type { Instance } from "@versia/client/schemas";
import type { z } from "zod";
export const useSSOConfig = (): Ref<Instance["sso"] | null> => {
export const useSSOConfig = (): Ref<z.infer<
typeof Instance.shape.sso
> | null> => {
const instance = useInstance();
return computed(() => instance.value?.sso || null);

View file

@ -1,6 +1,7 @@
import type { Client, Output } from "@versia/client";
import type { Notification, Status } from "@versia/client/types";
import type { Notification, Status } from "@versia/client/schemas";
import { useIntervalFn } from "@vueuse/core";
import type { z } from "zod";
export interface TimelineOptions<T> {
fetchFunction: (client: Client, options: object) => Promise<Output<T[]>>;
@ -8,10 +9,9 @@ export interface TimelineOptions<T> {
limit?: number;
}
export function useTimeline<T extends Status | Notification>(
client: Client,
options: TimelineOptions<T>,
) {
export function useTimeline<
T extends z.infer<typeof Status> | z.infer<typeof Notification>,
>(client: Client, options: TimelineOptions<T>) {
const items = ref<T[]>([]) as Ref<T[]>;
const isLoading = ref(false);
const hasReachedEnd = ref(false);