@orpc/client 0.0.0-next.904b0c2 → 0.0.0-next.910f96e

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/README.md CHANGED
@@ -53,6 +53,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
53
53
  - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
54
  - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
55
  - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
56
+ - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
56
57
  - [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
57
58
  - [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
58
59
  - [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
@@ -1,8 +1,8 @@
1
1
  import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
2
2
  import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
3
- import { a as ClientContext, b as ClientOptions } from '../../shared/client.87WXDX8t.mjs';
4
- import { d as StandardLinkClient, b as StandardLink } from '../../shared/client.D9lmRwGB.mjs';
5
- import { f as StandardRPCLinkOptions } from '../../shared/client.BC0T26HA.mjs';
3
+ import { a as ClientContext, b as ClientOptions } from '../../shared/client.C0lT7w02.mjs';
4
+ import { d as StandardLinkClient, b as StandardLink } from '../../shared/client.5813Ufvs.mjs';
5
+ import { f as StandardRPCLinkOptions } from '../../shared/client.Bt94sjrK.mjs';
6
6
  import '@orpc/shared';
7
7
 
8
8
  interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
@@ -1,8 +1,8 @@
1
1
  import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
2
2
  import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
3
- import { a as ClientContext, b as ClientOptions } from '../../shared/client.87WXDX8t.js';
4
- import { d as StandardLinkClient, b as StandardLink } from '../../shared/client.BaocqKnn.js';
5
- import { f as StandardRPCLinkOptions } from '../../shared/client.CZFIVTQj.js';
3
+ import { a as ClientContext, b as ClientOptions } from '../../shared/client.C0lT7w02.js';
4
+ import { d as StandardLinkClient, b as StandardLink } from '../../shared/client.grRbC25r.js';
5
+ import { f as StandardRPCLinkOptions } from '../../shared/client.D-jrSuDb.js';
6
6
  import '@orpc/shared';
7
7
 
8
8
  interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
@@ -1,5 +1,5 @@
1
1
  import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch';
2
- import { S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLinkCodec, d as StandardRPCSerializer } from '../../shared/client.D77bw0hs.mjs';
2
+ import { S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLinkCodec, d as StandardRPCSerializer } from '../../shared/client.DhAxdT4W.mjs';
3
3
  import '@orpc/shared';
4
4
  import '@orpc/standard-server';
5
5
  import '../../shared/client.jKEwIsRd.mjs';
@@ -1,9 +1,10 @@
1
- export { I as InvalidEventIteratorRetryResponse, b as StandardLink, d as StandardLinkClient, c as StandardLinkCodec, a as StandardLinkOptions, S as StandardLinkPlugin } from '../../shared/client.D9lmRwGB.mjs';
2
- export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, h as StandardRPCLinkCodec, g as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, i as StandardRPCSerializer } from '../../shared/client.BC0T26HA.mjs';
3
- import { H as HTTPPath } from '../../shared/client.87WXDX8t.mjs';
1
+ export { I as InvalidEventIteratorRetryResponse, b as StandardLink, d as StandardLinkClient, c as StandardLinkCodec, a as StandardLinkOptions, S as StandardLinkPlugin } from '../../shared/client.5813Ufvs.mjs';
2
+ export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, h as StandardRPCLinkCodec, g as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, i as StandardRPCSerializer } from '../../shared/client.Bt94sjrK.mjs';
3
+ import { H as HTTPPath } from '../../shared/client.C0lT7w02.mjs';
4
4
  import '@orpc/shared';
5
5
  import '@orpc/standard-server';
6
6
 
7
7
  declare function toHttpPath(path: readonly string[]): HTTPPath;
8
+ declare function getMalformedResponseErrorCode(status: number): string;
8
9
 
9
- export { toHttpPath };
10
+ export { getMalformedResponseErrorCode, toHttpPath };
@@ -1,9 +1,10 @@
1
- export { I as InvalidEventIteratorRetryResponse, b as StandardLink, d as StandardLinkClient, c as StandardLinkCodec, a as StandardLinkOptions, S as StandardLinkPlugin } from '../../shared/client.BaocqKnn.js';
2
- export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, h as StandardRPCLinkCodec, g as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, i as StandardRPCSerializer } from '../../shared/client.CZFIVTQj.js';
3
- import { H as HTTPPath } from '../../shared/client.87WXDX8t.js';
1
+ export { I as InvalidEventIteratorRetryResponse, b as StandardLink, d as StandardLinkClient, c as StandardLinkCodec, a as StandardLinkOptions, S as StandardLinkPlugin } from '../../shared/client.grRbC25r.js';
2
+ export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, h as StandardRPCLinkCodec, g as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, i as StandardRPCSerializer } from '../../shared/client.D-jrSuDb.js';
3
+ import { H as HTTPPath } from '../../shared/client.C0lT7w02.js';
4
4
  import '@orpc/shared';
