diff --git a/package.json b/package.json index 79c463d..9575f00 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ }, "dependencies": { "h3": "^1.0.1", - "nanoid": "^4.0.0", "ohash": "^1.0.0", "ufo": "^1.0.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d20d934..c1893f6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,14 +11,12 @@ importers: concurrently: ^7.5.0 eslint: ^8.25.0 h3: ^1.0.1 - nanoid: ^4.0.0 ohash: ^1.0.0 tsup: 6.4.0 typescript: ^4.7.4 ufo: ^1.0.0 dependencies: h3: 1.0.1 - nanoid: 4.0.0 ohash: 1.0.0 ufo: 1.0.0 devDependencies: diff --git a/src/client/index.ts b/src/client/index.ts index 1717aba..e29968e 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -2,7 +2,6 @@ import { type CreateTRPCClientOptions, type inferRouterProxyClient, createTRPCPr import { type AnyRouter } from '@trpc/server' import { createFlatProxy, createRecursiveProxy } from '@trpc/server/shared' import { hash } from 'ohash' -import { nanoid } from 'nanoid' import { type DecoratedProcedureRecord } from './types' // @ts-expect-error: Nuxt auto-imports import { getCurrentInstance, onScopeDispose, useAsyncData, ref, unref } from '#imports' @@ -31,20 +30,20 @@ export function createNuxtProxyDecoration (name: stri const [input, otherOptions] = args - const { trpc, ...asyncDataOptions } = otherOptions || {} as any - - let controller: AbortController - - if (trpc?.abortOnUnmount) { - if (getCurrentInstance()) { - onScopeDispose(() => { - controller?.abort?.() - }) - } - controller = typeof AbortController !== 'undefined' ? new AbortController() : {} as AbortController - } - if (lastArg === 'useQuery') { + const { trpc, ...asyncDataOptions } = otherOptions || {} as any + + let controller: AbortController + + if (trpc?.abortOnUnmount) { + if (getCurrentInstance()) { + onScopeDispose(() => { + controller?.abort?.() + }) + } + controller = typeof AbortController !== 'undefined' ? new AbortController() : {} as AbortController + } + const queryKey = getQueryKey(path, input) return useAsyncData(queryKey, () => (client as any)[path].query(input, { signal: controller?.signal, @@ -52,28 +51,6 @@ export function createNuxtProxyDecoration (name: stri }), asyncDataOptions) } - if (lastArg === 'useMutation') { - const reactiveInput = ref(null) - const { refresh, ...result } = useAsyncData(nanoid(), () => (client as any)[path].mutate(reactiveInput.value, { - signal: controller?.signal, - ...trpc - }), { - ...asyncDataOptions, - immediate: false - }) - - async function mutate (_input: any) { - reactiveInput.value = _input - await refresh() - return unref(result.data) - } - - return { - mutate, - ...result - } - } - return (client as any)[path][lastArg](input) }) } diff --git a/src/client/types.ts b/src/client/types.ts index 8002404..25ac136 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -13,7 +13,6 @@ import type { } from '@trpc/server' import { type inferObservableValue, type Unsubscribable } from '@trpc/server/observable' import { inferTransformedProcedureOutput } from '@trpc/server/shared' -// import { inferTransformedProcedureOutput } from '@trpc/server/shared' import type { AsyncData, AsyncDataOptions, @@ -22,10 +21,6 @@ import type { _Transform } from 'nuxt/dist/app/composables/asyncData' -// Modified @trpc/client and @trpc/react-query types -// https://github.com/trpc/trpc/blob/next/packages/client/src/createTRPCClientProxy.ts -// https://github.com/trpc/trpc/blob/next/packages/react-query/src/createTRPCReact.tsx - interface TRPCRequestOptions extends _TRPCRequestOptions { abortOnUnmount?: boolean } @@ -65,15 +60,6 @@ type DecorateProcedure< ) => AsyncData, PickKeys>, TRPCClientErrorLike>, query: Resolver } : TProcedure extends AnyMutationProcedure ? { - useMutation: < - TData = inferTransformedProcedureOutput, - Transform extends _Transform = _Transform, - PickKeys extends KeyOfRes = KeyOfRes, - >( - opts?: AsyncDataOptions & { trpc?: TRPCRequestOptions }, - ) => AsyncData, PickKeys>, TRPCClientErrorLike> & { - mutate: (input: inferProcedureInput) => Promise, PickKeys>> - }, mutate: Resolver } : TProcedure extends AnySubscriptionProcedure ? { subscribe: SubscriptionResolver