@orpc/client 0.0.0-next.1d55ec0 → 0.0.0-next.3f3f19b

Sign up to get free protection for your applications and to get access to all the features.
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 {
@@ -80,3 +79,4 @@ export {
80
79
  createProcedureClient,
81
80
  createRouterClient
82
81
  };
82
+ //# sourceMappingURL=index.js.map
@@ -4,3 +4,4 @@ export * from './procedure';
4
4
  export * from './router';
5
5
  export * from '@orpc/shared/error';
6
6
  export declare const createORPCClient: typeof createRouterClient;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -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,4 +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>;
24
+ //# sourceMappingURL=procedure.d.ts.map
@@ -1,33 +1,9 @@
1
- import type { ContractProcedure, ContractRouter, SchemaOutput } from '@orpc/contract';
2
- import type { 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> ? 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>;
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.0.0-next.1d55ec0",
4
+ "version": "0.0.0-next.3f3f19b",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -24,22 +24,24 @@
24
24
  }
25
25
  },
26
26
  "files": [
27
- "!dist/*.tsbuildinfo",
27
+ "!**/*.map",
28
+ "!**/*.tsbuildinfo",
28
29
  "dist"
29
30
  ],
30
31
  "peerDependencies": {
31
- "@orpc/contract": "0.0.0-next.1d55ec0",
32
- "@orpc/server": "0.0.0-next.1d55ec0"
32
+ "@orpc/contract": "0.0.0-next.3f3f19b",
33
+ "@orpc/server": "0.0.0-next.3f3f19b"
33
34
  },
34
35
  "dependencies": {
35
- "@orpc/shared": "0.0.0-next.1d55ec0",
36
- "@orpc/transformer": "0.0.0-next.1d55ec0"
36
+ "@orpc/shared": "0.0.0-next.3f3f19b",
37
+ "@orpc/transformer": "0.0.0-next.3f3f19b"
37
38
  },
38
39
  "devDependencies": {
39
- "zod": "^3.23.8"
40
+ "zod": "^3.24.1",
41
+ "@orpc/openapi": "0.0.0-next.3f3f19b"
40
42
  },
41
43
  "scripts": {
42
- "build": "tsup --clean --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
44
+ "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
43
45
  "build:watch": "pnpm run build --watch",
44
46
  "type:check": "tsc -b"
45
47
  }