import type { Logger, OptimisticDataProvider } from '@zenstackhq/client-helpers'; import type { FetchFn } from '@zenstackhq/client-helpers/fetch'; import type { GetProcedureNames, GetSlicedOperations, ModelAllowsCreate, OperationsRequiringCreate, ProcedureFunc, QueryOptions } from '@zenstackhq/orm'; import type { GetModels, SchemaDef } from '@zenstackhq/schema'; export type { TransactionOperation, TransactionResults } from '@zenstackhq/client-helpers'; /** * Context type for configuring the hooks. */ export type QueryContext = { /** * The endpoint to use for the queries. */ endpoint?: string; /** * A custom fetch function for sending the HTTP requests. */ fetch?: FetchFn; /** * If logging is enabled. */ logging?: Logger; }; /** * Extra query options. */ export type ExtraQueryOptions = { /** * Whether to opt-in to optimistic updates for this query. Defaults to `true`. */ optimisticUpdate?: boolean; } & QueryContext; /** * Extra mutation options. */ export type ExtraMutationOptions = { /** * Whether to automatically invalidate queries potentially affected by the mutation. Defaults to `true`. */ invalidateQueries?: boolean; /** * Whether to optimistically update queries potentially affected by the mutation. Defaults to `false`. */ optimisticUpdate?: boolean; /** * A callback for computing optimistic update data for each query cache entry. */ optimisticDataProvider?: OptimisticDataProvider; } & QueryContext; type HooksOperationsRequiringCreate = OperationsRequiringCreate extends any ? `use${Capitalize}` : never; type Modifiers = '' | 'Suspense' | 'Infinite' | 'SuspenseInfinite'; /** * Trim CRUD operation hooks to include only eligible operations. */ export type TrimSlicedOperations, Options extends QueryOptions, T extends Record> = { [Key in keyof T as Key extends `use${Modifiers}${Capitalize>}` ? ModelAllowsCreate extends true ? Key : Key extends HooksOperationsRequiringCreate ? never : Key : never]: T[Key]; }; type WithOptimisticFlag = T extends object ? T & { /** * Indicates if the item is in an optimistic update state */ $optimistic?: boolean; } : T; export type WithOptimistic = T extends Array ? Array> : WithOptimisticFlag; export type ProcedureReturn> = Awaited>>;