/** * Provisions principals as authorization data, with no dependency on sessions or sign-in: the principals, principal_entities and principal_scope_overrides tables, the create/update/delete and scope mutations, the SPRT derivation that keeps a principal's capabilities in step with its owner, and the expiry sweep. The caller that opens the transaction sets jwt.claims.principal_id to a principal's user_id. Credentials for principals (API keys, child sessions, token exchange) are principal_auth_module, which builds on this one. * @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 { principalsModuleKeys } from '../query-keys'; import { principalsModuleMutationKeys } from '../mutation-keys'; import type { PrincipalsModuleSelect, PrincipalsModuleWithRelations, PrincipalsModulePatch, } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { PrincipalsModuleSelect, PrincipalsModuleWithRelations, PrincipalsModulePatch, } from '../../orm/input-types'; /** * Provisions principals as authorization data, with no dependency on sessions or sign-in: the principals, principal_entities and principal_scope_overrides tables, the create/update/delete and scope mutations, the SPRT derivation that keeps a principal's capabilities in step with its owner, and the expiry sweep. The caller that opens the transaction sets jwt.claims.principal_id to a principal's user_id. Credentials for principals (API keys, child sessions, token exchange) are principal_auth_module, which builds on this one. * * @example * ```tsx * const { mutate, isPending } = useUpdatePrincipalsModuleMutation({ * selection: { fields: { id: true, name: true } }, * }); * * mutate({ id: 'value-here', principalsModulePatch: { name: 'Updated' } }); * ``` */ export function useUpdatePrincipalsModuleMutation( params: { selection: { fields: S & PrincipalsModuleSelect; } & HookStrictSelect, PrincipalsModuleSelect>; } & Omit< UseMutationOptions< { updatePrincipalsModule: { principalsModule: InferSelectResult; }; }, Error, { id: string; principalsModulePatch: PrincipalsModulePatch; } >, 'mutationFn' > ): UseMutationResult< { updatePrincipalsModule: { principalsModule: InferSelectResult; }; }, Error, { id: string; principalsModulePatch: PrincipalsModulePatch; } >; export function useUpdatePrincipalsModuleMutation( params: { selection: SelectionConfig; } & Omit< UseMutationOptions< any, Error, { id: string; principalsModulePatch: PrincipalsModulePatch; } >, 'mutationFn' > ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: principalsModuleMutationKeys.all, mutationFn: ({ id, principalsModulePatch, }: { id: string; principalsModulePatch: PrincipalsModulePatch; }) => getClient() .principalsModule.update({ where: { id, }, data: principalsModulePatch, select: args.select, }) .unwrap(), onSuccess: (_, variables) => { queryClient.invalidateQueries({ queryKey: principalsModuleKeys.detail(variables.id), }); queryClient.invalidateQueries({ queryKey: principalsModuleKeys.lists(), }); }, ...mutationOptions, }); }