import { InfiniteData, InfiniteQueryObserverOptions, MutationObserver, MutationObserverOptions } from '@tanstack/query-core'; import { WeavyType } from '../client/weavy'; import { AppUpProperties, AppsResultType, AppTypeGuid, AppTypeString, AppType, AppUidType } from '../types/app.types'; import { QueryController } from '../controllers/query-controller'; import { MutationAbortProps } from '../types/query.types'; /** * Options for reading a single app. * * This is the one and only query for app data: every component observes it, whether or not the component is allowed to * create the app. Creating is done separately by {@link ensureApp}, which seeds this query with the result. * * The split matters because a TanStack query has a single `queryFn` shared by every observer of its key, and an * observer that joins a fetch already in flight never gets to apply its own options * (see https://github.com/TanStack/query/blob/main/packages/query-core/src/query.ts, `Query.fetch`). Letting creating * and lookup-only components supply different `queryFn`s for `["apps", uid]` therefore made the effective request * depend on which component happened to fetch first. * * @param weavy - The weavy client. * @param uid - Unique app identifier or app id. * @returns Query options for the app. */ export declare function getAppOptions(weavy: WeavyType, uid: string | number): import('@tanstack/query-core').QueryObserverOptions; /** * Options for the mutation that makes sure an app exists. * * Creating an app is a write, so it runs as a mutation rather than as the `queryFn` of `["apps", uid]`. A TanStack * query pairs exactly one `queryFn` with a key (https://github.com/TanStack/query/discussions/4020), so letting a * creating component and a lookup-only component supply different ones made the effective request depend on whichever * happened to fetch first — and when the lookup won, the app was never created at all. * * Being a mutation also keeps the default `networkMode`, so an upsert attempted while offline is paused and retried in * order once the connection returns * (https://tanstack.com/query/latest/docs/framework/react/guides/network-mode), which a bare `weavy.fetch` would not * do — it would simply reject, leaving the app uncreated. * * `onSuccess` writes the app straight into the app query. That is the documented way to avoid spending a second * request on data the response already carries * (https://tanstack.com/query/latest/docs/framework/react/guides/updates-from-mutation-responses), and it reaches * every observer of the app, lookup-only components included. * * Concurrent upserts for the same uid are not deduplicated here. Callers are expected to upsert only when the app is * missing or its data has changed, and the request is an idempotent upsert, so the worst case is a duplicate write * rather than a wrong result. * * @param weavy - The weavy client. * @param uid - Unique app identifier. App ids cannot be upserted and must not be passed. * @param type - The type of app to create. * @param members - Members for the app. Creates the app with `POST /api/apps` instead of upserting it by uid. * @param appData - Additional app properties, such as name and directory. * @returns Mutation options for the upsert. */ export declare function getEnsureAppMutationOptions(weavy: WeavyType, uid: string, type: AppTypeGuid, members?: (number | string)[], appData?: AppUpProperties): MutationObserverOptions; export type MutateAddAppVariables = { name?: string; members: (number | string)[]; type: AppTypeString; uid?: string; }; export type CreateAppMutationType = MutationObserver; export declare function getCreateAppMutationOptions(weavy: WeavyType): { mutationFn: ({ name, members, type, uid }: MutateAddAppVariables) => Promise; onSettled: () => Promise; }; export declare function getCreateAppMutation(weavy: WeavyType): CreateAppMutationType; export declare function mutateApp(weavy: WeavyType, app: T, appData?: AppUpProperties): Promise; export type MutateAppSubscribeProps = { subscribe: boolean; }; export type MutateAppSubscribeContextType = { previousSubscribe: boolean | undefined; subscribe: boolean; } | undefined; export declare function getAppSubscribeMutationOptions(weavy: WeavyType, app: AppType): { mutationFn: ({ subscribe }: MutateAppSubscribeProps) => Promise; onMutate: (variables: MutateAppSubscribeProps) => { previousSubscribe: boolean | undefined; subscribe: boolean; }; onError(error: Error, variables: MutateAppSubscribeProps, context: MutateAppSubscribeContextType): void; }; /** * Gets multiple apps at once. */ export declare function getMultipleAppsOptions(weavy: WeavyType, uids: Array, types?: AppTypeGuid[], member?: string): import('@tanstack/query-core').QueryObserverOptions; /** * Gets number of unread conversations/apps. * Agent-chat-only queries exclude apps with a uid to keep contextual chats out of the standalone inbox. */ export declare function getAppsUnreadOptions(weavy: WeavyType, types?: AppTypeGuid[] | null, member?: string): import('@tanstack/query-core').QueryObserverOptions; export type AppsListFilterType = { around?: number; orderBy?: string | null; }; /** * Gets a paginated app list. Agent-chat-only queries exclude apps with a uid, matching the unread query. */ export declare function getAppListOptions(weavy: WeavyType, types?: AppTypeGuid[] | null, member?: string, filters?: AppsListFilterType, searchText?: () => string | undefined, options?: object): InfiniteQueryObserverOptions>; /** * Support function to use multiple controllers to get apps instead of getting a proper app list directly. * * @param multipleAppsQueryMap - Map of AppType query controllers * @returns */ export declare function mapMultipleAppsAsAppList(multipleAppsQueryMap: Map>): { result: { data: AppsResultType | undefined; isPending: boolean; }; }; //# sourceMappingURL=app.d.ts.map