// AUTO-GENERATED by mizan — do not edit import { ref, computed, onMounted, onUnmounted, onServerPrefetch, type ComputedRef } from 'vue' import { registerContext, type ContextState } from '@mizan/base' import { fetchUserContext, type UserContextData, type UserContextParams, callUpdateProfile, callEcho, callWhoami, callFindUser, callRenameUser } from '../index' export function useUserContext(params: UserContextParams) { const state = ref>({ data: null, status: 'idle', error: null }) let handle: ReturnType | null = null onMounted(() => { handle = registerContext('user', params, () => fetchUserContext(params)) handle.subscribe(() => { state.value = handle!.getState() }) handle.refetch() }) onServerPrefetch(async () => { handle = registerContext('user', params, () => fetchUserContext(params)) await handle.refetch() state.value = handle.getState() }) onUnmounted(() => { handle?.unregister() }) return { state, userProfile: computed(() => state.value.data?.user_profile ?? null) as ComputedRef, userOrders: computed(() => state.value.data?.user_orders ?? null) as ComputedRef, loading: computed(() => state.value.status === 'loading'), error: computed(() => state.value.error), } } export function useUpdateProfile() { const isPending = ref(false) const error = ref(null) async function mutate(args: Parameters[0]) { isPending.value = true; error.value = null try { return await callUpdateProfile(args) } catch (e) { error.value = e as Error; throw e } finally { isPending.value = false } } return { mutate, isPending, error } } export function useEcho() { const isPending = ref(false) const error = ref(null) async function mutate(args: Parameters[0]) { isPending.value = true; error.value = null try { return await callEcho(args) } catch (e) { error.value = e as Error; throw e } finally { isPending.value = false } } return { mutate, isPending, error } } export function useWhoami() { const isPending = ref(false) const error = ref(null) async function mutate() { isPending.value = true; error.value = null try { return await callWhoami() } catch (e) { error.value = e as Error; throw e } finally { isPending.value = false } } return { mutate, isPending, error } } export function useFindUser() { const isPending = ref(false) const error = ref(null) async function mutate(args: Parameters[0]) { isPending.value = true; error.value = null try { return await callFindUser(args) } catch (e) { error.value = e as Error; throw e } finally { isPending.value = false } } return { mutate, isPending, error } } export function useRenameUser() { const isPending = ref(false) const error = ref(null) async function mutate(args: Parameters[0]) { isPending.value = true; error.value = null try { return await callRenameUser(args) } catch (e) { error.value = e as Error; throw e } finally { isPending.value = false } } return { mutate, isPending, error } } export type { ContextState } from '@mizan/base' export { configure, initSession, MizanError } from '@mizan/base'