import { UseQueryResult, UseMutationResult } from '@tanstack/react-query'; import { DescribeManifest, SchemaRegistry } from '@davepi/ui-core'; import { ReactNode, ReactElement } from 'react'; import { L as ListParams, c as ListResponse } from '../client-BLdA4Ob7.js'; /** * Fetch and cache `/_describe` for the lifetime of the session. * * The manifest changes only when the backend redeploys or hot-reloads a * schema, so we treat it as effectively static (`staleTime: Infinity`). * Refetch on focus is disabled — too noisy for what is essentially a * boot-time blob. Force a refetch with `queryClient.invalidateQueries(['davepi','describe'])` * if you need to. * * Returns both the raw manifest and a memoised `SchemaRegistry` (the * widget resolver / label generator / relation graph consume the latter). * * When an ancestor `` has injected a manifest * (e.g. one fetched through a custom OAuth data layer), that takes * precedence and no network fetch happens — so schema-driven widgets like * `RelationPicker` work no matter how the app sourced the manifest. * * @example * const { data, isPending } = useDescribe(); * if (isPending) return ; * console.log(data.registry.paths()); */ interface UseDescribeData { manifest: DescribeManifest; registry: SchemaRegistry; } declare function useDescribe(): UseQueryResult; /** * Unauthenticated variant useful for displaying the login page without * requiring a token first. Reads `/_describe` only when the backend has * `DESCRIBE_REQUIRES_AUTH=false`; otherwise the call 401s and the hook * returns an error. */ declare function useAnonymousDescribe(): UseQueryResult; /** * Inject an already-fetched `/_describe` manifest so every `useDescribe()` * consumer below — `ResourceForm`, `RelationPicker`, `Sidebar`, … — reads it * instead of fetching through the `AuthProvider` client. * * This is the escape hatch for apps that obtain the manifest out of band: * a custom OAuth data layer, server-side preloading, tests, or storybooks. * Without it, deeply nested widgets that hardcode `useDescribe()` come up * empty whenever the standard auth-gated query isn't the source of truth * (e.g. "Unknown relation target" from `RelationPicker` in OAuth mode). * * @example * const { data: manifest } = useMyOAuthDescribeQuery(); * return ( * * * * ); */ interface DescribeProviderProps { /** * The raw `/_describe` manifest. While `undefined` (still loading), the * provider is inert and `useDescribe()` falls back to its normal * auth-gated fetch. */ manifest: DescribeManifest | undefined; children: ReactNode; } declare function DescribeProvider({ manifest, children }: DescribeProviderProps): ReactElement; /** * Resource hooks built on TanStack Query. * * Every list/get/create/update/delete operation against the davepi REST * surface flows through these hooks so cache invalidation stays * consistent. The query-key shape is `['davepi','resource',path,kind,...]` * which lets a mutation against e.g. `account` invalidate every list/get * for that path with a single call. * * Pass the schema's API version when constructing the resource path; * default is `v1`. */ interface UseResourceListOptions { version?: string; params?: ListParams; enabled?: boolean; } declare function resourcePath(path: string, version?: string): string; declare function useResourceList>(path: string, opts?: UseResourceListOptions): UseQueryResult>; interface UseResourceOptions { version?: string; include?: string[]; enabled?: boolean; } declare function useResource>(path: string, id: string | undefined, opts?: UseResourceOptions): UseQueryResult; interface MutationOptions { version?: string; /** Extra related-resource paths to invalidate on success. */ invalidate?: string[]; } declare function useCreateResource>(path: string, opts?: MutationOptions): UseMutationResult>; declare function useUpdateResource>(path: string, opts?: MutationOptions): UseMutationResult; }>; declare function useDeleteResource(path: string, opts?: MutationOptions): UseMutationResult<{ acknowledged: boolean; }, Error, string>; export { DescribeProvider, type DescribeProviderProps, type MutationOptions, type UseDescribeData, type UseResourceListOptions, type UseResourceOptions, resourcePath, useAnonymousDescribe, useCreateResource, useDeleteResource, useDescribe, useResource, useResourceList, useUpdateResource };