/
githubmirror
/
trpc
Обзор
Документация
Войти
/
githubmirror
/
trpc
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/react-query/src/shared/proxy/decorationProxy.ts
35 строк
1 KB
Julius Marminge
chore: eslint updates (#6748)
05 май 2025, 12:33
Не верифицирован
05 май 2025, 12:33
f35eb5a
Код
Авторство
О чём код?
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import'; import { createRecursiveProxy } from '@trpc/server/unstable-core-do-not-import'; import type { CreateReactQueryHooks } from '../hooks/createHooksInternal'; /** * Create proxy for decorating procedures * @internal */ export function createReactDecoration< TRouter extends AnyRouter, TSSRContext = unknown, >(hooks: CreateReactQueryHooks<TRouter, TSSRContext>) { return createRecursiveProxy(({ path, args }) => { const pathCopy = [...path]; // The last arg is for instance `.useMutation` or `.useQuery()` // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const lastArg = pathCopy.pop()!; if (lastArg === 'useMutation') { return (hooks as any)[lastArg](pathCopy, ...args); } if (lastArg === '_def') { return { path: pathCopy, }; } const [input, ...rest] = args; const opts = rest[0] ?? {}; return (hooks as any)[lastArg](pathCopy, input, opts); }); }