@orpc/client 1.0.0-beta.3 → 1.0.0-beta.5

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.
@@ -1,7 +1,6 @@
1
- import { C as ClientPlugin, S as StandardLinkOptions } from '../shared/client.aGal-uGY.js';
2
- export { a as CompositeClientPlugin } from '../shared/client.aGal-uGY.js';
3
1
  import { Value } from '@orpc/shared';
4
- import { C as ClientOptionsOut, a as ClientContext } from '../shared/client.CupM8eRP.js';
2
+ import { S as StandardLinkPlugin, a as StandardLinkOptions } from '../shared/client.grRbC25r.js';
3
+ import { b as ClientOptions } from '../shared/client.C0lT7w02.js';
5
4
  import '@orpc/standard-server';
6
5
 
7
6
  interface ClientRetryPluginAttemptOptions {
@@ -25,7 +24,7 @@ interface ClientRetryPluginContext {
25
24
  */
26
25
  retryDelay?: Value<number, [
27
26
  attemptOptions: ClientRetryPluginAttemptOptions,
28
- clientOptions: ClientOptionsOut<ClientRetryPluginContext>,
27
+ clientOptions: ClientOptions<ClientRetryPluginContext>,
29
28
  path: readonly string[],
30
29
  input: unknown
31
30
  ]>;
@@ -36,21 +35,21 @@ interface ClientRetryPluginContext {
36
35
  */
37
36
  shouldRetry?: Value<boolean, [
38
37
  attemptOptions: ClientRetryPluginAttemptOptions,
39
- clientOptions: ClientOptionsOut<ClientRetryPluginContext>,
38
+ clientOptions: ClientOptions<ClientRetryPluginContext>,
40
39
  path: readonly string[],
41
40
  input: unknown
42
41
  ]>;
43
42
  /**
44
43
  * The hook called when retrying, and return the unsubscribe function.
45
44
  */
46
- onRetry?: (options: ClientRetryPluginAttemptOptions, clientOptions: ClientOptionsOut<ClientRetryPluginContext>, path: readonly string[], input: unknown) => void | (() => void);
45
+ onRetry?: (options: ClientRetryPluginAttemptOptions, clientOptions: ClientOptions<ClientRetryPluginContext>, path: readonly string[], input: unknown) => void | (() => void);
47
46
  }
48
47
  declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
49
48
  }
50
49
  interface ClientRetryPluginOptions {
51
50
  default?: ClientRetryPluginContext;
52
51
  }
53
- declare class ClientRetryPlugin<T extends ClientContext & ClientRetryPluginContext> implements ClientPlugin<T> {
52
+ declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
54
53
  private readonly defaultRetry;
55
54
  private readonly defaultRetryDelay;
56
55
  private readonly defaultShouldRetry;
@@ -59,4 +58,4 @@ declare class ClientRetryPlugin<T extends ClientContext & ClientRetryPluginConte
59
58
  init(options: StandardLinkOptions<T>): void;
60
59
  }
61
60
 
62
- export { ClientPlugin, ClientRetryPlugin, type ClientRetryPluginAttemptOptions, type ClientRetryPluginContext, ClientRetryPluginInvalidEventIteratorRetryResponse, type ClientRetryPluginOptions };
61
+ export { ClientRetryPlugin, type ClientRetryPluginAttemptOptions, type ClientRetryPluginContext, ClientRetryPluginInvalidEventIteratorRetryResponse, type ClientRetryPluginOptions };
@@ -1,4 +1,3 @@
1
- export { C as CompositeClientPlugin } from '../shared/client.CvnV7_uV.mjs';
2
1
  import { isAsyncIteratorObject, value } from '@orpc/shared';
3
2
  import { getEventMeta } from '@orpc/standard-server';
4
3
 
@@ -1,27 +1,30 @@
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, C as ClientOptionsOut, b as ClientLink } from './client.CupM8eRP.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
- encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
7
- decode(response: StandardLazyResponse, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<unknown>;
6
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
7
+ decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
8
8
  }
9
9
  interface StandardLinkClient<T extends ClientContext> {
10
- call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
10
+ call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
11
11
  }
12
12
 
13
13
  declare class InvalidEventIteratorRetryResponse extends Error {
14
14
  }
