-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client)!: make
@orpc/client
independent (#151)
* init * error * client * remove @orpc/contract from query * serializer * fix recursive dependencies problem * client * sync pnpm-lock * fix tsconfig.json
- Loading branch information
Showing
138 changed files
with
743 additions
and
841 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './orpc-link' | ||
export * from './rpc-link' | ||
export * from './types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
...es/client/src/adapters/fetch/orpc-link.ts → ...ges/client/src/adapters/fetch/rpc-link.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,24 @@ | ||
import type { Client, ClientContext } from '@orpc/contract' | ||
import { oc } from '@orpc/contract' | ||
import { implement, os } from '@orpc/server' | ||
import { z } from 'zod' | ||
import type { ContractRouterClient } from '@orpc/contract' | ||
import type { RouterClient } from '@orpc/server' | ||
import type { router as contract } from '../../contract/tests/shared' | ||
import type { router } from '../../server/tests/shared' | ||
import type { ClientLink } from './types' | ||
import { createORPCClient } from './client' | ||
|
||
describe('createORPCClient', () => { | ||
const pingContract = oc | ||
.input(z.object({ in: z.string() }).transform(i => i.in)) | ||
.output(z.string().transform(out => ({ out }))) | ||
|
||
const pongContract = oc.input(z.number()) | ||
const contractRouter = oc.router({ | ||
ping: pingContract, | ||
nested: { | ||
pong: pongContract, | ||
}, | ||
}) | ||
|
||
const ping = implement(pingContract).handler(name => `ping ${name}`) | ||
const pong = implement(pongContract).handler(num => `pong ${num}`) | ||
|
||
const router = implement(contractRouter).router({ | ||
ping, | ||
nested: os.lazy(() => Promise.resolve({ default: { | ||
pong: os.lazy(() => Promise.resolve({ default: pong })), | ||
} })), | ||
}) | ||
|
||
it('build correct types with contract router', () => { | ||
const client = createORPCClient<typeof contractRouter>({} as any) | ||
|
||
expectTypeOf(client.ping).toEqualTypeOf<Client<ClientContext, { in: string }, { out: string }, Error>>() | ||
expectTypeOf(client.nested.pong).toEqualTypeOf<Client<ClientContext, number, unknown, Error>>() | ||
}) | ||
|
||
it('build correct types with router', () => { | ||
const client = createORPCClient<typeof router>({} as any) | ||
|
||
expectTypeOf(client.ping).toEqualTypeOf<Client<ClientContext, { in: string }, { out: string }, Error>>() | ||
expectTypeOf(client.nested.pong).toEqualTypeOf<Client<ClientContext, number, string, Error>>() | ||
}) | ||
|
||
it('pass correct context', () => { | ||
type Context = { a: number } | ||
const client = createORPCClient<typeof router, Context>({} as any) | ||
|
||
expectTypeOf(client.ping).toEqualTypeOf<Client<{ a: number }, { in: string }, { out: string }, Error>>() | ||
expectTypeOf(client.nested.pong).toEqualTypeOf < Client < { a: number }, number, string, Error>>() | ||
}) | ||
it('createORPCClient require match context between client and link', () => { | ||
const _1: RouterClient<typeof router, { cache: string }> = createORPCClient({} as ClientLink<{ cache: string }>) | ||
const _11: RouterClient<typeof router, { cache?: string }> = createORPCClient({} as ClientLink<{ cache?: string }>) | ||
const _111: RouterClient<typeof router, { cache?: string }> = createORPCClient({} as ClientLink<{ cache?: string, tags?: string[] }>) | ||
const _1111: RouterClient<typeof router> = createORPCClient({} as ClientLink<{ cache?: string }>) | ||
// @ts-expect-error -- cache is required | ||
const _11111: RouterClient<typeof router> = createORPCClient({} as ClientLink<{ cache: string }>) | ||
// @ts-expect-error -- expect cache is optional | ||
const _2: RouterClient<typeof router, { cache?: string }> = createORPCClient({} as ClientLink<{ cache: string }>) | ||
// @ts-expect-error -- expect cache is number | ||
const _3: RouterClient<typeof router, { cache?: number }> = createORPCClient({} as ClientLink<{ cache?: string }>) | ||
|
||
const _4: ContractRouterClient<typeof contract> = createORPCClient({} as ClientLink<{ cache?: string }>) | ||
// @ts-expect-error -- cache is required | ||
const _44: ContractRouterClient<typeof contract> = createORPCClient({} as ClientLink<{ cache: string }>) | ||
const _444: ContractRouterClient<typeof contract, { cache: string }> = createORPCClient({} as ClientLink<{ cache: string }>) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.