@orpc/client 0.0.0-next.b6be6f0 → 0.0.0-next.c099c92

Sign up to get free protection for your applications and to get access to all the features.
package/dist/fetch.js CHANGED
@@ -1,8 +1,8 @@
1
1
  // src/adapters/fetch/orpc-link.ts
2
+ import { ORPCError } from "@orpc/contract";
2
3
  import { ORPCPayloadCodec } from "@orpc/server/fetch";
3
4
  import { ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE, trim } from "@orpc/shared";
4
- import { ORPCError } from "@orpc/shared/error";
5
- var ORPCLink = class {
5
+ var RPCLink = class {
6
6
  fetch;
7
7
  payloadCodec;
8
8
  maxURLLength;
@@ -34,13 +34,14 @@ var ORPCLink = class {
34
34
  }, clientContext);
35
35
  const decoded = await this.payloadCodec.decode(response);
36
36
  if (!response.ok) {
37
- const error = ORPCError.fromJSON(decoded) ?? new ORPCError({
37
+ if (ORPCError.isValidJSON(decoded)) {
38
+ throw ORPCError.fromJSON(decoded);
39
+ }
40
+ throw new ORPCError("INTERNAL_SERVER_ERROR", {
38
41
  status: response.status,
39
- code: "INTERNAL_SERVER_ERROR",
40
42
  message: "Internal server error",
41
43
  cause: decoded
42
44
  });
43
- throw error;
44
45
  }
45
46
  return decoded;
46
47
  }
@@ -75,13 +76,12 @@ var ORPCLink = class {
75
76
  body: encoded.body
76
77
  };
77
78
  }
78
- throw new ORPCError({
79
- code: "BAD_REQUEST",
79
+ throw new ORPCError("BAD_REQUEST", {
80
80
  message: "Cannot encode the request, please check the url length or payload."
81
81
  });
82
82
  }
83
83
  };
84
84
  export {
85
- ORPCLink
85
+ RPCLink
86
86
  };
87
87
  //# sourceMappingURL=fetch.js.map
package/dist/index.js CHANGED
@@ -31,9 +31,12 @@ var DynamicLink = class {
31
31
  };
32
32
 
33
33
  // src/index.ts
34
- export * from "@orpc/shared/error";
34
+ import { isDefinedError, ORPCError, safe } from "@orpc/contract";
35
35
  export {
36
36
  DynamicLink,
37
- createORPCClient
37
+ ORPCError,
38
+ createORPCClient,
39
+ isDefinedError,
40
+ safe
38
41
  };
39
42
  //# sourceMappingURL=index.js.map
@@ -1,10 +1,9 @@
1
- import type { HTTPMethod } from '@orpc/contract';
2
- import type { ProcedureClientOptions } from '@orpc/server';
1
+ import type { ClientOptions, HTTPMethod } from '@orpc/contract';
3
2
  import type { Promisable } from '@orpc/shared';
4
3
  import type { ClientLink } from '../../types';
5
4
  import type { FetchWithContext } from './types';
6
5
  import { type PublicORPCPayloadCodec } from '@orpc/server/fetch';
7
- export interface ORPCLinkOptions<TClientContext> {
6
+ export interface RPCLinkOptions<TClientContext> {
8
7
  /**
9
8
  * Base url for all requests.
10
9
  */
@@ -20,7 +19,7 @@ export interface ORPCLinkOptions<TClientContext> {
20
19
  *
21
20
  * @default 'POST'
22
21
  */
23
- method?: (path: readonly string[], input: unknown, context: TClientContext) => Promisable<HTTPMethod | undefined>;
22
+ method?(path: readonly string[], input: unknown, context: TClientContext): Promisable<HTTPMethod | undefined>;
24
23
  /**
25
24
  * The method to use when the payload cannot safely pass to the server with method return from method function.
26
25
  * Do not use GET as fallback method, it's very dangerous.
@@ -28,11 +27,11 @@ export interface ORPCLinkOptions<TClientContext> {
28
27
  * @default 'POST'
29
28
  */
30
29
  fallbackMethod?: HTTPMethod;
31
- headers?: (path: readonly string[], input: unknown, context: TClientContext) => Promisable<Headers | Record<string, string>>;
30
+ headers?(path: readonly string[], input: unknown, context: TClientContext): Promisable<Headers | Record<string, string>>;
32
31
  fetch?: FetchWithContext<TClientContext>;
33
32
  payloadCodec?: PublicORPCPayloadCodec;
34
33
  }
35
- export declare class ORPCLink<TClientContext> implements ClientLink<TClientContext> {
34
+ export declare class RPCLink<TClientContext> implements ClientLink<TClientContext> {
36
35
  private readonly fetch;
37
36
  private readonly payloadCodec;
38
37
  private readonly maxURLLength;
@@ -40,8 +39,8 @@ export declare class ORPCLink<TClientContext> implements ClientLink<TClientConte
40
39
  private readonly getMethod;
41
40
  private readonly getHeaders;
42
41
  private readonly url;
43
- constructor(options: ORPCLinkOptions<TClientContext>);
44
- call(path: readonly string[], input: unknown, options: ProcedureClientOptions<TClientContext>): Promise<unknown>;
42
+ constructor(options: RPCLinkOptions<TClientContext>);
43
+ call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
45
44
  private encode;
46
45
  }
47
46
  //# sourceMappingURL=orpc-link.d.ts.map
@@ -1,5 +1,5 @@
1
- import type { ContractRouter } from '@orpc/contract';
2
- import type { ANY_ROUTER, RouterClient } from '@orpc/server';
1
+ import type { ContractRouter, ContractRouterClient } from '@orpc/contract';
2
+ import type { AnyRouter, RouterClient } from '@orpc/server';
3
3
  import type { ClientLink } from './types';
4
4
  export interface createORPCClientOptions {
5
5
  /**
@@ -7,5 +7,5 @@ export interface createORPCClientOptions {
7
7
  */
8
8
  path?: string[];
9
9
  }
10
- export declare function createORPCClient<TRouter extends ANY_ROUTER | ContractRouter, TClientContext = unknown>(link: ClientLink<TClientContext>, options?: createORPCClientOptions): RouterClient<TRouter, TClientContext>;
10
+ export declare function createORPCClient<TRouter extends AnyRouter | ContractRouter<any>, TClientContext = unknown>(link: ClientLink<TClientContext>, options?: createORPCClientOptions): TRouter extends ContractRouter<any> ? ContractRouterClient<TRouter, TClientContext> : TRouter extends AnyRouter ? RouterClient<TRouter, TClientContext> : never;
11
11
  //# sourceMappingURL=client.d.ts.map
@@ -1,4 +1,4 @@
1
- import type { ProcedureClientOptions } from '@orpc/server';
1
+ import type { ClientOptions } from '@orpc/contract';
2
2
  import type { Promisable } from '@orpc/shared';
3
3
  import type { ClientLink } from './types';
4
4
  /**
@@ -8,6 +8,6 @@ import type { ClientLink } from './types';
8
8
  export declare class DynamicLink<TClientContext> implements ClientLink<TClientContext> {
9
9
  private readonly linkResolver;
10
10
  constructor(linkResolver: (path: readonly string[], input: unknown, context: TClientContext) => Promisable<ClientLink<TClientContext>>);
11
- call(path: readonly string[], input: unknown, options: ProcedureClientOptions<TClientContext>): Promise<unknown>;
11
+ call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
12
12
  }
13
13
  //# sourceMappingURL=dynamic-link.d.ts.map
@@ -2,5 +2,5 @@
2
2
  export * from './client';
3
3
  export * from './dynamic-link';
4
4
  export * from './types';
5
- export * from '@orpc/shared/error';
5
+ export { isDefinedError, ORPCError, safe } from '@orpc/contract';
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
- import type { ProcedureClientOptions } from '@orpc/server';
1
+ import type { ClientOptions } from '@orpc/contract';
2
2
  export interface ClientLink<TClientContext> {
3
- call: (path: readonly string[], input: unknown, options: ProcedureClientOptions<TClientContext>) => Promise<unknown>;
3
+ call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
4
4
  }
5
5
  //# sourceMappingURL=types.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.b6be6f0",
4
+ "version": "0.0.0-next.c099c92",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -33,16 +33,14 @@
33
33
  "!**/*.tsbuildinfo",
34
34
  "dist"
35
35
  ],
36
- "peerDependencies": {
37
- "@orpc/contract": "0.0.0-next.b6be6f0"
38
- },
39
36
  "dependencies": {
40
- "@orpc/server": "0.0.0-next.b6be6f0",
41
- "@orpc/shared": "0.0.0-next.b6be6f0"
37
+ "@orpc/server": "0.0.0-next.c099c92",
38
+ "@orpc/contract": "0.0.0-next.c099c92",
39
+ "@orpc/shared": "0.0.0-next.c099c92"
42
40
  },
43
41
  "devDependencies": {
44
42
  "zod": "^3.24.1",
45
- "@orpc/openapi": "0.0.0-next.b6be6f0"
43
+ "@orpc/openapi": "0.0.0-next.c099c92"
46
44
  },
47
45
  "scripts": {
48
46
  "build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/adapters/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",