5
5
  import '@orpc/standard-server';
6
6
 
7
7
  declare function toHttpPath(path: readonly string[]): HTTPPath;
8
+ declare function getMalformedResponseErrorCode(status: number): string;
8
9
 
9
- export { toHttpPath };
10
+ export { getMalformedResponseErrorCode, toHttpPath };
@@ -1,4 +1,4 @@
1
- export { I as InvalidEventIteratorRetryResponse, a as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLinkCodec, d as StandardRPCSerializer, t as toHttpPath } from '../../shared/client.D77bw0hs.mjs';
1
+ export { I as InvalidEventIteratorRetryResponse, a as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLinkCodec, d as StandardRPCSerializer, g as getMalformedResponseErrorCode, t as toHttpPath } from '../../shared/client.DhAxdT4W.mjs';
2
2
  import '@orpc/shared';
3
3
  import '@orpc/standard-server';
4
4
  import '../../shared/client.jKEwIsRd.mjs';
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientContext, b as ClientOptions, c as ClientPromiseResult, F as FriendlyClientOptions } from './shared/client.87WXDX8t.mjs';
2
- export { f as Client, e as ClientRest, d as HTTPMethod, H as HTTPPath } from './shared/client.87WXDX8t.mjs';
3
- import { Promisable, MaybeOptionalOptions } from '@orpc/shared';
4
- export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
1
+ import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientContext, b as ClientOptions, c as ClientPromiseResult, F as FriendlyClientOptions } from './shared/client.C0lT7w02.mjs';
2
+ export { f as Client, e as ClientRest, d as HTTPMethod, H as HTTPPath } from './shared/client.C0lT7w02.mjs';
3
+ import { Promisable, MaybeOptionalOptions, ThrowableError } from '@orpc/shared';
4
+ export { Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
5
5
  export { ErrorEvent } from '@orpc/standard-server';
6
6
 
7
7
  interface createORPCClientOptions {
@@ -133,20 +133,23 @@ declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TRetur
133
133
  error: (error: unknown) => Promise<unknown>;
134
134
  }): AsyncGenerator<TMap, TMap, TNext>;
135
135
 
136
- type SafeResult<TOutput, TError extends Error> = [error: null, data: TOutput, isDefined: false] & {
136
+ type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false, success: true] & {
137
137
  error: null;
138
138
  data: TOutput;
139
139
  isDefined: false;
140
- } | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false] & {
140
+ success: true;
141
+ } | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, success: false] & {
141
142
  error: Exclude<TError, ORPCError<any, any>>;
142
143
  data: undefined;
143
144
  isDefined: false;
144
- } | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true] & {
145
+ success: false;
146
+ } | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, success: false] & {
145
147
  error: Extract<TError, ORPCError<any, any>>;
146
148
  data: undefined;
147
149
  isDefined: true;
150
+ success: false;
148
151
  };
149
- declare function safe<TOutput, TError extends Error>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
152
+ declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
150
153
  declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
151
154
 
152
155
  export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, type CommonORPCErrorCode, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, type ORPCErrorCode, type ORPCErrorJSON, type ORPCErrorOptions, type SafeResult, createORPCClient, type createORPCClientOptions, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, isORPCErrorStatus, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientContext, b as ClientOptions, c as ClientPromiseResult, F as FriendlyClientOptions } from './shared/client.87WXDX8t.js';
2
- export { f as Client, e as ClientRest, d as HTTPMethod, H as HTTPPath } from './shared/client.87WXDX8t.js';
3
- import { Promisable, MaybeOptionalOptions } from '@orpc/shared';
4
- export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
1
+ import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientContext, b as ClientOptions, c as ClientPromiseResult, F as FriendlyClientOptions } from './shared/client.C0lT7w02.js';
2
+ export { f as Client, e as ClientRest, d as HTTPMethod, H as HTTPPath } from './shared/client.C0lT7w02.js';
3
+ import { Promisable, MaybeOptionalOptions, ThrowableError } from '@orpc/shared';
4
+ export { Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
5
5
  export { ErrorEvent } from '@orpc/standard-server';
6
6
 
7
7
  interface createORPCClientOptions {
@@ -133,20 +133,23 @@ declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TRetur
133
133
  error: (error: unknown) => Promise<unknown>;
134
134
  }): AsyncGenerator<TMap, TMap, TNext>;
