Skip to content

Commit 2a8f4df

Browse files
authored
feat(trpc): support client helpers for Nuxt (#1762)
1 parent 8cbda73 commit 2a8f4df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+15378
-2459
lines changed

packages/plugins/trpc/res/client/v10/next.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { AnyRouter } from '@trpc/server';
44
import type { NextPageContext } from 'next';
55
import { type CreateTRPCNext, createTRPCNext as _createTRPCNext } from '@trpc/next';
66
import type { DeepOverrideAtPath } from './utils';
7-
import type { ClientType } from '../routers';
87

98
export function createTRPCNext<
109
TRouter extends AnyRouter,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* eslint-disable */
2+
3+
import type { AnyRouter } from '@trpc/server';
4+
import { createTRPCNuxtClient as _createTRPCNuxtClient } from 'trpc-nuxt/client';
5+
import type { DeepOverrideAtPath } from './utils';
6+
7+
export function createTRPCNuxtClient<TRouter extends AnyRouter, TPath extends string | undefined = undefined>(
8+
opts: Parameters<typeof _createTRPCNuxtClient<TRouter>>[0]
9+
) {
10+
const r = _createTRPCNuxtClient<TRouter>(opts);
11+
return r as DeepOverrideAtPath<typeof r, ClientType<TRouter>, TPath>;
12+
}

packages/plugins/trpc/res/client/v10/react.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { AnyRouter } from '@trpc/server';
44
import type { CreateTRPCReactOptions } from '@trpc/react-query/shared';
55
import { type CreateTRPCReact, createTRPCReact as _createTRPCReact } from '@trpc/react-query';
66
import type { DeepOverrideAtPath } from './utils';
7-
import type { ClientType } from '../routers';
87

98
export function createTRPCReact<
109
TRouter extends AnyRouter,

packages/plugins/trpc/res/client/v10/utils.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,17 @@ export type DeepOverrideAtPath<T, R, Path extends string | undefined = undefined
3030
: Path extends keyof T
3131
? Omit<T, Path> & Record<Path, DeepOverride<T[Path], R>>
3232
: never;
33+
34+
// Utility type from 'trpc-nuxt'
35+
export type KeysOf<T> = Array<T extends T ? (keyof T extends string ? keyof T : never) : never>;
36+
37+
// Utility type from 'trpc-nuxt'
38+
export type PickFrom<T, K extends Array<string>> = T extends Array<any>
39+
? T
40+
: T extends Record<string, any>
41+
? keyof T extends K[number]
42+
? T
43+
: K[number] extends never
44+
? T
45+
: Pick<T, K[number]>
46+
: T;

packages/plugins/trpc/res/client/v11/next.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { AnyTRPCRouter as AnyRouter } from '@trpc/server';
44
import type { NextPageContext } from 'next';
55
import { type CreateTRPCNext, createTRPCNext as _createTRPCNext } from '@trpc/next';
66
import type { DeepOverrideAtPath } from './utils';
7-
import type { ClientType } from '../routers';
87

98
export function createTRPCNext<
109
TRouter extends AnyRouter,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* eslint-disable */
2+
3+
import type { AnyTRPCRouter as AnyRouter } from '@trpc/server';
4+
import { createTRPCNuxtClient as _createTRPCNuxtClient } from 'trpc-nuxt/client';
5+
import type { DeepOverrideAtPath } from './utils';
6+
7+
export function createTRPCNuxtClient<TRouter extends AnyRouter, TPath extends string | undefined = undefined>(
8+
opts: Parameters<typeof _createTRPCNuxtClient<TRouter>>[0]
9+
) {
10+
const r = _createTRPCNuxtClient<TRouter>(opts);
11+
return r as DeepOverrideAtPath<typeof r, ClientType<TRouter>, TPath>;
12+
}

packages/plugins/trpc/res/client/v11/react.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { AnyTRPCRouter as AnyRouter } from '@trpc/server';
44
import type { CreateTRPCReactOptions } from '@trpc/react-query/shared';
55
import { type CreateTRPCReact, createTRPCReact as _createTRPCReact } from '@trpc/react-query';
66
import type { DeepOverrideAtPath } from './utils';
7-
import type { ClientType } from '../routers';
87

98
export function createTRPCReact<
109
TRouter extends AnyRouter,

packages/plugins/trpc/res/client/v11/utils.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../v10/utils.ts

0 commit comments

Comments
 (0)