15
+ interface StandardLinkPlugin<T extends ClientContext> {
16
+ init?(options: StandardLinkOptions<T>): void;
17
+ }
15
18
  interface StandardLinkOptions<T extends ClientContext> {
16
19
  interceptors?: Interceptor<{
17
20
  path: readonly string[];
18
21
  input: unknown;
19
- options: ClientOptionsOut<T>;
20
- }, unknown, unknown>[];
22
+ options: ClientOptions<T>;
23
+ }, unknown, ThrowableError>[];
21
24
  clientInterceptors?: Interceptor<{
22
25
  request: StandardRequest;
23
- }, StandardLazyResponse, unknown>[];
24
- plugins?: ClientPlugin<T>[];
26
+ }, StandardLazyResponse, ThrowableError>[];
27
+ plugins?: StandardLinkPlugin<T>[];
25
28
  }
26
29
  declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
27
30
  #private;
@@ -30,16 +33,7 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
30
33
  private readonly interceptors;
31
34
  private readonly clientInterceptors;
32
35
  constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
33
- call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
34
- }
35
-
36
- interface ClientPlugin<T extends ClientContext> {
37
- init?(options: StandardLinkOptions<T>): void;
38
- }
39
- declare class CompositeClientPlugin<T extends ClientContext> implements ClientPlugin<T> {
40
- private readonly plugins;
41
- constructor(plugins?: ClientPlugin<T>[]);
42
- init(options: StandardLinkOptions<T>): void;
36
+ call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
43
37
  }
44
38
 
