@orpc/client 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,28 +1,27 @@
1
1
  // src/procedure.ts
2
- import {
3
- ORPC_HEADER,
4
- ORPC_HEADER_VALUE
5
- } from "@orpc/contract";
2
+ import { ORPC_HEADER, ORPC_HEADER_VALUE } from "@orpc/contract";
6
3
  import { trim } from "@orpc/shared";
7
4
  import { ORPCError } from "@orpc/shared/error";
8
5
  import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer";
6
+ var serializer = new ORPCSerializer();
7
+ var deserializer = new ORPCDeserializer();
9
8
  function createProcedureClient(options) {
10
- const serializer = new ORPCSerializer();
11
- const deserializer = new ORPCDeserializer();
12
- const client = async (input) => {
9
+ const client = async (...args) => {
10
+ const [input, callerOptions] = args;
13
11
  const fetch_ = options.fetch ?? fetch;
14
12
  const url = `${trim(options.baseURL, "/")}/${options.path.map(encodeURIComponent).join("/")}`;
15
13
  let headers = await options.headers?.(input);
16
14
  headers = headers instanceof Headers ? headers : new Headers(headers);
17
15
  const { body, headers: headers_ } = serializer.serialize(input);
18
16
  for (const [key, value] of headers_.entries()) {
19
- headers.set(key, value);
17
+ headers.append(key, value);
20
18
  }
21
19
  headers.set(ORPC_HEADER, ORPC_HEADER_VALUE);
22
20
  const response = await fetch_(url, {
23
21
  method: "POST",
24
22
  headers,
25
- body
23
+ body,
24
+ signal: callerOptions?.signal
26
25
  });
27
26
  const json = await (async () => {
28
27
  try {
@@ -1,8 +1,5 @@
1
+ import type { Caller } from '@orpc/server';
1
2
  import type { Promisable } from '@orpc/shared';
2
- import { type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
3
- export interface ProcedureClient<TInputSchema extends Schema, TOutputSchema extends Schema, TFuncOutput extends SchemaOutput<TOutputSchema>> {
4
- (input: SchemaInput<TInputSchema>): Promise<SchemaOutput<TOutputSchema, TFuncOutput>>;
5
- }
6
3
  export interface CreateProcedureClientOptions {
7
4
  /**
8
5
  * The base url of the server.
@@ -23,5 +20,5 @@ export interface CreateProcedureClientOptions {
23
20
  */
24
21
  path: string[];
25
22
  }
26
- export declare function createProcedureClient<TInputSchema extends Schema, TOutputSchema extends Schema, TFuncOutput extends SchemaOutput<TOutputSchema>>(options: CreateProcedureClientOptions): ProcedureClient<TInputSchema, TOutputSchema, TFuncOutput>;
23
+ export declare function createProcedureClient<TInput, TOutput>(options: CreateProcedureClientOptions): Caller<TInput, TOutput>;
27
24
  //# sourceMappingURL=procedure.d.ts.map
@@ -1,34 +1,9 @@
1
- import type { ContractProcedure, ContractRouter, SchemaOutput } from '@orpc/contract';
2
- import type { Lazy, Procedure, Router } from '@orpc/server';
3
- import type { Promisable } from '@orpc/shared';
4
- import { type ProcedureClient } from './procedure';
5
- export type RouterClientWithContractRouter<TRouter extends ContractRouter> = {
6
- [K in keyof TRouter]: TRouter[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? ProcedureClient<UInputSchema, UOutputSchema, SchemaOutput<UOutputSchema>> : TRouter[K] extends ContractRouter ? RouterClientWithContractRouter<TRouter[K]> : never;
1
+ import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
2
+ import type { Caller, Lazy, Procedure, Router } from '@orpc/server';
3
+ import type { SetOptional } from '@orpc/shared';
4
+ import type { CreateProcedureClientOptions } from './procedure';
5
+ export type RouterClient<T extends Router<any> | ContractRouter> = {
6
+ [K in keyof T]: T[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> | Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> | Lazy<Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput>> ? Caller<SchemaInput<UInputSchema>, SchemaOutput<UOutputSchema, UFuncOutput>> : T[K] extends Router<any> | ContractRouter ? RouterClient<T[K]> : never;
7
7
  };
8
- export type RouterClientWithRouter<TRouter extends Router<any>> = {
9
- [K in keyof TRouter]: TRouter[K] extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> | Lazy<Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput>> ? ProcedureClient<UInputSchema, UOutputSchema, UFuncOutput> : TRouter[K] extends Router<any> ? RouterClientWithRouter<TRouter[K]> : never;
10
- };
11
- export interface CreateRouterClientOptions {
12
- /**
13
- * The base url of the server.
14
- */
15
- baseURL: string;
16
- /**
17
- * The fetch function used to make the request.
18
- * @default global fetch
19
- */
20
- fetch?: typeof fetch;
21
- /**
22
- * The headers used to make the request.
23
- * Invoked before the request is made.
24
- */
25
- headers?: (input: unknown) => Promisable<Headers | Record<string, string>>;
26
- /**
27
- * This used for internal purpose only.
28
- *
29
- * @internal
30
- */
31
- path?: string[];
32
- }
33
- export declare function createRouterClient<TRouter extends Router<any> | ContractRouter>(options: CreateRouterClientOptions): TRouter extends Router<any> ? RouterClientWithRouter<TRouter> : TRouter extends ContractRouter ? RouterClientWithContractRouter<TRouter> : never;
8
+ export declare function createRouterClient<T extends Router<any> | ContractRouter>(options: SetOptional<CreateProcedureClientOptions, 'path'>): RouterClient<T>;
34
9
  //# sourceMappingURL=router.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/client",
3
3
  "type": "module",
4
- "version": "0.14.0",
4
+ "version": "0.16.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -29,16 +29,16 @@
29
29
  "dist"
30
30
  ],
31
31
  "peerDependencies": {
32
- "@orpc/contract": "0.14.0",
33
- "@orpc/server": "0.14.0"
32
+ "@orpc/contract": "0.16.0",
33
+ "@orpc/server": "0.16.0"
34
34
  },
35
35
  "dependencies": {
36
- "@orpc/shared": "0.14.0",
37
- "@orpc/transformer": "0.14.0"
36
+ "@orpc/transformer": "0.16.0",
37
+ "@orpc/shared": "0.16.0"
38
38
  },
39
39
  "devDependencies": {
40
- "zod": "^3.23.8",
41
- "@orpc/openapi": "0.14.0"
40
+ "zod": "^3.24.1",
41
+ "@orpc/openapi": "0.16.0"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",