135
135
 
136
- type SafeResult<TOutput, TError extends Error> = [error: null, data: TOutput, isDefined: false] & {
136
+ type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false, success: true] & {
137
137
  error: null;
138
138
  data: TOutput;
139
139
  isDefined: false;
140
- } | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false] & {
140
+ success: true;
141
+ } | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, success: false] & {
141
142
  error: Exclude<TError, ORPCError<any, any>>;
142
143
  data: undefined;
143
144
  isDefined: false;
144
- } | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true] & {
145
+ success: false;
146
+ } | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, success: false] & {
145
147
  error: Extract<TError, ORPCError<any, any>>;
146
148
  data: undefined;
147
149
  isDefined: true;
150
+ success: false;
148
151
  };
149
- declare function safe<TOutput, TError extends Error>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
152
+ declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
150
153
  declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
151
154
 
152
155
  export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, type CommonORPCErrorCode, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, type ORPCErrorCode, type ORPCErrorJSON, type ORPCErrorOptions, type SafeResult, createORPCClient, type createORPCClientOptions, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, isORPCErrorStatus, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
package/dist/index.mjs CHANGED
@@ -7,20 +7,20 @@ async function safe(promise) {
7
7
  try {
8
8
  const output = await promise;
9
9
  return Object.assign(
10
- [null, output, false],
11
- { error: null, data: output, isDefined: false }
10
+ [null, output, false, true],
11
+ { error: null, data: output, isDefined: false, success: true }
12
12
  );
13
13
  } catch (e) {
14
14
  const error = e;
15
15
  if (isDefinedError(error)) {
16
16
  return Object.assign(
17
- [error, void 0, true],
18
- { error, data: void 0, isDefined: true }
17
+ [error, void 0, true, false],
18
+ { error, data: void 0, isDefined: true, success: false }
19
19
  );
20
20
  }
21
21
  return Object.assign(
22
- [error, void 0, false],
23
- { error, data: void 0, isDefined: false }
22
+ [error, void 0, false, false],
23
+ { error, data: void 0, isDefined: false, success: false }
24
24
  );
25
25
  }
26
26
  }
@@ -1,6 +1,6 @@
1
1
  import { Value } from '@orpc/shared';
2
- import { S as StandardLinkPlugin, a as StandardLinkOptions } from '../shared/client.D9lmRwGB.mjs';
3
- import { b as ClientOptions } from '../shared/client.87WXDX8t.mjs';
2
+ import { S as StandardLinkPlugin, a as StandardLinkOptions } from '../shared/client.5813Ufvs.mjs';
3
+ import { b as ClientOptions } from '../shared/client.C0lT7w02.mjs';
4
4
  import '@orpc/standard-server';
5
5
 
