/** * Provisions the principals subsystem: a principals table, a principal_entities junction table, create/delete mutations, and org API key management. Supports both human-owned principals (AuthzDirectOwner, AuthzHumanOnly) and org-owned principals (AuthzEntityMembership with is_admin). Org principal and org API key functions are only generated when an org-scoped memberships_module exists for the database. * @generated by @constructive-io/graphql-codegen * DO NOT EDIT - changes will be overwritten */ import { useMutation, useQueryClient } from '@tanstack/react-query'; import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query'; import { getClient } from '../client'; import { buildSelectionArgs } from '../selection'; import type { SelectionConfig } from '../selection'; import { principalAuthModuleKeys } from '../query-keys'; import { principalAuthModuleMutationKeys } from '../mutation-keys'; import type { PrincipalAuthModuleSelect, PrincipalAuthModuleWithRelations, PrincipalAuthModulePatch, } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { PrincipalAuthModuleSelect, PrincipalAuthModuleWithRelations, PrincipalAuthModulePatch, } from '../../orm/input-types'; /** * Provisions the principals subsystem: a principals table, a principal_entities junction table, create/delete mutations, and org API key management. Supports both human-owned principals (AuthzDirectOwner, AuthzHumanOnly) and org-owned principals (AuthzEntityMembership with is_admin). Org principal and org API key functions are only generated when an org-scoped memberships_module exists for the database. * * @example * ```tsx * const { mutate, isPending } = useUpdatePrincipalAuthModuleMutation({ * selection: { fields: { id: true, name: true } }, * }); * * mutate({ id: 'value-here', principalAuthModulePatch: { name: 'Updated' } }); * ``` */ export function useUpdatePrincipalAuthModuleMutation( params: { selection: { fields: S & PrincipalAuthModuleSelect; } & HookStrictSelect, PrincipalAuthModuleSelect>; } & Omit< UseMutationOptions< { updatePrincipalAuthModule: { principalAuthModule: InferSelectResult; }; }, Error, { id: string; principalAuthModulePatch: PrincipalAuthModulePatch; } >, 'mutationFn' > ): UseMutationResult< { updatePrincipalAuthModule: { principalAuthModule: InferSelectResult; }; }, Error, { id: string; principalAuthModulePatch: PrincipalAuthModulePatch; } >; export function useUpdatePrincipalAuthModuleMutation( params: { selection: SelectionConfig; } & Omit< UseMutationOptions< any, Error, { id: string; principalAuthModulePatch: PrincipalAuthModulePatch; } >, 'mutationFn' > ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: principalAuthModuleMutationKeys.all, mutationFn: ({ id, principalAuthModulePatch, }: { id: string; principalAuthModulePatch: PrincipalAuthModulePatch; }) => getClient() .principalAuthModule.update({ where: { id, }, data: principalAuthModulePatch, select: args.select, }) .unwrap(), onSuccess: (_, variables) => { queryClient.invalidateQueries({ queryKey: principalAuthModuleKeys.detail(variables.id), }); queryClient.invalidateQueries({ queryKey: principalAuthModuleKeys.lists(), }); }, ...mutationOptions, }); }