{"version":3,"file":"mutation-options.mjs","sources":["../src/mutation-options.ts"],"sourcesContent":["import type { DefaultError, WithRequired } from '@tanstack/query-core'\nimport type { CreateMutationOptions } from './types'\n\n/**\n * You can generally pass everything to `mutationOptions` that you can also pass to `injectMutation`. A\n * `mutationKey` is required on this overload so the mutation can be looked up later, e.g. with\n * `injectMutationState`.\n *\n * @see {@link injectMutation} to run the mutation these options describe.\n * @param options - The mutation options to use, identical to what you'd pass to `injectMutation`, with a\n * required `mutationKey`.\n * @returns The same options object, unchanged.\n *\n * @example\n * Looking the mutation up elsewhere via its `mutationKey`, e.g. for a global \"saving…\" indicator:\n * ```angular-ts\n * import { mutationOptions, injectMutationState } from '@tanstack/angular-query-experimental'\n *\n * const createPostOptions = mutationOptions({\n *   mutationKey: ['posts', 'create'],\n *   mutationFn: createPost,\n * })\n *\n * @Component({\n *   selector: 'saving-indicator',\n *   template: `\n *     @if (isCreatingPost()) {\n *       <span>Saving…</span>\n *     }\n *   `,\n * })\n * export class SavingIndicator {\n *   readonly #pendingCreates = injectMutationState(() => ({\n *     filters: { mutationKey: createPostOptions.mutationKey, status: 'pending' },\n *   }))\n *   readonly isCreatingPost = computed(() => this.#pendingCreates().length > 0)\n * }\n * ```\n */\nexport function mutationOptions<\n  TData = unknown,\n  TError = DefaultError,\n  TVariables = void,\n  TOnMutateResult = unknown,\n>(\n  options: WithRequired<\n    CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n    'mutationKey'\n  >,\n): WithRequired<\n  CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n  'mutationKey'\n>\n/**\n * You can generally pass everything to `mutationOptions` that you can also pass to `injectMutation`. No\n * `mutationKey` is required on this overload — use this when you don't need to target the mutation via a\n * `mutationKey` filter later (e.g. with `injectMutationState`); it can still be observed through other\n * filters, such as `status`.\n *\n * @see {@link injectMutation} to run the mutation these options describe.\n * @param options - The mutation options to use, identical to what you'd pass to `injectMutation`, without a\n * `mutationKey`.\n * @returns The same options object, unchanged.\n * @remarks See the other overload's example for looking a mutation up via `injectMutationState`.\n *\n * @example\n * Sharing options across services, so `QueriesService` stays the single place a mutation is defined:\n * ```angular-ts\n * import { mutationOptions, injectMutation } from '@tanstack/angular-query-experimental'\n *\n * @Injectable({ providedIn: 'root' })\n * export class QueriesService {\n *   readonly #queryClient = inject(QueryClient)\n *\n *   updatePost(id: number) {\n *     return mutationOptions({\n *       mutationFn: (post: Partial<Post>) => putPost(id, post),\n *       onSuccess: (newPost) => this.#queryClient.setQueryData(['posts', id], newPost),\n *     })\n *   }\n * }\n *\n * @Component({\n *   selector: 'post',\n *   template: `<button (click)=\"save()\">Save</button>`,\n * })\n * export class Post {\n *   readonly queries = inject(QueriesService)\n *   readonly id = signal(0)\n *   readonly updatePostMutation = injectMutation(() => this.queries.updatePost(this.id()))\n *\n *   save() {\n *     this.updatePostMutation.mutate({ title: 'New Title' })\n *   }\n * }\n * ```\n */\nexport function mutationOptions<\n  TData = unknown,\n  TError = DefaultError,\n  TVariables = void,\n  TOnMutateResult = unknown,\n>(\n  options: Omit<\n    CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n    'mutationKey'\n  >,\n): Omit<\n  CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n  'mutationKey'\n>\nexport function mutationOptions<\n  TData = unknown,\n  TError = DefaultError,\n  TVariables = void,\n  TOnMutateResult = unknown,\n>(\n  options: CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n): CreateMutationOptions<TData, TError, TVariables, TOnMutateResult> {\n  return options\n}\n"],"names":[],"mappings":"AA+GO,SAAS,gBAMd,SACmE;AACnE,SAAO;AACT;"}