/** * 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, CreatePrincipalsModuleInput, } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { PrincipalsModuleSelect, PrincipalsModuleWithRelations, CreatePrincipalsModuleInput, } 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 } = useCreatePrincipalsModuleMutation({ * selection: { fields: { id: true, name: true } }, * }); * * mutate({ name: 'New item' }); * ``` */ export function useCreatePrincipalsModuleMutation( params: { selection: { fields: S & PrincipalsModuleSelect; } & HookStrictSelect, PrincipalsModuleSelect>; } & Omit< UseMutationOptions< { createPrincipalsModule: { principalsModule: InferSelectResult; }; }, Error, CreatePrincipalsModuleInput['principalsModule'] >, 'mutationFn' > ): UseMutationResult< { createPrincipalsModule: { principalsModule: InferSelectResult; }; }, Error, CreatePrincipalsModuleInput['principalsModule'] >; export function useCreatePrincipalsModuleMutation( params: { selection: SelectionConfig; } & Omit< UseMutationOptions, 'mutationFn' > ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: principalsModuleMutationKeys.create(), mutationFn: (data: CreatePrincipalsModuleInput['principalsModule']) => getClient() .principalsModule.create({ data, select: args.select, }) .unwrap(), onSuccess: () => { queryClient.invalidateQueries({ queryKey: principalsModuleKeys.lists(), }); }, ...mutationOptions, }); }