6
6
  interface ClientRetryPluginAttemptOptions {
@@ -16,7 +16,11 @@ interface ClientRetryPluginContext {
16
16
  *
17
17
  * @default 0
18
18
  */
19
- retry?: number;
19
+ retry?: Value<number, [
20
+ clientOptions: ClientOptions<ClientRetryPluginContext>,
21
+ path: readonly string[],
22
+ input: unknown
23
+ ]>;
20
24
  /**
21
25
  * Delay (in ms) before retrying.
22
26
  *
@@ -1,6 +1,6 @@
1
1
  import { Value } from '@orpc/shared';
2
- import { S as StandardLinkPlugin, a as StandardLinkOptions } from '../shared/client.BaocqKnn.js';
3
- import { b as ClientOptions } from '../shared/client.87WXDX8t.js';
2
+ import { S as StandardLinkPlugin, a as StandardLinkOptions } from '../shared/client.grRbC25r.js';
3
+ import { b as ClientOptions } from '../shared/client.C0lT7w02.js';
4
4
  import '@orpc/standard-server';
5
5
 
6
6
  interface ClientRetryPluginAttemptOptions {
@@ -16,7 +16,11 @@ interface ClientRetryPluginContext {
16
16
  *
17
17
  * @default 0
18
18
  */
19
- retry?: number;
19
+ retry?: Value<number, [
20
+ clientOptions: ClientOptions<ClientRetryPluginContext>,
21
+ path: readonly string[],
22
+ input: unknown
23
+ ]>;
20
24
  /**
21
25
  * Delay (in ms) before retrying.
22
26
  *
@@ -1,4 +1,4 @@
1
- import { isAsyncIteratorObject, value } from '@orpc/shared';
1
+ import { value, isAsyncIteratorObject } from '@orpc/shared';
2
2
  import { getEventMeta } from '@orpc/standard-server';
3
3
 
4
4
  class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
@@ -17,7 +17,12 @@ class ClientRetryPlugin {
17
17
  init(options) {
18
18
  options.interceptors ??= [];
19
19
  options.interceptors.push(async (interceptorOptions) => {
20
- const maxAttempts = interceptorOptions.options.context.retry ?? this.defaultRetry;
20
+ const maxAttempts = await value(
21
+ interceptorOptions.options.context.retry ?? this.defaultRetry,
22
+ interceptorOptions.options,
23
+ interceptorOptions.path,
24
+ interceptorOptions.input
25
+ );
21
26
  const retryDelay = interceptorOptions.options.context.retryDelay ?? this.defaultRetryDelay;
22
27
  const shouldRetry = interceptorOptions.options.context.shouldRetry ?? this.defaultShouldRetry;
23
28
  const onRetry = interceptorOptions.options.context.onRetry ?? this.defaultOnRetry;
@@ -1,6 +1,6 @@
1
- import { Interceptor } from '@orpc/shared';
1
+ import { Interceptor, ThrowableError } from '@orpc/shared';
2
2
  import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
- import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.87WXDX8t.js';
3
+ import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.C0lT7w02.mjs';
4
4
 
5
5
  interface StandardLinkCodec<T extends ClientContext> {
6
6
  encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
@@ -20,10 +20,10 @@ interface StandardLinkOptions<T extends ClientContext> {
20
20
  path: readonly string[];
21
21
  input: unknown;
22
22
  options: ClientOptions<T>;
23
- }, unknown, unknown>[];
23
+ }, unknown, ThrowableError>[];
24
24
  clientInterceptors?: Interceptor<{
25
25
  request: StandardRequest;
26
- }, StandardLazyResponse, unknown>[];
26
+ }, StandardLazyResponse, ThrowableError>[];
27
27
  plugins?: StandardLinkPlugin<T>[];
28
28
  }
29
29
  declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
@@ -1,5 +1,5 @@
1
- import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.87WXDX8t.mjs';
2
- import { c as StandardLinkCodec, a as StandardLinkOptions } from './client.D9lmRwGB.mjs';
1
+ import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.C0lT7w02.mjs';
2
+ import { c as StandardLinkCodec, a as StandardLinkOptions } from './client.5813Ufvs.mjs';
3
3
  import { Segment, Value } from '@orpc/shared';
4
4
  import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
5
 
@@ -1,6 +1,8 @@
1
+ import { PromiseWithError } from '@orpc/shared';
2
+
1
3
  type HTTPPath = `/${string}`;
2
4
  type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
3
- type ClientContext = Record<string, any>;
5
+ type ClientContext = Record<PropertyKey, any>;
4
6
  type FriendlyClientOptions<TClientContext extends ClientContext> = {
5
7
  signal?: AbortSignal;
6
8
  lastEventId?: string | undefined;
@@ -10,12 +12,8 @@ type FriendlyClientOptions<TClientContext extends ClientContext> = {
10
12
  context: TClientContext;
11
13
  });
12
14
  type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
13
- type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
14
- __error?: {
15
- type: TError;
16
- };
17
- };
18
- interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
15
+ type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
16
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
19
17
  (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
20
18
  }
21
19
  type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
@@ -1,6 +1,8 @@
1
+ import { PromiseWithError } from '@orpc/shared';
2
+
1
3
  type HTTPPath = `/${string}`;
2
4
  type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
3
- type ClientContext = Record<string, any>;
5
+ type ClientContext = Record<PropertyKey, any>;
4
6
  type FriendlyClientOptions<TClientContext extends ClientContext> = {
5
7
  signal?: AbortSignal;
6
8
  lastEventId?: string | undefined;
@@ -10,12 +12,8 @@ type FriendlyClientOptions<TClientContext extends ClientContext> = {
10
12
  context: TClientContext;
11
13
  });
12
14
  type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
13
- type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
14
- __error?: {
15
- type: TError;
16
- };
17
- };
18
- interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
15
+ type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
16
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
19
17
  (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
20
18
  }
21
19
  type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
@@ -1,5 +1,5 @@
1
- import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.87WXDX8t.js';
2
- import { c as StandardLinkCodec, a as StandardLinkOptions } from './client.BaocqKnn.js';
1
+ import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.C0lT7w02.js';
2
+ import { c as StandardLinkCodec, a as StandardLinkOptions } from './client.grRbC25r.js';
3
3
  import { Segment, Value } from '@orpc/shared';
4
4
  import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
5
 
@@ -1,6 +1,6 @@
1
1
  import { toArray, intercept, isObject, value, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared';
2
2
  import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server';
3
- import { b as isORPCErrorStatus, O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.jKEwIsRd.mjs';
3
+ import { C as COMMON_ORPC_ERROR_DEFS, b as isORPCErrorStatus, O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.jKEwIsRd.mjs';
4
4
 
5
5
  class InvalidEventIteratorRetryResponse extends Error {
6
6
  }
@@ -183,6 +183,9 @@ class StandardRPCJsonSerializer {
183
183
  function toHttpPath(path) {
184
184
  return `/${path.map(encodeURIComponent).join("/")}`;
185
185
  }
186
+ function getMalformedResponseErrorCode(status) {
187
+ return Object.entries(COMMON_ORPC_ERROR_DEFS).find(([, def]) => def.status === status)?.[0] ?? "MALFORMED_ORPC_ERROR_RESPONSE";
188
+ }
186
189
 
187
190
  class StandardRPCLinkCodec {
188
191
  constructor(serializer, options) {
@@ -252,7 +255,7 @@ class StandardRPCLinkCodec {
252
255
  if (ORPCError.isValidJSON(deserialized)) {
253
256
  throw ORPCError.fromJSON(deserialized);
254
257
  }
255
- throw new ORPCError("MALFORMED_ORPC_ERROR_RESPONSE", {
258
+ throw new ORPCError(getMalformedResponseErrorCode(response.status), {
256
259
  status: response.status,
257
260
  data: deserialized
258
261
  });
@@ -330,4 +333,4 @@ class StandardRPCSerializer {
330
333
  }
331
334
  }
332
335
 
333
- export { InvalidEventIteratorRetryResponse as I, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLinkCodec as c, StandardRPCSerializer as d, toHttpPath as t };
336
+ export { InvalidEventIteratorRetryResponse as I, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLinkCodec as c, StandardRPCSerializer as d, getMalformedResponseErrorCode as g, toHttpPath as t };
@@ -1,6 +1,6 @@
1
- import { Interceptor } from '@orpc/shared';
1
+ import { Interceptor, ThrowableError } from '@orpc/shared';
2
2
  import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
- import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.87WXDX8t.mjs';
3
+ import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.C0lT7w02.js';
4
4
 
5
5
  interface StandardLinkCodec<T extends ClientContext> {
6
6
  encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
@@ -20,10 +20,10 @@ interface StandardLinkOptions<T extends ClientContext> {
20
20
  path: readonly string[];
21
21
  input: unknown;
22
22
  options: ClientOptions<T>;
23
- }, unknown, unknown>[];
23
+ }, unknown, ThrowableError>[];
24
24
  clientInterceptors?: Interceptor<{
25
25
  request: StandardRequest;
26
- }, StandardLazyResponse, unknown>[];
26
+ }, StandardLazyResponse, ThrowableError>[];
27
27
  plugins?: StandardLinkPlugin<T>[];
28
28
  }
29
29
  declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
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.904b0c2",
4
+ "version": "0.0.0-next.910f96e",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -39,9 +39,9 @@
39
39
  "dist"
40
40
  ],
41
41
  "dependencies": {
42
- "@orpc/shared": "0.0.0-next.904b0c2",
43
- "@orpc/standard-server-fetch": "0.0.0-next.904b0c2",
44
- "@orpc/standard-server": "0.0.0-next.904b0c2"
42
+ "@orpc/shared": "0.0.0-next.910f96e",
43
+ "@orpc/standard-server": "0.0.0-next.910f96e",
44
+ "@orpc/standard-server-fetch": "0.0.0-next.910f96e"
45
45
  },
46
46
  "devDependencies": {
47
47
  "zod": "^3.24.2"