/** * 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 { useQuery } from '@tanstack/react-query'; import type { UseQueryOptions, UseQueryResult, QueryClient } from '@tanstack/react-query'; import { getClient } from '../client'; import { buildSelectionArgs } from '../selection'; import type { SelectionConfig } from '../selection'; import { principalsModuleKeys } from '../query-keys'; import type { PrincipalsModuleSelect, PrincipalsModuleWithRelations } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { PrincipalsModuleSelect, PrincipalsModuleWithRelations } from '../../orm/input-types'; /** Query key factory - re-exported from query-keys.ts */ export const principalsModuleQueryKey = principalsModuleKeys.detail; /** * 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 { data, isLoading } = usePrincipalsModuleQuery({ * id: 'some-id', * selection: { fields: { id: true, name: true } }, * }); * ``` */ export function usePrincipalsModuleQuery< S extends PrincipalsModuleSelect, TData = { principalsModule: InferSelectResult | null; }, >( params: { id: string; selection: { fields: S; } & HookStrictSelect, PrincipalsModuleSelect>; } & Omit< UseQueryOptions< { principalsModule: InferSelectResult | null; }, Error, TData >, 'queryKey' | 'queryFn' > ): UseQueryResult; export function usePrincipalsModuleQuery( params: { id: string; selection: SelectionConfig; } & Omit, 'queryKey' | 'queryFn'> ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...queryOptions } = params ?? {}; void _selection; return useQuery({ queryKey: principalsModuleKeys.detail(params.id), queryFn: () => getClient() .principalsModule.findOne({ id: params.id, select: args.select, }) .unwrap(), ...queryOptions, }); } /** * 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 * ```ts * const data = await fetchPrincipalsModuleQuery({ * id: 'some-id', * selection: { fields: { id: true } }, * }); * ``` */ export async function fetchPrincipalsModuleQuery(params: { id: string; selection: { fields: S; } & HookStrictSelect, PrincipalsModuleSelect>; }): Promise<{ principalsModule: InferSelectResult | null; }>; export async function fetchPrincipalsModuleQuery(params: { id: string; selection: SelectionConfig; }): Promise { const args = buildSelectionArgs(params.selection); return getClient() .principalsModule.findOne({ id: params.id, select: args.select, }) .unwrap(); } /** * 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 * ```ts * await prefetchPrincipalsModuleQuery(queryClient, { id: 'some-id', selection: { fields: { id: true } } }); * ``` */ export async function prefetchPrincipalsModuleQuery( queryClient: QueryClient, params: { id: string; selection: { fields: S; } & HookStrictSelect, PrincipalsModuleSelect>; } ): Promise; export async function prefetchPrincipalsModuleQuery( queryClient: QueryClient, params: { id: string; selection: SelectionConfig; } ): Promise { const args = buildSelectionArgs(params.selection); await queryClient.prefetchQuery({ queryKey: principalsModuleKeys.detail(params.id), queryFn: () => getClient() .principalsModule.findOne({ id: params.id, select: args.select, }) .unwrap(), }); }