Skip to content

Commit

Permalink
rename createClient -> createORPCClient
Browse files Browse the repository at this point in the history
  • Loading branch information
unnoq committed Dec 29, 2024
1 parent 166482f commit a49a3a8
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 33 deletions.
10 changes: 5 additions & 5 deletions packages/client/src/client.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type { ProcedureClient } from '@orpc/server'
import { oc } from '@orpc/contract'
import { os } from '@orpc/server'
import { z } from 'zod'
import { createClient } from './client'
import { createORPCClient } from './client'

describe('createClient', () => {
describe('createORPCClient', () => {
const pingContract = oc
.input(z.object({ in: z.string() }).transform(i => i.in))
.output(z.string().transform(out => ({ out })))
Expand All @@ -28,22 +28,22 @@ describe('createClient', () => {
})

it('build correct types with contract router', () => {
const client = createClient<typeof contractRouter>({} as any)
const client = createORPCClient<typeof contractRouter>({} as any)

expectTypeOf(client.ping).toMatchTypeOf<ProcedureClient<{ in: string }, { out: string }, unknown>>()
expectTypeOf(client.nested.pong).toMatchTypeOf<ProcedureClient<number, unknown, unknown>>()
})

it('build correct types with router', () => {
const client = createClient<typeof router>({} as any)
const client = createORPCClient<typeof router>({} as any)

expectTypeOf(client.ping).toMatchTypeOf<ProcedureClient<{ in: string }, { out: string }, unknown>>()
expectTypeOf(client.nested.pong).toMatchTypeOf<ProcedureClient<number, string, unknown>>()
})

it('pass correct context', () => {
type Context = { a: number }
const client = createClient<typeof router, Context>({} as any)
const client = createORPCClient<typeof router, Context>({} as any)

expectTypeOf(client.ping).toEqualTypeOf<ProcedureClient<{ in: string }, { out: string }, { a: number }>>()
expectTypeOf(client.nested.pong).toEqualTypeOf<ProcedureClient<number, string, { a: number }>>()
Expand Down
12 changes: 6 additions & 6 deletions packages/client/src/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { ClientLink } from './types'
import { createClient } from './client'
import { createORPCClient } from './client'

beforeEach(() => {
vi.clearAllMocks()
})

describe('createClient', () => {
describe('createORPCClient', () => {
const mockedLink: ClientLink<unknown> = {
call: vi.fn().mockReturnValue('__mocked__'),
}

it('works', async () => {
const client = createClient(mockedLink) as any
const client = createORPCClient(mockedLink) as any

expect(await client.ping({ value: 'hello' })).toEqual('__mocked__')
expect(mockedLink.call).toBeCalledTimes(1)
Expand All @@ -26,23 +26,23 @@ describe('createClient', () => {
it('works with signal', async () => {
const controller = new AbortController()
const signal = controller.signal
const client = createClient(mockedLink) as any
const client = createORPCClient(mockedLink) as any

expect(await client.ping({ value: 'hello' }, { signal })).toEqual('__mocked__')
expect(mockedLink.call).toBeCalledTimes(1)
expect(mockedLink.call).toBeCalledWith(['ping'], { value: 'hello' }, { signal })
})

it('works with context', async () => {
const client = createClient(mockedLink) as any
const client = createORPCClient(mockedLink) as any

expect(await client.ping({ value: 'hello' }, { context: { userId: '123' } })).toEqual('__mocked__')
expect(mockedLink.call).toBeCalledTimes(1)
expect(mockedLink.call).toBeCalledWith(['ping'], { value: 'hello' }, { context: { userId: '123' } })
})

it('not recursive on symbol', async () => {
const client = createClient(mockedLink) as any
const client = createORPCClient(mockedLink) as any
expect(client[Symbol('test')]).toBeUndefined()
})
})
8 changes: 4 additions & 4 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import type { ContractRouter } from '@orpc/contract'
import type { ANY_ROUTER, ProcedureClient, RouterClient } from '@orpc/server'
import type { ClientLink } from './types'

export interface CreateClientOptions {
export interface createORPCClientOptions {
/**
* Use as base path for all procedure, useful when you only want to call a subset of the procedure.
*/
path?: string[]
}

export function createClient<TRouter extends ANY_ROUTER | ContractRouter, TClientContext = unknown>(
export function createORPCClient<TRouter extends ANY_ROUTER | ContractRouter, TClientContext = unknown>(
link: ClientLink<TClientContext>,
options?: CreateClientOptions,
options?: createORPCClientOptions,
): RouterClient<TRouter, TClientContext> {
const path = options?.path ?? []

Expand All @@ -25,7 +25,7 @@ export function createClient<TRouter extends ANY_ROUTER | ContractRouter, TClien
return Reflect.get(target, key)
}

return createClient(link, {
return createORPCClient(link, {
...options,
path: [...path, key],
})
Expand Down
4 changes: 2 additions & 2 deletions packages/client/tests/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { os } from '@orpc/server'
import { ORPCHandler } from '@orpc/server/fetch'
import { z } from 'zod'
import { createClient } from '../src'
import { createORPCClient } from '../src'
import { ORPCLink } from '../src/adapters/fetch'

export const orpcServer = os
Expand Down Expand Up @@ -110,4 +110,4 @@ const orpcLink = new ORPCLink({
},
})

export const client = createClient<typeof appRouter>(orpcLink)
export const client = createORPCClient<typeof appRouter>(orpcLink)
4 changes: 2 additions & 2 deletions packages/react-query/tests/helpers.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createClient } from '@orpc/client'
import { createORPCClient } from '@orpc/client'
import { ORPCLink } from '@orpc/client/fetch'
import { os } from '@orpc/server'
import { ORPCHandler } from '@orpc/server/fetch'
Expand Down Expand Up @@ -105,7 +105,7 @@ const orpcLink = new ORPCLink({
},
})

export const orpcClient = createClient<typeof appRouter, { batch?: boolean } | undefined>(orpcLink)
export const orpcClient = createORPCClient<typeof appRouter, { batch?: boolean } | undefined>(orpcLink)

export const orpc = createORPCReactQueryUtils(orpcClient)

Expand Down
4 changes: 2 additions & 2 deletions packages/react/tests/orpc.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RouterClient } from '@orpc/server'
import { createClient } from '@orpc/client'
import { createORPCClient } from '@orpc/client'
import { ORPCLink } from '@orpc/client/fetch'
import { os } from '@orpc/server'
import { ORPCHandler } from '@orpc/server/fetch'
Expand Down Expand Up @@ -106,7 +106,7 @@ const orpcLink = new ORPCLink({
},
})

export const orpcClient = createClient<typeof appRouter>(orpcLink)
export const orpcClient = createORPCClient<typeof appRouter>(orpcLink)

export const { orpc, ORPCContext } = createORPCReact<RouterClient<typeof appRouter, unknown>>()

Expand Down
4 changes: 2 additions & 2 deletions packages/vue-query/tests/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createClient } from '@orpc/client'
import { createORPCClient } from '@orpc/client'
import { ORPCLink } from '@orpc/client/fetch'
import { os } from '@orpc/server'
import { ORPCHandler } from '@orpc/server/fetch'
Expand Down Expand Up @@ -98,7 +98,7 @@ const orpcLink = new ORPCLink({
},
})

export const orpcClient = createClient<typeof appRouter, { batch?: boolean } | undefined>(orpcLink)
export const orpcClient = createORPCClient<typeof appRouter, { batch?: boolean } | undefined>(orpcLink)

export const orpc = createORPCVueQueryUtils(orpcClient)

Expand Down
4 changes: 2 additions & 2 deletions playgrounds/contract-openapi/src/playground-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
*/

import type { contract } from './contract'
import { createClient } from '@orpc/client'
import { createORPCClient } from '@orpc/client'
import { ORPCLink } from '@orpc/client/fetch'

const orpcLink = new ORPCLink({
url: 'http://localhost:3000/api',
})

const orpc = createClient<typeof contract>(orpcLink)
const orpc = createORPCClient<typeof contract>(orpcLink)

const planets = await orpc.planet.list({})

Expand Down
4 changes: 2 additions & 2 deletions playgrounds/expressjs/src/playground-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
*/

import type { router } from './router'
import { createClient } from '@orpc/client'
import { createORPCClient } from '@orpc/client'
import { ORPCLink } from '@orpc/client/fetch'

const orpcLink = new ORPCLink({
url: 'http://localhost:3000/api',
})

const orpc = createClient<typeof router>(orpcLink)
const orpc = createORPCClient<typeof router>(orpcLink)

const planets = await orpc.planet.list({})

Expand Down
4 changes: 2 additions & 2 deletions playgrounds/nextjs/src/lib/orpc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { router } from '@/app/api/[...rest]/router'
import { createClient } from '@orpc/client'
import { createORPCClient } from '@orpc/client'
import { ORPCLink } from '@orpc/client/fetch'
import { createORPCReact } from '@orpc/react'

Expand All @@ -10,6 +10,6 @@ const orpcLink = new ORPCLink({
}),
})

export const orpcClient = createClient<typeof router>(orpcLink)
export const orpcClient = createORPCClient<typeof router>(orpcLink)

export const { orpc, ORPCContext } = createORPCReact<typeof orpcClient>()
4 changes: 2 additions & 2 deletions playgrounds/nuxt/lib/orpc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { router } from '~/server/router'
import { createClient } from '@orpc/client'
import { createORPCClient } from '@orpc/client'
import { ORPCLink } from '@orpc/client/fetch'
import { createORPCVueQueryUtils } from '@orpc/vue-query'

Expand All @@ -10,6 +10,6 @@ const orpcLink = new ORPCLink({
}),
})

export const client = createClient<typeof router>(orpcLink)
export const client = createORPCClient<typeof router>(orpcLink)

export const orpc = createORPCVueQueryUtils(client)
4 changes: 2 additions & 2 deletions playgrounds/openapi/src/playground-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
*/

import type { router } from './router'
import { createClient } from '@orpc/client'
import { createORPCClient } from '@orpc/client'
import { ORPCLink } from '@orpc/client/fetch'

const orpcLink = new ORPCLink({
url: 'http://localhost:3000/api',
})

const orpc = createClient<typeof router>(orpcLink)
const orpc = createORPCClient<typeof router>(orpcLink)

const planets = await orpc.planet.list({})

Expand Down

0 comments on commit a49a3a8

Please sign in to comment.