45
- export { type ClientPlugin as C, InvalidEventIteratorRetryResponse as I, type StandardLinkOptions as S, CompositeClientPlugin as a, type StandardLinkClient as b, type StandardLinkCodec as c, StandardLink as d };
39
+ export { InvalidEventIteratorRetryResponse as I, type StandardLinkPlugin as S, type StandardLinkOptions as a, StandardLink as b, type StandardLinkCodec as c, type StandardLinkClient as d };
@@ -0,0 +1,103 @@
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
+ import { Segment, Value } from '@orpc/shared';
4
+ import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
+
6
+ declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
7
+ readonly BIGINT: 0;
8
+ readonly DATE: 1;
9
+ readonly NAN: 2;
10
+ readonly UNDEFINED: 3;
11
+ readonly URL: 4;
12
+ readonly REGEXP: 5;
13
+ readonly SET: 6;
14
+ readonly MAP: 7;
15
+ };
16
+ type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]];
17
+ type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]];
18
+ interface StandardRPCCustomJsonSerializer {
19
+ type: number;
20
+ condition(data: unknown): boolean;
21
+ serialize(data: any): unknown;
22
+ deserialize(serialized: any): unknown;
23
+ }
24
+ interface StandardRPCJsonSerializerOptions {
25
+ customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[];
26
+ }
27
+ declare class StandardRPCJsonSerializer {
28
+ private readonly customSerializers;
29
+ constructor(options?: StandardRPCJsonSerializerOptions);
30
+ serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized;
31
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown;
32
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown;
33
+ }
34
+
35
+ declare class StandardRPCSerializer {
36
+ #private;
37
+ private readonly jsonSerializer;
38
+ constructor(jsonSerializer: StandardRPCJsonSerializer);
39
+ serialize(data: unknown): object;
40
+ deserialize(data: unknown): unknown;
41
+ }
42
+
43
+ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
44
+ /**
45
+ * Base url for all requests.
46
+ */
47
+ url: Value<string | URL, [
48
+ options: ClientOptions<T>,
49
+ path: readonly string[],
50
+ input: unknown
51
+ ]>;
52
+ /**
53
+ * The maximum length of the URL.
54
+ *
55
+ * @default 2083
56
+ */
57
+ maxUrlLength?: Value<number, [
58
+ options: ClientOptions<T>,
59
+ path: readonly string[],
60
+ input: unknown
61
+ ]>;
62
+ /**
63
+ * The method used to make the request.
64
+ *
65
+ * @default 'POST'
66
+ */
67
+ method?: Value<HTTPMethod, [
68
+ options: ClientOptions<T>,
69
+ path: readonly string[],
70
+ input: unknown
71
+ ]>;
72
+ /**
73
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
74
+ * GET is not allowed, it's very dangerous.
75
+ *
76
+ * @default 'POST'
77
+ */
78
+ fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
79
+ /**
80
+ * Inject headers to the request.
81
+ */
82
+ headers?: Value<StandardHeaders, [
83
+ options: ClientOptions<T>,
84
+ path: readonly string[],
85
+ input: unknown
86
+ ]>;
87
+ }
88
+ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
89
+ private readonly serializer;
90
+ private readonly baseUrl;
91
+ private readonly maxUrlLength;
92
+ private readonly fallbackMethod;
93
+ private readonly expectedMethod;
94
+ private readonly headers;
95
+ constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
96
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
97
+ decode(response: StandardLazyResponse): Promise<unknown>;
98
+ }
99
+
100
+ interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
101
+ }
102
+
103
+ export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, type StandardRPCJsonSerializedMetaItem as a, type StandardRPCJsonSerialized as b, type StandardRPCCustomJsonSerializer as c, type StandardRPCJsonSerializerOptions as d, StandardRPCJsonSerializer as e, type StandardRPCLinkOptions as f, type StandardRPCLinkCodecOptions as g, StandardRPCLinkCodec as h, StandardRPCSerializer as i };
@@ -0,0 +1,30 @@
1
+ import { PromiseWithError } from '@orpc/shared';
2
+
3
+ type HTTPPath = `/${string}`;
4
+ type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
5
+ type ClientContext = Record<PropertyKey, any>;
6
+ type FriendlyClientOptions<TClientContext extends ClientContext> = {
7
+ signal?: AbortSignal;
8
+ lastEventId?: string | undefined;
9
+ } & (Record<never, never> extends TClientContext ? {
10
+ context?: TClientContext;
11
+ } : {
12
+ context: TClientContext;
13
+ });
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>];
15
+ type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
16
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
17
+ (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
18
+ }
19
+ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
20
+ [k: string]: NestedClient<TClientContext>;
21
+ };
22
+ type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
23
+ type ClientOptions<TClientContext extends ClientContext> = FriendlyClientOptions<TClientContext> & {
24
+ context: TClientContext;
25
+ };
26
+ interface ClientLink<TClientContext extends ClientContext> {
27
+ call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
28
+ }
29
+
30
+ export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientContext as a, ClientOptions as b, ClientPromiseResult as c, HTTPMethod as d, ClientRest as e, Client as f };
@@ -0,0 +1,30 @@
1
+ import { PromiseWithError } from '@orpc/shared';
2
+
3
+ type HTTPPath = `/${string}`;
4
+ type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
5
+ type ClientContext = Record<PropertyKey, any>;
6
+ type FriendlyClientOptions<TClientContext extends ClientContext> = {
7
+ signal?: AbortSignal;
8
+ lastEventId?: string | undefined;
9
+ } & (Record<never, never> extends TClientContext ? {
10
+ context?: TClientContext;
11
+ } : {
12
+ context: TClientContext;
13
+ });
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>];
15
+ type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
16
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
17
+ (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
18
+ }
19
+ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
20
+ [k: string]: NestedClient<TClientContext>;
21
+ };
22
+ type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
23
+ type ClientOptions<TClientContext extends ClientContext> = FriendlyClientOptions<TClientContext> & {
24
+ context: TClientContext;
25
+ };
26
+ interface ClientLink<TClientContext extends ClientContext> {
27
+ call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
28
+ }
29
+
30
+ export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientContext as a, ClientOptions as b, ClientPromiseResult as c, HTTPMethod as d, ClientRest as e, Client as f };
@@ -0,0 +1,103 @@
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
+ import { Segment, Value } from '@orpc/shared';
4
+ import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
+
6
+ declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
7
+ readonly BIGINT: 0;
8
+ readonly DATE: 1;
9
+ readonly NAN: 2;
10
+ readonly UNDEFINED: 3;
11
+ readonly URL: 4;
12
+ readonly REGEXP: 5;
13
+ readonly SET: 6;
14
+ readonly MAP: 7;
15
+ };
16
+ type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]];
17
+ type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]];
18
+ interface StandardRPCCustomJsonSerializer {
19
+ type: number;
20
+ condition(data: unknown): boolean;
21
+ serialize(data: any): unknown;
22
+ deserialize(serialized: any): unknown;
23
+ }
24
+ interface StandardRPCJsonSerializerOptions {
25
+ customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[];
26
+ }
27
+ declare class StandardRPCJsonSerializer {
28
+ private readonly customSerializers;
29
+ constructor(options?: StandardRPCJsonSerializerOptions);
30
+ serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized;
31
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown;
32
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown;
33
+ }
34
+
35
+ declare class StandardRPCSerializer {
36
+ #private;
37
+ private readonly jsonSerializer;
38
+ constructor(jsonSerializer: StandardRPCJsonSerializer);
39
+ serialize(data: unknown): object;
40
+ deserialize(data: unknown): unknown;
41
+ }
42
+
43
+ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
44
+ /**
45
+ * Base url for all requests.
46
+ */
47
+ url: Value<string | URL, [
48
+ options: ClientOptions<T>,
49
+ path: readonly string[],
50
+ input: unknown
51
+ ]>;
52
+ /**
53
+ * The maximum length of the URL.
54
+ *
55
+ * @default 2083
56
+ */
57
+ maxUrlLength?: Value<number, [
58
+ options: ClientOptions<T>,
59
+ path: readonly string[],
60
+ input: unknown
61
+ ]>;
62
+ /**
63
+ * The method used to make the request.
64
+ *
65
+ * @default 'POST'
66
+ */
67
+ method?: Value<HTTPMethod, [
68
+ options: ClientOptions<T>,
69
+ path: readonly string[],
70
+ input: unknown
71
+ ]>;
72
+ /**
73
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
74
+ * GET is not allowed, it's very dangerous.
75
+ *
76
+ * @default 'POST'
77
+ */
78
+ fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
79
+ /**
80
+ * Inject headers to the request.
81
+ */
82
+ headers?: Value<StandardHeaders, [
83
+ options: ClientOptions<T>,
84
+ path: readonly string[],
85
+ input: unknown
86
+ ]>;
87
+ }
88
+ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
89
+ private readonly serializer;
90
+ private readonly baseUrl;
91
+ private readonly maxUrlLength;
92
+ private readonly fallbackMethod;
93
+ private readonly expectedMethod;
94
+ private readonly headers;
95
+ constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
96
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
97
+ decode(response: StandardLazyResponse): Promise<unknown>;
98
+ }
99
+
100
+ interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
101
+ }
102
+
103
+ export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, type StandardRPCJsonSerializedMetaItem as a, type StandardRPCJsonSerialized as b, type StandardRPCCustomJsonSerializer as c, type StandardRPCJsonSerializerOptions as d, StandardRPCJsonSerializer as e, type StandardRPCLinkOptions as f, type StandardRPCLinkCodecOptions as g, StandardRPCLinkCodec as h, StandardRPCSerializer as i };
@@ -1,7 +1,6 @@
1
- import { intercept, isObject, value, trim, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared';
2
- import { C as CompositeClientPlugin } from './client.CvnV7_uV.mjs';
3
- import { ErrorEvent } from '@orpc/standard-server';
4
- import { O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.BacCdg3F.mjs';
1
+ import { toArray, intercept, isObject, value, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared';
2
+ import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server';
3
+ import { C as COMMON_ORPC_ERROR_DEFS, b as isORPCErrorStatus, O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.jKEwIsRd.mjs';
5
4
 
6
5
  class InvalidEventIteratorRetryResponse extends Error {
7
6
  }
@@ -9,10 +8,11 @@ class StandardLink {
9
8
  constructor(codec, sender, options = {}) {
10
9
  this.codec = codec;
11
10
  this.sender = sender;
12
- const plugin = new CompositeClientPlugin(options.plugins);
13
- plugin.init(options);
14
- this.interceptors = options.interceptors ?? [];
15
- this.clientInterceptors = options.clientInterceptors ?? [];
11
+ for (const plugin of toArray(options.plugins)) {
12
+ plugin.init?.(options);
13
+ }
14
+ this.interceptors = toArray(options.interceptors);
15
+ this.clientInterceptors = toArray(options.clientInterceptors);
16
16
  }
17
17
  interceptors;
18
18
  clientInterceptors;
@@ -180,6 +180,13 @@ class StandardRPCJsonSerializer {
180
180
  }
181
181
  }
182
182
 
183
+ function toHttpPath(path) {
184
+ return `/${path.map(encodeURIComponent).join("/")}`;
185
+ }
186
+ function getMalformedResponseErrorCode(status) {
187
+ return Object.entries(COMMON_ORPC_ERROR_DEFS).find(([, def]) => def.status === status)?.[0] ?? "MALFORMED_ORPC_ERROR_RESPONSE";
188
+ }
189
+
183
190
  class StandardRPCLinkCodec {
184
191
  constructor(serializer, options) {
185
192
  this.serializer = serializer;
@@ -196,17 +203,11 @@ class StandardRPCLinkCodec {
196
203
  headers;
197
204
  async encode(path, input, options) {
198
205
  const expectedMethod = await value(this.expectedMethod, options, path, input);
199
- const headers = { ...await value(this.headers, options, path, input) };
206
+ let headers = await value(this.headers, options, path, input);
200
207
  const baseUrl = await value(this.baseUrl, options, path, input);
201
- const url = new URL(`${trim(baseUrl.toString(), "/")}/${path.map(encodeURIComponent).join("/")}`);
208
+ const url = new URL(`${baseUrl.toString().replace(/\/$/, "")}${toHttpPath(path)}`);
202
209
  if (options.lastEventId !== void 0) {
203
- if (Array.isArray(headers["last-event-id"])) {
204
- headers["last-event-id"] = [...headers["last-event-id"], options.lastEventId];
205
- } else if (headers["last-event-id"] !== void 0) {
206
- headers["last-event-id"] = [headers["last-event-id"], options.lastEventId];
207
- } else {
208
- headers["last-event-id"] = options.lastEventId;
209
- }
210
+ headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
210
211
  }
211
212
  const serialized = this.serializer.serialize(input);
212
213
  if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
@@ -232,7 +233,7 @@ class StandardRPCLinkCodec {
232
233
  };
233
234
  }
234
235
  async decode(response) {
235
- const isOk = response.status >= 200 && response.status < 300;
236
+ const isOk = !isORPCErrorStatus(response.status);
236
237
  const deserialized = await (async () => {
237
238
  let isBodyOk = false;
238
239
  try {
@@ -254,8 +255,9 @@ class StandardRPCLinkCodec {
254
255
  if (ORPCError.isValidJSON(deserialized)) {
255
256
  throw ORPCError.fromJSON(deserialized);
256
257
  }
257
- throw new Error("Invalid RPC error response format.", {
258
- cause: deserialized
258
+ throw new ORPCError(getMalformedResponseErrorCode(response.status), {
259
+ status: response.status,
260
+ data: deserialized
259
261
  });
260
262
  }
261
263
  return deserialized;
@@ -331,4 +333,4 @@ class StandardRPCSerializer {
331
333
  }
332
334
  }
333
335
 
334
- 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 };
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,27 +1,30 @@
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, C as ClientOptionsOut, b as ClientLink } from './client.CupM8eRP.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
- encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
7
- decode(response: StandardLazyResponse, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<unknown>;
6
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
7
+ decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
8
8
  }
9
9
  interface StandardLinkClient<T extends ClientContext> {
10
- call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
10
+ call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
11
11
  }
12
12
 
13
13
  declare class InvalidEventIteratorRetryResponse extends Error {
14
14
  }
15
+ interface StandardLinkPlugin<T extends ClientContext> {
16
+ init?(options: StandardLinkOptions<T>): void;
17
+ }
15
18
  interface StandardLinkOptions<T extends ClientContext> {
16
19
  interceptors?: Interceptor<{
17
20
  path: readonly string[];
18
21
  input: unknown;
19
- options: ClientOptionsOut<T>;
20
- }, unknown, unknown>[];
22
+ options: ClientOptions<T>;
23
+ }, unknown, ThrowableError>[];
21
24
  clientInterceptors?: Interceptor<{
22
25
  request: StandardRequest;
23
- }, StandardLazyResponse, unknown>[];
24
- plugins?: ClientPlugin<T>[];
26
+ }, StandardLazyResponse, ThrowableError>[];
27
+ plugins?: StandardLinkPlugin<T>[];
25
28
  }
26
29
  declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
27
30
  #private;
@@ -30,16 +33,7 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
30
33
  private readonly interceptors;
31
34
  private readonly clientInterceptors;
32
35
  constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
33
- call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
34
- }
35
-
36
- interface ClientPlugin<T extends ClientContext> {
37
- init?(options: StandardLinkOptions<T>): void;
38
- }
39
- declare class CompositeClientPlugin<T extends ClientContext> implements ClientPlugin<T> {
40
- private readonly plugins;
41
- constructor(plugins?: ClientPlugin<T>[]);
42
- init(options: StandardLinkOptions<T>): void;
36
+ call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
43
37
  }
44
38
 
45
- export { type ClientPlugin as C, InvalidEventIteratorRetryResponse as I, type StandardLinkOptions as S, CompositeClientPlugin as a, type StandardLinkClient as b, type StandardLinkCodec as c, StandardLink as d };
39
+ export { InvalidEventIteratorRetryResponse as I, type StandardLinkPlugin as S, type StandardLinkOptions as a, StandardLink as b, type StandardLinkCodec as c, type StandardLinkClient as d };
@@ -91,8 +91,8 @@ class ORPCError extends Error {
91
91
  status;
92
92
  data;
93
93
  constructor(code, ...[options]) {
94
- if (options?.status && (options.status < 400 || options.status >= 600)) {
95
- throw new Error("[ORPCError] The error status code must be in the 400-599 range.");
94
+ if (options?.status && !isORPCErrorStatus(options.status)) {
95
+ throw new Error("[ORPCError] Invalid error status code.");
96
96
  }
97
97
  const message = fallbackORPCErrorMessage(code, options?.message);
98
98
  super(message, options);
@@ -136,6 +136,9 @@ function toORPCError(error) {
136
136
  cause: error
137
137
  });
138
138
  }
139
+ function isORPCErrorStatus(status) {
140
+ return status < 200 || status >= 400;
141
+ }
139
142
 
140
143
  function mapEventIterator(iterator, maps) {
141
144
  return async function* () {
@@ -169,4 +172,4 @@ function mapEventIterator(iterator, maps) {
169
172
  }();
170
173
  }
171
174
 
172
- export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };
175
+ export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, isORPCErrorStatus as b, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/client",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.3",
4
+ "version": "1.0.0-beta.5",
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": "1.0.0-beta.3",
43
- "@orpc/standard-server": "1.0.0-beta.3",
44
- "@orpc/standard-server-fetch": "1.0.0-beta.3"
42
+ "@orpc/shared": "1.0.0-beta.5",
43
+ "@orpc/standard-server-fetch": "1.0.0-beta.5",
44
+ "@orpc/standard-server": "1.0.0-beta.5"
45
45
  },
46
46
  "devDependencies": {
47
47
  "zod": "^3.24.2"
@@ -1,30 +0,0 @@
1
- type ClientContext = Record<string, any>;
2
- type ClientOptions<TClientContext extends ClientContext> = {
3
- signal?: AbortSignal;
4
- lastEventId?: string | undefined;
5
- } & (Record<never, never> extends TClientContext ? {
6
- context?: TClientContext;
7
- } : {
8
- context: TClientContext;
9
- });
10
- type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options: ClientOptions<TClientContext>];
11
- type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
12
- __error?: {
13
- type: TError;
14
- };
15
- };
16
- interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
17
- (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
18
- }
19
- type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
20
- [k: string]: NestedClient<TClientContext>;
21
- };
22
- type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
23
- type ClientOptionsOut<TClientContext extends ClientContext> = ClientOptions<TClientContext> & {
24
- context: TClientContext;
25
- };
26
- interface ClientLink<TClientContext extends ClientContext> {
27
- call: (path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>) => Promise<unknown>;
28
- }
29
-
30
- export type { ClientOptionsOut as C, InferClientContext as I, NestedClient as N, ClientContext as a, ClientLink as b, ClientPromiseResult as c, ClientOptions as d, ClientRest as e, Client as f };
@@ -1,30 +0,0 @@
1
- type ClientContext = Record<string, any>;
2
- type ClientOptions<TClientContext extends ClientContext> = {
3
- signal?: AbortSignal;
4
- lastEventId?: string | undefined;
5
- } & (Record<never, never> extends TClientContext ? {
6
- context?: TClientContext;
7
- } : {
8
- context: TClientContext;
9
- });
10
- type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options: ClientOptions<TClientContext>];
11
- type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
12
- __error?: {
13
- type: TError;
14
- };
15
- };
16
- interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
17
- (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
18
- }
19
- type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
20
- [k: string]: NestedClient<TClientContext>;
21
- };
22
- type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
23
- type ClientOptionsOut<TClientContext extends ClientContext> = ClientOptions<TClientContext> & {
24
- context: TClientContext;
25
- };
26
- interface ClientLink<TClientContext extends ClientContext> {
27
- call: (path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>) => Promise<unknown>;
28
- }
29
-
30
- export type { ClientOptionsOut as C, InferClientContext as I, NestedClient as N, ClientContext as a, ClientLink as b, ClientPromiseResult as c, ClientOptions as d, ClientRest as e, Client as f };